@pixelzx/genesis 2026.6.4 → 2026.6.5
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/CHANGELOG.md +18 -0
- package/dist/.buildstamp +1 -1
- package/dist/abort-CcNxEsSq.js +201 -0
- package/dist/abort.runtime-DZJDSf0d.js +2 -0
- package/dist/abort.runtime.js +1 -1
- package/dist/accounts-B7M6y8l8.js +107 -0
- package/dist/accounts-DddcYo7u.js +2 -0
- package/dist/accounts-v0Cqfnse.js +104 -0
- package/dist/acp-cli-D_2_Nim8.js +2193 -0
- package/dist/acp-spawn-BZPupfsZ.js +2 -0
- package/dist/acp-spawn-CWfIrbK7.js +1093 -0
- package/dist/acp-stateful-target-driver-DpCTjH5T.js +89 -0
- package/dist/action-agents-fjIM4rpc.js +67 -0
- package/dist/action-focus-cx1pm1ym.js +132 -0
- package/dist/action-help-DtyAnULB.js +7 -0
- package/dist/action-info-DF30-xZl.js +101 -0
- package/dist/action-kill-rsSdXzvX.js +33 -0
- package/dist/action-list-4VN835m2.js +21 -0
- package/dist/action-log-L032mq5B.js +30 -0
- package/dist/action-send-Dm62UP-n.js +39 -0
- package/dist/action-spawn-BuZHKlpL.js +47 -0
- package/dist/action-unfocus-CTIWf8WX.js +29 -0
- package/dist/actions.runtime-0ezEcm7K.js +18 -0
- package/dist/actions.runtime-DKsCTTnH.js +5 -0
- package/dist/actions.runtime.js +1 -1
- package/dist/agent-BTOBOCIw.js +2 -0
- package/dist/agent-command-C-_EFUUu.js +874 -0
- package/dist/agent-harness-runtime-Bye6j3EL.js +144 -0
- package/dist/agent-runner-utils-CX2vCMkx.js +239 -0
- package/dist/agent-runner.runtime-BBqrjZv4.js +3455 -0
- package/dist/agent-runner.runtime.js +1 -1
- package/dist/agent-runtime-D1LIGcNj.js +18 -0
- package/dist/agents-CME2O1l9.js +5 -0
- package/dist/agents-DsDQvAPy.js +954 -0
- package/dist/aliases-C807OidC.js +2 -0
- package/dist/aliases-jq1ap6Dz.js +96 -0
- package/dist/api-BbxKoRkD.js +3 -0
- package/dist/api-CwJPCW9U.js +139 -0
- package/dist/api-N5Kaaq64.js +5 -0
- package/dist/approval-gateway-resolver-DIPFgTnx.js +29 -0
- package/dist/approval-gateway-runtime-i0yziXk2.js +2 -0
- package/dist/approval-handler-runtime-Cdm-10f9.js +439 -0
- package/dist/approval-native-runtime-BRjeBoqL.js +729 -0
- package/dist/attempt-execution.runtime-NFTF7Cbt.js +509 -0
- package/dist/attempt-execution.runtime.js +1 -1
- package/dist/attempt.prompt-helpers-DuBXv46v.js +221 -0
- package/dist/attempt.tool-run-context-Qf-tbC-C.js +933 -0
- package/dist/audit-DsDfRhB8.js +939 -0
- package/dist/audit.runtime-ComjcUGJ.js +7 -0
- package/dist/audit.runtime.js +1 -1
- package/dist/auth-BT_gqC-D.js +2 -0
- package/dist/auth-DeUz_8w8.js +383 -0
- package/dist/auth-order-DM7UkPDa.js +96 -0
- package/dist/auth-order-yS8hXrXh.js +2 -0
- package/dist/bash-tools-D0M9gBDu.js +3 -0
- package/dist/bash-tools-tnj1gSbO.js +2824 -0
- package/dist/binding-routing-C7atXiTD.js +85 -0
- package/dist/binding-targets-CCv7agx9.js +121 -0
- package/dist/bridge-server-C5O9rTJg.js +113 -0
- package/dist/browser-control-auth-GGN_kbqE.js +2 -0
- package/dist/browser-node-runtime-B-uTSVqP.js +12 -0
- package/dist/browser-profiles-Dex2eaLH.js +2 -0
- package/dist/browser-runtime-BPocB6yO.js +387 -0
- package/dist/browser-setup-tools-gHfYeDWA.js +13 -0
- package/dist/build-BqG7RkBz.js +550 -0
- package/dist/build-info.json +3 -3
- package/dist/bundled/boot-md/handler.js +2 -2
- package/dist/bundled/session-memory/handler.js +1 -1
- package/dist/call-BI4JvjcR.js +3 -0
- package/dist/call-wY43fzOF.js +331 -0
- package/dist/call.runtime-Dh61oVeL.js +2 -0
- package/dist/call.runtime.js +1 -1
- package/dist/capability-cli-BHz-2Stx.js +1401 -0
- package/dist/catchup-Be7tHJwK.js +300 -0
- package/dist/channel-B-6VmF4-.js +840 -0
- package/dist/channel-BCJccV-O.js +226 -0
- package/dist/channel-BDZqLbod.js +1100 -0
- package/dist/channel-BQDNgTea.js +1174 -0
- package/dist/channel-BwjThGwK.js +453 -0
- package/dist/channel-CPoThmda.js +595 -0
- package/dist/channel-CUT8NJ-B.js +350 -0
- package/dist/channel-C_Y7lv8v.js +491 -0
- package/dist/channel-Ck7-C-lB.js +297 -0
- package/dist/channel-DOpVjq4i.js +1802 -0
- package/dist/channel-core-QV9-eAtb.js +5 -0
- package/dist/channel-inbound-D_tebgdx.js +31 -0
- package/dist/channel-plugin-runtime-DXcBwNNM.js +771 -0
- package/dist/channel-runtime-D4ci0o4V.js +425 -0
- package/dist/channel-sAdF_zH-.js +1320 -0
- package/dist/channel.runtime-1swLIpNV.js +89 -0
- package/dist/channel.runtime-B9hljdNF.js +4 -0
- package/dist/channel.runtime-CSbR2pni.js +430 -0
- package/dist/channel.runtime-CdpqhnLO.js +2364 -0
- package/dist/channel.runtime-DOx6WROg.js +40130 -0
- package/dist/channel.runtime-H5Kb2LbC.js +109 -0
- package/dist/channel.runtime-V7boBc_e.js +576 -0
- package/dist/channel.runtime.js +1 -1
- package/dist/channel.setup-BXyeNJ2_.js +10 -0
- package/dist/channels-KU7bwUUs.js +733 -0
- package/dist/channels-cli-CTX6_5z3.js +268 -0
- package/dist/chat-C_i6Wp50.js +2830 -0
- package/dist/clawbot-cli-CLGPtbt-.js +9 -0
- package/dist/cli/daemon-cli.js +3 -3
- package/dist/cli-BhwHu1dK.js +72 -0
- package/dist/cli-CFsq8f2H.js +2 -0
- package/dist/cli-CNVlwurq.js +219 -0
- package/dist/cli-DLP8hKbi.js +2 -0
- package/dist/cli-runner-BbNBHV6v.js +286 -0
- package/dist/cli-runner.runtime-CfPaauuM.js +4 -0
- package/dist/cli-runner.runtime-MxBlCOO2.js +3 -0
- package/dist/cli-runner.runtime.js +1 -1
- package/dist/cli-startup-metadata.json +2 -2
- package/dist/cli.runtime-3cD-pSyn.js +1261 -0
- package/dist/cli.runtime.js +1 -1
- package/dist/client-Bl0d_7ak.js +138 -0
- package/dist/client-ClJyHgmq.js +713 -0
- package/dist/command-auth-DO32coey.js +76 -0
- package/dist/command-config-resolution-CAsa4fGg.js +2 -0
- package/dist/command-config-resolution-D6YcwuRh.js +23 -0
- package/dist/command-config-resolution.runtime-CSHDu35A.js +2 -0
- package/dist/command-config-resolution.runtime.js +1 -1
- package/dist/command-registry-BJEQrMqR.js +4 -0
- package/dist/command-registry-DI9i95nj.js +9 -0
- package/dist/command-registry-core-BpF1mggD.js +106 -0
- package/dist/command-secret-gateway-DDNHxysD.js +528 -0
- package/dist/command-status.runtime-DqYUCcEA.js +87 -0
- package/dist/command-status.runtime.js +1 -1
- package/dist/commands-acp-C_zCJPvL.js +77 -0
- package/dist/commands-compact.runtime-B6e3kwMS.js +10 -0
- package/dist/commands-compact.runtime.js +1 -1
- package/dist/commands-handlers.runtime-B0gTkAC0.js +4599 -0
- package/dist/commands-handlers.runtime.js +1 -1
- package/dist/commands-status-BgZ64sA8.js +16 -0
- package/dist/commands-status.runtime-JI89gIEU.js +3 -0
- package/dist/commands-status.runtime.js +1 -1
- package/dist/commands-subagents-control.runtime-B0hdcBxr.js +2 -0
- package/dist/commands-subagents-control.runtime-DUeSQ5j4.js +3 -0
- package/dist/commands-subagents-control.runtime.js +1 -1
- package/dist/commands-system-prompt-B7moUaCI.js +158 -0
- package/dist/commands-system-prompt-DTUkp9TH.js +2 -0
- package/dist/commands.runtime-BjCVVqol.js +167 -0
- package/dist/commands.runtime.js +1 -1
- package/dist/compact-BNJH56SX.js +1118 -0
- package/dist/compact.runtime-CYI8Yi9d.js +12 -0
- package/dist/compact.runtime.js +1 -1
- package/dist/completion-cli-Bb1Tk-vM.js +328 -0
- package/dist/config-DxkleHmo.js +252 -0
- package/dist/config-cli-CtaRB_f8.js +1078 -0
- package/dist/configure-Bp8WFryM.js +1252 -0
- package/dist/configure-DQ_X5zyT.js +2 -0
- package/dist/connect-options-BkWD0Wvv.js +699 -0
- package/dist/control-auth-Iqyldslx.js +125 -0
- package/dist/control-service-xIhkqyZE.js +156 -0
- package/dist/control-ui/assets/agents-Dh_TAFxm.js +1052 -0
- package/dist/control-ui/assets/canvas-BBkF0c_Z.js +269 -0
- package/dist/control-ui/assets/channel-config-extras-CNdHdere.js +2 -0
- package/dist/control-ui/assets/channels-DxBxgFLI.js +463 -0
- package/dist/control-ui/assets/cron-DI85RTUE.js +933 -0
- package/dist/control-ui/assets/de-ona0Q7Bc.js +2 -0
- package/dist/control-ui/assets/debug-DnDu2pj9.js +94 -0
- package/dist/control-ui/assets/es-Dn-oNRUH.js +2 -0
- package/dist/control-ui/assets/format-BvrOTETl.js +9 -0
- package/dist/control-ui/assets/fr-DXJ2RnNl.js +2 -0
- package/dist/control-ui/assets/i18n-BiXTtoQW.js +3 -0
- package/dist/control-ui/assets/id-BWsRmAR3.js +2 -0
- package/dist/control-ui/assets/index-YAwpI05T.js +6366 -0
- package/dist/control-ui/assets/instances-CRNiJVGJ.js +57 -0
- package/dist/control-ui/assets/ja-JP-BUkQN13S.js +2 -0
- package/dist/control-ui/assets/ko-Q_K13wyH.js +2 -0
- package/dist/control-ui/assets/logs-CzRlG5kP.js +74 -0
- package/dist/control-ui/assets/mcp-CAYQSRMs.js +373 -0
- package/dist/control-ui/assets/nodes-92SUclba.js +618 -0
- package/dist/control-ui/assets/pl-WlhlBCqd.js +2 -0
- package/dist/control-ui/assets/plugins-TwSBb6p5.js +273 -0
- package/dist/control-ui/assets/pt-BR-CVchspYo.js +2 -0
- package/dist/control-ui/assets/sessions-CHmx5D2H.js +306 -0
- package/dist/control-ui/assets/skills-C-34EOwN.js +323 -0
- package/dist/control-ui/assets/skills-shared-BbxW-wNm.js +11 -0
- package/dist/control-ui/assets/th-C4FUN3Mq.js +2 -0
- package/dist/control-ui/assets/tr-CoySBXqw.js +2 -0
- package/dist/control-ui/assets/uk-C-mkZs9j.js +2 -0
- package/dist/control-ui/assets/wallet-DjjoYuDY.js +285 -0
- package/dist/control-ui/assets/zh-CN-B7HXiLrY.js +2 -0
- package/dist/control-ui/assets/zh-TW-CKLRstBM.js +2 -0
- package/dist/control-ui/index.html +3 -3
- package/dist/conversation-id-BZtOqHIz.js +38 -0
- package/dist/conversation-id-D1Q9qPFH.js +235 -0
- package/dist/conversation-runtime-B1QZ-DEM.js +31 -0
- package/dist/core-BdVAy0Wv.js +275 -0
- package/dist/cron-cli-BWM2kRKU.js +713 -0
- package/dist/daemon-cli-MRl5nyuF.js +12 -0
- package/dist/dashboard-BkdlJrnf.js +2 -0
- package/dist/dashboard-C9m86rHv.js +81 -0
- package/dist/delegate-BjUvKQlo.js +64 -0
- package/dist/detached-task-runtime-BAEzkNB8.js +73 -0
- package/dist/devices-cli-B1n6tl9f.js +498 -0
- package/dist/diagnostics-DZxWkW3i.js +154 -0
- package/dist/direct-dm-qw-uk31C.js +64 -0
- package/dist/dispatch-D0xiJ6Up.js +1131 -0
- package/dist/dispatch-acp-DVN58m9G.js +981 -0
- package/dist/dispatch-acp-manager.runtime-C8t1i5Wt.js +3 -0
- package/dist/dispatch-acp-manager.runtime.js +1 -1
- package/dist/dispatch-acp.runtime-FR0DUPpn.js +19 -0
- package/dist/dispatch-acp.runtime.js +1 -1
- package/dist/doctor-device-pairing-DIbiBPlL.js +307 -0
- package/dist/doctor-gateway-daemon-flow-BFjRlXvA.js +250 -0
- package/dist/doctor-gateway-health-uZrukX3c.js +63 -0
- package/dist/doctor-health-DKpg1bxM.js +59 -0
- package/dist/doctor-health-contributions-BoXX8ubw.js +493 -0
- package/dist/doctor-prompter-CLf5Uf10.js +56 -0
- package/dist/doctor-workspace-status-Cw61BbGy.js +75 -0
- package/dist/dreaming-Bk8dVfGi.js +1574 -0
- package/dist/dreaming-narrative-DGSQa-0N.js +595 -0
- package/dist/embedded-gateway-stub.runtime-sokWrs6B.js +9 -0
- package/dist/embedded-gateway-stub.runtime.js +1 -1
- package/dist/entry.js +2 -2
- package/dist/exec-approvals-cli-CnNETs_u.js +498 -0
- package/dist/extensionAPI.js +1 -1
- package/dist/extensions/active-memory/index.js +1 -1
- package/dist/extensions/bluebubbles/api.js +3 -3
- package/dist/extensions/bluebubbles/channel-plugin-api.js +1 -1
- package/dist/extensions/browser/browser-bridge.js +1 -1
- package/dist/extensions/browser/browser-config.js +4 -4
- package/dist/extensions/browser/browser-control-auth.js +2 -2
- package/dist/extensions/browser/browser-doctor.js +2 -2
- package/dist/extensions/browser/browser-maintenance.js +2 -2
- package/dist/extensions/browser/browser-profiles.js +2 -2
- package/dist/extensions/browser/browser-runtime-api.js +10 -10
- package/dist/extensions/browser/index.js +1 -1
- package/dist/extensions/browser/plugin-registration.js +1 -1
- package/dist/extensions/browser/register.runtime.js +3 -3
- package/dist/extensions/browser/runtime-api.js +11 -11
- package/dist/extensions/browser/test-support.js +1 -1
- package/dist/extensions/device-pair/api.js +1 -1
- package/dist/extensions/device-pair/index.js +3 -3
- package/dist/extensions/device-pair/notify.js +1 -1
- package/dist/extensions/device-pair/pair-command-approve.js +1 -1
- package/dist/extensions/google-meet/index.js +2 -2
- package/dist/extensions/imessage/api.js +3 -3
- package/dist/extensions/imessage/channel-plugin-api.js +1 -1
- package/dist/extensions/imessage/runtime-api.js +3 -3
- package/dist/extensions/irc/api.js +2 -2
- package/dist/extensions/irc/channel-plugin-api.js +1 -1
- package/dist/extensions/line/api.js +2 -2
- package/dist/extensions/line/channel-plugin-api.js +1 -1
- package/dist/extensions/line/contract-api.js +1 -1
- package/dist/extensions/line/runtime-api.js +4 -4
- package/dist/extensions/line/setup-api.js +1 -1
- package/dist/extensions/llm-task/index.js +2 -2
- package/dist/extensions/lobster/index.js +3 -3
- package/dist/extensions/lobster/runtime-api.js +1 -1
- package/dist/extensions/mattermost/api.js +1 -1
- package/dist/extensions/mattermost/channel-plugin-api.js +1 -1
- package/dist/extensions/mattermost/channel-plugin-runtime.js +1 -1
- package/dist/extensions/mattermost/policy-api.js +1 -1
- package/dist/extensions/mattermost/runtime-api.js +4 -4
- package/dist/extensions/mattermost/slash-route-api.js +1 -1
- package/dist/extensions/memory-core/api.js +1 -1
- package/dist/extensions/memory-core/cli-metadata.js +2 -2
- package/dist/extensions/memory-core/index.js +3 -3
- package/dist/extensions/memory-lancedb/cli-metadata.js +1 -1
- package/dist/extensions/msteams/api.js +1 -1
- package/dist/extensions/msteams/channel-plugin-api.js +1 -1
- package/dist/extensions/msteams/runtime-api.js +3 -3
- package/dist/extensions/msteams/test-api.js +1 -1
- package/dist/extensions/nextcloud-talk/api.js +1 -1
- package/dist/extensions/nextcloud-talk/channel-plugin-api.js +1 -1
- package/dist/extensions/nextcloud-talk/runtime-api.js +2 -2
- package/dist/extensions/openshell/index.js +2 -2
- package/dist/extensions/signal/api.js +6 -6
- package/dist/extensions/signal/channel-plugin-api.js +1 -1
- package/dist/extensions/signal/reaction-runtime-api.js +1 -1
- package/dist/extensions/signal/runtime-api.js +7 -7
- package/dist/extensions/skill-workshop/api.js +1 -1
- package/dist/extensions/skill-workshop/index.js +1 -1
- package/dist/extensions/synology-chat/api.js +1 -1
- package/dist/extensions/synology-chat/channel-plugin-api.js +1 -1
- package/dist/extensions/tlon/api.js +2 -2
- package/dist/extensions/tlon/channel-plugin-api.js +1 -1
- package/dist/extensions/tlon/runtime-api.js +1 -1
- package/dist/extensions/tlon/test-api.js +1 -1
- package/dist/extensions/twitch/api.js +1 -1
- package/dist/extensions/twitch/channel-plugin-api.js +1 -1
- package/dist/extensions/twitch/setup-plugin-api.js +1 -1
- package/dist/extensions/zalo/api.js +3 -3
- package/dist/extensions/zalo/channel-plugin-api.js +1 -1
- package/dist/extensions/zalo/runtime-api.js +2 -2
- package/dist/extensions/zalo/setup-api.js +2 -2
- package/dist/extensions/zalouser/api.js +3 -3
- package/dist/extensions/zalouser/channel-plugin-api.js +1 -1
- package/dist/extensions/zalouser/runtime-api.js +6 -6
- package/dist/extensions/zalouser/setup-plugin-api.js +1 -1
- package/dist/extensions/zalouser/test-api.js +1 -1
- package/dist/fallbacks-BwNexEVP.js +31 -0
- package/dist/fallbacks-GwVAaFt5.js +2 -0
- package/dist/fallbacks-shared-DmepG9Mq.js +111 -0
- package/dist/gateway-BB4hdlYm.js +115 -0
- package/dist/gateway-cli-Bzz62NC8.js +1283 -0
- package/dist/gateway-rpc-dyJV2osv.js +14 -0
- package/dist/gateway-rpc.runtime-DYVOEv4W.js +23 -0
- package/dist/gateway-rpc.runtime.js +1 -1
- package/dist/gateway-runtime-CqSQCYo0.js +15 -0
- package/dist/gateway-status-DdCiwrPt.js +584 -0
- package/dist/genesis-tools-Bh6dAUhK.js +9166 -0
- package/dist/genesis-tools.runtime-CiIUponP.js +2 -0
- package/dist/genesis-tools.runtime.js +1 -1
- package/dist/get-reply-from-config.runtime-Cu2DcwOW.js +2 -0
- package/dist/get-reply-from-config.runtime.js +1 -1
- package/dist/get-reply-qVmTjhwr.js +3897 -0
- package/dist/graph-users-kkSJYBNX.js +1337 -0
- package/dist/health-CFyVDYng.js +469 -0
- package/dist/health-Cl371mu8.js +3 -0
- package/dist/health-route-D0IspgUK.js +41 -0
- package/dist/health-route-D2tFKCLv.js +2 -0
- package/dist/heartbeat-runner-Bmi8YsXz.js +5 -0
- package/dist/heartbeat-runner-FSCWra2R.js +1292 -0
- package/dist/heartbeat-runner.runtime-QF8dg4j-.js +4 -0
- package/dist/heartbeat-runner.runtime.js +1 -1
- package/dist/hooks-cli-DYoG7Dz1.js +433 -0
- package/dist/image-fallbacks-5ckuJ46I.js +31 -0
- package/dist/image-fallbacks-DYnqzK01.js +2 -0
- package/dist/inbound-reply-dispatch-D5pqDZRa.js +73 -0
- package/dist/index.js +2 -2
- package/dist/infra-runtime-D08WIqN2.js +39 -0
- package/dist/init-BCgwiSZj.js +59 -0
- package/dist/library-CP9n_7AP.js +45 -0
- package/dist/lifecycle-BYam90xH.js +229 -0
- package/dist/lifecycle-DS58sNmu.js +571 -0
- package/dist/lifecycle.runtime-DMwss7xM.js +2 -0
- package/dist/lifecycle.runtime.js +1 -1
- package/dist/list-CASc4IWz.js +131 -0
- package/dist/list-CBPrBS2u.js +1212 -0
- package/dist/list-Cf7fcqQd.js +2 -0
- package/dist/list-Dqd2QyTH.js +2 -0
- package/dist/list.probe-BWcMSWDF.js +419 -0
- package/dist/llm-slug-generator-4LADFhXT.js +79 -0
- package/dist/llm-slug-generator.js +1 -1
- package/dist/load-config-DI-LDL6p.js +35 -0
- package/dist/local-dispatch.runtime-WDgraH3j.js +8 -0
- package/dist/local-dispatch.runtime.js +1 -1
- package/dist/logs-cli-zoBIelUH.js +265 -0
- package/dist/logs-cli.runtime-DxKNxXAz.js +2 -0
- package/dist/logs-cli.runtime.js +1 -1
- package/dist/main-session-restart-recovery-DWZfkOzH.js +206 -0
- package/dist/managed-image-attachments-DLDa1aE2.js +2 -0
- package/dist/managed-image-attachments-a4v60Bk3.js +635 -0
- package/dist/manager-CfUcsSI9.js +2057 -0
- package/dist/manager-DmBBLCOg.js +2 -0
- package/dist/markdown-to-line-B0mPruD_.js +790 -0
- package/dist/mcp/plugin-tools-serve.js +1 -1
- package/dist/mcp-cli-CLL9nfvE.js +725 -0
- package/dist/mcp-http-p7GbtbMx.js +529 -0
- package/dist/memory-core-host-runtime-cli-CZNYkDoE.js +9 -0
- package/dist/message-CRyNLXch.js +232 -0
- package/dist/message-action-runner-5Y4EFpWh.js +1407 -0
- package/dist/message-action-runner-Dxv-GXkn.js +2 -0
- package/dist/message-actions-DtoR6Mr2.js +143 -0
- package/dist/message.gateway.runtime-RI4cvk_E.js +2 -0
- package/dist/message.gateway.runtime.js +1 -1
- package/dist/models-auth-status-DsheCXaS.js +201 -0
- package/dist/models-cli-CQQG1U-p.js +219 -0
- package/dist/monitor-BRRSjPQY.js +1459 -0
- package/dist/monitor-Ch-cG7Si.js +1661 -0
- package/dist/monitor-ChBhfnC-.js +788 -0
- package/dist/monitor-CsvCTpjq.js +671 -0
- package/dist/monitor-DjemBuVh.js +1237 -0
- package/dist/monitor-LyGEO-KI.js +2 -0
- package/dist/monitor-auth-DVCdDwlp.js +207 -0
- package/dist/monitor-processing-Cib3ZjUe.js +1974 -0
- package/dist/monitor.runtime-DLBFALbV.js +2 -0
- package/dist/monitor.runtime.js +1 -1
- package/dist/monitor.webhook-Dktr8JA-.js +180 -0
- package/dist/msteams-G5I2CO13.js +35 -0
- package/dist/native-hook-relay-B1ArNeG5.js +519 -0
- package/dist/nextcloud-talk-DimOAfaR.js +17 -0
- package/dist/node-cli-RIjV0id4.js +2276 -0
- package/dist/nodes-cli-Cke-B80I.js +1046 -0
- package/dist/nodes-utils-CsTqKwN9.js +84 -0
- package/dist/nodes.helpers-DYpGCFer.js +34 -0
- package/dist/notify-zBChwf0-.js +315 -0
- package/dist/onboard-D6UawRld.js +2 -0
- package/dist/onboard-DfoCtk3_.js +70 -0
- package/dist/onboard-helpers-BKQMe3RX.js +6 -0
- package/dist/onboard-helpers-BLBJlQ50.js +204 -0
- package/dist/onboard-interactive-GAbQD437.js +24 -0
- package/dist/onboard-non-interactive-Bqi-JXh3.js +635 -0
- package/dist/onboard-remote-CNpTyVws.js +193 -0
- package/dist/onboard-remote-GFp2lT6Y.js +2 -0
- package/dist/onboard-skills-BQneolfo.js +2 -0
- package/dist/onboard-skills-BipqJ48b.js +134 -0
- package/dist/openai-http-CLDWjSKC.js +500 -0
- package/dist/openresponses-http-DNvXNiw_.js +1128 -0
- package/dist/operator-approvals-client-gaflvETF.js +68 -0
- package/dist/outbound.runtime-ByVsvEri.js +2 -0
- package/dist/outbound.runtime.js +1 -1
- package/dist/pair-command-approve-Dzkubc-8.js +44 -0
- package/dist/persistent-bindings.lifecycle-BhdRK7Lp.js +2 -0
- package/dist/persistent-bindings.lifecycle-DQ0AiHuy.js +85 -0
- package/dist/pi-embedded-C789hs31.js +4 -0
- package/dist/pi-embedded-CXLkrOwv.js +2905 -0
- package/dist/pi-embedded.runtime-BaHYLgKa.js +4 -0
- package/dist/pi-embedded.runtime.js +1 -1
- package/dist/pi-tool-definition-adapter-DFutc0D4.js +229 -0
- package/dist/pi-tools-k60jrAVq.js +1057 -0
- package/dist/pi-tools.before-tool-call-CFy20GCz.js +2 -0
- package/dist/pi-tools.before-tool-call-DJmPOVfQ.js +433 -0
- package/dist/plugin-BfFuIgXQ.js +12195 -0
- package/dist/plugin-enabled-dXOUnZwX.js +140 -0
- package/dist/plugin-registration-CEAozQhV.js +23 -0
- package/dist/plugin-sdk/.boundary-entry-shims.stamp +1 -1
- package/dist/plugin-sdk/acp-binding-runtime.js +1 -1
- package/dist/plugin-sdk/acp-runtime.js +2 -2
- package/dist/plugin-sdk/agent-harness-runtime.js +5 -5
- package/dist/plugin-sdk/agent-harness.js +6 -6
- package/dist/plugin-sdk/agent-runtime.js +2 -2
- package/dist/plugin-sdk/approval-gateway-runtime.js +2 -2
- package/dist/plugin-sdk/approval-handler-runtime.js +3 -3
- package/dist/plugin-sdk/approval-runtime.js +1 -1
- package/dist/plugin-sdk/browser-node-runtime.js +4 -4
- package/dist/plugin-sdk/browser-setup-tools.js +3 -3
- package/dist/plugin-sdk/browser-support.js +7 -7
- package/dist/plugin-sdk/channel-core.js +2 -2
- package/dist/plugin-sdk/channel-inbound.js +2 -2
- package/dist/plugin-sdk/command-auth.js +1 -1
- package/dist/plugin-sdk/command-status-runtime.js +1 -1
- package/dist/plugin-sdk/compat.js +1 -1
- package/dist/plugin-sdk/conversation-binding-runtime.js +1 -1
- package/dist/plugin-sdk/conversation-runtime.js +3 -3
- package/dist/plugin-sdk/core.js +2 -2
- package/dist/plugin-sdk/direct-dm.js +1 -1
- package/dist/plugin-sdk/gateway-runtime.js +3 -3
- package/dist/plugin-sdk/inbound-reply-dispatch.js +1 -1
- package/dist/plugin-sdk/index.js +1 -1
- package/dist/plugin-sdk/infra-runtime.js +2 -2
- package/dist/plugin-sdk/irc.js +2 -2
- package/dist/plugin-sdk/matrix.js +1 -1
- package/dist/plugin-sdk/memory-core-host-runtime-cli.js +2 -2
- package/dist/plugin-sdk/memory-core.js +2 -2
- package/dist/plugin-sdk/msteams.js +2 -2
- package/dist/plugin-sdk/nextcloud-talk.js +2 -2
- package/dist/plugin-sdk/nostr.js +1 -1
- package/dist/plugin-sdk/reply-dispatch-runtime.js +1 -1
- package/dist/plugin-sdk/reply-runtime.js +4 -4
- package/dist/plugin-sdk/runtime-secret-resolution.js +1 -1
- package/dist/plugin-sdk/runtime.js +2 -2
- package/dist/plugin-sdk/session-visibility.js +1 -1
- package/dist/plugin-sdk/testing.js +4 -4
- package/dist/plugin-sdk/tlon.js +1 -1
- package/dist/plugin-sdk/zalo.js +1 -1
- package/dist/plugin-sdk/zalouser.js +1 -1
- package/dist/plugin-service-BOpLQ8BU.js +2892 -0
- package/dist/plugins/runtime/index.js +1 -1
- package/dist/policy-DiIlt2yW.js +328 -0
- package/dist/postinstall-inventory.json +445 -445
- package/dist/prepare.runtime-Bd8adOy3.js +815 -0
- package/dist/prepare.runtime.js +1 -1
- package/dist/probe-BOlTfbzG.js +2 -0
- package/dist/probe-BSRvsN95.js +2205 -0
- package/dist/probe-CDfjQSnz.js +74 -0
- package/dist/probe-D7gHyiZV.js +241 -0
- package/dist/probe-DTNKTWSs.js +2 -0
- package/dist/probe-DcryDdZh.js +45 -0
- package/dist/probe-nyesoHxj.js +1443 -0
- package/dist/program-BFGavenz.js +111 -0
- package/dist/prompt-select-styled-BhY1zahx.js +20 -0
- package/dist/protocol-DxLbSF2J.js +2477 -0
- package/dist/provider-dispatcher-C-yy1D7r.js +22 -0
- package/dist/provider-dispatcher-ErSjESTP.js +2 -0
- package/dist/qr-cli-C1-oy_ho.js +349 -0
- package/dist/qr-cli-DmEs63Sb.js +2 -0
- package/dist/reaction-runtime-api-gua650a7.js +116 -0
- package/dist/reactions-R-rA7cXz.js +998 -0
- package/dist/register-service-commands-DkbqNKVB.js +71 -0
- package/dist/register.agent-C3nW9wDn.js +248 -0
- package/dist/register.configure-BzLHCu95.js +15 -0
- package/dist/register.maintenance-BHFQo4gr.js +363 -0
- package/dist/register.message-CsYRdfKi.js +329 -0
- package/dist/register.onboard-DltySQ6C.js +88 -0
- package/dist/register.runtime-6Sk1Njnp.js +81 -0
- package/dist/register.runtime.js +1 -1
- package/dist/register.setup-CDvVQJuj.js +150 -0
- package/dist/register.status-health-sessions-B8lorJ2x.js +1215 -0
- package/dist/register.subclis-BD4fuAci.js +3 -0
- package/dist/register.subclis-CbRd3F_m.js +29 -0
- package/dist/register.subclis-core-Dtq9dAjI.js +249 -0
- package/dist/reply-dispatch-runtime-DldslKSK.js +13 -0
- package/dist/reply-runtime-2EGTfk-1.js +11 -0
- package/dist/reply.runtime-OaHntzIS.js +2 -0
- package/dist/reply.runtime.js +1 -1
- package/dist/restart-health-BjmfJCUM.js +202 -0
- package/dist/restart-health-hw909zlD.js +2 -0
- package/dist/root-help-_hHiERsR.js +44 -0
- package/dist/routes-BxCk7Pue.js +3341 -0
- package/dist/routes-C1_6oFmZ.js +2 -0
- package/dist/rpc-zRbkEo6W.js +61 -0
- package/dist/rpc.runtime-BZSYNDPa.js +21 -0
- package/dist/rpc.runtime.js +1 -1
- package/dist/run-delivery.runtime-D6YDo67d.js +530 -0
- package/dist/run-delivery.runtime.js +1 -1
- package/dist/run-embedded.runtime-BsgPrPDa.js +4 -0
- package/dist/run-embedded.runtime.js +1 -1
- package/dist/run-execution-cli.runtime-CggaHhrJ.js +4 -0
- package/dist/run-execution-cli.runtime.js +1 -1
- package/dist/run-executor.runtime-CKkLEr_T.js +277 -0
- package/dist/run-executor.runtime.js +1 -1
- package/dist/run-main-CJYYkV6H.js +567 -0
- package/dist/run-subagent-registry.runtime-B0sgf_oy.js +2 -0
- package/dist/run-subagent-registry.runtime.js +1 -1
- package/dist/run-wait-DHizeptL.js +135 -0
- package/dist/runtime-EtV_ChXX.js +9 -0
- package/dist/runtime-api-6H864Pmt.js +9 -0
- package/dist/runtime-api-CbZqRBZQ.js +14 -0
- package/dist/runtime-api-ZxEgu8cW.js +4 -0
- package/dist/runtime-api-j9A6jYUr.js +9 -0
- package/dist/runtime-embedded-pi.runtime-BHjCPnxo.js +2 -0
- package/dist/runtime-embedded-pi.runtime.js +1 -1
- package/dist/runtime-hvRzTSAZ.js +973 -0
- package/dist/runtime-internal-C_KZYzFK.js +2 -0
- package/dist/runtime-options-BZEOCnMg.js +275 -0
- package/dist/runtime-schema-R7LWe58K.js +28576 -0
- package/dist/scan-BNDE3dSE.js +523 -0
- package/dist/scan-TG6lVEQ2.js +2 -0
- package/dist/secrets-cli-twD2FWoZ.js +2101 -0
- package/dist/security-cli-Cd1A5yhL.js +486 -0
- package/dist/selection-CqqmU0Hi.js +7764 -0
- package/dist/selection-CsM62vcz.js +2 -0
- package/dist/send-D-EgB64m.js +156 -0
- package/dist/send-DPk5hW1W.js +102 -0
- package/dist/send.runtime-3QDkKN71.js +2 -0
- package/dist/send.runtime.js +1 -1
- package/dist/server-C94r_Qff.js +77 -0
- package/dist/server-Ceiopn_v.js +13 -0
- package/dist/server-context-BFJlu5HY.js +2 -0
- package/dist/server-context-PNEqhnTM.js +847 -0
- package/dist/server-node-events-QOAWLsDC.js +481 -0
- package/dist/server-plugin-bootstrap-CgsjzB17.js +2 -0
- package/dist/server-plugin-bootstrap-Dfuf75EN.js +12728 -0
- package/dist/server-restart-sentinel-BMPqZ7Jw.js +697 -0
- package/dist/server.impl-CCoQpvB7.js +12864 -0
- package/dist/session-kill-http-oPi3ajEp.js +110 -0
- package/dist/session-reset-service-CzDd6PBK.js +497 -0
- package/dist/session-route-DUOQE8-f.js +93 -0
- package/dist/session-status.runtime-W5tlGbXw.js +2 -0
- package/dist/session-status.runtime.js +1 -1
- package/dist/session-subagent-reactivation.runtime-yoYn1awK.js +2 -0
- package/dist/session-subagent-reactivation.runtime.js +1 -1
- package/dist/session-tab-registry-DkeCaT-2.js +581 -0
- package/dist/session-visibility-B4CFjv43.js +147 -0
- package/dist/sessions-helpers-CDfOVWe3.js +305 -0
- package/dist/sessions-history-http-QXeTdxXM.js +383 -0
- package/dist/sessions-patch-xb4bXPwh.js +309 -0
- package/dist/sessions-resolve-BPlrW8C3.js +174 -0
- package/dist/sessions.runtime-yYJXudA9.js +2 -0
- package/dist/sessions.runtime.js +1 -1
- package/dist/setup-0Im0LL1d.js +636 -0
- package/dist/setup-api-BxwfqXN-.js +29 -0
- package/dist/setup-core-BWwXgEuM.js +171 -0
- package/dist/setup-core-DzHNbQLG.js +176 -0
- package/dist/setup-surface-BVnqDsfU.js +286 -0
- package/dist/setup-surface-BajZWmKz2.js +403 -0
- package/dist/setup-surface-rDO3YjSb.js +219 -0
- package/dist/setup.finalize-BsnPbdwc.js +547 -0
- package/dist/setup.gateway-config-BFawSWHL.js +250 -0
- package/dist/shared-52tFSlVk.js +121 -0
- package/dist/shared-C8ENgtxM.js +198 -0
- package/dist/shared-DbXvU7JV.js +76 -0
- package/dist/slash-state-CMuPwgKt.js +1911 -0
- package/dist/src-IzaHgU6a.js +3974 -0
- package/dist/startup-context-xJS8ckSG.js +312 -0
- package/dist/status-BO4LMTER.js +2 -0
- package/dist/status-BwY1tASe.js +3 -0
- package/dist/status-BxG6n-ko.js +397 -0
- package/dist/status-Co_cq2vy.js +2 -0
- package/dist/status-DKNeRGzW.js +190 -0
- package/dist/status-DzlIHiTS.js +209 -0
- package/dist/status-all-DF7qaWjo.js +498 -0
- package/dist/status-json-CgCilobT.js +14 -0
- package/dist/status-json-command-DAa78z3e.js +84 -0
- package/dist/status-runtime-shared-CRCuxXn_.js +257 -0
- package/dist/status-subagents.runtime-hUsBd4C5.js +18 -0
- package/dist/status-subagents.runtime.js +1 -1
- package/dist/status-text-BdbRrl1G.js +237 -0
- package/dist/status.gateway-connection.runtime-BmSTYFFO.js +2 -0
- package/dist/status.gateway-connection.runtime.js +1 -1
- package/dist/status.gather-CItmFIHS.js +292 -0
- package/dist/status.gather-qB6WOoH7.js +2 -0
- package/dist/status.runtime-ClZCgYx1.js +2 -0
- package/dist/status.runtime.js +1 -1
- package/dist/status.scan-overview-B0b0Mvng.js +379 -0
- package/dist/status.scan-xY7nUi9N.js +65 -0
- package/dist/status.scan.fast-json-BANGHOys.js +132 -0
- package/dist/status.scan.fast-json-M-DmMy2l.js +2 -0
- package/dist/status.summary-B3PlFnWw.js +2 -0
- package/dist/status.summary-adB75FOM.js +214 -0
- package/dist/subagent-announce-B4w7Mcpr.js +351 -0
- package/dist/subagent-announce-delivery-Dma0A4gL.js +726 -0
- package/dist/subagent-announce-output-sUPLcge-.js +364 -0
- package/dist/subagent-control-CxR0WRrx.js +506 -0
- package/dist/subagent-followup.runtime-XeFe_LA0.js +68 -0
- package/dist/subagent-followup.runtime.js +1 -1
- package/dist/subagent-orphan-recovery-CJPHy8JV.js +305 -0
- package/dist/subagent-registry-CjMWjRCE.js +1753 -0
- package/dist/subagent-registry-H20VxEu0.js +3 -0
- package/dist/subagent-registry.runtime.js +1 -1
- package/dist/subagent-spawn-CRM5x6cV.js +1005 -0
- package/dist/system-cli-BJ5mMirj.js +59 -0
- package/dist/targets-CUnlEj96.js +67 -0
- package/dist/task-executor-DKnEwQ6v.js +360 -0
- package/dist/task-owner-access-CfypP1Yc.js +74 -0
- package/dist/task-registry-delivery-runtime-BB6ZzpqH.js +2 -0
- package/dist/task-registry-delivery-runtime-CvHa0gv-.js +3 -0
- package/dist/task-registry-pQuAfAL9.js +2366 -0
- package/dist/task-registry.maintenance-Bfd87wEV.js +416 -0
- package/dist/task-registry.maintenance-VgfbW0yt.js +2 -0
- package/dist/telegram/token.js +1 -1
- package/dist/testing-C_mngO0u.js +575 -0
- package/dist/text-report-Ct6t3he6.js +587 -0
- package/dist/tool-resolution-C4KGgPH-.js +90 -0
- package/dist/tools-effective-inventory-Bo2QC-m8.js +152 -0
- package/dist/tools-invoke-http-CBZPFh5L.js +206 -0
- package/dist/trash-DhZow3jd.js +24 -0
- package/dist/tui-cli-BPdQPozP.js +4575 -0
- package/dist/update-cli-BRi3mVAU.js +1759 -0
- package/dist/upgrade-D9zejtCk.js +1226 -0
- package/dist/video-generation-task-status-BSBQ0_FO.js +163 -0
- package/dist/wait-for-idle-before-flush-D1dTT9th.js +5986 -0
- package/dist/wizard-models-ysyV_WWR.js +334 -0
- package/package.json +1 -1
- package/dist/abort-DaihtnYj.js +0 -201
- package/dist/abort.runtime-BUT9L_5l.js +0 -2
- package/dist/accounts-BY5wsBnV.js +0 -104
- package/dist/accounts-DGth1vsM.js +0 -107
- package/dist/accounts-Do6Ir-q3.js +0 -2
- package/dist/acp-cli-BHgjn8rh.js +0 -2193
- package/dist/acp-spawn-BAM_Jrft.js +0 -2
- package/dist/acp-spawn-DyBD_Y_t.js +0 -1093
- package/dist/acp-stateful-target-driver-DKGnfjWu.js +0 -89
- package/dist/action-agents-CzMSNQdc.js +0 -67
- package/dist/action-focus-CpjIrZFe.js +0 -132
- package/dist/action-help-BhE9UosK.js +0 -7
- package/dist/action-info-CH2j6dKT.js +0 -101
- package/dist/action-kill-CB4AnLIf.js +0 -33
- package/dist/action-list-CQ8LbzvR.js +0 -21
- package/dist/action-log-DZblh247.js +0 -30
- package/dist/action-send-DMe0B4FG.js +0 -39
- package/dist/action-spawn-CkKMESb5.js +0 -47
- package/dist/action-unfocus-DjQzPZwU.js +0 -29
- package/dist/actions.runtime-CUdRdpLB.js +0 -5
- package/dist/actions.runtime-CxRstWdN.js +0 -18
- package/dist/agent-command-Nh_kPL3z.js +0 -874
- package/dist/agent-harness-runtime-BEb7Wk1m.js +0 -144
- package/dist/agent-q6U-cKJn.js +0 -2
- package/dist/agent-runner-utils-x_qJ6xYC.js +0 -239
- package/dist/agent-runner.runtime-DRvTfUPd.js +0 -3455
- package/dist/agent-runtime-jSYYQd6f.js +0 -18
- package/dist/agents-BKOpsZXw.js +0 -5
- package/dist/agents-BY34ViPX.js +0 -954
- package/dist/aliases-CD5YlX7d.js +0 -2
- package/dist/aliases-Dq31zANx.js +0 -96
- package/dist/api-BhxN9fxJ.js +0 -139
- package/dist/api-DjL_3olO.js +0 -5
- package/dist/api-jIYND-S5.js +0 -3
- package/dist/approval-gateway-resolver-BfvdJW5s.js +0 -29
- package/dist/approval-gateway-runtime-BBf976nt.js +0 -2
- package/dist/approval-handler-runtime-Bq4p5wvg.js +0 -439
- package/dist/approval-native-runtime-IrisOZrU.js +0 -729
- package/dist/attempt-execution.runtime-BXGalt-_.js +0 -509
- package/dist/attempt.prompt-helpers-A-pc2LfL.js +0 -221
- package/dist/attempt.tool-run-context-Ukna4ck-.js +0 -933
- package/dist/audit-CVUpfDvE.js +0 -939
- package/dist/audit.runtime-CsuGXvud.js +0 -7
- package/dist/auth-CjcZyRUW.js +0 -383
- package/dist/auth-order-DIkyTpW4.js +0 -2
- package/dist/auth-order-Dpt1K1rT.js +0 -96
- package/dist/auth-sVuL2xeZ.js +0 -2
- package/dist/bash-tools-DDv0zQh9.js +0 -2824
- package/dist/bash-tools-s-QSvRmt.js +0 -3
- package/dist/binding-routing-Cz5R2kFK.js +0 -85
- package/dist/binding-targets-D4j2hdQh.js +0 -121
- package/dist/bridge-server-X8SdeAI3.js +0 -113
- package/dist/browser-control-auth-BrF3DZxC.js +0 -2
- package/dist/browser-node-runtime-BecPmKOx.js +0 -12
- package/dist/browser-profiles-BxAKEG3x.js +0 -2
- package/dist/browser-runtime-D9fTDscJ.js +0 -387
- package/dist/browser-setup-tools--AQGWGvl.js +0 -13
- package/dist/build-B0nbyXrw.js +0 -550
- package/dist/call-BvqN9kay.js +0 -3
- package/dist/call-Dk5rTl-p.js +0 -331
- package/dist/call.runtime-Bx1hKDwO.js +0 -2
- package/dist/capability-cli-286Z3Bq3.js +0 -1401
- package/dist/catchup-DyeQ6GNj.js +0 -300
- package/dist/channel-B5m01jSZ.js +0 -1802
- package/dist/channel-BE26v3WU.js +0 -840
- package/dist/channel-BS7r_Zt1.js +0 -226
- package/dist/channel-BUWCqkGh.js +0 -1320
- package/dist/channel-BhgKqvZn.js +0 -453
- package/dist/channel-Bx703sxQ.js +0 -297
- package/dist/channel-CDjlEQAM.js +0 -491
- package/dist/channel-ChrqAgRS.js +0 -595
- package/dist/channel-Crmp3BHh.js +0 -1100
- package/dist/channel-D7GdDfBl.js +0 -1174
- package/dist/channel-DqSzRIul.js +0 -350
- package/dist/channel-core-DIwclC34.js +0 -5
- package/dist/channel-inbound-DPW1gRUU.js +0 -31
- package/dist/channel-plugin-runtime-BJhRSlBI.js +0 -771
- package/dist/channel-runtime-sV_Sg0EO.js +0 -425
- package/dist/channel.runtime-4BaNapRW.js +0 -89
- package/dist/channel.runtime-Bk2w0Yzd.js +0 -2364
- package/dist/channel.runtime-Bo5_2imz.js +0 -109
- package/dist/channel.runtime-CdYWlMyL.js +0 -40130
- package/dist/channel.runtime-CrYmCmSw.js +0 -4
- package/dist/channel.runtime-D3APPhVs.js +0 -430
- package/dist/channel.runtime-DjF1Gg6N.js +0 -576
- package/dist/channel.setup-BxXrmAYb.js +0 -10
- package/dist/channels-DHcJgMnw.js +0 -733
- package/dist/channels-cli-Dnq08u4r.js +0 -268
- package/dist/chat-BGU3UVKD.js +0 -2830
- package/dist/clawbot-cli-C-rqJUW-.js +0 -9
- package/dist/cli-BlnGJbLJ.js +0 -219
- package/dist/cli-D0RU1q0-.js +0 -2
- package/dist/cli-DBw79G2t.js +0 -72
- package/dist/cli-Dul37_xp.js +0 -2
- package/dist/cli-runner-DY8BKEmu.js +0 -286
- package/dist/cli-runner.runtime-5JMuegF9.js +0 -3
- package/dist/cli-runner.runtime-DQROn9Ve.js +0 -4
- package/dist/cli.runtime-CGOUREQg.js +0 -1261
- package/dist/client-CCBN1ydB.js +0 -138
- package/dist/client-PHLyQ8il.js +0 -713
- package/dist/command-auth-79QKQZZ3.js +0 -76
- package/dist/command-config-resolution-BKAgMItc.js +0 -2
- package/dist/command-config-resolution-BUCAmCZ_.js +0 -23
- package/dist/command-config-resolution.runtime-BVtfeARM.js +0 -2
- package/dist/command-registry-C9axn0de.js +0 -4
- package/dist/command-registry-DkcFlIyM.js +0 -9
- package/dist/command-registry-core-DEDRtJmS.js +0 -106
- package/dist/command-secret-gateway-g0alGmKz.js +0 -528
- package/dist/command-status.runtime-Dw6Zj5hL.js +0 -87
- package/dist/commands-acp-De-XFc40.js +0 -77
- package/dist/commands-compact.runtime-6gixR2a8.js +0 -10
- package/dist/commands-handlers.runtime-DCmZAlRN.js +0 -4599
- package/dist/commands-status-CION7GYY.js +0 -16
- package/dist/commands-status.runtime-FBwoHftv.js +0 -3
- package/dist/commands-subagents-control.runtime-C2xgOYKM.js +0 -2
- package/dist/commands-subagents-control.runtime-CgIEblx3.js +0 -3
- package/dist/commands-system-prompt-B-jC-KV-.js +0 -158
- package/dist/commands-system-prompt-DeK5Jhy_.js +0 -2
- package/dist/commands.runtime-CHSb1kYa.js +0 -167
- package/dist/compact-Dwchggv2.js +0 -1118
- package/dist/compact.runtime-jDUYMSjR.js +0 -12
- package/dist/completion-cli-DGiZcg4E.js +0 -328
- package/dist/config-Bnb9qa1S.js +0 -252
- package/dist/config-cli-BuZ5RUhD.js +0 -1078
- package/dist/configure-BLNGlWh0.js +0 -1252
- package/dist/configure-nPzsEeOb.js +0 -2
- package/dist/connect-options-C9cvS-bh.js +0 -699
- package/dist/control-auth-D2-P54fW.js +0 -125
- package/dist/control-service-CqUPgxlx.js +0 -156
- package/dist/control-ui/assets/agents-CA3uz9sP.js +0 -1052
- package/dist/control-ui/assets/canvas-D0sLy568.js +0 -269
- package/dist/control-ui/assets/channel-config-extras-CWzNTLS-.js +0 -2
- package/dist/control-ui/assets/channels-DXgjbWts.js +0 -463
- package/dist/control-ui/assets/cron-D-rffMH6.js +0 -933
- package/dist/control-ui/assets/de-l9FbKtxt.js +0 -2
- package/dist/control-ui/assets/debug-Vf_bLYLB.js +0 -94
- package/dist/control-ui/assets/es-CC-t9AUQ.js +0 -2
- package/dist/control-ui/assets/format-BL-FisEP.js +0 -9
- package/dist/control-ui/assets/fr-DZKceqST.js +0 -2
- package/dist/control-ui/assets/i18n-DFH8x0DD.js +0 -3
- package/dist/control-ui/assets/id-D93YKkrM.js +0 -2
- package/dist/control-ui/assets/index-lWAwAXYo.js +0 -6366
- package/dist/control-ui/assets/instances-BmzzTloa.js +0 -57
- package/dist/control-ui/assets/ja-JP-DoPdk5L_.js +0 -2
- package/dist/control-ui/assets/ko-8TeOGGHm.js +0 -2
- package/dist/control-ui/assets/logs-BjPSImvD.js +0 -74
- package/dist/control-ui/assets/mcp-CQGmuKdR.js +0 -281
- package/dist/control-ui/assets/nodes-CDhqPGsD.js +0 -618
- package/dist/control-ui/assets/pl-BSP1Y3tH.js +0 -2
- package/dist/control-ui/assets/plugins-D4fXQx07.js +0 -273
- package/dist/control-ui/assets/pt-BR-D4-81_zm.js +0 -2
- package/dist/control-ui/assets/sessions-DzjXl7P7.js +0 -306
- package/dist/control-ui/assets/skills-BTQrLVPj.js +0 -323
- package/dist/control-ui/assets/skills-shared-CX4mwYFK.js +0 -11
- package/dist/control-ui/assets/th-DrnubOIu.js +0 -2
- package/dist/control-ui/assets/tr-BMyrj0eZ.js +0 -2
- package/dist/control-ui/assets/uk-CZhU3bHK.js +0 -2
- package/dist/control-ui/assets/wallet-DPb6whuj.js +0 -285
- package/dist/control-ui/assets/zh-CN-CH12jxSw.js +0 -2
- package/dist/control-ui/assets/zh-TW-CaTySceX.js +0 -2
- package/dist/conversation-id-BAzJOKBB.js +0 -235
- package/dist/conversation-id-WJLKuyy9.js +0 -38
- package/dist/conversation-runtime-D8fK5aI0.js +0 -31
- package/dist/core-DywmHt1k.js +0 -275
- package/dist/cron-cli-CeEJRkfR.js +0 -713
- package/dist/daemon-cli-BZZOjJHx.js +0 -12
- package/dist/dashboard-C0NRxmP3.js +0 -81
- package/dist/dashboard-DqhPgQv-.js +0 -2
- package/dist/delegate-DwVbOeR5.js +0 -64
- package/dist/detached-task-runtime-DiDRj-v-.js +0 -73
- package/dist/devices-cli-BKVbpwVc.js +0 -498
- package/dist/diagnostics-gh3UN_iV.js +0 -154
- package/dist/direct-dm-CwHHUkHV.js +0 -64
- package/dist/dispatch-B5af8_1v.js +0 -1131
- package/dist/dispatch-acp-DgOnUWBl.js +0 -981
- package/dist/dispatch-acp-manager.runtime-XWNjVh_M.js +0 -3
- package/dist/dispatch-acp.runtime-BdYL_ZqM.js +0 -19
- package/dist/doctor-device-pairing-CtGzWmXB.js +0 -307
- package/dist/doctor-gateway-daemon-flow-CCBI0jL4.js +0 -250
- package/dist/doctor-gateway-health-CkjqPFDl.js +0 -63
- package/dist/doctor-health-BOhuy1vP.js +0 -59
- package/dist/doctor-health-contributions-ChEuyLAY.js +0 -493
- package/dist/doctor-prompter-9nOTFD0Q.js +0 -56
- package/dist/doctor-workspace-status-CO5Ocwlt.js +0 -75
- package/dist/dreaming-GOPEFPio.js +0 -1574
- package/dist/dreaming-narrative-DfxHaxOU.js +0 -595
- package/dist/embedded-gateway-stub.runtime-B2OWcbsK.js +0 -9
- package/dist/exec-approvals-cli-CGeFtFbB.js +0 -498
- package/dist/fallbacks-CdfWAgNP.js +0 -2
- package/dist/fallbacks-eXbQ8TBp.js +0 -31
- package/dist/fallbacks-shared-akcCu5CD.js +0 -111
- package/dist/gateway-D-dDKqwi.js +0 -115
- package/dist/gateway-cli-DBS06Da8.js +0 -1283
- package/dist/gateway-rpc-Cxa8dVW5.js +0 -14
- package/dist/gateway-rpc.runtime-D76s-oxs.js +0 -23
- package/dist/gateway-runtime-Dhm_gLh1.js +0 -15
- package/dist/gateway-status-C_L_CdOg.js +0 -584
- package/dist/genesis-tools-rRJB3JXY.js +0 -9166
- package/dist/genesis-tools.runtime-6oKokqaA.js +0 -2
- package/dist/get-reply-BkiDsDVY.js +0 -3897
- package/dist/get-reply-from-config.runtime-CHKCcj9D.js +0 -2
- package/dist/graph-users-BnXIYyC5.js +0 -1337
- package/dist/health-ZsJNENSY.js +0 -3
- package/dist/health-osa9LOJf.js +0 -469
- package/dist/health-route-8TdKOYLp.js +0 -2
- package/dist/health-route-BdLtX2Bg.js +0 -41
- package/dist/heartbeat-runner-BCbkAprr.js +0 -1292
- package/dist/heartbeat-runner-Dc1K8S94.js +0 -5
- package/dist/heartbeat-runner.runtime-pJaAsgLY.js +0 -4
- package/dist/hooks-cli-C3ggAz0i.js +0 -433
- package/dist/image-fallbacks-CiSae-lb.js +0 -2
- package/dist/image-fallbacks-vI8KUh6N.js +0 -31
- package/dist/inbound-reply-dispatch-DLM60UDh.js +0 -73
- package/dist/infra-runtime-CrHVeejV.js +0 -39
- package/dist/init-BKeEiV2q.js +0 -59
- package/dist/library-CHB7yTo5.js +0 -45
- package/dist/lifecycle-CUULToPr.js +0 -229
- package/dist/lifecycle-DCMpTRD2.js +0 -571
- package/dist/lifecycle.runtime-CP4gRxWv.js +0 -2
- package/dist/list-0zDFAWTF.js +0 -2
- package/dist/list-BaxVHTAN.js +0 -131
- package/dist/list-CMRMgrPs.js +0 -1212
- package/dist/list-DSrBtnKI.js +0 -2
- package/dist/list.probe-BJYSCsJY.js +0 -419
- package/dist/llm-slug-generator-Bn_wrWYw.js +0 -79
- package/dist/load-config-qC2BWt8E.js +0 -35
- package/dist/local-dispatch.runtime-DyU7urGc.js +0 -8
- package/dist/logs-cli-zK71r_PE.js +0 -265
- package/dist/logs-cli.runtime-k0UtiaRP.js +0 -2
- package/dist/main-session-restart-recovery-DMT0Oj9a.js +0 -206
- package/dist/managed-image-attachments-B6XXE4--.js +0 -635
- package/dist/managed-image-attachments-BTzWoDWE.js +0 -2
- package/dist/manager-BCKuWA67.js +0 -2057
- package/dist/manager-rGwNUzMp.js +0 -2
- package/dist/markdown-to-line-DmPbXQA1.js +0 -790
- package/dist/mcp-cli-CYpPNMcE.js +0 -725
- package/dist/mcp-http-wiE81iKg.js +0 -529
- package/dist/memory-core-host-runtime-cli-BOSQRX1T.js +0 -9
- package/dist/message-CUDzVGD8.js +0 -232
- package/dist/message-action-runner-Dy0IpKa4.js +0 -1407
- package/dist/message-action-runner-KkBFzZdg.js +0 -2
- package/dist/message-actions-Dcdb5aSR.js +0 -143
- package/dist/message.gateway.runtime-D86fFO99.js +0 -2
- package/dist/models-auth-status-DkiX4s0b.js +0 -201
- package/dist/models-cli-CSUot1R3.js +0 -219
- package/dist/monitor-BA8ByMKR.js +0 -2
- package/dist/monitor-Bv1GIHW5.js +0 -1661
- package/dist/monitor-DTFY0ruF.js +0 -788
- package/dist/monitor-DXH-vNGn.js +0 -1459
- package/dist/monitor-Df5k8NGk.js +0 -671
- package/dist/monitor-Dk2YRF26.js +0 -1237
- package/dist/monitor-auth-CZOW753A.js +0 -207
- package/dist/monitor-processing-Clta8N4C.js +0 -1974
- package/dist/monitor.runtime-3ORbPT0X.js +0 -2
- package/dist/monitor.webhook-CRyTxENk.js +0 -180
- package/dist/msteams-BE0VieXF.js +0 -35
- package/dist/native-hook-relay-DAwGGuEx.js +0 -519
- package/dist/nextcloud-talk-DfYlTFsm.js +0 -17
- package/dist/node-cli-Bzyci_X_.js +0 -2276
- package/dist/nodes-cli-Er3OZkuk.js +0 -1046
- package/dist/nodes-utils-Cp8QZO8-.js +0 -84
- package/dist/nodes.helpers-CwKAAnRA.js +0 -34
- package/dist/notify-D_5n_vEJ.js +0 -315
- package/dist/onboard-BE82RudQ.js +0 -2
- package/dist/onboard-Bk4xL8X7.js +0 -70
- package/dist/onboard-helpers-D4WYa-6g.js +0 -204
- package/dist/onboard-helpers-MuFxPZg5.js +0 -6
- package/dist/onboard-interactive-0zmI-9ia.js +0 -24
- package/dist/onboard-non-interactive-DIRB95mT.js +0 -635
- package/dist/onboard-remote-7qR1knbU.js +0 -2
- package/dist/onboard-remote-CLmoySkk.js +0 -193
- package/dist/onboard-skills-C_873OK_.js +0 -134
- package/dist/onboard-skills-DrlBYc0t.js +0 -2
- package/dist/openai-http-DzCBqW6b.js +0 -500
- package/dist/openresponses-http-B2zgO5hQ.js +0 -1128
- package/dist/operator-approvals-client-mGBl4ptH.js +0 -68
- package/dist/outbound.runtime--HS-MxM_.js +0 -2
- package/dist/pair-command-approve-CCTSQKJH.js +0 -44
- package/dist/persistent-bindings.lifecycle-CnmqGsQf.js +0 -85
- package/dist/persistent-bindings.lifecycle-Dav1TX9E.js +0 -2
- package/dist/pi-embedded-BSKL8IgF.js +0 -4
- package/dist/pi-embedded-DMM8Pfp7.js +0 -2905
- package/dist/pi-embedded.runtime-Bv_roBVx.js +0 -4
- package/dist/pi-tool-definition-adapter-OrxjlSIM.js +0 -229
- package/dist/pi-tools-DD1YegeL.js +0 -1057
- package/dist/pi-tools.before-tool-call-J9ujp9Wp.js +0 -433
- package/dist/pi-tools.before-tool-call-hGEgKGZQ.js +0 -2
- package/dist/plugin-Cg3pHepG.js +0 -12195
- package/dist/plugin-enabled-wEQ8BQNw.js +0 -140
- package/dist/plugin-registration-DLcLJgqz.js +0 -23
- package/dist/plugin-service-BogBl5qk.js +0 -2892
- package/dist/policy-Bkh8Xtnb.js +0 -328
- package/dist/prepare.runtime-Cd31ie7u.js +0 -815
- package/dist/probe-9IM22Rkf.js +0 -2
- package/dist/probe-ButCyV3d.js +0 -1443
- package/dist/probe-D7QBUio1.js +0 -45
- package/dist/probe-DV6CWm0r.js +0 -74
- package/dist/probe-DkfetvwA.js +0 -2
- package/dist/probe-Dxo-LQjn.js +0 -2205
- package/dist/probe-nil3qQAV.js +0 -241
- package/dist/program-AcjZFtZQ.js +0 -111
- package/dist/prompt-select-styled-BSf77q2T.js +0 -20
- package/dist/protocol-C4I0nfuT.js +0 -2477
- package/dist/provider-dispatcher-CkiPxKIr.js +0 -22
- package/dist/provider-dispatcher-PmsHJlUO.js +0 -2
- package/dist/qr-cli-BHY0TO2W.js +0 -2
- package/dist/qr-cli-BbjDJSKp.js +0 -349
- package/dist/reaction-runtime-api-DOigJrbq.js +0 -116
- package/dist/reactions-CogkrjNr.js +0 -998
- package/dist/register-service-commands-IA3Nfza5.js +0 -71
- package/dist/register.agent-DD0aSYye.js +0 -248
- package/dist/register.configure-BOy4i7Ah.js +0 -15
- package/dist/register.maintenance-CUp6FEOF.js +0 -363
- package/dist/register.message-DezTIpNI.js +0 -329
- package/dist/register.onboard-Brpxl9p3.js +0 -88
- package/dist/register.runtime-BfH5rSb_.js +0 -81
- package/dist/register.setup-CIt4FVv0.js +0 -150
- package/dist/register.status-health-sessions-IbGZwSaG.js +0 -1215
- package/dist/register.subclis-B1H4fYxP.js +0 -29
- package/dist/register.subclis-D-_xtNVs.js +0 -3
- package/dist/register.subclis-core-CkJelRU8.js +0 -249
- package/dist/reply-dispatch-runtime-Lu4Metex.js +0 -13
- package/dist/reply-runtime-CgPzru94.js +0 -11
- package/dist/reply.runtime-sw14BA5F.js +0 -2
- package/dist/restart-health-1MNBua3p.js +0 -202
- package/dist/restart-health-BWGpwgPv.js +0 -2
- package/dist/root-help-B3zoC2OP.js +0 -44
- package/dist/routes-BM6fbday.js +0 -3341
- package/dist/routes-pVc_QLiP.js +0 -2
- package/dist/rpc-BGOWS7nj.js +0 -61
- package/dist/rpc.runtime-Ca9K3sx8.js +0 -21
- package/dist/run-delivery.runtime-CabntI64.js +0 -530
- package/dist/run-embedded.runtime-Q7wrP6Qn.js +0 -4
- package/dist/run-execution-cli.runtime-CtRUFc-M.js +0 -4
- package/dist/run-executor.runtime-Nm38xsKA.js +0 -277
- package/dist/run-main-kE0nFgvK.js +0 -567
- package/dist/run-subagent-registry.runtime-D9_scMUr.js +0 -2
- package/dist/run-wait-B2K_6JNL.js +0 -135
- package/dist/runtime-BZ296jTK.js +0 -9
- package/dist/runtime-DnZsw7MB.js +0 -973
- package/dist/runtime-api-BL9vpbvb.js +0 -14
- package/dist/runtime-api-BbsLJB4C.js +0 -9
- package/dist/runtime-api-ChwFrQRw.js +0 -9
- package/dist/runtime-api-_fH7M3Qh.js +0 -4
- package/dist/runtime-embedded-pi.runtime-TOdW-E-2.js +0 -2
- package/dist/runtime-internal-DGwOFi_E.js +0 -2
- package/dist/runtime-options-CSPfxkb1.js +0 -275
- package/dist/runtime-schema-CMRvOPkk.js +0 -28576
- package/dist/scan-D6gkNpKl.js +0 -523
- package/dist/scan-_9J5-5L6.js +0 -2
- package/dist/secrets-cli-DlVSRQPM.js +0 -2101
- package/dist/security-cli-DtzNOYL2.js +0 -486
- package/dist/selection-CBJZE_FL.js +0 -7764
- package/dist/selection-XsoEF2p2.js +0 -2
- package/dist/send-BAaDBRfi.js +0 -156
- package/dist/send-BB-M1afy.js +0 -102
- package/dist/send.runtime-CI_75KUP.js +0 -2
- package/dist/server-B_BiVYFv.js +0 -13
- package/dist/server-D58E1Cua.js +0 -77
- package/dist/server-context-D5AnCc1E.js +0 -2
- package/dist/server-context-bt09wrJu.js +0 -847
- package/dist/server-node-events-CUx4-7FL.js +0 -481
- package/dist/server-plugin-bootstrap-CU5P500z.js +0 -12708
- package/dist/server-plugin-bootstrap-CXm9xWXR.js +0 -2
- package/dist/server-restart-sentinel-ByFI_0MB.js +0 -697
- package/dist/server.impl-BBBEDK9u.js +0 -12864
- package/dist/session-kill-http-9MoO6FXC.js +0 -110
- package/dist/session-reset-service-redPsOs-.js +0 -497
- package/dist/session-route-C8oB2UYs.js +0 -93
- package/dist/session-status.runtime-D3bYBPJe.js +0 -2
- package/dist/session-subagent-reactivation.runtime-aat7tUag.js +0 -2
- package/dist/session-tab-registry-CAJ_oDsb.js +0 -581
- package/dist/session-visibility-Dq88jJYB.js +0 -147
- package/dist/sessions-helpers-C8-IkqhO.js +0 -305
- package/dist/sessions-history-http-4Ftuwnes.js +0 -383
- package/dist/sessions-patch-BsyNHOaz.js +0 -309
- package/dist/sessions-resolve-gKLz2Bup.js +0 -174
- package/dist/sessions.runtime-C1W59rQY.js +0 -2
- package/dist/setup-DhvXyU_5.js +0 -636
- package/dist/setup-api-B9Y4qPgq.js +0 -29
- package/dist/setup-core-CdFQ6ZXC.js +0 -176
- package/dist/setup-core-kXUD3Kat.js +0 -171
- package/dist/setup-surface-BFL9WfBs.js +0 -219
- package/dist/setup-surface-Cxg_nSWc.js +0 -286
- package/dist/setup-surface-DbooMj782.js +0 -403
- package/dist/setup.finalize-CKxukDYi.js +0 -547
- package/dist/setup.gateway-config-BhEtXwaB.js +0 -250
- package/dist/shared-BNVKrp5y.js +0 -76
- package/dist/shared-CM3mnx7z.js +0 -198
- package/dist/shared-CfrsSVhL.js +0 -121
- package/dist/slash-state-2Z-om57Q.js +0 -1911
- package/dist/src-DAoKvK_N.js +0 -3974
- package/dist/startup-context-CtYAdYwd.js +0 -312
- package/dist/status-B2M0Imij.js +0 -3
- package/dist/status-Bd-BNmiE.js +0 -2
- package/dist/status-D6nbpHFi.js +0 -397
- package/dist/status-MByUxUGu.js +0 -209
- package/dist/status-QUjO1tkz.js +0 -2
- package/dist/status-all-DPa-BiHk.js +0 -498
- package/dist/status-erNo8YmW.js +0 -190
- package/dist/status-json-command-C9rbAyj-.js +0 -84
- package/dist/status-json-tO3CQXIQ.js +0 -14
- package/dist/status-runtime-shared-DmBB_gmT.js +0 -257
- package/dist/status-subagents.runtime-BXAZr5y0.js +0 -18
- package/dist/status-text-BCeYk0-q.js +0 -237
- package/dist/status.gateway-connection.runtime-bt35dapy.js +0 -2
- package/dist/status.gather-B9a-CEev.js +0 -292
- package/dist/status.gather-ahBLFzk6.js +0 -2
- package/dist/status.runtime-BrErwtfc.js +0 -2
- package/dist/status.scan-D2mvM4II.js +0 -65
- package/dist/status.scan-overview-uOOaqp1t.js +0 -379
- package/dist/status.scan.fast-json-C9dkN28s.js +0 -2
- package/dist/status.scan.fast-json-DY3Or8S4.js +0 -132
- package/dist/status.summary-Cf4p2BPK.js +0 -2
- package/dist/status.summary-DxfZCcNa.js +0 -214
- package/dist/subagent-announce-CyQZsAIm.js +0 -351
- package/dist/subagent-announce-delivery-CgdPNjMA.js +0 -726
- package/dist/subagent-announce-output-D1xi4Tk1.js +0 -364
- package/dist/subagent-control-D-O6I8Mt.js +0 -506
- package/dist/subagent-followup.runtime-BbA7NPAq.js +0 -68
- package/dist/subagent-orphan-recovery-C6_cmAyE.js +0 -305
- package/dist/subagent-registry-Dn_XpDh0.js +0 -1753
- package/dist/subagent-registry-DodFw3pu.js +0 -3
- package/dist/subagent-spawn-Dw5lttXp.js +0 -1005
- package/dist/system-cli-CSqO2Z4K.js +0 -59
- package/dist/targets-CMdwh9lR.js +0 -67
- package/dist/task-executor-DgZSfcBk.js +0 -360
- package/dist/task-owner-access-9c38idlo.js +0 -74
- package/dist/task-registry-Z-lBPkNj.js +0 -2366
- package/dist/task-registry-delivery-runtime-DOV4qoj4.js +0 -2
- package/dist/task-registry-delivery-runtime-EATr0C3C.js +0 -3
- package/dist/task-registry.maintenance-C1YMEwhk.js +0 -416
- package/dist/task-registry.maintenance-CBfaUWcp.js +0 -2
- package/dist/testing-CFk04o9M.js +0 -575
- package/dist/text-report-QhVG354o.js +0 -587
- package/dist/tool-resolution-D6V4tg-G.js +0 -90
- package/dist/tools-effective-inventory-DFU7yYvD.js +0 -152
- package/dist/tools-invoke-http-y6WIa3Ku.js +0 -206
- package/dist/trash-rhbwNhfQ.js +0 -24
- package/dist/tui-cli-BfxeO4YM.js +0 -4575
- package/dist/update-cli-DaN9bvPV.js +0 -1759
- package/dist/upgrade-f5dlIxir.js +0 -1226
- package/dist/video-generation-task-status-yX54iO8n.js +0 -163
- package/dist/wait-for-idle-before-flush-mZrBNr5z.js +0 -5986
- package/dist/wizard-models-D_avLyHR.js +0 -334
|
@@ -0,0 +1,2905 @@
|
|
|
1
|
+
import { i as formatErrorMessage } from "./errors-CufR9eHH.js";
|
|
2
|
+
import { c as normalizeOptionalString, s as normalizeOptionalLowercaseString } from "./string-coerce-DPP_aYVc.js";
|
|
3
|
+
import { m as resolveUserPath } from "./utils-CWrkFsp0.js";
|
|
4
|
+
import { t as sanitizeForLog } from "./ansi-cSbP14w0.js";
|
|
5
|
+
import { i as freezeDiagnosticTraceContext } from "./diagnostic-trace-context-CKUtfhcl.js";
|
|
6
|
+
import { i as isCronSessionKey } from "./session-key-utils-DDwuwYKT.js";
|
|
7
|
+
import { n as DEFAULT_MODEL, r as DEFAULT_PROVIDER, t as DEFAULT_CONTEXT_TOKENS } from "./defaults-Dg3aovOH.js";
|
|
8
|
+
import { n as resolveProviderIdForAuth } from "./provider-auth-aliases-BbTvwhGb.js";
|
|
9
|
+
import { b as resolveAgentWorkspaceDir, m as resolveSessionAgentIds, r as resolveAgentExecutionContract, t as hasConfiguredModelFallbacks } from "./agent-scope-Duyu_T59.js";
|
|
10
|
+
import { n as resolveSafeTimeoutDelayMs } from "./timer-delay-Hmw9LpJm.js";
|
|
11
|
+
import { i as isMarkdownCapableMessageChannel } from "./message-channel-bhWoqTRw.js";
|
|
12
|
+
import { n as ensureAuthProfileStore } from "./store-DTru4oXw.js";
|
|
13
|
+
import { t as getGlobalHookRunner } from "./hook-runner-global-KWJ-vVaB.js";
|
|
14
|
+
import { i as resolveContextEngine } from "./registry-DAnIkg-h.js";
|
|
15
|
+
import { $ as resolveProviderAuthProfileId, x as prepareProviderRuntimeAuth } from "./provider-runtime-Bfrieldi.js";
|
|
16
|
+
import { t as resolveGenesisAgentDir } from "./agent-paths-B6ef9_Hd.js";
|
|
17
|
+
import { t as ensureGenesisModelsJson } from "./models-config-OmJAbUii.js";
|
|
18
|
+
import { t as ensureContextEnginesInitialized } from "./init-BCgwiSZj.js";
|
|
19
|
+
import { t as ensureRuntimePluginsLoaded } from "./runtime-plugins-D-LHbMKG.js";
|
|
20
|
+
import { n as sleepWithAbort } from "./backoff-BvquQSEM.js";
|
|
21
|
+
import { s as emitAgentPlanEvent } from "./agent-events-ZcJylLt0.js";
|
|
22
|
+
import { a as normalizeUsage, t as derivePromptTokens } from "./usage-kQP5oKIr.js";
|
|
23
|
+
import { n as extractAssistantTextForPhase } from "./chat-message-content-iIHjZfPu.js";
|
|
24
|
+
import { _ as resolveSessionCompactionCheckpointReason, a as readPiModelContextTokens, d as runPostCompactionSideEffects, f as captureCompactionCheckpointSnapshot, g as persistSessionCompactionCheckpoint, i as buildAgentRuntimeAuthPlan, o as asCompactionHookRunner, p as cleanupCompactionCheckpointSnapshot, r as buildAgentRuntimePlan } from "./build-BqG7RkBz.js";
|
|
25
|
+
import { i as enqueueCommandInLane } from "./command-queue-ZNgpV0Hl.js";
|
|
26
|
+
import { a as formatContextWindowWarningMessage, i as formatContextWindowBlockMessage, n as CONTEXT_WINDOW_WARN_BELOW_TOKENS, o as resolveContextWindowInfo, r as evaluateContextWindowGuard, t as CONTEXT_WINDOW_HARD_MIN_TOKENS } from "./context-window-guard-Cu2XpRjp.js";
|
|
27
|
+
import { r as isSilentReplyPayloadText } from "./tokens-QeRE8ZG7.js";
|
|
28
|
+
import { H as sessionLikelyHasOversizedToolResults, U as truncateOversizedToolResultsInSession, V as resolveLiveToolResultMaxChars } from "./wait-for-idle-before-flush-D1dTT9th.js";
|
|
29
|
+
import { m as isStrictAgenticExecutionContractActive } from "./genesis-tools-Bh6dAUhK.js";
|
|
30
|
+
import { _ as createEmbeddedRunReplayState, d as resolveIncompleteTurnPayloadText, f as resolvePlanningOnlyRetryInstruction, g as resolveRunLivenessState, h as resolveReplayInvalidFlag, i as selectAgentHarness, l as resolveAckExecutionFastPathInstruction, m as resolveReasoningOnlyRetryInstruction, o as STRICT_AGENTIC_BLOCKED_TEXT, p as resolvePlanningOnlyRetryLimit, r as runAgentHarnessAttemptWithFallback, s as extractPlanningOnlyPlanDetails, t as maybeCompactAgentHarnessSession, u as resolveEmptyResponseRetryInstruction, v as observeReplayMetadata } from "./selection-CqqmU0Hi.js";
|
|
31
|
+
import { o as normalizeTextForComparison, r as pickFallbackThinkingLevel } from "./pi-embedded-helpers-DGOg4B7z.js";
|
|
32
|
+
import { D as formatRawAssistantErrorForUi, l as isRawApiErrorPayload, n as formatBillingErrorMessage, o as getApiErrorPayloadFingerprint, t as BILLING_ERROR_USER_MESSAGE, x as isTimeoutErrorMessage } from "./sanitize-user-facing-text-ChBSMati.js";
|
|
33
|
+
import { a as formatAssistantErrorText, b as parseImageSizeError, c as isBillingAssistantError, f as isFailoverAssistantError, h as isRateLimitAssistantError, i as extractObservedOverflowTokenCount, m as isLikelyContextOverflowError, p as isFailoverErrorMessage, s as isAuthAssistantError, t as classifyFailoverReason, u as isCompactionFailureError, y as parseImageDimensionError } from "./errors-CGZ3mSha.js";
|
|
34
|
+
import { n as coerceToFailoverError, r as describeFailoverError, s as resolveFailoverStatus, t as FailoverError } from "./failover-error-DIw1Fbgc.js";
|
|
35
|
+
import "./auth-profiles-Cb6SKo5h.js";
|
|
36
|
+
import { a as markAuthProfileUsed, i as markAuthProfileFailure, s as resolveProfilesUnavailableReason, u as isProfileInCooldown } from "./usage-450JMlAq.js";
|
|
37
|
+
import { n as resolveAuthProfileOrder, t as resolveAuthProfileEligibility } from "./order-9BRC-BeT.js";
|
|
38
|
+
import { t as markAuthProfileGood } from "./profiles-DGFYr60_.js";
|
|
39
|
+
import { t as redactIdentifier } from "./redact-identifier-BBwdMS-c.js";
|
|
40
|
+
import { t as sanitizeForConsole } from "./console-sanitize-Kgg5rmjN.js";
|
|
41
|
+
import { n as applyLocalNoAuthHeaderOverride, r as getApiKeyForModel, t as applyAuthHeaderOverride, u as shouldPreferExplicitConfigApiKeyAuth } from "./model-auth-BwQ1st1y.js";
|
|
42
|
+
import { t as log } from "./logger-CpDY2YMO.js";
|
|
43
|
+
import { d as sanitizeRuntimeProviderRequestOverrides, s as resolveProviderRequestConfig } from "./provider-request-config-BMEdYnvj.js";
|
|
44
|
+
import { o as retireSessionMcpRuntime, s as retireSessionMcpRuntimeForSessionKey } from "./pi-bundle-mcp-runtime-D1wJkj1k.js";
|
|
45
|
+
import "./pi-bundle-mcp-tools-Gy-eWTZ3.js";
|
|
46
|
+
import { u as parseReplyDirectives } from "./payloads-BdjK9QVA.js";
|
|
47
|
+
import { s as hasOutboundReplyContent } from "./reply-payload-BXIttfWn.js";
|
|
48
|
+
import { b as formatToolAggregate, l as runContextEngineMaintenance } from "./attempt.tool-run-context-Qf-tbC-C.js";
|
|
49
|
+
import { a as shouldAllowCooldownProbeForReason, i as LiveSessionModelSwitchError, o as buildApiErrorObservationFields } from "./model-fallback-DaCGmGxK.js";
|
|
50
|
+
import { n as isLikelyMutatingToolName } from "./tool-mutation-xORYf6qk.js";
|
|
51
|
+
import { n as extractAssistantThinking, o as formatReasoningMessage, r as extractAssistantVisibleText } from "./pi-embedded-utils-Bew-Oqsb.js";
|
|
52
|
+
import { i as generateSecureToken } from "./secure-random-XRbPM_Nv.js";
|
|
53
|
+
import { n as resolveGlobalLane, r as resolveSessionLane } from "./lanes-8BGNzkfa.js";
|
|
54
|
+
import "./runs-B8F_WpB_.js";
|
|
55
|
+
import "./extra-params-5UV3qKl7.js";
|
|
56
|
+
import { o as buildEmbeddedCompactionRuntimeContext, s as resolveEmbeddedCompactionTarget } from "./attempt.thread-helpers-vnn3lVdg.js";
|
|
57
|
+
import { n as resolveModelAsync } from "./model-gCK0R8Nc.js";
|
|
58
|
+
import { a as resolveStoredSessionKeyForSessionId, i as resolveSessionKeyForRequest, n as shouldSwitchToLiveModel, t as clearLiveModelSwitchPending } from "./live-model-switch-DUFEk7fX.js";
|
|
59
|
+
import { n as resolveRunWorkspaceDir, t as redactRunIdentifier } from "./workspace-run-BsoUN3s_.js";
|
|
60
|
+
import fs from "node:fs/promises";
|
|
61
|
+
import { randomBytes } from "node:crypto";
|
|
62
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
63
|
+
//#region src/agents/pi-embedded-runner/compact.queued.ts
|
|
64
|
+
/**
|
|
65
|
+
* Compacts a session with lane queueing (session lane + global lane).
|
|
66
|
+
* Use this from outside a lane context. If already inside a lane, use
|
|
67
|
+
* `compactEmbeddedPiSessionDirect` to avoid deadlocks.
|
|
68
|
+
*/
|
|
69
|
+
async function compactEmbeddedPiSession(params) {
|
|
70
|
+
ensureRuntimePluginsLoaded({
|
|
71
|
+
config: params.config,
|
|
72
|
+
workspaceDir: params.workspaceDir,
|
|
73
|
+
allowGatewaySubagentBinding: params.allowGatewaySubagentBinding
|
|
74
|
+
});
|
|
75
|
+
ensureContextEnginesInitialized();
|
|
76
|
+
const contextEngine = await resolveContextEngine(params.config);
|
|
77
|
+
const agentDir = params.agentDir ?? resolveGenesisAgentDir();
|
|
78
|
+
let contextTokenBudget = params.contextTokenBudget;
|
|
79
|
+
if (!contextTokenBudget || !Number.isFinite(contextTokenBudget) || contextTokenBudget <= 0) {
|
|
80
|
+
const resolvedCompactionTarget = resolveEmbeddedCompactionTarget({
|
|
81
|
+
config: params.config,
|
|
82
|
+
provider: params.provider,
|
|
83
|
+
modelId: params.model,
|
|
84
|
+
authProfileId: params.authProfileId,
|
|
85
|
+
defaultProvider: DEFAULT_PROVIDER,
|
|
86
|
+
defaultModel: DEFAULT_MODEL
|
|
87
|
+
});
|
|
88
|
+
const ceProvider = resolvedCompactionTarget.provider ?? "openai";
|
|
89
|
+
const ceModelId = resolvedCompactionTarget.model ?? "gpt-5.5";
|
|
90
|
+
const { model: ceModel } = await resolveModelAsync(ceProvider, ceModelId, agentDir, params.config);
|
|
91
|
+
const ceRuntimeModel = ceModel;
|
|
92
|
+
contextTokenBudget = resolveContextWindowInfo({
|
|
93
|
+
cfg: params.config,
|
|
94
|
+
provider: ceProvider,
|
|
95
|
+
modelId: ceModelId,
|
|
96
|
+
modelContextTokens: readPiModelContextTokens(ceModel),
|
|
97
|
+
modelContextWindow: ceRuntimeModel?.contextWindow,
|
|
98
|
+
defaultTokens: DEFAULT_CONTEXT_TOKENS
|
|
99
|
+
}).tokens;
|
|
100
|
+
}
|
|
101
|
+
const contextEngineRuntimeContext = buildCompactionContextEngineRuntimeContext({
|
|
102
|
+
params,
|
|
103
|
+
agentDir,
|
|
104
|
+
contextTokenBudget
|
|
105
|
+
});
|
|
106
|
+
const harnessResult = await maybeCompactAgentHarnessSession({
|
|
107
|
+
...params,
|
|
108
|
+
contextEngine,
|
|
109
|
+
contextTokenBudget,
|
|
110
|
+
contextEngineRuntimeContext
|
|
111
|
+
});
|
|
112
|
+
if (harnessResult) {
|
|
113
|
+
await contextEngine.dispose?.();
|
|
114
|
+
return harnessResult;
|
|
115
|
+
}
|
|
116
|
+
const sessionLane = resolveSessionLane(params.sessionKey?.trim() || params.sessionId);
|
|
117
|
+
const globalLane = resolveGlobalLane(params.lane);
|
|
118
|
+
const enqueueGlobal = params.enqueue ?? ((task, opts) => enqueueCommandInLane(globalLane, task, opts));
|
|
119
|
+
return enqueueCommandInLane(sessionLane, () => enqueueGlobal(async () => {
|
|
120
|
+
let checkpointSnapshot = null;
|
|
121
|
+
let checkpointSnapshotRetained = false;
|
|
122
|
+
try {
|
|
123
|
+
const engineOwnsCompaction = contextEngine.info.ownsCompaction === true;
|
|
124
|
+
checkpointSnapshot = engineOwnsCompaction ? captureCompactionCheckpointSnapshot({
|
|
125
|
+
sessionManager: SessionManager.open(params.sessionFile),
|
|
126
|
+
sessionFile: params.sessionFile
|
|
127
|
+
}) : null;
|
|
128
|
+
const hookRunner = engineOwnsCompaction ? asCompactionHookRunner(getGlobalHookRunner()) : null;
|
|
129
|
+
const hookSessionKey = params.sessionKey?.trim() || params.sessionId;
|
|
130
|
+
const { sessionAgentId } = resolveSessionAgentIds({
|
|
131
|
+
sessionKey: params.sessionKey,
|
|
132
|
+
config: params.config
|
|
133
|
+
});
|
|
134
|
+
const resolvedMessageProvider = params.messageChannel ?? params.messageProvider;
|
|
135
|
+
const hookCtx = {
|
|
136
|
+
sessionId: params.sessionId,
|
|
137
|
+
agentId: sessionAgentId,
|
|
138
|
+
sessionKey: hookSessionKey,
|
|
139
|
+
workspaceDir: resolveUserPath(params.workspaceDir),
|
|
140
|
+
messageProvider: resolvedMessageProvider
|
|
141
|
+
};
|
|
142
|
+
const runtimeContext = contextEngineRuntimeContext;
|
|
143
|
+
if (hookRunner?.hasHooks?.("before_compaction") && hookRunner.runBeforeCompaction) try {
|
|
144
|
+
await hookRunner.runBeforeCompaction({
|
|
145
|
+
messageCount: -1,
|
|
146
|
+
sessionFile: params.sessionFile
|
|
147
|
+
}, hookCtx);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
log.warn("before_compaction hook failed", { errorMessage: formatErrorMessage(err) });
|
|
150
|
+
}
|
|
151
|
+
const result = await contextEngine.compact({
|
|
152
|
+
sessionId: params.sessionId,
|
|
153
|
+
sessionKey: params.sessionKey,
|
|
154
|
+
sessionFile: params.sessionFile,
|
|
155
|
+
tokenBudget: contextTokenBudget,
|
|
156
|
+
currentTokenCount: params.currentTokenCount,
|
|
157
|
+
compactionTarget: params.trigger === "manual" ? "threshold" : "budget",
|
|
158
|
+
customInstructions: params.customInstructions,
|
|
159
|
+
force: params.trigger === "manual",
|
|
160
|
+
runtimeContext
|
|
161
|
+
});
|
|
162
|
+
if (result.ok && result.compacted) {
|
|
163
|
+
if (params.config && params.sessionKey && checkpointSnapshot) try {
|
|
164
|
+
const postLeafId = SessionManager.open(params.sessionFile).getLeafId() ?? void 0;
|
|
165
|
+
checkpointSnapshotRetained = await persistSessionCompactionCheckpoint({
|
|
166
|
+
cfg: params.config,
|
|
167
|
+
sessionKey: params.sessionKey,
|
|
168
|
+
sessionId: params.sessionId,
|
|
169
|
+
reason: resolveSessionCompactionCheckpointReason({ trigger: params.trigger }),
|
|
170
|
+
snapshot: checkpointSnapshot,
|
|
171
|
+
summary: result.result?.summary,
|
|
172
|
+
firstKeptEntryId: result.result?.firstKeptEntryId,
|
|
173
|
+
tokensBefore: result.result?.tokensBefore,
|
|
174
|
+
tokensAfter: result.result?.tokensAfter,
|
|
175
|
+
postSessionFile: params.sessionFile,
|
|
176
|
+
postLeafId,
|
|
177
|
+
postEntryId: postLeafId
|
|
178
|
+
}) !== null;
|
|
179
|
+
} catch (err) {
|
|
180
|
+
log.warn("failed to persist compaction checkpoint", { errorMessage: formatErrorMessage(err) });
|
|
181
|
+
}
|
|
182
|
+
await runContextEngineMaintenance({
|
|
183
|
+
contextEngine,
|
|
184
|
+
sessionId: params.sessionId,
|
|
185
|
+
sessionKey: params.sessionKey,
|
|
186
|
+
sessionFile: params.sessionFile,
|
|
187
|
+
reason: "compaction",
|
|
188
|
+
runtimeContext
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (engineOwnsCompaction && result.ok && result.compacted) await runPostCompactionSideEffects({
|
|
192
|
+
config: params.config,
|
|
193
|
+
sessionKey: params.sessionKey,
|
|
194
|
+
sessionFile: params.sessionFile
|
|
195
|
+
});
|
|
196
|
+
if (result.ok && result.compacted && hookRunner?.hasHooks?.("after_compaction") && hookRunner.runAfterCompaction) try {
|
|
197
|
+
await hookRunner.runAfterCompaction({
|
|
198
|
+
messageCount: -1,
|
|
199
|
+
compactedCount: -1,
|
|
200
|
+
tokenCount: result.result?.tokensAfter,
|
|
201
|
+
sessionFile: params.sessionFile
|
|
202
|
+
}, hookCtx);
|
|
203
|
+
} catch (err) {
|
|
204
|
+
log.warn("after_compaction hook failed", { errorMessage: formatErrorMessage(err) });
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
ok: result.ok,
|
|
208
|
+
compacted: result.compacted,
|
|
209
|
+
reason: result.reason,
|
|
210
|
+
result: result.result ? {
|
|
211
|
+
summary: result.result.summary ?? "",
|
|
212
|
+
firstKeptEntryId: result.result.firstKeptEntryId ?? "",
|
|
213
|
+
tokensBefore: result.result.tokensBefore,
|
|
214
|
+
tokensAfter: result.result.tokensAfter,
|
|
215
|
+
details: result.result.details
|
|
216
|
+
} : void 0
|
|
217
|
+
};
|
|
218
|
+
} finally {
|
|
219
|
+
if (!checkpointSnapshotRetained) await cleanupCompactionCheckpointSnapshot(checkpointSnapshot);
|
|
220
|
+
await contextEngine.dispose?.();
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
function buildCompactionContextEngineRuntimeContext(params) {
|
|
225
|
+
return {
|
|
226
|
+
...params.params,
|
|
227
|
+
...buildEmbeddedCompactionRuntimeContext({
|
|
228
|
+
sessionKey: params.params.sessionKey,
|
|
229
|
+
messageChannel: params.params.messageChannel,
|
|
230
|
+
messageProvider: params.params.messageProvider,
|
|
231
|
+
agentAccountId: params.params.agentAccountId,
|
|
232
|
+
currentChannelId: params.params.currentChannelId,
|
|
233
|
+
currentThreadTs: params.params.currentThreadTs,
|
|
234
|
+
currentMessageId: params.params.currentMessageId,
|
|
235
|
+
authProfileId: params.params.authProfileId,
|
|
236
|
+
workspaceDir: params.params.workspaceDir,
|
|
237
|
+
agentDir: params.agentDir,
|
|
238
|
+
config: params.params.config,
|
|
239
|
+
skillsSnapshot: params.params.skillsSnapshot,
|
|
240
|
+
senderIsOwner: params.params.senderIsOwner,
|
|
241
|
+
senderId: params.params.senderId,
|
|
242
|
+
provider: params.params.provider,
|
|
243
|
+
modelId: params.params.model,
|
|
244
|
+
thinkLevel: params.params.thinkLevel,
|
|
245
|
+
reasoningLevel: params.params.reasoningLevel,
|
|
246
|
+
bashElevated: params.params.bashElevated,
|
|
247
|
+
extraSystemPrompt: params.params.extraSystemPrompt,
|
|
248
|
+
ownerNumbers: params.params.ownerNumbers
|
|
249
|
+
}),
|
|
250
|
+
tokenBudget: params.contextTokenBudget,
|
|
251
|
+
currentTokenCount: params.params.currentTokenCount
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/agents/pi-embedded-runner/run/failover-policy.ts
|
|
256
|
+
function shouldEscalateRetryLimit(reason) {
|
|
257
|
+
return Boolean(reason && reason !== "timeout" && reason !== "model_not_found" && reason !== "format" && reason !== "session_expired");
|
|
258
|
+
}
|
|
259
|
+
function shouldRotatePrompt(params) {
|
|
260
|
+
return params.failoverFailure && params.failoverReason !== "timeout";
|
|
261
|
+
}
|
|
262
|
+
function shouldRotateAssistant(params) {
|
|
263
|
+
return !params.aborted && (params.failoverFailure || params.failoverReason !== null) || params.timedOut && !params.timedOutDuringCompaction;
|
|
264
|
+
}
|
|
265
|
+
function mergeRetryFailoverReason(params) {
|
|
266
|
+
return params.failoverReason ?? (params.timedOut ? "timeout" : null) ?? params.previous;
|
|
267
|
+
}
|
|
268
|
+
function resolveRunFailoverDecision(params) {
|
|
269
|
+
if (params.stage === "retry_limit") {
|
|
270
|
+
if (params.fallbackConfigured && shouldEscalateRetryLimit(params.failoverReason)) return {
|
|
271
|
+
action: "fallback_model",
|
|
272
|
+
reason: params.failoverReason ?? "unknown"
|
|
273
|
+
};
|
|
274
|
+
return { action: "return_error_payload" };
|
|
275
|
+
}
|
|
276
|
+
if (params.stage === "prompt") {
|
|
277
|
+
if (params.externalAbort) return {
|
|
278
|
+
action: "surface_error",
|
|
279
|
+
reason: params.failoverReason
|
|
280
|
+
};
|
|
281
|
+
if (!params.profileRotated && shouldRotatePrompt(params)) return {
|
|
282
|
+
action: "rotate_profile",
|
|
283
|
+
reason: params.failoverReason
|
|
284
|
+
};
|
|
285
|
+
if (params.fallbackConfigured && params.failoverFailure) return {
|
|
286
|
+
action: "fallback_model",
|
|
287
|
+
reason: params.failoverReason ?? "unknown"
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
action: "surface_error",
|
|
291
|
+
reason: params.failoverReason
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (params.externalAbort) return {
|
|
295
|
+
action: "surface_error",
|
|
296
|
+
reason: params.failoverReason
|
|
297
|
+
};
|
|
298
|
+
const assistantShouldRotate = shouldRotateAssistant(params);
|
|
299
|
+
if (!params.profileRotated && assistantShouldRotate) return {
|
|
300
|
+
action: "rotate_profile",
|
|
301
|
+
reason: params.failoverReason
|
|
302
|
+
};
|
|
303
|
+
if (assistantShouldRotate && params.fallbackConfigured) return {
|
|
304
|
+
action: "fallback_model",
|
|
305
|
+
reason: params.timedOut ? "timeout" : params.failoverReason ?? "unknown"
|
|
306
|
+
};
|
|
307
|
+
if (!assistantShouldRotate) return { action: "continue_normal" };
|
|
308
|
+
return {
|
|
309
|
+
action: "surface_error",
|
|
310
|
+
reason: params.failoverReason
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/agents/pi-embedded-runner/run/assistant-failover.ts
|
|
315
|
+
async function handleAssistantFailover(params) {
|
|
316
|
+
let overloadProfileRotations = params.overloadProfileRotations;
|
|
317
|
+
let decision = params.initialDecision;
|
|
318
|
+
const sameModelIdleTimeoutRetry = () => {
|
|
319
|
+
params.warn(`[llm-idle-timeout] ${sanitizeForLog(params.provider)}/${sanitizeForLog(params.modelId)} produced no reply before the idle watchdog; retrying same model`);
|
|
320
|
+
return {
|
|
321
|
+
action: "retry",
|
|
322
|
+
overloadProfileRotations,
|
|
323
|
+
retryKind: "same_model_idle_timeout",
|
|
324
|
+
lastRetryFailoverReason: mergeRetryFailoverReason({
|
|
325
|
+
previous: params.previousRetryFailoverReason,
|
|
326
|
+
failoverReason: params.failoverReason,
|
|
327
|
+
timedOut: true
|
|
328
|
+
})
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
if (decision.action === "rotate_profile") {
|
|
332
|
+
if (params.lastProfileId) {
|
|
333
|
+
const reason = params.timedOut ? "timeout" : params.assistantProfileFailureReason;
|
|
334
|
+
await params.maybeMarkAuthProfileFailure({
|
|
335
|
+
profileId: params.lastProfileId,
|
|
336
|
+
reason,
|
|
337
|
+
modelId: params.modelId
|
|
338
|
+
});
|
|
339
|
+
if (params.timedOut && !params.isProbeSession) params.warn(`Profile ${params.lastProfileId} timed out. Trying next account...`);
|
|
340
|
+
if (params.cloudCodeAssistFormatError) params.warn(`Profile ${params.lastProfileId} hit Cloud Code Assist format error. Tool calls will be sanitized on retry.`);
|
|
341
|
+
}
|
|
342
|
+
if (params.failoverReason === "overloaded") {
|
|
343
|
+
overloadProfileRotations += 1;
|
|
344
|
+
if (overloadProfileRotations > params.overloadProfileRotationLimit && params.fallbackConfigured) {
|
|
345
|
+
const status = resolveFailoverStatus("overloaded");
|
|
346
|
+
params.warn(`overload profile rotation cap reached for ${sanitizeForLog(params.provider)}/${sanitizeForLog(params.modelId)} after ${overloadProfileRotations} rotations; escalating to model fallback`);
|
|
347
|
+
params.logAssistantFailoverDecision("fallback_model", { status });
|
|
348
|
+
return {
|
|
349
|
+
action: "throw",
|
|
350
|
+
overloadProfileRotations,
|
|
351
|
+
error: new FailoverError("The AI service is temporarily overloaded. Please try again in a moment.", {
|
|
352
|
+
reason: "overloaded",
|
|
353
|
+
provider: params.activeErrorContext.provider,
|
|
354
|
+
model: params.activeErrorContext.model,
|
|
355
|
+
profileId: params.lastProfileId,
|
|
356
|
+
status,
|
|
357
|
+
rawError: params.lastAssistant?.errorMessage?.trim()
|
|
358
|
+
})
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (params.failoverReason === "rate_limit") params.maybeEscalateRateLimitProfileFallback({
|
|
363
|
+
failoverProvider: params.activeErrorContext.provider,
|
|
364
|
+
failoverModel: params.activeErrorContext.model,
|
|
365
|
+
logFallbackDecision: params.logAssistantFailoverDecision
|
|
366
|
+
});
|
|
367
|
+
if (await params.advanceAuthProfile()) {
|
|
368
|
+
params.logAssistantFailoverDecision("rotate_profile");
|
|
369
|
+
await params.maybeBackoffBeforeOverloadFailover(params.failoverReason);
|
|
370
|
+
return {
|
|
371
|
+
action: "retry",
|
|
372
|
+
overloadProfileRotations,
|
|
373
|
+
lastRetryFailoverReason: mergeRetryFailoverReason({
|
|
374
|
+
previous: params.previousRetryFailoverReason,
|
|
375
|
+
failoverReason: params.failoverReason,
|
|
376
|
+
timedOut: params.timedOut
|
|
377
|
+
})
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
if (params.idleTimedOut && params.allowSameModelIdleTimeoutRetry) return sameModelIdleTimeoutRetry();
|
|
381
|
+
decision = resolveRunFailoverDecision({
|
|
382
|
+
stage: "assistant",
|
|
383
|
+
aborted: params.aborted,
|
|
384
|
+
externalAbort: params.externalAbort,
|
|
385
|
+
fallbackConfigured: params.fallbackConfigured,
|
|
386
|
+
failoverFailure: params.failoverFailure,
|
|
387
|
+
failoverReason: params.failoverReason,
|
|
388
|
+
timedOut: params.timedOut,
|
|
389
|
+
timedOutDuringCompaction: params.timedOutDuringCompaction,
|
|
390
|
+
profileRotated: true
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (decision.action === "fallback_model") {
|
|
394
|
+
await params.maybeBackoffBeforeOverloadFailover(params.failoverReason);
|
|
395
|
+
const message = resolveAssistantFailoverErrorMessage(params);
|
|
396
|
+
const status = resolveFailoverStatus(decision.reason) ?? (isTimeoutErrorMessage(message) ? 408 : void 0);
|
|
397
|
+
params.logAssistantFailoverDecision("fallback_model", { status });
|
|
398
|
+
return {
|
|
399
|
+
action: "throw",
|
|
400
|
+
overloadProfileRotations,
|
|
401
|
+
error: new FailoverError(message, {
|
|
402
|
+
reason: decision.reason,
|
|
403
|
+
provider: params.activeErrorContext.provider,
|
|
404
|
+
model: params.activeErrorContext.model,
|
|
405
|
+
profileId: params.lastProfileId,
|
|
406
|
+
status,
|
|
407
|
+
rawError: params.lastAssistant?.errorMessage?.trim()
|
|
408
|
+
})
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (decision.action === "surface_error") {
|
|
412
|
+
if (!params.externalAbort && params.idleTimedOut && params.allowSameModelIdleTimeoutRetry) return sameModelIdleTimeoutRetry();
|
|
413
|
+
params.logAssistantFailoverDecision("surface_error");
|
|
414
|
+
if (!params.externalAbort && !params.timedOut) {
|
|
415
|
+
const message = resolveAssistantFailoverErrorMessage(params);
|
|
416
|
+
const reason = resolveSurfaceErrorReason(decision.reason, params);
|
|
417
|
+
const status = resolveFailoverStatus(reason) ?? (isTimeoutErrorMessage(message) ? 408 : void 0);
|
|
418
|
+
return {
|
|
419
|
+
action: "throw",
|
|
420
|
+
overloadProfileRotations,
|
|
421
|
+
error: new FailoverError(message, {
|
|
422
|
+
reason,
|
|
423
|
+
provider: params.activeErrorContext.provider,
|
|
424
|
+
model: params.activeErrorContext.model,
|
|
425
|
+
profileId: params.lastProfileId,
|
|
426
|
+
status,
|
|
427
|
+
rawError: params.lastAssistant?.errorMessage?.trim()
|
|
428
|
+
})
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
action: "continue_normal",
|
|
434
|
+
overloadProfileRotations
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function resolveAssistantFailoverErrorMessage(params) {
|
|
438
|
+
return (params.lastAssistant ? formatAssistantErrorText(params.lastAssistant, {
|
|
439
|
+
cfg: params.config,
|
|
440
|
+
sessionKey: params.sessionKey,
|
|
441
|
+
provider: params.activeErrorContext.provider,
|
|
442
|
+
model: params.activeErrorContext.model
|
|
443
|
+
}) : void 0) || params.lastAssistant?.errorMessage?.trim() || (params.timedOut ? "LLM request timed out." : params.rateLimitFailure ? "LLM request rate limited." : params.billingFailure ? formatBillingErrorMessage(params.activeErrorContext.provider, params.activeErrorContext.model) : params.authFailure ? "LLM request unauthorized." : "LLM request failed.");
|
|
444
|
+
}
|
|
445
|
+
function resolveSurfaceErrorReason(declared, params) {
|
|
446
|
+
if (declared) return declared;
|
|
447
|
+
if (params.billingFailure) return "billing";
|
|
448
|
+
if (params.authFailure) return "auth";
|
|
449
|
+
if (params.rateLimitFailure) return "rate_limit";
|
|
450
|
+
return "unknown";
|
|
451
|
+
}
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/agents/runtime-auth-refresh.ts
|
|
454
|
+
function clampRuntimeAuthRefreshDelayMs(params) {
|
|
455
|
+
return resolveSafeTimeoutDelayMs(params.refreshAt - params.now, { minMs: params.minDelayMs });
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/agents/pi-embedded-runner/usage-accumulator.ts
|
|
459
|
+
const createUsageAccumulator = () => ({
|
|
460
|
+
input: 0,
|
|
461
|
+
output: 0,
|
|
462
|
+
cacheRead: 0,
|
|
463
|
+
cacheWrite: 0,
|
|
464
|
+
total: 0,
|
|
465
|
+
lastInput: 0,
|
|
466
|
+
lastOutput: 0,
|
|
467
|
+
lastCacheRead: 0,
|
|
468
|
+
lastCacheWrite: 0,
|
|
469
|
+
lastTotal: 0
|
|
470
|
+
});
|
|
471
|
+
const hasUsageValues = (usage) => !!usage && [
|
|
472
|
+
usage.input,
|
|
473
|
+
usage.output,
|
|
474
|
+
usage.cacheRead,
|
|
475
|
+
usage.cacheWrite,
|
|
476
|
+
usage.total
|
|
477
|
+
].some((value) => typeof value === "number" && Number.isFinite(value) && value > 0);
|
|
478
|
+
const mergeUsageIntoAccumulator = (target, usage) => {
|
|
479
|
+
if (!hasUsageValues(usage)) return;
|
|
480
|
+
const callTotal = usage.total ?? (usage.input ?? 0) + (usage.output ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
|
|
481
|
+
target.input += usage.input ?? 0;
|
|
482
|
+
target.output += usage.output ?? 0;
|
|
483
|
+
target.cacheRead += usage.cacheRead ?? 0;
|
|
484
|
+
target.cacheWrite += usage.cacheWrite ?? 0;
|
|
485
|
+
target.total += callTotal;
|
|
486
|
+
target.lastInput = usage.input ?? 0;
|
|
487
|
+
target.lastOutput = usage.output ?? 0;
|
|
488
|
+
target.lastCacheRead = usage.cacheRead ?? 0;
|
|
489
|
+
target.lastCacheWrite = usage.cacheWrite ?? 0;
|
|
490
|
+
target.lastTotal = callTotal;
|
|
491
|
+
};
|
|
492
|
+
const toNormalizedUsage = (usage) => {
|
|
493
|
+
if (!(usage.input > 0 || usage.output > 0 || usage.cacheRead > 0 || usage.cacheWrite > 0 || usage.total > 0)) return;
|
|
494
|
+
return {
|
|
495
|
+
input: usage.input || void 0,
|
|
496
|
+
output: usage.output || void 0,
|
|
497
|
+
cacheRead: usage.cacheRead || void 0,
|
|
498
|
+
cacheWrite: usage.cacheWrite || void 0,
|
|
499
|
+
total: usage.total || void 0
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
const toLastCallUsage = (usage) => {
|
|
503
|
+
if (!(usage.lastInput > 0 || usage.lastOutput > 0 || usage.lastCacheRead > 0 || usage.lastCacheWrite > 0 || usage.lastTotal > 0)) return;
|
|
504
|
+
return {
|
|
505
|
+
input: usage.lastInput || void 0,
|
|
506
|
+
output: usage.lastOutput || void 0,
|
|
507
|
+
cacheRead: usage.lastCacheRead || void 0,
|
|
508
|
+
cacheWrite: usage.lastCacheWrite || void 0,
|
|
509
|
+
total: usage.lastTotal || void 0
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/agents/pi-embedded-runner/run/helpers.ts
|
|
514
|
+
const RUNTIME_AUTH_REFRESH_MARGIN_MS = 300 * 1e3;
|
|
515
|
+
const RUNTIME_AUTH_REFRESH_RETRY_MS = 60 * 1e3;
|
|
516
|
+
const RUNTIME_AUTH_REFRESH_MIN_DELAY_MS = 5 * 1e3;
|
|
517
|
+
function resolveOverloadFailoverBackoffMs(cfg) {
|
|
518
|
+
return cfg?.auth?.cooldowns?.overloadedBackoffMs ?? 0;
|
|
519
|
+
}
|
|
520
|
+
function resolveOverloadProfileRotationLimit(cfg) {
|
|
521
|
+
return cfg?.auth?.cooldowns?.overloadedProfileRotations ?? 1;
|
|
522
|
+
}
|
|
523
|
+
function resolveRateLimitProfileRotationLimit(cfg) {
|
|
524
|
+
return cfg?.auth?.cooldowns?.rateLimitedProfileRotations ?? 1;
|
|
525
|
+
}
|
|
526
|
+
const ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL = "ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL";
|
|
527
|
+
const ANTHROPIC_MAGIC_STRING_REPLACEMENT = "ANTHROPIC MAGIC STRING TRIGGER REFUSAL (redacted)";
|
|
528
|
+
function scrubAnthropicRefusalMagic(prompt) {
|
|
529
|
+
if (!prompt.includes(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL)) return prompt;
|
|
530
|
+
return prompt.replaceAll(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL, ANTHROPIC_MAGIC_STRING_REPLACEMENT);
|
|
531
|
+
}
|
|
532
|
+
function createCompactionDiagId() {
|
|
533
|
+
return `ovf-${Date.now().toString(36)}-${generateSecureToken(4)}`;
|
|
534
|
+
}
|
|
535
|
+
const BASE_RUN_RETRY_ITERATIONS = 24;
|
|
536
|
+
const RUN_RETRY_ITERATIONS_PER_PROFILE = 8;
|
|
537
|
+
const MIN_RUN_RETRY_ITERATIONS = 32;
|
|
538
|
+
const MAX_RUN_RETRY_ITERATIONS = 160;
|
|
539
|
+
function resolveMaxRunRetryIterations(profileCandidateCount) {
|
|
540
|
+
const scaled = BASE_RUN_RETRY_ITERATIONS + Math.max(1, profileCandidateCount) * RUN_RETRY_ITERATIONS_PER_PROFILE;
|
|
541
|
+
return Math.min(MAX_RUN_RETRY_ITERATIONS, Math.max(MIN_RUN_RETRY_ITERATIONS, scaled));
|
|
542
|
+
}
|
|
543
|
+
function resolveActiveErrorContext(params) {
|
|
544
|
+
const assistantProvider = params.assistant?.provider?.trim();
|
|
545
|
+
const assistantModel = params.assistant?.model?.trim();
|
|
546
|
+
return {
|
|
547
|
+
provider: assistantProvider || params.provider,
|
|
548
|
+
model: assistantModel || params.model
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function buildUsageAgentMetaFields(params) {
|
|
552
|
+
const usage = toNormalizedUsage(params.usageAccumulator);
|
|
553
|
+
if (usage && params.lastTurnTotal && params.lastTurnTotal > 0) usage.total = params.lastTurnTotal;
|
|
554
|
+
return {
|
|
555
|
+
usage,
|
|
556
|
+
lastCallUsage: normalizeUsage(params.lastAssistantUsage) ?? toLastCallUsage(params.usageAccumulator),
|
|
557
|
+
promptTokens: derivePromptTokens(params.lastRunPromptUsage)
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Build agentMeta for error return paths, preserving accumulated usage so that
|
|
562
|
+
* session totalTokens reflects the actual context size rather than going stale.
|
|
563
|
+
* Without this, error returns omit usage and the session keeps whatever
|
|
564
|
+
* totalTokens was set by the previous successful run.
|
|
565
|
+
*/
|
|
566
|
+
function buildErrorAgentMeta(params) {
|
|
567
|
+
const usageMeta = buildUsageAgentMetaFields({
|
|
568
|
+
usageAccumulator: params.usageAccumulator,
|
|
569
|
+
lastAssistantUsage: params.lastAssistant?.usage,
|
|
570
|
+
lastRunPromptUsage: params.lastRunPromptUsage,
|
|
571
|
+
lastTurnTotal: params.lastTurnTotal
|
|
572
|
+
});
|
|
573
|
+
return {
|
|
574
|
+
sessionId: params.sessionId,
|
|
575
|
+
provider: params.provider,
|
|
576
|
+
model: params.model,
|
|
577
|
+
...params.contextTokens ? { contextTokens: params.contextTokens } : {},
|
|
578
|
+
...usageMeta.usage ? { usage: usageMeta.usage } : {},
|
|
579
|
+
...usageMeta.lastCallUsage ? { lastCallUsage: usageMeta.lastCallUsage } : {},
|
|
580
|
+
...usageMeta.promptTokens ? { promptTokens: usageMeta.promptTokens } : {}
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function resolveFinalAssistantVisibleText(lastAssistant) {
|
|
584
|
+
if (!lastAssistant) return;
|
|
585
|
+
return extractAssistantVisibleText(lastAssistant).trim() || void 0;
|
|
586
|
+
}
|
|
587
|
+
function resolveFinalAssistantRawText(lastAssistant) {
|
|
588
|
+
if (!lastAssistant) return;
|
|
589
|
+
return (extractAssistantTextForPhase(lastAssistant, { phase: "final_answer" }) ?? extractAssistantTextForPhase(lastAssistant) ?? "").trim() || void 0;
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/agents/pi-embedded-runner/run/auth-controller.ts
|
|
593
|
+
function createEmbeddedRunAuthController(params) {
|
|
594
|
+
const applyPreparedRuntimeRequestOverrides = (paramsForApply) => {
|
|
595
|
+
if (!paramsForApply.preparedAuth.baseUrl && !paramsForApply.preparedAuth.request) return;
|
|
596
|
+
const runtimeRequestConfig = resolveProviderRequestConfig({
|
|
597
|
+
provider: paramsForApply.runtimeModel.provider,
|
|
598
|
+
api: paramsForApply.runtimeModel.api,
|
|
599
|
+
baseUrl: paramsForApply.preparedAuth.baseUrl ?? paramsForApply.runtimeModel.baseUrl,
|
|
600
|
+
providerHeaders: paramsForApply.runtimeModel.headers && typeof paramsForApply.runtimeModel.headers === "object" ? paramsForApply.runtimeModel.headers : void 0,
|
|
601
|
+
request: sanitizeRuntimeProviderRequestOverrides(paramsForApply.preparedAuth.request),
|
|
602
|
+
capability: "llm",
|
|
603
|
+
transport: "stream"
|
|
604
|
+
});
|
|
605
|
+
params.setRuntimeModel({
|
|
606
|
+
...paramsForApply.runtimeModel,
|
|
607
|
+
...paramsForApply.preparedAuth.baseUrl ? { baseUrl: paramsForApply.preparedAuth.baseUrl } : {},
|
|
608
|
+
...runtimeRequestConfig.headers ? { headers: runtimeRequestConfig.headers } : {}
|
|
609
|
+
});
|
|
610
|
+
params.setEffectiveModel({
|
|
611
|
+
...params.getEffectiveModel(),
|
|
612
|
+
...paramsForApply.preparedAuth.baseUrl ? { baseUrl: paramsForApply.preparedAuth.baseUrl } : {},
|
|
613
|
+
...runtimeRequestConfig.headers ? { headers: runtimeRequestConfig.headers } : {}
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
const hasRefreshableRuntimeAuth = () => Boolean(params.getRuntimeAuthState()?.sourceApiKey.trim());
|
|
617
|
+
const nextRuntimeAuthGeneration = () => (params.getRuntimeAuthState()?.generation ?? 0) + 1;
|
|
618
|
+
const prepareRuntimeAuthForModel = async (prepareParams) => prepareProviderRuntimeAuth({
|
|
619
|
+
provider: prepareParams.runtimeModel.provider,
|
|
620
|
+
config: params.config,
|
|
621
|
+
workspaceDir: params.workspaceDir,
|
|
622
|
+
env: process.env,
|
|
623
|
+
context: {
|
|
624
|
+
config: params.config,
|
|
625
|
+
agentDir: params.agentDir,
|
|
626
|
+
workspaceDir: params.workspaceDir,
|
|
627
|
+
env: process.env,
|
|
628
|
+
provider: prepareParams.runtimeModel.provider,
|
|
629
|
+
modelId: params.getModelId(),
|
|
630
|
+
model: prepareParams.runtimeModel,
|
|
631
|
+
apiKey: prepareParams.apiKey,
|
|
632
|
+
authMode: prepareParams.authMode,
|
|
633
|
+
profileId: prepareParams.profileId
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
const clearRuntimeAuthRefreshTimer = () => {
|
|
637
|
+
const runtimeAuthState = params.getRuntimeAuthState();
|
|
638
|
+
if (!runtimeAuthState?.refreshTimer) return;
|
|
639
|
+
clearTimeout(runtimeAuthState.refreshTimer);
|
|
640
|
+
runtimeAuthState.refreshTimer = void 0;
|
|
641
|
+
};
|
|
642
|
+
const stopRuntimeAuthRefreshTimer = () => {
|
|
643
|
+
if (!params.getRuntimeAuthState()) return;
|
|
644
|
+
params.setRuntimeAuthRefreshCancelled(true);
|
|
645
|
+
clearRuntimeAuthRefreshTimer();
|
|
646
|
+
};
|
|
647
|
+
const refreshRuntimeAuth = async (reason) => {
|
|
648
|
+
const runtimeAuthState = params.getRuntimeAuthState();
|
|
649
|
+
if (!runtimeAuthState) return;
|
|
650
|
+
if (runtimeAuthState.refreshInFlight) {
|
|
651
|
+
await runtimeAuthState.refreshInFlight;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const refreshGeneration = runtimeAuthState.generation;
|
|
655
|
+
const refreshProfileId = runtimeAuthState.profileId;
|
|
656
|
+
let refreshPromise;
|
|
657
|
+
refreshPromise = (async () => {
|
|
658
|
+
const currentRuntimeAuthState = params.getRuntimeAuthState();
|
|
659
|
+
const sourceApiKey = currentRuntimeAuthState?.sourceApiKey.trim() ?? "";
|
|
660
|
+
if (!sourceApiKey) throw new Error(`Runtime auth refresh requires a source credential.`);
|
|
661
|
+
const runtimeModel = params.getRuntimeModel();
|
|
662
|
+
params.log.debug(`Refreshing runtime auth for ${runtimeModel.provider} (${reason})...`);
|
|
663
|
+
const preparedAuth = await prepareRuntimeAuthForModel({
|
|
664
|
+
runtimeModel,
|
|
665
|
+
apiKey: sourceApiKey,
|
|
666
|
+
authMode: currentRuntimeAuthState?.authMode ?? "unknown",
|
|
667
|
+
profileId: currentRuntimeAuthState?.profileId
|
|
668
|
+
});
|
|
669
|
+
if (!preparedAuth?.apiKey) throw new Error(`Provider "${runtimeModel.provider}" does not support runtime auth refresh.`);
|
|
670
|
+
const activeRuntimeAuthState = params.getRuntimeAuthState();
|
|
671
|
+
if (!activeRuntimeAuthState || activeRuntimeAuthState.generation !== refreshGeneration || activeRuntimeAuthState.profileId !== refreshProfileId || activeRuntimeAuthState.sourceApiKey.trim() !== sourceApiKey) {
|
|
672
|
+
params.log.debug(`Ignoring stale runtime auth refresh for ${runtimeModel.provider}; auth state advanced before ${reason} refresh completed.`);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
params.authStorage.setRuntimeApiKey(runtimeModel.provider, preparedAuth.apiKey);
|
|
676
|
+
applyPreparedRuntimeRequestOverrides({
|
|
677
|
+
runtimeModel,
|
|
678
|
+
preparedAuth
|
|
679
|
+
});
|
|
680
|
+
params.setRuntimeAuthState({
|
|
681
|
+
...activeRuntimeAuthState,
|
|
682
|
+
expiresAt: preparedAuth.expiresAt
|
|
683
|
+
});
|
|
684
|
+
if (preparedAuth.expiresAt) {
|
|
685
|
+
const remaining = preparedAuth.expiresAt - Date.now();
|
|
686
|
+
params.log.debug(`Runtime auth refreshed for ${runtimeModel.provider}; expires in ${Math.max(0, Math.floor(remaining / 1e3))}s.`);
|
|
687
|
+
}
|
|
688
|
+
})().catch((err) => {
|
|
689
|
+
const runtimeModel = params.getRuntimeModel();
|
|
690
|
+
params.log.warn(`Runtime auth refresh failed for ${runtimeModel.provider}: ${formatErrorMessage(err)}`);
|
|
691
|
+
throw err;
|
|
692
|
+
}).finally(() => {
|
|
693
|
+
const activeState = params.getRuntimeAuthState();
|
|
694
|
+
if (activeState && activeState.generation === refreshGeneration && activeState.refreshInFlight === refreshPromise) activeState.refreshInFlight = void 0;
|
|
695
|
+
});
|
|
696
|
+
runtimeAuthState.refreshInFlight = refreshPromise;
|
|
697
|
+
await refreshPromise;
|
|
698
|
+
};
|
|
699
|
+
const scheduleRuntimeAuthRefresh = () => {
|
|
700
|
+
const runtimeAuthState = params.getRuntimeAuthState();
|
|
701
|
+
if (!runtimeAuthState || params.getRuntimeAuthRefreshCancelled()) return;
|
|
702
|
+
const runtimeModel = params.getRuntimeModel();
|
|
703
|
+
if (!hasRefreshableRuntimeAuth()) {
|
|
704
|
+
params.log.warn(`Skipping runtime auth refresh scheduling for ${runtimeModel.provider}; source credential missing.`);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (!runtimeAuthState.expiresAt) return;
|
|
708
|
+
clearRuntimeAuthRefreshTimer();
|
|
709
|
+
const now = Date.now();
|
|
710
|
+
const delayMs = clampRuntimeAuthRefreshDelayMs({
|
|
711
|
+
refreshAt: runtimeAuthState.expiresAt - RUNTIME_AUTH_REFRESH_MARGIN_MS,
|
|
712
|
+
now,
|
|
713
|
+
minDelayMs: RUNTIME_AUTH_REFRESH_MIN_DELAY_MS
|
|
714
|
+
});
|
|
715
|
+
const timer = setTimeout(() => {
|
|
716
|
+
if (params.getRuntimeAuthRefreshCancelled()) return;
|
|
717
|
+
refreshRuntimeAuth("scheduled").then(() => scheduleRuntimeAuthRefresh()).catch(() => {
|
|
718
|
+
if (params.getRuntimeAuthRefreshCancelled()) return;
|
|
719
|
+
const retryTimer = setTimeout(() => {
|
|
720
|
+
if (params.getRuntimeAuthRefreshCancelled()) return;
|
|
721
|
+
refreshRuntimeAuth("scheduled-retry").then(() => scheduleRuntimeAuthRefresh()).catch(() => void 0);
|
|
722
|
+
}, RUNTIME_AUTH_REFRESH_RETRY_MS);
|
|
723
|
+
const activeRuntimeAuthState = params.getRuntimeAuthState();
|
|
724
|
+
if (activeRuntimeAuthState) activeRuntimeAuthState.refreshTimer = retryTimer;
|
|
725
|
+
if (params.getRuntimeAuthRefreshCancelled() && activeRuntimeAuthState) {
|
|
726
|
+
clearTimeout(retryTimer);
|
|
727
|
+
activeRuntimeAuthState.refreshTimer = void 0;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}, delayMs);
|
|
731
|
+
runtimeAuthState.refreshTimer = timer;
|
|
732
|
+
if (params.getRuntimeAuthRefreshCancelled()) {
|
|
733
|
+
clearTimeout(timer);
|
|
734
|
+
runtimeAuthState.refreshTimer = void 0;
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
const resolveAuthProfileFailoverReason = (failoverParams) => {
|
|
738
|
+
if (failoverParams.allInCooldown) {
|
|
739
|
+
const profileIds = (failoverParams.profileIds ?? params.profileCandidates).filter((id) => typeof id === "string" && id.length > 0);
|
|
740
|
+
return resolveProfilesUnavailableReason({
|
|
741
|
+
store: params.authStore,
|
|
742
|
+
profileIds
|
|
743
|
+
}) ?? "unknown";
|
|
744
|
+
}
|
|
745
|
+
return classifyFailoverReason(failoverParams.message, { provider: params.getProvider() }) ?? "auth";
|
|
746
|
+
};
|
|
747
|
+
const throwAuthProfileFailover = (failoverParams) => {
|
|
748
|
+
const provider = params.getProvider();
|
|
749
|
+
const modelId = params.getModelId();
|
|
750
|
+
const fallbackMessage = `No available auth profile for ${provider} (all in cooldown or unavailable).`;
|
|
751
|
+
const message = failoverParams.message?.trim() || (failoverParams.error ? formatErrorMessage(failoverParams.error).trim() : "") || fallbackMessage;
|
|
752
|
+
const reason = resolveAuthProfileFailoverReason({
|
|
753
|
+
allInCooldown: failoverParams.allInCooldown,
|
|
754
|
+
message,
|
|
755
|
+
profileIds: params.profileCandidates
|
|
756
|
+
});
|
|
757
|
+
if (params.fallbackConfigured) throw new FailoverError(message, {
|
|
758
|
+
reason,
|
|
759
|
+
provider,
|
|
760
|
+
model: modelId,
|
|
761
|
+
status: resolveFailoverStatus(reason),
|
|
762
|
+
cause: failoverParams.error
|
|
763
|
+
});
|
|
764
|
+
if (failoverParams.error instanceof Error) throw failoverParams.error;
|
|
765
|
+
throw new Error(message);
|
|
766
|
+
};
|
|
767
|
+
const resolveApiKeyForCandidate = async (candidate) => {
|
|
768
|
+
return getApiKeyForModel({
|
|
769
|
+
model: params.getRuntimeModel(),
|
|
770
|
+
cfg: params.config,
|
|
771
|
+
profileId: candidate,
|
|
772
|
+
store: params.authStore,
|
|
773
|
+
agentDir: params.agentDir,
|
|
774
|
+
lockedProfile: candidate != null && candidate === params.lockedProfileId
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
const applyApiKeyInfo = async (candidate) => {
|
|
778
|
+
const apiKeyInfo = await resolveApiKeyForCandidate(candidate);
|
|
779
|
+
params.setApiKeyInfo(apiKeyInfo);
|
|
780
|
+
const resolvedProfileId = apiKeyInfo.profileId ?? candidate;
|
|
781
|
+
if (!apiKeyInfo.apiKey) {
|
|
782
|
+
if (apiKeyInfo.mode !== "aws-sdk") {
|
|
783
|
+
const runtimeModel = params.getRuntimeModel();
|
|
784
|
+
throw new Error(`No API key resolved for provider "${runtimeModel.provider}" (auth mode: ${apiKeyInfo.mode}).`);
|
|
785
|
+
}
|
|
786
|
+
const runtimeModel = params.getRuntimeModel();
|
|
787
|
+
const AWS_SDK_AUTH_SENTINEL = "__aws_sdk_auth__";
|
|
788
|
+
try {
|
|
789
|
+
const preparedAuth = await prepareRuntimeAuthForModel({
|
|
790
|
+
runtimeModel,
|
|
791
|
+
apiKey: AWS_SDK_AUTH_SENTINEL,
|
|
792
|
+
authMode: apiKeyInfo.mode,
|
|
793
|
+
profileId: apiKeyInfo.profileId
|
|
794
|
+
});
|
|
795
|
+
applyPreparedRuntimeRequestOverrides({
|
|
796
|
+
runtimeModel,
|
|
797
|
+
preparedAuth: preparedAuth ?? {}
|
|
798
|
+
});
|
|
799
|
+
if (preparedAuth?.apiKey) {
|
|
800
|
+
clearRuntimeAuthRefreshTimer();
|
|
801
|
+
params.authStorage.setRuntimeApiKey(runtimeModel.provider, preparedAuth.apiKey);
|
|
802
|
+
params.setRuntimeAuthState({
|
|
803
|
+
generation: nextRuntimeAuthGeneration(),
|
|
804
|
+
sourceApiKey: AWS_SDK_AUTH_SENTINEL,
|
|
805
|
+
authMode: apiKeyInfo.mode,
|
|
806
|
+
profileId: resolvedProfileId,
|
|
807
|
+
expiresAt: preparedAuth.expiresAt
|
|
808
|
+
});
|
|
809
|
+
if (preparedAuth.expiresAt) scheduleRuntimeAuthRefresh();
|
|
810
|
+
params.setLastProfileId(resolvedProfileId);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
} catch (error) {
|
|
814
|
+
params.log.warn(`prepareProviderRuntimeAuth failed for ${runtimeModel.provider}, falling back to sentinel: ${formatErrorMessage(error)}`);
|
|
815
|
+
}
|
|
816
|
+
clearRuntimeAuthRefreshTimer();
|
|
817
|
+
params.authStorage.setRuntimeApiKey(runtimeModel.provider, AWS_SDK_AUTH_SENTINEL);
|
|
818
|
+
params.setRuntimeAuthState(null);
|
|
819
|
+
params.setLastProfileId(resolvedProfileId);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
let runtimeAuthHandled = false;
|
|
823
|
+
const runtimeModel = params.getRuntimeModel();
|
|
824
|
+
const preparedAuth = await prepareRuntimeAuthForModel({
|
|
825
|
+
runtimeModel,
|
|
826
|
+
apiKey: apiKeyInfo.apiKey,
|
|
827
|
+
authMode: apiKeyInfo.mode,
|
|
828
|
+
profileId: apiKeyInfo.profileId
|
|
829
|
+
});
|
|
830
|
+
applyPreparedRuntimeRequestOverrides({
|
|
831
|
+
runtimeModel,
|
|
832
|
+
preparedAuth: preparedAuth ?? {}
|
|
833
|
+
});
|
|
834
|
+
if (preparedAuth?.apiKey) {
|
|
835
|
+
clearRuntimeAuthRefreshTimer();
|
|
836
|
+
params.authStorage.setRuntimeApiKey(runtimeModel.provider, preparedAuth.apiKey);
|
|
837
|
+
params.setRuntimeAuthState({
|
|
838
|
+
generation: nextRuntimeAuthGeneration(),
|
|
839
|
+
sourceApiKey: apiKeyInfo.apiKey,
|
|
840
|
+
authMode: apiKeyInfo.mode,
|
|
841
|
+
profileId: apiKeyInfo.profileId,
|
|
842
|
+
expiresAt: preparedAuth.expiresAt
|
|
843
|
+
});
|
|
844
|
+
if (preparedAuth.expiresAt) scheduleRuntimeAuthRefresh();
|
|
845
|
+
runtimeAuthHandled = true;
|
|
846
|
+
}
|
|
847
|
+
if (!runtimeAuthHandled) {
|
|
848
|
+
clearRuntimeAuthRefreshTimer();
|
|
849
|
+
params.authStorage.setRuntimeApiKey(runtimeModel.provider, apiKeyInfo.apiKey);
|
|
850
|
+
params.setRuntimeAuthState(null);
|
|
851
|
+
}
|
|
852
|
+
params.setLastProfileId(apiKeyInfo.profileId);
|
|
853
|
+
};
|
|
854
|
+
const advanceAuthProfile = async () => {
|
|
855
|
+
if (params.lockedProfileId) return false;
|
|
856
|
+
let nextIndex = params.getProfileIndex() + 1;
|
|
857
|
+
while (nextIndex < params.profileCandidates.length) {
|
|
858
|
+
const candidate = params.profileCandidates[nextIndex];
|
|
859
|
+
if (candidate && isProfileInCooldown(params.authStore, candidate, void 0, params.getModelId())) {
|
|
860
|
+
nextIndex += 1;
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
try {
|
|
864
|
+
await applyApiKeyInfo(candidate);
|
|
865
|
+
params.setProfileIndex(nextIndex);
|
|
866
|
+
params.setThinkLevel(params.initialThinkLevel);
|
|
867
|
+
params.attemptedThinking.clear();
|
|
868
|
+
return true;
|
|
869
|
+
} catch (err) {
|
|
870
|
+
if (candidate && candidate === params.lockedProfileId) throw err;
|
|
871
|
+
nextIndex += 1;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return false;
|
|
875
|
+
};
|
|
876
|
+
const initializeAuthProfile = async () => {
|
|
877
|
+
try {
|
|
878
|
+
const autoProfileCandidates = params.profileCandidates.filter((candidate) => typeof candidate === "string" && candidate.length > 0 && candidate !== params.lockedProfileId);
|
|
879
|
+
const modelId = params.getModelId();
|
|
880
|
+
const allAutoProfilesInCooldown = autoProfileCandidates.length > 0 && autoProfileCandidates.every((candidate) => isProfileInCooldown(params.authStore, candidate, void 0, modelId));
|
|
881
|
+
const unavailableReason = allAutoProfilesInCooldown ? resolveProfilesUnavailableReason({
|
|
882
|
+
store: params.authStore,
|
|
883
|
+
profileIds: autoProfileCandidates
|
|
884
|
+
}) ?? "unknown" : null;
|
|
885
|
+
const allowTransientCooldownProbe = params.allowTransientCooldownProbe && allAutoProfilesInCooldown && shouldAllowCooldownProbeForReason(unavailableReason);
|
|
886
|
+
let didTransientCooldownProbe = false;
|
|
887
|
+
while (params.getProfileIndex() < params.profileCandidates.length) {
|
|
888
|
+
const candidate = params.profileCandidates[params.getProfileIndex()];
|
|
889
|
+
if (candidate && candidate !== params.lockedProfileId && isProfileInCooldown(params.authStore, candidate, void 0, modelId)) if (allowTransientCooldownProbe && !didTransientCooldownProbe) {
|
|
890
|
+
didTransientCooldownProbe = true;
|
|
891
|
+
params.log.warn(`probing cooldowned auth profile for ${params.getProvider()}/${modelId} due to ${unavailableReason ?? "transient"} unavailability`);
|
|
892
|
+
} else {
|
|
893
|
+
params.setProfileIndex(params.getProfileIndex() + 1);
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
await applyApiKeyInfo(params.profileCandidates[params.getProfileIndex()]);
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
if (params.getProfileIndex() >= params.profileCandidates.length) throwAuthProfileFailover({ allInCooldown: true });
|
|
900
|
+
} catch (err) {
|
|
901
|
+
if (err instanceof FailoverError) throw err;
|
|
902
|
+
if (params.profileCandidates[params.getProfileIndex()] === params.lockedProfileId) throwAuthProfileFailover({
|
|
903
|
+
allInCooldown: false,
|
|
904
|
+
error: err
|
|
905
|
+
});
|
|
906
|
+
if (!await advanceAuthProfile()) throwAuthProfileFailover({
|
|
907
|
+
allInCooldown: false,
|
|
908
|
+
error: err
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
const maybeRefreshRuntimeAuthForAuthError = async (errorText, retried) => {
|
|
913
|
+
if (!params.getRuntimeAuthState() || retried) return false;
|
|
914
|
+
if (!isFailoverErrorMessage(errorText, { provider: params.getProvider() })) return false;
|
|
915
|
+
if (classifyFailoverReason(errorText, { provider: params.getProvider() }) !== "auth") return false;
|
|
916
|
+
try {
|
|
917
|
+
await refreshRuntimeAuth("auth-error");
|
|
918
|
+
scheduleRuntimeAuthRefresh();
|
|
919
|
+
return true;
|
|
920
|
+
} catch {
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
return {
|
|
925
|
+
advanceAuthProfile,
|
|
926
|
+
initializeAuthProfile,
|
|
927
|
+
maybeRefreshRuntimeAuthForAuthError,
|
|
928
|
+
stopRuntimeAuthRefreshTimer
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
//#endregion
|
|
932
|
+
//#region src/agents/pi-embedded-runner/run/backend.ts
|
|
933
|
+
async function runEmbeddedAttemptWithBackend(params) {
|
|
934
|
+
return runAgentHarnessAttemptWithFallback(params);
|
|
935
|
+
}
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region src/agents/pi-embedded-runner/run/failover-observation.ts
|
|
938
|
+
function normalizeFailoverDecisionObservationBase(base) {
|
|
939
|
+
return {
|
|
940
|
+
...base,
|
|
941
|
+
failoverReason: base.failoverReason ?? (base.timedOut ? "timeout" : null),
|
|
942
|
+
profileFailureReason: base.profileFailureReason ?? (base.timedOut ? "timeout" : null)
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function createFailoverDecisionLogger(base) {
|
|
946
|
+
const normalizedBase = normalizeFailoverDecisionObservationBase(base);
|
|
947
|
+
const safeProfileId = normalizedBase.profileId ? redactIdentifier(normalizedBase.profileId, { len: 12 }) : void 0;
|
|
948
|
+
const safeRunId = sanitizeForConsole(normalizedBase.runId) ?? "-";
|
|
949
|
+
const safeProvider = sanitizeForConsole(normalizedBase.provider) ?? "-";
|
|
950
|
+
const safeModel = sanitizeForConsole(normalizedBase.model) ?? "-";
|
|
951
|
+
const safeSourceProvider = sanitizeForConsole(normalizedBase.sourceProvider) ?? safeProvider;
|
|
952
|
+
const safeSourceModel = sanitizeForConsole(normalizedBase.sourceModel) ?? safeModel;
|
|
953
|
+
const profileText = safeProfileId ?? "-";
|
|
954
|
+
const reasonText = normalizedBase.failoverReason ?? "none";
|
|
955
|
+
const sourceChanged = safeSourceProvider !== safeProvider || safeSourceModel !== safeModel;
|
|
956
|
+
return (decision, extra) => {
|
|
957
|
+
const observedError = buildApiErrorObservationFields(normalizedBase.rawError);
|
|
958
|
+
const safeRawErrorPreview = sanitizeForConsole(observedError.rawErrorPreview);
|
|
959
|
+
const shouldSuppressRawErrorConsoleSuffix = observedError.providerRuntimeFailureKind === "auth_html_403" || observedError.providerRuntimeFailureKind === "auth_scope" || observedError.providerRuntimeFailureKind === "auth_refresh";
|
|
960
|
+
const rawErrorConsoleSuffix = safeRawErrorPreview && !shouldSuppressRawErrorConsoleSuffix ? ` rawError=${safeRawErrorPreview}` : "";
|
|
961
|
+
log.warn("embedded run failover decision", {
|
|
962
|
+
event: "embedded_run_failover_decision",
|
|
963
|
+
tags: [
|
|
964
|
+
"error_handling",
|
|
965
|
+
"failover",
|
|
966
|
+
normalizedBase.stage,
|
|
967
|
+
decision
|
|
968
|
+
],
|
|
969
|
+
runId: normalizedBase.runId,
|
|
970
|
+
stage: normalizedBase.stage,
|
|
971
|
+
decision,
|
|
972
|
+
failoverReason: normalizedBase.failoverReason,
|
|
973
|
+
profileFailureReason: normalizedBase.profileFailureReason,
|
|
974
|
+
provider: normalizedBase.provider,
|
|
975
|
+
model: normalizedBase.model,
|
|
976
|
+
sourceProvider: normalizedBase.sourceProvider ?? normalizedBase.provider,
|
|
977
|
+
sourceModel: normalizedBase.sourceModel ?? normalizedBase.model,
|
|
978
|
+
profileId: safeProfileId,
|
|
979
|
+
fallbackConfigured: normalizedBase.fallbackConfigured,
|
|
980
|
+
timedOut: normalizedBase.timedOut,
|
|
981
|
+
aborted: normalizedBase.aborted,
|
|
982
|
+
status: extra?.status,
|
|
983
|
+
...observedError,
|
|
984
|
+
consoleMessage: `embedded run failover decision: runId=${safeRunId} stage=${normalizedBase.stage} decision=${decision} reason=${reasonText} from=${safeSourceProvider}/${safeSourceModel}${sourceChanged ? ` to=${safeProvider}/${safeModel}` : ""} profile=${profileText}${rawErrorConsoleSuffix}`
|
|
985
|
+
});
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/agents/tool-error-summary.ts
|
|
990
|
+
const EXEC_LIKE_TOOL_NAMES = new Set(["exec", "bash"]);
|
|
991
|
+
function isExecLikeToolName(toolName) {
|
|
992
|
+
return EXEC_LIKE_TOOL_NAMES.has(normalizeOptionalLowercaseString(toolName) ?? "");
|
|
993
|
+
}
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region src/agents/pi-embedded-runner/run/payloads.ts
|
|
996
|
+
const RECOVERABLE_TOOL_ERROR_KEYWORDS = [
|
|
997
|
+
"required",
|
|
998
|
+
"missing",
|
|
999
|
+
"invalid",
|
|
1000
|
+
"must be",
|
|
1001
|
+
"must have",
|
|
1002
|
+
"needs",
|
|
1003
|
+
"requires"
|
|
1004
|
+
];
|
|
1005
|
+
function isRecoverableToolError(error) {
|
|
1006
|
+
const errorLower = normalizeOptionalLowercaseString(error) ?? "";
|
|
1007
|
+
return RECOVERABLE_TOOL_ERROR_KEYWORDS.some((keyword) => errorLower.includes(keyword));
|
|
1008
|
+
}
|
|
1009
|
+
function isVerboseToolDetailEnabled(level) {
|
|
1010
|
+
return level === "on" || level === "full";
|
|
1011
|
+
}
|
|
1012
|
+
function resolveRawAssistantAnswerText(lastAssistant) {
|
|
1013
|
+
if (!lastAssistant) return "";
|
|
1014
|
+
return normalizeOptionalString(extractAssistantTextForPhase(lastAssistant, { phase: "final_answer" }) ?? extractAssistantTextForPhase(lastAssistant)) ?? "";
|
|
1015
|
+
}
|
|
1016
|
+
function shouldIncludeToolErrorDetails(params) {
|
|
1017
|
+
if (isVerboseToolDetailEnabled(params.verboseLevel)) return true;
|
|
1018
|
+
return isExecLikeToolName(params.lastToolError.toolName) && params.lastToolError.timedOut === true && (params.isCronTrigger === true || isCronSessionKey(params.sessionKey));
|
|
1019
|
+
}
|
|
1020
|
+
function resolveToolErrorWarningPolicy(params) {
|
|
1021
|
+
const normalizedToolName = normalizeOptionalLowercaseString(params.lastToolError.toolName) ?? "";
|
|
1022
|
+
const includeDetails = shouldIncludeToolErrorDetails(params);
|
|
1023
|
+
if (params.suppressToolErrorWarnings) return {
|
|
1024
|
+
showWarning: false,
|
|
1025
|
+
includeDetails
|
|
1026
|
+
};
|
|
1027
|
+
if (isExecLikeToolName(params.lastToolError.toolName) && !includeDetails) return {
|
|
1028
|
+
showWarning: false,
|
|
1029
|
+
includeDetails
|
|
1030
|
+
};
|
|
1031
|
+
if (normalizedToolName === "sessions_send") return {
|
|
1032
|
+
showWarning: false,
|
|
1033
|
+
includeDetails
|
|
1034
|
+
};
|
|
1035
|
+
if (params.lastToolError.mutatingAction ?? isLikelyMutatingToolName(params.lastToolError.toolName)) return {
|
|
1036
|
+
showWarning: true,
|
|
1037
|
+
includeDetails
|
|
1038
|
+
};
|
|
1039
|
+
if (params.suppressToolErrors) return {
|
|
1040
|
+
showWarning: false,
|
|
1041
|
+
includeDetails
|
|
1042
|
+
};
|
|
1043
|
+
return {
|
|
1044
|
+
showWarning: !params.hasUserFacingReply && !isRecoverableToolError(params.lastToolError.error),
|
|
1045
|
+
includeDetails
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function buildEmbeddedRunPayloads(params) {
|
|
1049
|
+
const replyItems = [];
|
|
1050
|
+
const useMarkdown = params.toolResultFormat === "markdown";
|
|
1051
|
+
const suppressAssistantArtifacts = params.didSendDeterministicApprovalPrompt === true;
|
|
1052
|
+
const lastAssistantErrored = params.lastAssistant?.stopReason === "error";
|
|
1053
|
+
const errorText = params.lastAssistant && lastAssistantErrored ? suppressAssistantArtifacts ? void 0 : formatAssistantErrorText(params.lastAssistant, {
|
|
1054
|
+
cfg: params.config,
|
|
1055
|
+
sessionKey: params.sessionKey,
|
|
1056
|
+
provider: params.provider,
|
|
1057
|
+
model: params.model
|
|
1058
|
+
}) : void 0;
|
|
1059
|
+
const rawErrorMessage = lastAssistantErrored ? normalizeOptionalString(params.lastAssistant?.errorMessage) : void 0;
|
|
1060
|
+
const rawErrorFingerprint = rawErrorMessage ? getApiErrorPayloadFingerprint(rawErrorMessage) : null;
|
|
1061
|
+
const formattedRawErrorMessage = rawErrorMessage ? formatRawAssistantErrorForUi(rawErrorMessage) : null;
|
|
1062
|
+
const normalizedFormattedRawErrorMessage = formattedRawErrorMessage ? normalizeTextForComparison(formattedRawErrorMessage) : null;
|
|
1063
|
+
const normalizedRawErrorText = rawErrorMessage ? normalizeTextForComparison(rawErrorMessage) : null;
|
|
1064
|
+
const normalizedErrorText = errorText ? normalizeTextForComparison(errorText) : null;
|
|
1065
|
+
const normalizedGenericBillingErrorText = normalizeTextForComparison(BILLING_ERROR_USER_MESSAGE);
|
|
1066
|
+
const genericErrorText = "The AI service returned an error. Please try again.";
|
|
1067
|
+
if (errorText) replyItems.push({
|
|
1068
|
+
text: errorText,
|
|
1069
|
+
isError: true
|
|
1070
|
+
});
|
|
1071
|
+
if (params.inlineToolResultsAllowed && params.verboseLevel !== "off" && params.toolMetas.length > 0) for (const { toolName, meta } of params.toolMetas) {
|
|
1072
|
+
const { text: cleanedText, mediaUrls, audioAsVoice, replyToId, replyToTag, replyToCurrent } = parseReplyDirectives(formatToolAggregate(toolName, meta ? [meta] : [], { markdown: useMarkdown }));
|
|
1073
|
+
if (cleanedText) replyItems.push({
|
|
1074
|
+
text: cleanedText,
|
|
1075
|
+
media: mediaUrls,
|
|
1076
|
+
audioAsVoice,
|
|
1077
|
+
replyToId,
|
|
1078
|
+
replyToTag,
|
|
1079
|
+
replyToCurrent
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
const reasoningText = suppressAssistantArtifacts ? "" : params.lastAssistant && params.reasoningLevel === "on" ? formatReasoningMessage(extractAssistantThinking(params.lastAssistant)) : "";
|
|
1083
|
+
if (reasoningText) replyItems.push({
|
|
1084
|
+
text: reasoningText,
|
|
1085
|
+
isReasoning: true
|
|
1086
|
+
});
|
|
1087
|
+
const fallbackAnswerText = params.lastAssistant ? extractAssistantVisibleText(params.lastAssistant) : "";
|
|
1088
|
+
const fallbackRawAnswerText = resolveRawAssistantAnswerText(params.lastAssistant);
|
|
1089
|
+
const shouldSuppressRawErrorText = (text) => {
|
|
1090
|
+
if (!lastAssistantErrored) return false;
|
|
1091
|
+
const trimmed = text.trim();
|
|
1092
|
+
if (!trimmed) return false;
|
|
1093
|
+
if (errorText) {
|
|
1094
|
+
const normalized = normalizeTextForComparison(trimmed);
|
|
1095
|
+
if (normalized && normalizedErrorText && normalized === normalizedErrorText) return true;
|
|
1096
|
+
if (trimmed === genericErrorText) return true;
|
|
1097
|
+
if (normalized && normalizedGenericBillingErrorText && normalized === normalizedGenericBillingErrorText) return true;
|
|
1098
|
+
}
|
|
1099
|
+
if (rawErrorMessage && trimmed === rawErrorMessage) return true;
|
|
1100
|
+
if (formattedRawErrorMessage && trimmed === formattedRawErrorMessage) return true;
|
|
1101
|
+
if (normalizedRawErrorText) {
|
|
1102
|
+
const normalized = normalizeTextForComparison(trimmed);
|
|
1103
|
+
if (normalized && normalized === normalizedRawErrorText) return true;
|
|
1104
|
+
}
|
|
1105
|
+
if (normalizedFormattedRawErrorMessage) {
|
|
1106
|
+
const normalized = normalizeTextForComparison(trimmed);
|
|
1107
|
+
if (normalized && normalized === normalizedFormattedRawErrorMessage) return true;
|
|
1108
|
+
}
|
|
1109
|
+
if (rawErrorFingerprint) {
|
|
1110
|
+
const fingerprint = getApiErrorPayloadFingerprint(trimmed);
|
|
1111
|
+
if (fingerprint && fingerprint === rawErrorFingerprint) return true;
|
|
1112
|
+
}
|
|
1113
|
+
return isRawApiErrorPayload(trimmed);
|
|
1114
|
+
};
|
|
1115
|
+
const rawAnswerDirectiveState = fallbackRawAnswerText ? parseReplyDirectives(fallbackRawAnswerText) : null;
|
|
1116
|
+
const rawAnswerHasMedia = (rawAnswerDirectiveState?.mediaUrls?.length ?? 0) > 0 || rawAnswerDirectiveState?.audioAsVoice;
|
|
1117
|
+
const assistantTextsHaveMedia = params.assistantTexts.some((text) => {
|
|
1118
|
+
const parsed = parseReplyDirectives(text);
|
|
1119
|
+
return (parsed.mediaUrls?.length ?? 0) > 0 || parsed.audioAsVoice;
|
|
1120
|
+
});
|
|
1121
|
+
const normalizedAssistantTexts = normalizeTextForComparison(params.assistantTexts.join("\n\n"));
|
|
1122
|
+
const normalizedRawAnswerText = normalizeTextForComparison(rawAnswerDirectiveState?.text ?? "");
|
|
1123
|
+
const shouldPreferRawAnswerText = rawAnswerHasMedia && (!params.assistantTexts.length || !assistantTextsHaveMedia && normalizedAssistantTexts.length > 0 && normalizedAssistantTexts === normalizedRawAnswerText);
|
|
1124
|
+
const answerTexts = suppressAssistantArtifacts ? [] : (shouldPreferRawAnswerText && fallbackRawAnswerText ? [fallbackRawAnswerText] : params.assistantTexts.length ? params.assistantTexts : fallbackAnswerText ? [fallbackAnswerText] : []).filter((text) => !shouldSuppressRawErrorText(text));
|
|
1125
|
+
let hasUserFacingAssistantReply = false;
|
|
1126
|
+
for (const text of answerTexts) {
|
|
1127
|
+
const { text: cleanedText, mediaUrls, audioAsVoice, replyToId, replyToTag, replyToCurrent } = parseReplyDirectives(text);
|
|
1128
|
+
if (!cleanedText && (!mediaUrls || mediaUrls.length === 0) && !audioAsVoice) continue;
|
|
1129
|
+
replyItems.push({
|
|
1130
|
+
text: cleanedText,
|
|
1131
|
+
media: mediaUrls,
|
|
1132
|
+
audioAsVoice,
|
|
1133
|
+
replyToId,
|
|
1134
|
+
replyToTag,
|
|
1135
|
+
replyToCurrent
|
|
1136
|
+
});
|
|
1137
|
+
hasUserFacingAssistantReply = true;
|
|
1138
|
+
}
|
|
1139
|
+
if (params.lastToolError) {
|
|
1140
|
+
const warningPolicy = resolveToolErrorWarningPolicy({
|
|
1141
|
+
lastToolError: params.lastToolError,
|
|
1142
|
+
hasUserFacingReply: hasUserFacingAssistantReply,
|
|
1143
|
+
suppressToolErrors: Boolean(params.config?.messages?.suppressToolErrors),
|
|
1144
|
+
suppressToolErrorWarnings: params.suppressToolErrorWarnings,
|
|
1145
|
+
isCronTrigger: params.isCronTrigger,
|
|
1146
|
+
sessionKey: params.sessionKey,
|
|
1147
|
+
verboseLevel: params.verboseLevel
|
|
1148
|
+
});
|
|
1149
|
+
if (warningPolicy.showWarning) {
|
|
1150
|
+
const warningText = `⚠️ ${formatToolAggregate(params.lastToolError.toolName, params.lastToolError.meta ? [params.lastToolError.meta] : void 0, { markdown: useMarkdown })} failed${warningPolicy.includeDetails && params.lastToolError.error ? `: ${params.lastToolError.error}` : ""}`;
|
|
1151
|
+
const normalizedWarning = normalizeTextForComparison(warningText);
|
|
1152
|
+
if (!(normalizedWarning ? replyItems.some((item) => {
|
|
1153
|
+
if (!item.text) return false;
|
|
1154
|
+
const normalizedExisting = normalizeTextForComparison(item.text);
|
|
1155
|
+
return normalizedExisting.length > 0 && normalizedExisting === normalizedWarning;
|
|
1156
|
+
}) : false)) replyItems.push({
|
|
1157
|
+
text: warningText,
|
|
1158
|
+
isError: true
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
const hasAudioAsVoiceTag = replyItems.some((item) => item.audioAsVoice);
|
|
1163
|
+
return replyItems.map((item) => {
|
|
1164
|
+
const payload = {
|
|
1165
|
+
text: normalizeOptionalString(item.text),
|
|
1166
|
+
mediaUrls: item.media?.length ? item.media : void 0,
|
|
1167
|
+
mediaUrl: item.media?.[0],
|
|
1168
|
+
isError: item.isError,
|
|
1169
|
+
replyToId: item.replyToId,
|
|
1170
|
+
replyToTag: item.replyToTag,
|
|
1171
|
+
replyToCurrent: item.replyToCurrent,
|
|
1172
|
+
audioAsVoice: item.audioAsVoice || Boolean(hasAudioAsVoiceTag && item.media?.length)
|
|
1173
|
+
};
|
|
1174
|
+
if (payload.text && isSilentReplyPayloadText(payload.text, "NO_REPLY")) {
|
|
1175
|
+
const silentText = payload.text;
|
|
1176
|
+
payload.text = void 0;
|
|
1177
|
+
if (hasOutboundReplyContent(payload)) return payload;
|
|
1178
|
+
payload.text = silentText;
|
|
1179
|
+
}
|
|
1180
|
+
return payload;
|
|
1181
|
+
}).filter((p) => {
|
|
1182
|
+
if (!hasOutboundReplyContent(p)) return false;
|
|
1183
|
+
if (p.text && isSilentReplyPayloadText(p.text, "NO_REPLY")) return false;
|
|
1184
|
+
return true;
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
//#endregion
|
|
1188
|
+
//#region src/agents/pi-embedded-runner/run/retry-limit.ts
|
|
1189
|
+
function handleRetryLimitExhaustion(params) {
|
|
1190
|
+
if (params.decision.action === "fallback_model") throw new FailoverError(params.message, {
|
|
1191
|
+
reason: params.decision.reason,
|
|
1192
|
+
provider: params.provider,
|
|
1193
|
+
model: params.model,
|
|
1194
|
+
profileId: params.profileId,
|
|
1195
|
+
status: resolveFailoverStatus(params.decision.reason)
|
|
1196
|
+
});
|
|
1197
|
+
return {
|
|
1198
|
+
payloads: [{
|
|
1199
|
+
text: "Request failed after repeated internal retries. Please try again, or use /new to start a fresh session.",
|
|
1200
|
+
isError: true
|
|
1201
|
+
}],
|
|
1202
|
+
meta: {
|
|
1203
|
+
durationMs: params.durationMs,
|
|
1204
|
+
agentMeta: params.agentMeta,
|
|
1205
|
+
...params.replayInvalid ? { replayInvalid: true } : {},
|
|
1206
|
+
...params.livenessState ? { livenessState: params.livenessState } : {},
|
|
1207
|
+
error: {
|
|
1208
|
+
kind: "retry_limit",
|
|
1209
|
+
message: params.message
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
//#endregion
|
|
1215
|
+
//#region src/agents/pi-embedded-runner/run/setup.ts
|
|
1216
|
+
async function resolveHookModelSelection(params) {
|
|
1217
|
+
let provider = params.provider;
|
|
1218
|
+
let modelId = params.modelId;
|
|
1219
|
+
let modelResolveOverride;
|
|
1220
|
+
let legacyBeforeAgentStartResult;
|
|
1221
|
+
const hookRunner = params.hookRunner;
|
|
1222
|
+
if (hookRunner?.hasHooks("before_model_resolve")) try {
|
|
1223
|
+
const event = params.attachments ? {
|
|
1224
|
+
prompt: params.prompt,
|
|
1225
|
+
attachments: params.attachments
|
|
1226
|
+
} : { prompt: params.prompt };
|
|
1227
|
+
modelResolveOverride = await hookRunner.runBeforeModelResolve(event, params.hookContext);
|
|
1228
|
+
} catch (hookErr) {
|
|
1229
|
+
log.warn(`before_model_resolve hook failed: ${String(hookErr)}`);
|
|
1230
|
+
}
|
|
1231
|
+
if (hookRunner?.hasHooks("before_agent_start")) try {
|
|
1232
|
+
legacyBeforeAgentStartResult = await hookRunner.runBeforeAgentStart({ prompt: params.prompt }, params.hookContext);
|
|
1233
|
+
modelResolveOverride = {
|
|
1234
|
+
providerOverride: modelResolveOverride?.providerOverride ?? legacyBeforeAgentStartResult?.providerOverride,
|
|
1235
|
+
modelOverride: modelResolveOverride?.modelOverride ?? legacyBeforeAgentStartResult?.modelOverride
|
|
1236
|
+
};
|
|
1237
|
+
} catch (hookErr) {
|
|
1238
|
+
log.warn(`before_agent_start hook (legacy model resolve path) failed: ${String(hookErr)}`);
|
|
1239
|
+
}
|
|
1240
|
+
if (modelResolveOverride?.providerOverride) {
|
|
1241
|
+
provider = modelResolveOverride.providerOverride;
|
|
1242
|
+
log.info(`[hooks] provider overridden to ${provider}`);
|
|
1243
|
+
}
|
|
1244
|
+
if (modelResolveOverride?.modelOverride) {
|
|
1245
|
+
modelId = modelResolveOverride.modelOverride;
|
|
1246
|
+
log.info(`[hooks] model overridden to ${modelId}`);
|
|
1247
|
+
}
|
|
1248
|
+
return {
|
|
1249
|
+
provider,
|
|
1250
|
+
modelId,
|
|
1251
|
+
legacyBeforeAgentStartResult
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function buildBeforeModelResolveAttachments(images) {
|
|
1255
|
+
if (!images?.length) return;
|
|
1256
|
+
return images.map((img) => ({
|
|
1257
|
+
kind: "image",
|
|
1258
|
+
mimeType: img.mimeType
|
|
1259
|
+
}));
|
|
1260
|
+
}
|
|
1261
|
+
function resolveEffectiveRuntimeModel(params) {
|
|
1262
|
+
const ctxInfo = resolveContextWindowInfo({
|
|
1263
|
+
cfg: params.cfg,
|
|
1264
|
+
provider: params.provider,
|
|
1265
|
+
modelId: params.modelId,
|
|
1266
|
+
modelContextTokens: readPiModelContextTokens(params.runtimeModel),
|
|
1267
|
+
modelContextWindow: params.runtimeModel.contextWindow,
|
|
1268
|
+
defaultTokens: DEFAULT_CONTEXT_TOKENS
|
|
1269
|
+
});
|
|
1270
|
+
const effectiveModel = ctxInfo.tokens < (params.runtimeModel.contextWindow ?? Infinity) ? {
|
|
1271
|
+
...params.runtimeModel,
|
|
1272
|
+
contextWindow: ctxInfo.tokens
|
|
1273
|
+
} : params.runtimeModel;
|
|
1274
|
+
const ctxGuard = evaluateContextWindowGuard({
|
|
1275
|
+
info: ctxInfo,
|
|
1276
|
+
warnBelowTokens: CONTEXT_WINDOW_WARN_BELOW_TOKENS,
|
|
1277
|
+
hardMinTokens: CONTEXT_WINDOW_HARD_MIN_TOKENS
|
|
1278
|
+
});
|
|
1279
|
+
const runtimeBaseUrl = typeof params.runtimeModel.baseUrl === "string" ? params.runtimeModel.baseUrl : void 0;
|
|
1280
|
+
if (ctxGuard.shouldWarn) log.warn(formatContextWindowWarningMessage({
|
|
1281
|
+
provider: params.provider,
|
|
1282
|
+
modelId: params.modelId,
|
|
1283
|
+
guard: ctxGuard,
|
|
1284
|
+
runtimeBaseUrl
|
|
1285
|
+
}));
|
|
1286
|
+
if (ctxGuard.shouldBlock) {
|
|
1287
|
+
const message = formatContextWindowBlockMessage({
|
|
1288
|
+
guard: ctxGuard,
|
|
1289
|
+
runtimeBaseUrl
|
|
1290
|
+
});
|
|
1291
|
+
log.error(`blocked model (context window too small): ${params.provider}/${params.modelId} ctx=${ctxGuard.tokens} (min=${CONTEXT_WINDOW_HARD_MIN_TOKENS}) source=${ctxGuard.source}; ${message}`);
|
|
1292
|
+
throw new FailoverError(message, {
|
|
1293
|
+
reason: "unknown",
|
|
1294
|
+
provider: params.provider,
|
|
1295
|
+
model: params.modelId
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
return {
|
|
1299
|
+
ctxInfo,
|
|
1300
|
+
effectiveModel
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
//#endregion
|
|
1304
|
+
//#region src/agents/pi-embedded-runner/run/tool-media-payloads.ts
|
|
1305
|
+
function mergeAttemptToolMediaPayloads(params) {
|
|
1306
|
+
const mediaUrls = Array.from(new Set(params.toolMediaUrls?.map((url) => url.trim()).filter(Boolean) ?? []));
|
|
1307
|
+
if (mediaUrls.length === 0 && !params.toolAudioAsVoice) return params.payloads;
|
|
1308
|
+
const payloads = params.payloads?.length ? [...params.payloads] : [];
|
|
1309
|
+
const payloadIndex = payloads.findIndex((payload) => !payload.isReasoning);
|
|
1310
|
+
if (payloadIndex >= 0) {
|
|
1311
|
+
const payload = payloads[payloadIndex];
|
|
1312
|
+
const mergedMediaUrls = Array.from(new Set([...payload.mediaUrls ?? [], ...mediaUrls]));
|
|
1313
|
+
payloads[payloadIndex] = {
|
|
1314
|
+
...payload,
|
|
1315
|
+
mediaUrls: mergedMediaUrls.length ? mergedMediaUrls : void 0,
|
|
1316
|
+
mediaUrl: payload.mediaUrl ?? mergedMediaUrls[0],
|
|
1317
|
+
audioAsVoice: payload.audioAsVoice || params.toolAudioAsVoice || void 0
|
|
1318
|
+
};
|
|
1319
|
+
return payloads;
|
|
1320
|
+
}
|
|
1321
|
+
return [...payloads, {
|
|
1322
|
+
mediaUrls: mediaUrls.length ? mediaUrls : void 0,
|
|
1323
|
+
mediaUrl: mediaUrls[0],
|
|
1324
|
+
audioAsVoice: params.toolAudioAsVoice || void 0
|
|
1325
|
+
}];
|
|
1326
|
+
}
|
|
1327
|
+
//#endregion
|
|
1328
|
+
//#region src/agents/pi-embedded-runner/run.ts
|
|
1329
|
+
const MAX_SAME_MODEL_IDLE_TIMEOUT_RETRIES = 1;
|
|
1330
|
+
function createEmptyAuthProfileStore() {
|
|
1331
|
+
return {
|
|
1332
|
+
version: 1,
|
|
1333
|
+
profiles: {}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
function buildTraceToolSummary(params) {
|
|
1337
|
+
if (params.toolMetas.length === 0) return;
|
|
1338
|
+
const tools = [];
|
|
1339
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1340
|
+
for (const entry of params.toolMetas) {
|
|
1341
|
+
const toolName = normalizeOptionalString(entry.toolName);
|
|
1342
|
+
if (!toolName || seen.has(toolName)) continue;
|
|
1343
|
+
seen.add(toolName);
|
|
1344
|
+
tools.push(toolName);
|
|
1345
|
+
}
|
|
1346
|
+
return {
|
|
1347
|
+
calls: params.toolMetas.length,
|
|
1348
|
+
tools,
|
|
1349
|
+
failures: params.hadFailure ? 1 : 0
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Best-effort backfill of sessionKey from sessionId when not explicitly provided.
|
|
1354
|
+
* The return value is normalized: whitespace-only inputs collapse to undefined, and
|
|
1355
|
+
* successful resolution returns a trimmed session key. This is a read-only lookup
|
|
1356
|
+
* with no side effects.
|
|
1357
|
+
* See: https://github.com/PIXELZX0/Genesis/issues/60552
|
|
1358
|
+
*/
|
|
1359
|
+
function backfillSessionKey(params) {
|
|
1360
|
+
const trimmed = normalizeOptionalString(params.sessionKey);
|
|
1361
|
+
if (trimmed) return trimmed;
|
|
1362
|
+
if (!params.config || !params.sessionId) return;
|
|
1363
|
+
try {
|
|
1364
|
+
return normalizeOptionalString((normalizeOptionalString(params.agentId) ? resolveStoredSessionKeyForSessionId({
|
|
1365
|
+
cfg: params.config,
|
|
1366
|
+
sessionId: params.sessionId,
|
|
1367
|
+
agentId: params.agentId
|
|
1368
|
+
}) : resolveSessionKeyForRequest({
|
|
1369
|
+
cfg: params.config,
|
|
1370
|
+
sessionId: params.sessionId
|
|
1371
|
+
})).sessionKey);
|
|
1372
|
+
} catch (err) {
|
|
1373
|
+
log.warn(`[backfillSessionKey] Failed to resolve sessionKey for sessionId=${redactRunIdentifier(sanitizeForLog(params.sessionId))}: ${formatErrorMessage(err)}`);
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
function buildHandledReplyPayloads(reply) {
|
|
1378
|
+
const normalized = reply ?? { text: "NO_REPLY" };
|
|
1379
|
+
return [{
|
|
1380
|
+
text: normalized.text,
|
|
1381
|
+
mediaUrl: normalized.mediaUrl,
|
|
1382
|
+
mediaUrls: normalized.mediaUrls,
|
|
1383
|
+
replyToId: normalized.replyToId,
|
|
1384
|
+
audioAsVoice: normalized.audioAsVoice,
|
|
1385
|
+
isError: normalized.isError,
|
|
1386
|
+
isReasoning: normalized.isReasoning
|
|
1387
|
+
}];
|
|
1388
|
+
}
|
|
1389
|
+
async function runEmbeddedPiAgent(params) {
|
|
1390
|
+
const effectiveSessionKey = backfillSessionKey({
|
|
1391
|
+
config: params.config,
|
|
1392
|
+
sessionId: params.sessionId,
|
|
1393
|
+
sessionKey: params.sessionKey,
|
|
1394
|
+
agentId: params.agentId
|
|
1395
|
+
});
|
|
1396
|
+
if (effectiveSessionKey !== params.sessionKey) params = {
|
|
1397
|
+
...params,
|
|
1398
|
+
sessionKey: effectiveSessionKey
|
|
1399
|
+
};
|
|
1400
|
+
const sessionLane = resolveSessionLane(params.sessionKey?.trim() || params.sessionId);
|
|
1401
|
+
const globalLane = resolveGlobalLane(params.lane);
|
|
1402
|
+
const enqueueGlobal = params.enqueue ?? ((task, opts) => enqueueCommandInLane(globalLane, task, opts));
|
|
1403
|
+
const enqueueSession = params.enqueue ?? ((task, opts) => enqueueCommandInLane(sessionLane, task, opts));
|
|
1404
|
+
const channelHint = params.messageChannel ?? params.messageProvider;
|
|
1405
|
+
const resolvedToolResultFormat = params.toolResultFormat ?? (channelHint ? isMarkdownCapableMessageChannel(channelHint) ? "markdown" : "plain" : "markdown");
|
|
1406
|
+
const isProbeSession = params.sessionId?.startsWith("probe-") ?? false;
|
|
1407
|
+
const throwIfAborted = () => {
|
|
1408
|
+
if (!params.abortSignal?.aborted) return;
|
|
1409
|
+
const reason = params.abortSignal.reason;
|
|
1410
|
+
if (reason instanceof Error) throw reason;
|
|
1411
|
+
const abortErr = reason !== void 0 ? new Error("Operation aborted", { cause: reason }) : /* @__PURE__ */ new Error("Operation aborted");
|
|
1412
|
+
abortErr.name = "AbortError";
|
|
1413
|
+
throw abortErr;
|
|
1414
|
+
};
|
|
1415
|
+
throwIfAborted();
|
|
1416
|
+
return enqueueSession(() => {
|
|
1417
|
+
throwIfAborted();
|
|
1418
|
+
return enqueueGlobal(async () => {
|
|
1419
|
+
throwIfAborted();
|
|
1420
|
+
const started = Date.now();
|
|
1421
|
+
const workspaceResolution = resolveRunWorkspaceDir({
|
|
1422
|
+
workspaceDir: params.workspaceDir,
|
|
1423
|
+
sessionKey: params.sessionKey,
|
|
1424
|
+
agentId: params.agentId,
|
|
1425
|
+
config: params.config
|
|
1426
|
+
});
|
|
1427
|
+
const resolvedWorkspace = workspaceResolution.workspaceDir;
|
|
1428
|
+
const isCanonicalWorkspace = resolveUserPath(resolveAgentWorkspaceDir(params.config ?? {}, workspaceResolution.agentId)) === resolvedWorkspace;
|
|
1429
|
+
const redactedSessionId = redactRunIdentifier(params.sessionId);
|
|
1430
|
+
const redactedSessionKey = redactRunIdentifier(params.sessionKey);
|
|
1431
|
+
const redactedWorkspace = redactRunIdentifier(resolvedWorkspace);
|
|
1432
|
+
if (workspaceResolution.usedFallback) log.warn(`[workspace-fallback] caller=runEmbeddedPiAgent reason=${workspaceResolution.fallbackReason} run=${params.runId} session=${redactedSessionId} sessionKey=${redactedSessionKey} agent=${workspaceResolution.agentId} workspace=${redactedWorkspace}`);
|
|
1433
|
+
ensureRuntimePluginsLoaded({
|
|
1434
|
+
config: params.config,
|
|
1435
|
+
workspaceDir: resolvedWorkspace,
|
|
1436
|
+
allowGatewaySubagentBinding: params.allowGatewaySubagentBinding
|
|
1437
|
+
});
|
|
1438
|
+
let provider = (params.provider ?? "openai").trim() || "openai";
|
|
1439
|
+
let modelId = (params.model ?? "gpt-5.5").trim() || "gpt-5.5";
|
|
1440
|
+
const agentDir = params.agentDir ?? resolveGenesisAgentDir();
|
|
1441
|
+
const normalizedSessionKey = params.sessionKey?.trim();
|
|
1442
|
+
const fallbackConfigured = hasConfiguredModelFallbacks({
|
|
1443
|
+
cfg: params.config,
|
|
1444
|
+
agentId: params.agentId,
|
|
1445
|
+
sessionKey: normalizedSessionKey
|
|
1446
|
+
});
|
|
1447
|
+
const resolvedSessionKey = normalizedSessionKey;
|
|
1448
|
+
const hookRunner = getGlobalHookRunner();
|
|
1449
|
+
const hookCtx = {
|
|
1450
|
+
runId: params.runId,
|
|
1451
|
+
agentId: workspaceResolution.agentId,
|
|
1452
|
+
sessionKey: resolvedSessionKey,
|
|
1453
|
+
sessionId: params.sessionId,
|
|
1454
|
+
workspaceDir: resolvedWorkspace,
|
|
1455
|
+
modelProviderId: provider,
|
|
1456
|
+
modelId,
|
|
1457
|
+
messageProvider: params.messageProvider ?? void 0,
|
|
1458
|
+
trigger: params.trigger,
|
|
1459
|
+
channelId: params.messageChannel ?? params.messageProvider ?? void 0
|
|
1460
|
+
};
|
|
1461
|
+
if (params.trigger === "cron" && hookRunner?.hasHooks("before_agent_reply")) {
|
|
1462
|
+
const hookResult = await hookRunner.runBeforeAgentReply({ cleanedBody: params.prompt }, hookCtx);
|
|
1463
|
+
if (hookResult?.handled) return {
|
|
1464
|
+
payloads: buildHandledReplyPayloads(hookResult.reply),
|
|
1465
|
+
meta: {
|
|
1466
|
+
durationMs: Date.now() - started,
|
|
1467
|
+
agentMeta: {
|
|
1468
|
+
sessionId: params.sessionId,
|
|
1469
|
+
provider,
|
|
1470
|
+
model: modelId
|
|
1471
|
+
},
|
|
1472
|
+
finalAssistantVisibleText: hookResult.reply?.text ?? "NO_REPLY",
|
|
1473
|
+
finalAssistantRawText: hookResult.reply?.text ?? "NO_REPLY"
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
const hookSelection = await resolveHookModelSelection({
|
|
1478
|
+
prompt: params.prompt,
|
|
1479
|
+
attachments: buildBeforeModelResolveAttachments(params.images),
|
|
1480
|
+
provider,
|
|
1481
|
+
modelId,
|
|
1482
|
+
hookRunner,
|
|
1483
|
+
hookContext: hookCtx
|
|
1484
|
+
});
|
|
1485
|
+
provider = hookSelection.provider;
|
|
1486
|
+
modelId = hookSelection.modelId;
|
|
1487
|
+
const legacyBeforeAgentStartResult = hookSelection.legacyBeforeAgentStartResult;
|
|
1488
|
+
const agentHarness = selectAgentHarness({
|
|
1489
|
+
provider,
|
|
1490
|
+
modelId,
|
|
1491
|
+
config: params.config,
|
|
1492
|
+
agentId: params.agentId,
|
|
1493
|
+
sessionKey: params.sessionKey,
|
|
1494
|
+
agentHarnessId: params.agentHarnessId
|
|
1495
|
+
});
|
|
1496
|
+
const pluginHarnessOwnsTransport = agentHarness.id !== "pi";
|
|
1497
|
+
if (!pluginHarnessOwnsTransport) await ensureGenesisModelsJson(params.config, agentDir);
|
|
1498
|
+
const { model, error, authStorage, modelRegistry } = await resolveModelAsync(provider, modelId, agentDir, params.config, { skipPiDiscovery: pluginHarnessOwnsTransport });
|
|
1499
|
+
if (!model) throw new FailoverError(error ?? `Unknown model: ${provider}/${modelId}`, {
|
|
1500
|
+
reason: "model_not_found",
|
|
1501
|
+
provider,
|
|
1502
|
+
model: modelId
|
|
1503
|
+
});
|
|
1504
|
+
let runtimeModel = model;
|
|
1505
|
+
const resolvedRuntimeModel = resolveEffectiveRuntimeModel({
|
|
1506
|
+
cfg: params.config,
|
|
1507
|
+
provider,
|
|
1508
|
+
modelId,
|
|
1509
|
+
runtimeModel
|
|
1510
|
+
});
|
|
1511
|
+
const ctxInfo = resolvedRuntimeModel.ctxInfo;
|
|
1512
|
+
let effectiveModel = resolvedRuntimeModel.effectiveModel;
|
|
1513
|
+
const authStore = pluginHarnessOwnsTransport ? createEmptyAuthProfileStore() : ensureAuthProfileStore(agentDir, { allowKeychainPrompt: false });
|
|
1514
|
+
const preferredProfileId = params.authProfileId?.trim();
|
|
1515
|
+
let lockedProfileId = params.authProfileIdSource === "user" ? preferredProfileId : void 0;
|
|
1516
|
+
if (lockedProfileId) if (pluginHarnessOwnsTransport) {
|
|
1517
|
+
if (!buildAgentRuntimeAuthPlan({
|
|
1518
|
+
provider,
|
|
1519
|
+
authProfileProvider: lockedProfileId.split(":", 1)[0],
|
|
1520
|
+
sessionAuthProfileId: lockedProfileId,
|
|
1521
|
+
config: params.config,
|
|
1522
|
+
workspaceDir: resolvedWorkspace,
|
|
1523
|
+
harnessId: agentHarness.id
|
|
1524
|
+
}).forwardedAuthProfileId) lockedProfileId = void 0;
|
|
1525
|
+
} else {
|
|
1526
|
+
const lockedProfile = authStore.profiles[lockedProfileId];
|
|
1527
|
+
const lockedProfileProvider = lockedProfile ? resolveProviderIdForAuth(lockedProfile.provider, {
|
|
1528
|
+
config: params.config,
|
|
1529
|
+
workspaceDir: resolvedWorkspace
|
|
1530
|
+
}) : void 0;
|
|
1531
|
+
const runProvider = resolveProviderIdForAuth(provider, {
|
|
1532
|
+
config: params.config,
|
|
1533
|
+
workspaceDir: resolvedWorkspace
|
|
1534
|
+
});
|
|
1535
|
+
if (!lockedProfile || !lockedProfileProvider || lockedProfileProvider !== runProvider) lockedProfileId = void 0;
|
|
1536
|
+
}
|
|
1537
|
+
if (lockedProfileId && !pluginHarnessOwnsTransport) {
|
|
1538
|
+
if (!resolveAuthProfileEligibility({
|
|
1539
|
+
cfg: params.config,
|
|
1540
|
+
store: authStore,
|
|
1541
|
+
provider,
|
|
1542
|
+
profileId: lockedProfileId
|
|
1543
|
+
}).eligible) throw new Error(`Auth profile "${lockedProfileId}" is not configured for ${provider}.`);
|
|
1544
|
+
}
|
|
1545
|
+
const profileOrder = shouldPreferExplicitConfigApiKeyAuth(params.config, provider) ? [] : resolveAuthProfileOrder({
|
|
1546
|
+
cfg: params.config,
|
|
1547
|
+
store: authStore,
|
|
1548
|
+
provider,
|
|
1549
|
+
preferredProfile: preferredProfileId
|
|
1550
|
+
});
|
|
1551
|
+
const providerPreferredProfileId = lockedProfileId ? void 0 : resolveProviderAuthProfileId({
|
|
1552
|
+
provider,
|
|
1553
|
+
config: params.config,
|
|
1554
|
+
workspaceDir: resolvedWorkspace,
|
|
1555
|
+
context: {
|
|
1556
|
+
config: params.config,
|
|
1557
|
+
agentDir,
|
|
1558
|
+
workspaceDir: resolvedWorkspace,
|
|
1559
|
+
provider,
|
|
1560
|
+
modelId,
|
|
1561
|
+
preferredProfileId,
|
|
1562
|
+
lockedProfileId,
|
|
1563
|
+
profileOrder,
|
|
1564
|
+
authStore
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
const providerOrderedProfiles = providerPreferredProfileId && profileOrder.includes(providerPreferredProfileId) ? [providerPreferredProfileId, ...profileOrder.filter((profileId) => profileId !== providerPreferredProfileId)] : profileOrder;
|
|
1568
|
+
const profileCandidates = lockedProfileId ? [lockedProfileId] : providerOrderedProfiles.length > 0 ? providerOrderedProfiles : [void 0];
|
|
1569
|
+
let profileIndex = 0;
|
|
1570
|
+
const traceAttempts = [];
|
|
1571
|
+
const initialThinkLevel = params.thinkLevel ?? "off";
|
|
1572
|
+
let thinkLevel = initialThinkLevel;
|
|
1573
|
+
const attemptedThinking = /* @__PURE__ */ new Set();
|
|
1574
|
+
let apiKeyInfo = null;
|
|
1575
|
+
let lastProfileId;
|
|
1576
|
+
let runtimeAuthState = null;
|
|
1577
|
+
let runtimeAuthRefreshCancelled = false;
|
|
1578
|
+
const { advanceAuthProfile, initializeAuthProfile, maybeRefreshRuntimeAuthForAuthError, stopRuntimeAuthRefreshTimer } = createEmbeddedRunAuthController({
|
|
1579
|
+
config: params.config,
|
|
1580
|
+
agentDir,
|
|
1581
|
+
workspaceDir: resolvedWorkspace,
|
|
1582
|
+
authStore,
|
|
1583
|
+
authStorage,
|
|
1584
|
+
profileCandidates,
|
|
1585
|
+
lockedProfileId,
|
|
1586
|
+
initialThinkLevel,
|
|
1587
|
+
attemptedThinking,
|
|
1588
|
+
fallbackConfigured,
|
|
1589
|
+
allowTransientCooldownProbe: params.allowTransientCooldownProbe === true,
|
|
1590
|
+
getProvider: () => provider,
|
|
1591
|
+
getModelId: () => modelId,
|
|
1592
|
+
getRuntimeModel: () => runtimeModel,
|
|
1593
|
+
setRuntimeModel: (next) => {
|
|
1594
|
+
runtimeModel = next;
|
|
1595
|
+
},
|
|
1596
|
+
getEffectiveModel: () => effectiveModel,
|
|
1597
|
+
setEffectiveModel: (next) => {
|
|
1598
|
+
effectiveModel = next;
|
|
1599
|
+
},
|
|
1600
|
+
getApiKeyInfo: () => apiKeyInfo,
|
|
1601
|
+
setApiKeyInfo: (next) => {
|
|
1602
|
+
apiKeyInfo = next;
|
|
1603
|
+
},
|
|
1604
|
+
getLastProfileId: () => lastProfileId,
|
|
1605
|
+
setLastProfileId: (next) => {
|
|
1606
|
+
lastProfileId = next;
|
|
1607
|
+
},
|
|
1608
|
+
getRuntimeAuthState: () => runtimeAuthState,
|
|
1609
|
+
setRuntimeAuthState: (next) => {
|
|
1610
|
+
runtimeAuthState = next;
|
|
1611
|
+
},
|
|
1612
|
+
getRuntimeAuthRefreshCancelled: () => runtimeAuthRefreshCancelled,
|
|
1613
|
+
setRuntimeAuthRefreshCancelled: (next) => {
|
|
1614
|
+
runtimeAuthRefreshCancelled = next;
|
|
1615
|
+
},
|
|
1616
|
+
getProfileIndex: () => profileIndex,
|
|
1617
|
+
setProfileIndex: (next) => {
|
|
1618
|
+
profileIndex = next;
|
|
1619
|
+
},
|
|
1620
|
+
setThinkLevel: (next) => {
|
|
1621
|
+
thinkLevel = next;
|
|
1622
|
+
},
|
|
1623
|
+
log
|
|
1624
|
+
});
|
|
1625
|
+
if (!pluginHarnessOwnsTransport) await initializeAuthProfile();
|
|
1626
|
+
else if (lockedProfileId) lastProfileId = lockedProfileId;
|
|
1627
|
+
const { sessionAgentId } = resolveSessionAgentIds({
|
|
1628
|
+
sessionKey: params.sessionKey,
|
|
1629
|
+
config: params.config,
|
|
1630
|
+
agentId: params.agentId
|
|
1631
|
+
});
|
|
1632
|
+
const configuredExecutionContract = resolveAgentExecutionContract(params.config, sessionAgentId) ?? "default";
|
|
1633
|
+
const strictAgenticActive = isStrictAgenticExecutionContractActive({
|
|
1634
|
+
config: params.config,
|
|
1635
|
+
sessionKey: params.sessionKey,
|
|
1636
|
+
agentId: params.agentId,
|
|
1637
|
+
provider,
|
|
1638
|
+
modelId
|
|
1639
|
+
});
|
|
1640
|
+
const executionContract = strictAgenticActive ? "strict-agentic" : "default";
|
|
1641
|
+
const maxPlanningOnlyRetryAttempts = resolvePlanningOnlyRetryLimit(executionContract);
|
|
1642
|
+
const maxReasoningOnlyRetryAttempts = 2;
|
|
1643
|
+
const maxEmptyResponseRetryAttempts = 1;
|
|
1644
|
+
const MAX_TIMEOUT_COMPACTION_ATTEMPTS = 2;
|
|
1645
|
+
const MAX_OVERFLOW_COMPACTION_ATTEMPTS = 3;
|
|
1646
|
+
const MAX_RUN_LOOP_ITERATIONS = resolveMaxRunRetryIterations(profileCandidates.length);
|
|
1647
|
+
let overflowCompactionAttempts = 0;
|
|
1648
|
+
let toolResultTruncationAttempted = false;
|
|
1649
|
+
let bootstrapPromptWarningSignaturesSeen = params.bootstrapPromptWarningSignaturesSeen ?? (params.bootstrapPromptWarningSignature ? [params.bootstrapPromptWarningSignature] : []);
|
|
1650
|
+
const usageAccumulator = createUsageAccumulator();
|
|
1651
|
+
let lastRunPromptUsage;
|
|
1652
|
+
let autoCompactionCount = 0;
|
|
1653
|
+
let runLoopIterations = 0;
|
|
1654
|
+
let overloadProfileRotations = 0;
|
|
1655
|
+
let planningOnlyRetryAttempts = 0;
|
|
1656
|
+
let reasoningOnlyRetryAttempts = 0;
|
|
1657
|
+
let emptyResponseRetryAttempts = 0;
|
|
1658
|
+
let sameModelIdleTimeoutRetries = 0;
|
|
1659
|
+
let lastRetryFailoverReason = null;
|
|
1660
|
+
let planningOnlyRetryInstruction = null;
|
|
1661
|
+
let reasoningOnlyRetryInstruction = null;
|
|
1662
|
+
let emptyResponseRetryInstruction = null;
|
|
1663
|
+
const ackExecutionFastPathInstruction = resolveAckExecutionFastPathInstruction({
|
|
1664
|
+
provider,
|
|
1665
|
+
modelId,
|
|
1666
|
+
prompt: params.prompt
|
|
1667
|
+
});
|
|
1668
|
+
let rateLimitProfileRotations = 0;
|
|
1669
|
+
let timeoutCompactionAttempts = 0;
|
|
1670
|
+
const MAX_EMPTY_ERROR_RETRIES = 3;
|
|
1671
|
+
let emptyErrorRetries = 0;
|
|
1672
|
+
const overloadFailoverBackoffMs = resolveOverloadFailoverBackoffMs(params.config);
|
|
1673
|
+
const overloadProfileRotationLimit = resolveOverloadProfileRotationLimit(params.config);
|
|
1674
|
+
const rateLimitProfileRotationLimit = resolveRateLimitProfileRotationLimit(params.config);
|
|
1675
|
+
const maybeEscalateRateLimitProfileFallback = (params) => {
|
|
1676
|
+
rateLimitProfileRotations += 1;
|
|
1677
|
+
if (rateLimitProfileRotations <= rateLimitProfileRotationLimit || !fallbackConfigured) return;
|
|
1678
|
+
const status = resolveFailoverStatus("rate_limit");
|
|
1679
|
+
log.warn(`rate-limit profile rotation cap reached for ${sanitizeForLog(provider)}/${sanitizeForLog(modelId)} after ${rateLimitProfileRotations} rotations; escalating to model fallback`);
|
|
1680
|
+
params.logFallbackDecision("fallback_model", { status });
|
|
1681
|
+
throw new FailoverError("The AI service is temporarily rate-limited. Please try again in a moment.", {
|
|
1682
|
+
reason: "rate_limit",
|
|
1683
|
+
provider: params.failoverProvider,
|
|
1684
|
+
model: params.failoverModel,
|
|
1685
|
+
profileId: lastProfileId,
|
|
1686
|
+
status
|
|
1687
|
+
});
|
|
1688
|
+
};
|
|
1689
|
+
const maybeMarkAuthProfileFailure = async (failure) => {
|
|
1690
|
+
const { profileId, reason } = failure;
|
|
1691
|
+
if (!profileId || !reason || reason === "timeout") return;
|
|
1692
|
+
await markAuthProfileFailure({
|
|
1693
|
+
store: authStore,
|
|
1694
|
+
profileId,
|
|
1695
|
+
reason,
|
|
1696
|
+
cfg: params.config,
|
|
1697
|
+
agentDir,
|
|
1698
|
+
runId: params.runId,
|
|
1699
|
+
modelId: failure.modelId
|
|
1700
|
+
});
|
|
1701
|
+
};
|
|
1702
|
+
const resolveAuthProfileFailureReason = (failoverReason) => {
|
|
1703
|
+
if (!failoverReason || failoverReason === "timeout") return null;
|
|
1704
|
+
return failoverReason;
|
|
1705
|
+
};
|
|
1706
|
+
const maybeBackoffBeforeOverloadFailover = async (reason) => {
|
|
1707
|
+
if (reason !== "overloaded" || overloadFailoverBackoffMs <= 0) return;
|
|
1708
|
+
log.warn(`overload backoff before failover for ${provider}/${modelId}: delayMs=${overloadFailoverBackoffMs}`);
|
|
1709
|
+
try {
|
|
1710
|
+
await sleepWithAbort(overloadFailoverBackoffMs, params.abortSignal);
|
|
1711
|
+
} catch (err) {
|
|
1712
|
+
if (params.abortSignal?.aborted) {
|
|
1713
|
+
const abortErr = new Error("Operation aborted", { cause: err });
|
|
1714
|
+
abortErr.name = "AbortError";
|
|
1715
|
+
throw abortErr;
|
|
1716
|
+
}
|
|
1717
|
+
throw err;
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
ensureContextEnginesInitialized();
|
|
1721
|
+
const contextEngine = await resolveContextEngine(params.config);
|
|
1722
|
+
try {
|
|
1723
|
+
const runOwnsCompactionBeforeHook = async (reason) => {
|
|
1724
|
+
if (contextEngine.info.ownsCompaction !== true || !hookRunner?.hasHooks("before_compaction")) return;
|
|
1725
|
+
try {
|
|
1726
|
+
await hookRunner.runBeforeCompaction({
|
|
1727
|
+
messageCount: -1,
|
|
1728
|
+
sessionFile: params.sessionFile
|
|
1729
|
+
}, hookCtx);
|
|
1730
|
+
} catch (hookErr) {
|
|
1731
|
+
log.warn(`before_compaction hook failed during ${reason}: ${String(hookErr)}`);
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
const runOwnsCompactionAfterHook = async (reason, compactResult) => {
|
|
1735
|
+
if (contextEngine.info.ownsCompaction !== true || !compactResult.ok || !compactResult.compacted || !hookRunner?.hasHooks("after_compaction")) return;
|
|
1736
|
+
try {
|
|
1737
|
+
await hookRunner.runAfterCompaction({
|
|
1738
|
+
messageCount: -1,
|
|
1739
|
+
compactedCount: -1,
|
|
1740
|
+
tokenCount: compactResult.result?.tokensAfter,
|
|
1741
|
+
sessionFile: params.sessionFile
|
|
1742
|
+
}, hookCtx);
|
|
1743
|
+
} catch (hookErr) {
|
|
1744
|
+
log.warn(`after_compaction hook failed during ${reason}: ${String(hookErr)}`);
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
let authRetryPending = false;
|
|
1748
|
+
let accumulatedReplayState = createEmbeddedRunReplayState();
|
|
1749
|
+
let lastTurnTotal;
|
|
1750
|
+
while (true) {
|
|
1751
|
+
if (runLoopIterations >= MAX_RUN_LOOP_ITERATIONS) {
|
|
1752
|
+
const message = `Exceeded retry limit after ${runLoopIterations} attempts (max=${MAX_RUN_LOOP_ITERATIONS}).`;
|
|
1753
|
+
log.error(`[run-retry-limit] sessionKey=${params.sessionKey ?? params.sessionId} provider=${provider}/${modelId} attempts=${runLoopIterations} maxAttempts=${MAX_RUN_LOOP_ITERATIONS}`);
|
|
1754
|
+
return handleRetryLimitExhaustion({
|
|
1755
|
+
message,
|
|
1756
|
+
decision: resolveRunFailoverDecision({
|
|
1757
|
+
stage: "retry_limit",
|
|
1758
|
+
fallbackConfigured,
|
|
1759
|
+
failoverReason: lastRetryFailoverReason
|
|
1760
|
+
}),
|
|
1761
|
+
provider,
|
|
1762
|
+
model: modelId,
|
|
1763
|
+
profileId: lastProfileId,
|
|
1764
|
+
durationMs: Date.now() - started,
|
|
1765
|
+
agentMeta: buildErrorAgentMeta({
|
|
1766
|
+
sessionId: params.sessionId,
|
|
1767
|
+
provider,
|
|
1768
|
+
model: model.id,
|
|
1769
|
+
contextTokens: ctxInfo.tokens,
|
|
1770
|
+
usageAccumulator,
|
|
1771
|
+
lastRunPromptUsage,
|
|
1772
|
+
lastTurnTotal
|
|
1773
|
+
}),
|
|
1774
|
+
replayInvalid: accumulatedReplayState.replayInvalid ? true : void 0,
|
|
1775
|
+
livenessState: "blocked"
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
runLoopIterations += 1;
|
|
1779
|
+
const runtimeAuthRetry = authRetryPending;
|
|
1780
|
+
authRetryPending = false;
|
|
1781
|
+
attemptedThinking.add(thinkLevel);
|
|
1782
|
+
await fs.mkdir(resolvedWorkspace, { recursive: true });
|
|
1783
|
+
const basePrompt = provider === "anthropic" ? scrubAnthropicRefusalMagic(params.prompt) : params.prompt;
|
|
1784
|
+
const promptAdditions = [
|
|
1785
|
+
ackExecutionFastPathInstruction,
|
|
1786
|
+
planningOnlyRetryInstruction,
|
|
1787
|
+
reasoningOnlyRetryInstruction,
|
|
1788
|
+
emptyResponseRetryInstruction
|
|
1789
|
+
].filter((value) => typeof value === "string" && value.trim().length > 0);
|
|
1790
|
+
const prompt = promptAdditions.length > 0 ? `${basePrompt}\n\n${promptAdditions.join("\n\n")}` : basePrompt;
|
|
1791
|
+
let resolvedStreamApiKey;
|
|
1792
|
+
if (!runtimeAuthState && apiKeyInfo) resolvedStreamApiKey = apiKeyInfo.apiKey;
|
|
1793
|
+
const runtimePlan = buildAgentRuntimePlan({
|
|
1794
|
+
provider,
|
|
1795
|
+
modelId,
|
|
1796
|
+
model: effectiveModel,
|
|
1797
|
+
modelApi: effectiveModel.api,
|
|
1798
|
+
harnessId: agentHarness.id,
|
|
1799
|
+
harnessRuntime: agentHarness.id,
|
|
1800
|
+
allowHarnessAuthProfileForwarding: pluginHarnessOwnsTransport,
|
|
1801
|
+
authProfileProvider: lastProfileId?.split(":", 1)[0],
|
|
1802
|
+
sessionAuthProfileId: lastProfileId,
|
|
1803
|
+
config: params.config,
|
|
1804
|
+
workspaceDir: resolvedWorkspace,
|
|
1805
|
+
agentDir,
|
|
1806
|
+
agentId: workspaceResolution.agentId,
|
|
1807
|
+
thinkingLevel: thinkLevel,
|
|
1808
|
+
extraParamsOverride: {
|
|
1809
|
+
...params.streamParams,
|
|
1810
|
+
fastMode: params.fastMode
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
const attempt = await runEmbeddedAttemptWithBackend({
|
|
1814
|
+
sessionId: params.sessionId,
|
|
1815
|
+
sessionKey: resolvedSessionKey,
|
|
1816
|
+
sandboxSessionKey: params.sandboxSessionKey,
|
|
1817
|
+
trigger: params.trigger,
|
|
1818
|
+
memoryFlushWritePath: params.memoryFlushWritePath,
|
|
1819
|
+
messageChannel: params.messageChannel,
|
|
1820
|
+
messageProvider: params.messageProvider,
|
|
1821
|
+
agentAccountId: params.agentAccountId,
|
|
1822
|
+
messageTo: params.messageTo,
|
|
1823
|
+
messageThreadId: params.messageThreadId,
|
|
1824
|
+
groupId: params.groupId,
|
|
1825
|
+
groupChannel: params.groupChannel,
|
|
1826
|
+
groupSpace: params.groupSpace,
|
|
1827
|
+
memberRoleIds: params.memberRoleIds,
|
|
1828
|
+
spawnedBy: params.spawnedBy,
|
|
1829
|
+
isCanonicalWorkspace,
|
|
1830
|
+
senderId: params.senderId,
|
|
1831
|
+
senderName: params.senderName,
|
|
1832
|
+
senderUsername: params.senderUsername,
|
|
1833
|
+
senderE164: params.senderE164,
|
|
1834
|
+
senderIsOwner: params.senderIsOwner,
|
|
1835
|
+
currentChannelId: params.currentChannelId,
|
|
1836
|
+
currentThreadTs: params.currentThreadTs,
|
|
1837
|
+
currentMessageId: params.currentMessageId,
|
|
1838
|
+
replyToMode: params.replyToMode,
|
|
1839
|
+
hasRepliedRef: params.hasRepliedRef,
|
|
1840
|
+
sessionFile: params.sessionFile,
|
|
1841
|
+
workspaceDir: resolvedWorkspace,
|
|
1842
|
+
agentDir,
|
|
1843
|
+
config: params.config,
|
|
1844
|
+
allowGatewaySubagentBinding: params.allowGatewaySubagentBinding,
|
|
1845
|
+
contextEngine,
|
|
1846
|
+
contextTokenBudget: ctxInfo.tokens,
|
|
1847
|
+
skillsSnapshot: params.skillsSnapshot,
|
|
1848
|
+
prompt,
|
|
1849
|
+
transcriptPrompt: params.transcriptPrompt,
|
|
1850
|
+
images: params.images,
|
|
1851
|
+
imageOrder: params.imageOrder,
|
|
1852
|
+
clientTools: params.clientTools,
|
|
1853
|
+
disableTools: params.disableTools,
|
|
1854
|
+
provider,
|
|
1855
|
+
modelId,
|
|
1856
|
+
agentHarnessId: agentHarness.id,
|
|
1857
|
+
runtimePlan,
|
|
1858
|
+
model: applyAuthHeaderOverride(applyLocalNoAuthHeaderOverride(effectiveModel, apiKeyInfo), runtimeAuthState ? null : apiKeyInfo, params.config),
|
|
1859
|
+
resolvedApiKey: resolvedStreamApiKey,
|
|
1860
|
+
authProfileId: lastProfileId,
|
|
1861
|
+
authProfileIdSource: lockedProfileId ? "user" : "auto",
|
|
1862
|
+
initialReplayState: accumulatedReplayState,
|
|
1863
|
+
authStorage,
|
|
1864
|
+
modelRegistry,
|
|
1865
|
+
agentId: workspaceResolution.agentId,
|
|
1866
|
+
legacyBeforeAgentStartResult,
|
|
1867
|
+
thinkLevel,
|
|
1868
|
+
fastMode: params.fastMode,
|
|
1869
|
+
verboseLevel: params.verboseLevel,
|
|
1870
|
+
reasoningLevel: params.reasoningLevel,
|
|
1871
|
+
toolResultFormat: resolvedToolResultFormat,
|
|
1872
|
+
execOverrides: params.execOverrides,
|
|
1873
|
+
bashElevated: params.bashElevated,
|
|
1874
|
+
timeoutMs: params.timeoutMs,
|
|
1875
|
+
runId: params.runId,
|
|
1876
|
+
abortSignal: params.abortSignal,
|
|
1877
|
+
replyOperation: params.replyOperation,
|
|
1878
|
+
shouldEmitToolResult: params.shouldEmitToolResult,
|
|
1879
|
+
shouldEmitToolOutput: params.shouldEmitToolOutput,
|
|
1880
|
+
onPartialReply: params.onPartialReply,
|
|
1881
|
+
onAssistantMessageStart: params.onAssistantMessageStart,
|
|
1882
|
+
onBlockReply: params.onBlockReply,
|
|
1883
|
+
onBlockReplyFlush: params.onBlockReplyFlush,
|
|
1884
|
+
blockReplyBreak: params.blockReplyBreak,
|
|
1885
|
+
blockReplyChunking: params.blockReplyChunking,
|
|
1886
|
+
onReasoningStream: params.onReasoningStream,
|
|
1887
|
+
onReasoningEnd: params.onReasoningEnd,
|
|
1888
|
+
onToolResult: params.onToolResult,
|
|
1889
|
+
onAgentEvent: params.onAgentEvent,
|
|
1890
|
+
extraSystemPrompt: params.extraSystemPrompt,
|
|
1891
|
+
inputProvenance: params.inputProvenance,
|
|
1892
|
+
streamParams: params.streamParams,
|
|
1893
|
+
ownerNumbers: params.ownerNumbers,
|
|
1894
|
+
enforceFinalTag: params.enforceFinalTag,
|
|
1895
|
+
silentExpected: params.silentExpected,
|
|
1896
|
+
bootstrapContextMode: params.bootstrapContextMode,
|
|
1897
|
+
bootstrapContextRunKind: params.bootstrapContextRunKind,
|
|
1898
|
+
toolsAllow: params.toolsAllow,
|
|
1899
|
+
disableMessageTool: params.disableMessageTool,
|
|
1900
|
+
forceMessageTool: params.forceMessageTool,
|
|
1901
|
+
requireExplicitMessageTarget: params.requireExplicitMessageTarget,
|
|
1902
|
+
internalEvents: params.internalEvents,
|
|
1903
|
+
bootstrapPromptWarningSignaturesSeen,
|
|
1904
|
+
bootstrapPromptWarningSignature: bootstrapPromptWarningSignaturesSeen[bootstrapPromptWarningSignaturesSeen.length - 1]
|
|
1905
|
+
});
|
|
1906
|
+
const { aborted, externalAbort, promptError, promptErrorSource, preflightRecovery, timedOut, idleTimedOut, timedOutDuringCompaction, sessionIdUsed, lastAssistant: sessionLastAssistant, currentAttemptAssistant } = attempt;
|
|
1907
|
+
bootstrapPromptWarningSignaturesSeen = attempt.bootstrapPromptWarningSignaturesSeen ?? (attempt.bootstrapPromptWarningSignature ? Array.from(new Set([...bootstrapPromptWarningSignaturesSeen, attempt.bootstrapPromptWarningSignature])) : bootstrapPromptWarningSignaturesSeen);
|
|
1908
|
+
const lastAssistantUsage = normalizeUsage(sessionLastAssistant?.usage);
|
|
1909
|
+
const attemptUsage = attempt.attemptUsage ?? lastAssistantUsage;
|
|
1910
|
+
mergeUsageIntoAccumulator(usageAccumulator, attemptUsage);
|
|
1911
|
+
lastRunPromptUsage = lastAssistantUsage ?? attemptUsage;
|
|
1912
|
+
lastTurnTotal = lastAssistantUsage?.total ?? attemptUsage?.total;
|
|
1913
|
+
const attemptCompactionCount = Math.max(0, attempt.compactionCount ?? 0);
|
|
1914
|
+
autoCompactionCount += attemptCompactionCount;
|
|
1915
|
+
const activeErrorContext = resolveActiveErrorContext({
|
|
1916
|
+
provider,
|
|
1917
|
+
model: modelId,
|
|
1918
|
+
assistant: currentAttemptAssistant ?? sessionLastAssistant
|
|
1919
|
+
});
|
|
1920
|
+
const resolveReplayInvalidForAttempt = (incompleteTurnText) => accumulatedReplayState.replayInvalid || resolveReplayInvalidFlag({
|
|
1921
|
+
attempt,
|
|
1922
|
+
incompleteTurnText
|
|
1923
|
+
});
|
|
1924
|
+
if (resolveReplayInvalidForAttempt(null)) accumulatedReplayState.replayInvalid = true;
|
|
1925
|
+
accumulatedReplayState = observeReplayMetadata(accumulatedReplayState, attempt.replayMetadata);
|
|
1926
|
+
const formattedAssistantErrorText = sessionLastAssistant ? formatAssistantErrorText(sessionLastAssistant, {
|
|
1927
|
+
cfg: params.config,
|
|
1928
|
+
sessionKey: resolvedSessionKey ?? params.sessionId,
|
|
1929
|
+
provider: activeErrorContext.provider,
|
|
1930
|
+
model: activeErrorContext.model
|
|
1931
|
+
}) : void 0;
|
|
1932
|
+
const assistantErrorText = sessionLastAssistant?.stopReason === "error" ? sessionLastAssistant.errorMessage?.trim() || formattedAssistantErrorText : void 0;
|
|
1933
|
+
const canRestartForLiveSwitch = !attempt.didSendViaMessagingTool && !attempt.didSendDeterministicApprovalPrompt && !attempt.lastToolError && attempt.toolMetas.length === 0 && attempt.assistantTexts.length === 0;
|
|
1934
|
+
if (preflightRecovery?.handled) {
|
|
1935
|
+
log.info(`[context-overflow-precheck] early recovery route=${preflightRecovery.route} completed for ${provider}/${modelId}; retrying prompt`);
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
const requestedSelection = shouldSwitchToLiveModel({
|
|
1939
|
+
cfg: params.config,
|
|
1940
|
+
sessionKey: resolvedSessionKey,
|
|
1941
|
+
agentId: params.agentId,
|
|
1942
|
+
defaultProvider: DEFAULT_PROVIDER,
|
|
1943
|
+
defaultModel: DEFAULT_MODEL,
|
|
1944
|
+
currentProvider: provider,
|
|
1945
|
+
currentModel: modelId,
|
|
1946
|
+
currentAuthProfileId: preferredProfileId,
|
|
1947
|
+
currentAuthProfileIdSource: params.authProfileIdSource
|
|
1948
|
+
});
|
|
1949
|
+
if (requestedSelection && canRestartForLiveSwitch) {
|
|
1950
|
+
await clearLiveModelSwitchPending({
|
|
1951
|
+
cfg: params.config,
|
|
1952
|
+
sessionKey: resolvedSessionKey,
|
|
1953
|
+
agentId: params.agentId
|
|
1954
|
+
});
|
|
1955
|
+
log.info(`live session model switch requested during active attempt for ${params.sessionId}: ${provider}/${modelId} -> ${requestedSelection.provider}/${requestedSelection.model}`);
|
|
1956
|
+
throw new LiveSessionModelSwitchError(requestedSelection);
|
|
1957
|
+
}
|
|
1958
|
+
if (timedOut && !timedOutDuringCompaction) {
|
|
1959
|
+
const lastTurnPromptTokens = derivePromptTokens(lastRunPromptUsage);
|
|
1960
|
+
const tokenUsedRatio = lastTurnPromptTokens != null && ctxInfo.tokens > 0 ? lastTurnPromptTokens / ctxInfo.tokens : 0;
|
|
1961
|
+
if (timeoutCompactionAttempts >= MAX_TIMEOUT_COMPACTION_ATTEMPTS) log.warn(`[timeout-compaction] already attempted timeout compaction ${timeoutCompactionAttempts} time(s); falling through to failover rotation`);
|
|
1962
|
+
else if (tokenUsedRatio > .65) {
|
|
1963
|
+
const timeoutDiagId = createCompactionDiagId();
|
|
1964
|
+
timeoutCompactionAttempts++;
|
|
1965
|
+
log.warn(`[timeout-compaction] LLM timed out with high prompt token usage (${Math.round(tokenUsedRatio * 100)}%); attempting compaction before retry (attempt ${timeoutCompactionAttempts}/${MAX_TIMEOUT_COMPACTION_ATTEMPTS}) diagId=${timeoutDiagId}`);
|
|
1966
|
+
let timeoutCompactResult;
|
|
1967
|
+
await runOwnsCompactionBeforeHook("timeout recovery");
|
|
1968
|
+
try {
|
|
1969
|
+
const timeoutCompactionRuntimeContext = {
|
|
1970
|
+
...buildEmbeddedCompactionRuntimeContext({
|
|
1971
|
+
sessionKey: params.sessionKey,
|
|
1972
|
+
messageChannel: params.messageChannel,
|
|
1973
|
+
messageProvider: params.messageProvider,
|
|
1974
|
+
agentAccountId: params.agentAccountId,
|
|
1975
|
+
currentChannelId: params.currentChannelId,
|
|
1976
|
+
currentThreadTs: params.currentThreadTs,
|
|
1977
|
+
currentMessageId: params.currentMessageId,
|
|
1978
|
+
authProfileId: lastProfileId,
|
|
1979
|
+
workspaceDir: resolvedWorkspace,
|
|
1980
|
+
agentDir,
|
|
1981
|
+
config: params.config,
|
|
1982
|
+
skillsSnapshot: params.skillsSnapshot,
|
|
1983
|
+
senderIsOwner: params.senderIsOwner,
|
|
1984
|
+
senderId: params.senderId,
|
|
1985
|
+
provider,
|
|
1986
|
+
modelId,
|
|
1987
|
+
thinkLevel,
|
|
1988
|
+
reasoningLevel: params.reasoningLevel,
|
|
1989
|
+
bashElevated: params.bashElevated,
|
|
1990
|
+
extraSystemPrompt: params.extraSystemPrompt,
|
|
1991
|
+
ownerNumbers: params.ownerNumbers
|
|
1992
|
+
}),
|
|
1993
|
+
...attempt.promptCache ? { promptCache: attempt.promptCache } : {},
|
|
1994
|
+
runId: params.runId,
|
|
1995
|
+
trigger: "timeout_recovery",
|
|
1996
|
+
diagId: timeoutDiagId,
|
|
1997
|
+
attempt: timeoutCompactionAttempts,
|
|
1998
|
+
maxAttempts: MAX_TIMEOUT_COMPACTION_ATTEMPTS
|
|
1999
|
+
};
|
|
2000
|
+
timeoutCompactResult = await contextEngine.compact({
|
|
2001
|
+
sessionId: params.sessionId,
|
|
2002
|
+
sessionKey: params.sessionKey,
|
|
2003
|
+
sessionFile: params.sessionFile,
|
|
2004
|
+
tokenBudget: ctxInfo.tokens,
|
|
2005
|
+
force: true,
|
|
2006
|
+
compactionTarget: "budget",
|
|
2007
|
+
runtimeContext: timeoutCompactionRuntimeContext
|
|
2008
|
+
});
|
|
2009
|
+
} catch (compactErr) {
|
|
2010
|
+
log.warn(`[timeout-compaction] contextEngine.compact() threw during timeout recovery for ${provider}/${modelId}: ${String(compactErr)}`);
|
|
2011
|
+
timeoutCompactResult = {
|
|
2012
|
+
ok: false,
|
|
2013
|
+
compacted: false,
|
|
2014
|
+
reason: String(compactErr)
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
await runOwnsCompactionAfterHook("timeout recovery", timeoutCompactResult);
|
|
2018
|
+
if (timeoutCompactResult.compacted) {
|
|
2019
|
+
autoCompactionCount += 1;
|
|
2020
|
+
if (contextEngine.info.ownsCompaction === true) await runPostCompactionSideEffects({
|
|
2021
|
+
config: params.config,
|
|
2022
|
+
sessionKey: params.sessionKey,
|
|
2023
|
+
sessionFile: params.sessionFile
|
|
2024
|
+
});
|
|
2025
|
+
log.info(`[timeout-compaction] compaction succeeded for ${provider}/${modelId}; retrying prompt`);
|
|
2026
|
+
continue;
|
|
2027
|
+
} else log.warn(`[timeout-compaction] compaction did not reduce context for ${provider}/${modelId}; falling through to normal handling`);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
const contextOverflowError = !aborted ? (() => {
|
|
2031
|
+
if (promptError) {
|
|
2032
|
+
const errorText = formatErrorMessage(promptError);
|
|
2033
|
+
if (isLikelyContextOverflowError(errorText)) return {
|
|
2034
|
+
text: errorText,
|
|
2035
|
+
source: "promptError"
|
|
2036
|
+
};
|
|
2037
|
+
return null;
|
|
2038
|
+
}
|
|
2039
|
+
if (assistantErrorText && isLikelyContextOverflowError(assistantErrorText)) return {
|
|
2040
|
+
text: assistantErrorText,
|
|
2041
|
+
source: "assistantError"
|
|
2042
|
+
};
|
|
2043
|
+
return null;
|
|
2044
|
+
})() : null;
|
|
2045
|
+
if (contextOverflowError) {
|
|
2046
|
+
const overflowDiagId = createCompactionDiagId();
|
|
2047
|
+
const errorText = contextOverflowError.text;
|
|
2048
|
+
const msgCount = attempt.messagesSnapshot?.length ?? 0;
|
|
2049
|
+
const observedOverflowTokens = extractObservedOverflowTokenCount(errorText);
|
|
2050
|
+
log.warn(`[context-overflow-diag] sessionKey=${params.sessionKey ?? params.sessionId} provider=${provider}/${modelId} source=${contextOverflowError.source} messages=${msgCount} sessionFile=${params.sessionFile} diagId=${overflowDiagId} compactionAttempts=${overflowCompactionAttempts} observedTokens=${observedOverflowTokens ?? "unknown"} error=${errorText.slice(0, 200)}`);
|
|
2051
|
+
const isCompactionFailure = isCompactionFailureError(errorText);
|
|
2052
|
+
const hadAttemptLevelCompaction = attemptCompactionCount > 0;
|
|
2053
|
+
if (!isCompactionFailure && hadAttemptLevelCompaction && overflowCompactionAttempts < MAX_OVERFLOW_COMPACTION_ATTEMPTS) {
|
|
2054
|
+
overflowCompactionAttempts++;
|
|
2055
|
+
log.warn(`context overflow persisted after in-attempt compaction (attempt ${overflowCompactionAttempts}/${MAX_OVERFLOW_COMPACTION_ATTEMPTS}); retrying prompt without additional compaction for ${provider}/${modelId}`);
|
|
2056
|
+
continue;
|
|
2057
|
+
}
|
|
2058
|
+
if (!isCompactionFailure && !hadAttemptLevelCompaction && overflowCompactionAttempts < MAX_OVERFLOW_COMPACTION_ATTEMPTS) {
|
|
2059
|
+
if (log.isEnabled("debug")) log.debug(`[compaction-diag] decision diagId=${overflowDiagId} branch=compact isCompactionFailure=${isCompactionFailure} hasOversizedToolResults=unknown attempt=${overflowCompactionAttempts + 1} maxAttempts=${MAX_OVERFLOW_COMPACTION_ATTEMPTS}`);
|
|
2060
|
+
overflowCompactionAttempts++;
|
|
2061
|
+
log.warn(`context overflow detected (attempt ${overflowCompactionAttempts}/${MAX_OVERFLOW_COMPACTION_ATTEMPTS}); attempting auto-compaction for ${provider}/${modelId}`);
|
|
2062
|
+
let compactResult;
|
|
2063
|
+
await runOwnsCompactionBeforeHook("overflow recovery");
|
|
2064
|
+
try {
|
|
2065
|
+
const overflowCompactionRuntimeContext = {
|
|
2066
|
+
...buildEmbeddedCompactionRuntimeContext({
|
|
2067
|
+
sessionKey: params.sessionKey,
|
|
2068
|
+
messageChannel: params.messageChannel,
|
|
2069
|
+
messageProvider: params.messageProvider,
|
|
2070
|
+
agentAccountId: params.agentAccountId,
|
|
2071
|
+
currentChannelId: params.currentChannelId,
|
|
2072
|
+
currentThreadTs: params.currentThreadTs,
|
|
2073
|
+
currentMessageId: params.currentMessageId,
|
|
2074
|
+
authProfileId: lastProfileId,
|
|
2075
|
+
workspaceDir: resolvedWorkspace,
|
|
2076
|
+
agentDir,
|
|
2077
|
+
config: params.config,
|
|
2078
|
+
skillsSnapshot: params.skillsSnapshot,
|
|
2079
|
+
senderIsOwner: params.senderIsOwner,
|
|
2080
|
+
senderId: params.senderId,
|
|
2081
|
+
provider,
|
|
2082
|
+
modelId,
|
|
2083
|
+
thinkLevel,
|
|
2084
|
+
reasoningLevel: params.reasoningLevel,
|
|
2085
|
+
bashElevated: params.bashElevated,
|
|
2086
|
+
extraSystemPrompt: params.extraSystemPrompt,
|
|
2087
|
+
ownerNumbers: params.ownerNumbers
|
|
2088
|
+
}),
|
|
2089
|
+
...attempt.promptCache ? { promptCache: attempt.promptCache } : {},
|
|
2090
|
+
runId: params.runId,
|
|
2091
|
+
trigger: "overflow",
|
|
2092
|
+
...observedOverflowTokens !== void 0 ? { currentTokenCount: observedOverflowTokens } : {},
|
|
2093
|
+
diagId: overflowDiagId,
|
|
2094
|
+
attempt: overflowCompactionAttempts,
|
|
2095
|
+
maxAttempts: MAX_OVERFLOW_COMPACTION_ATTEMPTS
|
|
2096
|
+
};
|
|
2097
|
+
compactResult = await contextEngine.compact({
|
|
2098
|
+
sessionId: params.sessionId,
|
|
2099
|
+
sessionKey: params.sessionKey,
|
|
2100
|
+
sessionFile: params.sessionFile,
|
|
2101
|
+
tokenBudget: ctxInfo.tokens,
|
|
2102
|
+
...observedOverflowTokens !== void 0 ? { currentTokenCount: observedOverflowTokens } : {},
|
|
2103
|
+
force: true,
|
|
2104
|
+
compactionTarget: "budget",
|
|
2105
|
+
runtimeContext: overflowCompactionRuntimeContext
|
|
2106
|
+
});
|
|
2107
|
+
if (compactResult.ok && compactResult.compacted) await runContextEngineMaintenance({
|
|
2108
|
+
contextEngine,
|
|
2109
|
+
sessionId: params.sessionId,
|
|
2110
|
+
sessionKey: params.sessionKey,
|
|
2111
|
+
sessionFile: params.sessionFile,
|
|
2112
|
+
reason: "compaction",
|
|
2113
|
+
runtimeContext: overflowCompactionRuntimeContext
|
|
2114
|
+
});
|
|
2115
|
+
} catch (compactErr) {
|
|
2116
|
+
log.warn(`contextEngine.compact() threw during overflow recovery for ${provider}/${modelId}: ${String(compactErr)}`);
|
|
2117
|
+
compactResult = {
|
|
2118
|
+
ok: false,
|
|
2119
|
+
compacted: false,
|
|
2120
|
+
reason: String(compactErr)
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
await runOwnsCompactionAfterHook("overflow recovery", compactResult);
|
|
2124
|
+
if (compactResult.compacted) {
|
|
2125
|
+
if (preflightRecovery?.route === "compact_then_truncate") {
|
|
2126
|
+
const truncResult = await truncateOversizedToolResultsInSession({
|
|
2127
|
+
sessionFile: params.sessionFile,
|
|
2128
|
+
contextWindowTokens: ctxInfo.tokens,
|
|
2129
|
+
maxCharsOverride: resolveLiveToolResultMaxChars({
|
|
2130
|
+
contextWindowTokens: ctxInfo.tokens,
|
|
2131
|
+
cfg: params.config,
|
|
2132
|
+
agentId: sessionAgentId
|
|
2133
|
+
}),
|
|
2134
|
+
sessionId: params.sessionId,
|
|
2135
|
+
sessionKey: params.sessionKey
|
|
2136
|
+
});
|
|
2137
|
+
if (truncResult.truncated) log.info(`[context-overflow-precheck] post-compaction tool-result truncation succeeded for ${provider}/${modelId}; truncated ${truncResult.truncatedCount} tool result(s)`);
|
|
2138
|
+
else log.warn(`[context-overflow-precheck] post-compaction tool-result truncation did not help for ${provider}/${modelId}: ${truncResult.reason ?? "unknown"}`);
|
|
2139
|
+
}
|
|
2140
|
+
autoCompactionCount += 1;
|
|
2141
|
+
log.info(`auto-compaction succeeded for ${provider}/${modelId}; retrying prompt`);
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
log.warn(`auto-compaction failed for ${provider}/${modelId}: ${compactResult.reason ?? "nothing to compact"}`);
|
|
2145
|
+
}
|
|
2146
|
+
if (!toolResultTruncationAttempted) {
|
|
2147
|
+
const contextWindowTokens = ctxInfo.tokens;
|
|
2148
|
+
const toolResultMaxChars = resolveLiveToolResultMaxChars({
|
|
2149
|
+
contextWindowTokens,
|
|
2150
|
+
cfg: params.config,
|
|
2151
|
+
agentId: sessionAgentId
|
|
2152
|
+
});
|
|
2153
|
+
if (attempt.messagesSnapshot ? sessionLikelyHasOversizedToolResults({
|
|
2154
|
+
messages: attempt.messagesSnapshot,
|
|
2155
|
+
contextWindowTokens,
|
|
2156
|
+
maxCharsOverride: toolResultMaxChars
|
|
2157
|
+
}) : false) {
|
|
2158
|
+
toolResultTruncationAttempted = true;
|
|
2159
|
+
log.warn(`[context-overflow-recovery] Attempting tool result truncation for ${provider}/${modelId} (contextWindow=${contextWindowTokens} tokens)`);
|
|
2160
|
+
const truncResult = await truncateOversizedToolResultsInSession({
|
|
2161
|
+
sessionFile: params.sessionFile,
|
|
2162
|
+
contextWindowTokens,
|
|
2163
|
+
maxCharsOverride: toolResultMaxChars,
|
|
2164
|
+
sessionId: params.sessionId,
|
|
2165
|
+
sessionKey: params.sessionKey
|
|
2166
|
+
});
|
|
2167
|
+
if (truncResult.truncated) {
|
|
2168
|
+
log.info(`[context-overflow-recovery] Truncated ${truncResult.truncatedCount} tool result(s); retrying prompt`);
|
|
2169
|
+
continue;
|
|
2170
|
+
}
|
|
2171
|
+
log.warn(`[context-overflow-recovery] Tool result truncation did not help: ${truncResult.reason ?? "unknown"}`);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
if ((isCompactionFailure || overflowCompactionAttempts >= MAX_OVERFLOW_COMPACTION_ATTEMPTS) && log.isEnabled("debug")) log.debug(`[compaction-diag] decision diagId=${overflowDiagId} branch=give_up isCompactionFailure=${isCompactionFailure} hasOversizedToolResults=unknown attempt=${overflowCompactionAttempts} maxAttempts=${MAX_OVERFLOW_COMPACTION_ATTEMPTS}`);
|
|
2175
|
+
const kind = isCompactionFailure ? "compaction_failure" : "context_overflow";
|
|
2176
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2177
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2178
|
+
livenessState: "blocked"
|
|
2179
|
+
});
|
|
2180
|
+
return {
|
|
2181
|
+
payloads: [{
|
|
2182
|
+
text: "Context overflow: prompt too large for the model. Try /reset (or /new) to start a fresh session, or use a larger-context model.",
|
|
2183
|
+
isError: true
|
|
2184
|
+
}],
|
|
2185
|
+
meta: {
|
|
2186
|
+
durationMs: Date.now() - started,
|
|
2187
|
+
agentMeta: buildErrorAgentMeta({
|
|
2188
|
+
sessionId: sessionIdUsed,
|
|
2189
|
+
provider,
|
|
2190
|
+
model: model.id,
|
|
2191
|
+
contextTokens: ctxInfo.tokens,
|
|
2192
|
+
usageAccumulator,
|
|
2193
|
+
lastRunPromptUsage,
|
|
2194
|
+
lastAssistant: sessionLastAssistant,
|
|
2195
|
+
lastTurnTotal
|
|
2196
|
+
}),
|
|
2197
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2198
|
+
finalPromptText: attempt.finalPromptText,
|
|
2199
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2200
|
+
livenessState: "blocked",
|
|
2201
|
+
error: {
|
|
2202
|
+
kind,
|
|
2203
|
+
message: errorText
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
if (promptError && !aborted && promptErrorSource !== "compaction") {
|
|
2209
|
+
const normalizedPromptFailover = coerceToFailoverError(promptError, {
|
|
2210
|
+
provider: activeErrorContext.provider,
|
|
2211
|
+
model: activeErrorContext.model,
|
|
2212
|
+
profileId: lastProfileId
|
|
2213
|
+
});
|
|
2214
|
+
const promptErrorDetails = normalizedPromptFailover ? describeFailoverError(normalizedPromptFailover) : describeFailoverError(promptError);
|
|
2215
|
+
const errorText = promptErrorDetails.message || formatErrorMessage(promptError);
|
|
2216
|
+
if (await maybeRefreshRuntimeAuthForAuthError(errorText, runtimeAuthRetry)) {
|
|
2217
|
+
authRetryPending = true;
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2220
|
+
if (/incorrect role information|roles must alternate/i.test(errorText)) {
|
|
2221
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2222
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2223
|
+
livenessState: "blocked"
|
|
2224
|
+
});
|
|
2225
|
+
return {
|
|
2226
|
+
payloads: [{
|
|
2227
|
+
text: "Message ordering conflict - please try again. If this persists, use /new to start a fresh session.",
|
|
2228
|
+
isError: true
|
|
2229
|
+
}],
|
|
2230
|
+
meta: {
|
|
2231
|
+
durationMs: Date.now() - started,
|
|
2232
|
+
agentMeta: buildErrorAgentMeta({
|
|
2233
|
+
sessionId: sessionIdUsed,
|
|
2234
|
+
provider,
|
|
2235
|
+
model: model.id,
|
|
2236
|
+
contextTokens: ctxInfo.tokens,
|
|
2237
|
+
usageAccumulator,
|
|
2238
|
+
lastRunPromptUsage,
|
|
2239
|
+
lastAssistant: sessionLastAssistant,
|
|
2240
|
+
lastTurnTotal
|
|
2241
|
+
}),
|
|
2242
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2243
|
+
finalPromptText: attempt.finalPromptText,
|
|
2244
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2245
|
+
livenessState: "blocked",
|
|
2246
|
+
error: {
|
|
2247
|
+
kind: "role_ordering",
|
|
2248
|
+
message: errorText
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
const imageSizeError = parseImageSizeError(errorText);
|
|
2254
|
+
if (imageSizeError) {
|
|
2255
|
+
const maxMb = imageSizeError.maxMb;
|
|
2256
|
+
const maxMbLabel = typeof maxMb === "number" && Number.isFinite(maxMb) ? `${maxMb}` : null;
|
|
2257
|
+
const maxBytesHint = maxMbLabel ? ` (max ${maxMbLabel}MB)` : "";
|
|
2258
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2259
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2260
|
+
livenessState: "blocked"
|
|
2261
|
+
});
|
|
2262
|
+
return {
|
|
2263
|
+
payloads: [{
|
|
2264
|
+
text: `Image too large for the model${maxBytesHint}. Please compress or resize the image and try again.`,
|
|
2265
|
+
isError: true
|
|
2266
|
+
}],
|
|
2267
|
+
meta: {
|
|
2268
|
+
durationMs: Date.now() - started,
|
|
2269
|
+
agentMeta: buildErrorAgentMeta({
|
|
2270
|
+
sessionId: sessionIdUsed,
|
|
2271
|
+
provider,
|
|
2272
|
+
model: model.id,
|
|
2273
|
+
contextTokens: ctxInfo.tokens,
|
|
2274
|
+
usageAccumulator,
|
|
2275
|
+
lastRunPromptUsage,
|
|
2276
|
+
lastAssistant: sessionLastAssistant,
|
|
2277
|
+
lastTurnTotal
|
|
2278
|
+
}),
|
|
2279
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2280
|
+
finalPromptText: attempt.finalPromptText,
|
|
2281
|
+
replayInvalid: resolveReplayInvalidForAttempt(),
|
|
2282
|
+
livenessState: "blocked",
|
|
2283
|
+
error: {
|
|
2284
|
+
kind: "image_size",
|
|
2285
|
+
message: errorText
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
const promptFailoverReason = promptErrorDetails.reason ?? classifyFailoverReason(errorText, { provider });
|
|
2291
|
+
const promptProfileFailureReason = resolveAuthProfileFailureReason(promptFailoverReason);
|
|
2292
|
+
await maybeMarkAuthProfileFailure({
|
|
2293
|
+
profileId: lastProfileId,
|
|
2294
|
+
reason: promptProfileFailureReason,
|
|
2295
|
+
modelId
|
|
2296
|
+
});
|
|
2297
|
+
const promptFailoverFailure = promptFailoverReason !== null || isFailoverErrorMessage(errorText, { provider });
|
|
2298
|
+
const failedPromptProfileId = lastProfileId;
|
|
2299
|
+
const logPromptFailoverDecision = createFailoverDecisionLogger({
|
|
2300
|
+
stage: "prompt",
|
|
2301
|
+
runId: params.runId,
|
|
2302
|
+
rawError: errorText,
|
|
2303
|
+
failoverReason: promptFailoverReason,
|
|
2304
|
+
profileFailureReason: promptProfileFailureReason,
|
|
2305
|
+
provider,
|
|
2306
|
+
model: modelId,
|
|
2307
|
+
sourceProvider: provider,
|
|
2308
|
+
sourceModel: modelId,
|
|
2309
|
+
profileId: failedPromptProfileId,
|
|
2310
|
+
fallbackConfigured,
|
|
2311
|
+
aborted
|
|
2312
|
+
});
|
|
2313
|
+
if (promptFailoverReason === "rate_limit") maybeEscalateRateLimitProfileFallback({
|
|
2314
|
+
failoverProvider: provider,
|
|
2315
|
+
failoverModel: modelId,
|
|
2316
|
+
logFallbackDecision: logPromptFailoverDecision
|
|
2317
|
+
});
|
|
2318
|
+
let promptFailoverDecision = resolveRunFailoverDecision({
|
|
2319
|
+
stage: "prompt",
|
|
2320
|
+
aborted,
|
|
2321
|
+
externalAbort,
|
|
2322
|
+
fallbackConfigured,
|
|
2323
|
+
failoverFailure: promptFailoverFailure,
|
|
2324
|
+
failoverReason: promptFailoverReason,
|
|
2325
|
+
profileRotated: false
|
|
2326
|
+
});
|
|
2327
|
+
if (promptFailoverDecision.action === "rotate_profile" && await advanceAuthProfile()) {
|
|
2328
|
+
traceAttempts.push({
|
|
2329
|
+
provider,
|
|
2330
|
+
model: modelId,
|
|
2331
|
+
result: promptFailoverReason === "timeout" ? "timeout" : "rotate_profile",
|
|
2332
|
+
...promptFailoverReason ? { reason: promptFailoverReason } : {},
|
|
2333
|
+
stage: "prompt"
|
|
2334
|
+
});
|
|
2335
|
+
lastRetryFailoverReason = mergeRetryFailoverReason({
|
|
2336
|
+
previous: lastRetryFailoverReason,
|
|
2337
|
+
failoverReason: promptFailoverReason
|
|
2338
|
+
});
|
|
2339
|
+
logPromptFailoverDecision("rotate_profile");
|
|
2340
|
+
await maybeBackoffBeforeOverloadFailover(promptFailoverReason);
|
|
2341
|
+
continue;
|
|
2342
|
+
}
|
|
2343
|
+
if (promptFailoverDecision.action === "rotate_profile") promptFailoverDecision = resolveRunFailoverDecision({
|
|
2344
|
+
stage: "prompt",
|
|
2345
|
+
aborted,
|
|
2346
|
+
externalAbort,
|
|
2347
|
+
fallbackConfigured,
|
|
2348
|
+
failoverFailure: promptFailoverFailure,
|
|
2349
|
+
failoverReason: promptFailoverReason,
|
|
2350
|
+
profileRotated: true
|
|
2351
|
+
});
|
|
2352
|
+
const fallbackThinking = pickFallbackThinkingLevel({
|
|
2353
|
+
message: errorText,
|
|
2354
|
+
attempted: attemptedThinking
|
|
2355
|
+
});
|
|
2356
|
+
if (fallbackThinking) {
|
|
2357
|
+
log.warn(`unsupported thinking level for ${provider}/${modelId}; retrying with ${fallbackThinking}`);
|
|
2358
|
+
thinkLevel = fallbackThinking;
|
|
2359
|
+
continue;
|
|
2360
|
+
}
|
|
2361
|
+
if (promptFailoverDecision.action === "fallback_model") {
|
|
2362
|
+
const fallbackReason = promptFailoverDecision.reason ?? "unknown";
|
|
2363
|
+
const status = resolveFailoverStatus(fallbackReason);
|
|
2364
|
+
traceAttempts.push({
|
|
2365
|
+
provider,
|
|
2366
|
+
model: modelId,
|
|
2367
|
+
result: promptFailoverReason === "timeout" ? "timeout" : "fallback_model",
|
|
2368
|
+
reason: fallbackReason,
|
|
2369
|
+
stage: "prompt",
|
|
2370
|
+
...typeof status === "number" ? { status } : {}
|
|
2371
|
+
});
|
|
2372
|
+
logPromptFailoverDecision("fallback_model", { status });
|
|
2373
|
+
await maybeBackoffBeforeOverloadFailover(promptFailoverReason);
|
|
2374
|
+
throw normalizedPromptFailover ?? new FailoverError(errorText, {
|
|
2375
|
+
reason: fallbackReason,
|
|
2376
|
+
provider,
|
|
2377
|
+
model: modelId,
|
|
2378
|
+
profileId: lastProfileId,
|
|
2379
|
+
status
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
if (promptFailoverDecision.action === "surface_error") {
|
|
2383
|
+
traceAttempts.push({
|
|
2384
|
+
provider,
|
|
2385
|
+
model: modelId,
|
|
2386
|
+
result: promptFailoverReason === "timeout" ? "timeout" : "surface_error",
|
|
2387
|
+
...promptFailoverReason ? { reason: promptFailoverReason } : {},
|
|
2388
|
+
stage: "prompt"
|
|
2389
|
+
});
|
|
2390
|
+
logPromptFailoverDecision("surface_error");
|
|
2391
|
+
}
|
|
2392
|
+
throw promptError;
|
|
2393
|
+
}
|
|
2394
|
+
const assistantForFailover = currentAttemptAssistant ?? sessionLastAssistant;
|
|
2395
|
+
const fallbackThinking = pickFallbackThinkingLevel({
|
|
2396
|
+
message: assistantForFailover?.errorMessage,
|
|
2397
|
+
attempted: attemptedThinking
|
|
2398
|
+
});
|
|
2399
|
+
if (fallbackThinking && !aborted) {
|
|
2400
|
+
log.warn(`unsupported thinking level for ${provider}/${modelId}; retrying with ${fallbackThinking}`);
|
|
2401
|
+
thinkLevel = fallbackThinking;
|
|
2402
|
+
continue;
|
|
2403
|
+
}
|
|
2404
|
+
const authFailure = isAuthAssistantError(assistantForFailover);
|
|
2405
|
+
const rateLimitFailure = isRateLimitAssistantError(assistantForFailover);
|
|
2406
|
+
const billingFailure = isBillingAssistantError(assistantForFailover);
|
|
2407
|
+
const failoverFailure = isFailoverAssistantError(assistantForFailover);
|
|
2408
|
+
const assistantFailoverReason = classifyFailoverReason(assistantForFailover?.errorMessage ?? "", { provider: assistantForFailover?.provider });
|
|
2409
|
+
const assistantProfileFailureReason = resolveAuthProfileFailureReason(assistantFailoverReason);
|
|
2410
|
+
const cloudCodeAssistFormatError = attempt.cloudCodeAssistFormatError;
|
|
2411
|
+
const imageDimensionError = parseImageDimensionError(assistantForFailover?.errorMessage ?? "");
|
|
2412
|
+
const failedAssistantProfileId = lastProfileId;
|
|
2413
|
+
const logAssistantFailoverDecision = createFailoverDecisionLogger({
|
|
2414
|
+
stage: "assistant",
|
|
2415
|
+
runId: params.runId,
|
|
2416
|
+
rawError: assistantForFailover?.errorMessage?.trim(),
|
|
2417
|
+
failoverReason: assistantFailoverReason,
|
|
2418
|
+
profileFailureReason: assistantProfileFailureReason,
|
|
2419
|
+
provider: activeErrorContext.provider,
|
|
2420
|
+
model: activeErrorContext.model,
|
|
2421
|
+
sourceProvider: assistantForFailover?.provider ?? provider,
|
|
2422
|
+
sourceModel: assistantForFailover?.model ?? modelId,
|
|
2423
|
+
profileId: failedAssistantProfileId,
|
|
2424
|
+
fallbackConfigured,
|
|
2425
|
+
timedOut,
|
|
2426
|
+
aborted
|
|
2427
|
+
});
|
|
2428
|
+
if (authFailure && await maybeRefreshRuntimeAuthForAuthError(assistantForFailover?.errorMessage ?? "", runtimeAuthRetry)) {
|
|
2429
|
+
authRetryPending = true;
|
|
2430
|
+
continue;
|
|
2431
|
+
}
|
|
2432
|
+
if (imageDimensionError && lastProfileId) {
|
|
2433
|
+
const details = [
|
|
2434
|
+
imageDimensionError.messageIndex !== void 0 ? `message=${imageDimensionError.messageIndex}` : null,
|
|
2435
|
+
imageDimensionError.contentIndex !== void 0 ? `content=${imageDimensionError.contentIndex}` : null,
|
|
2436
|
+
imageDimensionError.maxDimensionPx !== void 0 ? `limit=${imageDimensionError.maxDimensionPx}px` : null
|
|
2437
|
+
].filter(Boolean).join(" ");
|
|
2438
|
+
log.warn(`Profile ${lastProfileId} rejected image payload${details ? ` (${details})` : ""}.`);
|
|
2439
|
+
}
|
|
2440
|
+
const assistantFailoverDecision = resolveRunFailoverDecision({
|
|
2441
|
+
stage: "assistant",
|
|
2442
|
+
aborted,
|
|
2443
|
+
externalAbort,
|
|
2444
|
+
fallbackConfigured,
|
|
2445
|
+
failoverFailure,
|
|
2446
|
+
failoverReason: assistantFailoverReason,
|
|
2447
|
+
timedOut,
|
|
2448
|
+
timedOutDuringCompaction,
|
|
2449
|
+
profileRotated: false
|
|
2450
|
+
});
|
|
2451
|
+
const assistantFailoverOutcome = await handleAssistantFailover({
|
|
2452
|
+
initialDecision: assistantFailoverDecision,
|
|
2453
|
+
aborted,
|
|
2454
|
+
externalAbort,
|
|
2455
|
+
fallbackConfigured,
|
|
2456
|
+
failoverFailure,
|
|
2457
|
+
failoverReason: assistantFailoverReason,
|
|
2458
|
+
timedOut,
|
|
2459
|
+
idleTimedOut,
|
|
2460
|
+
timedOutDuringCompaction,
|
|
2461
|
+
allowSameModelIdleTimeoutRetry: timedOut && idleTimedOut && !timedOutDuringCompaction && !fallbackConfigured && canRestartForLiveSwitch && sameModelIdleTimeoutRetries < MAX_SAME_MODEL_IDLE_TIMEOUT_RETRIES,
|
|
2462
|
+
assistantProfileFailureReason,
|
|
2463
|
+
lastProfileId,
|
|
2464
|
+
modelId,
|
|
2465
|
+
provider,
|
|
2466
|
+
activeErrorContext,
|
|
2467
|
+
lastAssistant: assistantForFailover,
|
|
2468
|
+
config: params.config,
|
|
2469
|
+
sessionKey: params.sessionKey ?? params.sessionId,
|
|
2470
|
+
authFailure,
|
|
2471
|
+
rateLimitFailure,
|
|
2472
|
+
billingFailure,
|
|
2473
|
+
cloudCodeAssistFormatError,
|
|
2474
|
+
isProbeSession,
|
|
2475
|
+
overloadProfileRotations,
|
|
2476
|
+
overloadProfileRotationLimit,
|
|
2477
|
+
previousRetryFailoverReason: lastRetryFailoverReason,
|
|
2478
|
+
logAssistantFailoverDecision,
|
|
2479
|
+
warn: (message) => log.warn(message),
|
|
2480
|
+
maybeMarkAuthProfileFailure,
|
|
2481
|
+
maybeEscalateRateLimitProfileFallback,
|
|
2482
|
+
maybeBackoffBeforeOverloadFailover,
|
|
2483
|
+
advanceAuthProfile
|
|
2484
|
+
});
|
|
2485
|
+
overloadProfileRotations = assistantFailoverOutcome.overloadProfileRotations;
|
|
2486
|
+
if (assistantFailoverOutcome.action === "retry") {
|
|
2487
|
+
traceAttempts.push({
|
|
2488
|
+
provider: activeErrorContext.provider,
|
|
2489
|
+
model: activeErrorContext.model,
|
|
2490
|
+
result: assistantFailoverOutcome.retryKind === "same_model_idle_timeout" || assistantFailoverReason === "timeout" ? "timeout" : "rotate_profile",
|
|
2491
|
+
...assistantFailoverReason ? { reason: assistantFailoverReason } : {},
|
|
2492
|
+
stage: "assistant"
|
|
2493
|
+
});
|
|
2494
|
+
if (assistantFailoverOutcome.retryKind === "same_model_idle_timeout") sameModelIdleTimeoutRetries += 1;
|
|
2495
|
+
lastRetryFailoverReason = assistantFailoverOutcome.lastRetryFailoverReason;
|
|
2496
|
+
continue;
|
|
2497
|
+
}
|
|
2498
|
+
if (assistantFailoverOutcome.action === "throw") {
|
|
2499
|
+
traceAttempts.push({
|
|
2500
|
+
provider: activeErrorContext.provider,
|
|
2501
|
+
model: activeErrorContext.model,
|
|
2502
|
+
result: assistantFailoverReason === "timeout" ? "timeout" : assistantFailoverDecision.action === "fallback_model" ? "fallback_model" : "error",
|
|
2503
|
+
...assistantFailoverReason ? { reason: assistantFailoverReason } : {},
|
|
2504
|
+
stage: "assistant",
|
|
2505
|
+
...typeof assistantFailoverOutcome.error.status === "number" ? { status: assistantFailoverOutcome.error.status } : {}
|
|
2506
|
+
});
|
|
2507
|
+
throw assistantFailoverOutcome.error;
|
|
2508
|
+
}
|
|
2509
|
+
const usageMeta = buildUsageAgentMetaFields({
|
|
2510
|
+
usageAccumulator,
|
|
2511
|
+
lastAssistantUsage: sessionLastAssistant?.usage,
|
|
2512
|
+
lastRunPromptUsage,
|
|
2513
|
+
lastTurnTotal
|
|
2514
|
+
});
|
|
2515
|
+
const agentMeta = {
|
|
2516
|
+
sessionId: sessionIdUsed,
|
|
2517
|
+
provider: sessionLastAssistant?.provider ?? provider,
|
|
2518
|
+
model: sessionLastAssistant?.model ?? model.id,
|
|
2519
|
+
contextTokens: ctxInfo.tokens,
|
|
2520
|
+
agentHarnessId: attempt.agentHarnessId,
|
|
2521
|
+
usage: usageMeta.usage,
|
|
2522
|
+
lastCallUsage: usageMeta.lastCallUsage,
|
|
2523
|
+
promptTokens: usageMeta.promptTokens,
|
|
2524
|
+
compactionCount: autoCompactionCount > 0 ? autoCompactionCount : void 0
|
|
2525
|
+
};
|
|
2526
|
+
const finalAssistantVisibleText = resolveFinalAssistantVisibleText(sessionLastAssistant);
|
|
2527
|
+
const finalAssistantRawText = resolveFinalAssistantRawText(sessionLastAssistant);
|
|
2528
|
+
const payloads = buildEmbeddedRunPayloads({
|
|
2529
|
+
assistantTexts: attempt.assistantTexts,
|
|
2530
|
+
toolMetas: attempt.toolMetas,
|
|
2531
|
+
lastAssistant: attempt.lastAssistant,
|
|
2532
|
+
lastToolError: attempt.lastToolError,
|
|
2533
|
+
config: params.config,
|
|
2534
|
+
isCronTrigger: params.trigger === "cron",
|
|
2535
|
+
sessionKey: params.sessionKey ?? params.sessionId,
|
|
2536
|
+
provider: activeErrorContext.provider,
|
|
2537
|
+
model: activeErrorContext.model,
|
|
2538
|
+
verboseLevel: params.verboseLevel,
|
|
2539
|
+
reasoningLevel: params.reasoningLevel,
|
|
2540
|
+
toolResultFormat: resolvedToolResultFormat,
|
|
2541
|
+
suppressToolErrorWarnings: params.suppressToolErrorWarnings,
|
|
2542
|
+
inlineToolResultsAllowed: false,
|
|
2543
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2544
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt
|
|
2545
|
+
});
|
|
2546
|
+
const payloadsWithToolMedia = mergeAttemptToolMediaPayloads({
|
|
2547
|
+
payloads,
|
|
2548
|
+
toolMediaUrls: attempt.toolMediaUrls,
|
|
2549
|
+
toolAudioAsVoice: attempt.toolAudioAsVoice
|
|
2550
|
+
});
|
|
2551
|
+
const attemptToolSummary = buildTraceToolSummary({
|
|
2552
|
+
toolMetas: attempt.toolMetas,
|
|
2553
|
+
hadFailure: Boolean(attempt.lastToolError)
|
|
2554
|
+
});
|
|
2555
|
+
if (timedOut && !timedOutDuringCompaction && !payloadsWithToolMedia?.length) {
|
|
2556
|
+
const timeoutText = idleTimedOut ? "The model did not produce a response before the LLM idle timeout. Please try again, or increase `agents.defaults.llm.idleTimeoutSeconds` in your config (set to 0 to disable)." : "Request timed out before a response was generated. Please try again, or increase `agents.defaults.timeoutSeconds` in your config.";
|
|
2557
|
+
const replayInvalid = resolveReplayInvalidForAttempt(null);
|
|
2558
|
+
const livenessState = resolveRunLivenessState({
|
|
2559
|
+
payloadCount: payloads.length,
|
|
2560
|
+
aborted,
|
|
2561
|
+
timedOut,
|
|
2562
|
+
attempt,
|
|
2563
|
+
incompleteTurnText: null
|
|
2564
|
+
});
|
|
2565
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2566
|
+
replayInvalid,
|
|
2567
|
+
livenessState
|
|
2568
|
+
});
|
|
2569
|
+
return {
|
|
2570
|
+
payloads: [{
|
|
2571
|
+
text: timeoutText,
|
|
2572
|
+
isError: true
|
|
2573
|
+
}],
|
|
2574
|
+
meta: {
|
|
2575
|
+
durationMs: Date.now() - started,
|
|
2576
|
+
agentMeta,
|
|
2577
|
+
aborted,
|
|
2578
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2579
|
+
finalPromptText: attempt.finalPromptText,
|
|
2580
|
+
finalAssistantVisibleText,
|
|
2581
|
+
finalAssistantRawText,
|
|
2582
|
+
replayInvalid,
|
|
2583
|
+
livenessState,
|
|
2584
|
+
toolSummary: attemptToolSummary,
|
|
2585
|
+
agentHarnessResultClassification: attempt.agentHarnessResultClassification
|
|
2586
|
+
},
|
|
2587
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2588
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt,
|
|
2589
|
+
messagingToolSentTexts: attempt.messagingToolSentTexts,
|
|
2590
|
+
messagingToolSentMediaUrls: attempt.messagingToolSentMediaUrls,
|
|
2591
|
+
messagingToolSentTargets: attempt.messagingToolSentTargets,
|
|
2592
|
+
successfulCronAdds: attempt.successfulCronAdds
|
|
2593
|
+
};
|
|
2594
|
+
}
|
|
2595
|
+
const payloadCount = payloadsWithToolMedia?.length ?? 0;
|
|
2596
|
+
const nextPlanningOnlyRetryInstruction = resolvePlanningOnlyRetryInstruction({
|
|
2597
|
+
provider,
|
|
2598
|
+
modelId,
|
|
2599
|
+
executionContract,
|
|
2600
|
+
prompt: params.prompt,
|
|
2601
|
+
aborted,
|
|
2602
|
+
timedOut,
|
|
2603
|
+
attempt
|
|
2604
|
+
});
|
|
2605
|
+
const nextReasoningOnlyRetryInstruction = resolveReasoningOnlyRetryInstruction({
|
|
2606
|
+
provider: activeErrorContext.provider,
|
|
2607
|
+
modelId: activeErrorContext.model,
|
|
2608
|
+
executionContract,
|
|
2609
|
+
aborted,
|
|
2610
|
+
timedOut,
|
|
2611
|
+
attempt
|
|
2612
|
+
});
|
|
2613
|
+
const nextEmptyResponseRetryInstruction = resolveEmptyResponseRetryInstruction({
|
|
2614
|
+
provider: activeErrorContext.provider,
|
|
2615
|
+
modelId: activeErrorContext.model,
|
|
2616
|
+
executionContract,
|
|
2617
|
+
payloadCount,
|
|
2618
|
+
aborted,
|
|
2619
|
+
timedOut,
|
|
2620
|
+
attempt
|
|
2621
|
+
});
|
|
2622
|
+
if (nextPlanningOnlyRetryInstruction && planningOnlyRetryAttempts < maxPlanningOnlyRetryAttempts) {
|
|
2623
|
+
const planDetails = extractPlanningOnlyPlanDetails(attempt.assistantTexts.join("\n\n").trim());
|
|
2624
|
+
if (planDetails) {
|
|
2625
|
+
emitAgentPlanEvent({
|
|
2626
|
+
runId: params.runId,
|
|
2627
|
+
...params.sessionKey ? { sessionKey: params.sessionKey } : {},
|
|
2628
|
+
data: {
|
|
2629
|
+
phase: "update",
|
|
2630
|
+
title: "Assistant proposed a plan",
|
|
2631
|
+
explanation: planDetails.explanation,
|
|
2632
|
+
steps: planDetails.steps,
|
|
2633
|
+
source: "planning_only_retry"
|
|
2634
|
+
}
|
|
2635
|
+
});
|
|
2636
|
+
params.onAgentEvent?.({
|
|
2637
|
+
stream: "plan",
|
|
2638
|
+
data: {
|
|
2639
|
+
phase: "update",
|
|
2640
|
+
title: "Assistant proposed a plan",
|
|
2641
|
+
explanation: planDetails.explanation,
|
|
2642
|
+
steps: planDetails.steps,
|
|
2643
|
+
source: "planning_only_retry"
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
}
|
|
2647
|
+
planningOnlyRetryAttempts += 1;
|
|
2648
|
+
planningOnlyRetryInstruction = nextPlanningOnlyRetryInstruction;
|
|
2649
|
+
log.warn(`planning-only turn detected: runId=${params.runId} sessionId=${params.sessionId} provider=${provider}/${modelId} contract=${executionContract} configured=${configuredExecutionContract} — retrying ${planningOnlyRetryAttempts}/${maxPlanningOnlyRetryAttempts} with act-now steer`);
|
|
2650
|
+
continue;
|
|
2651
|
+
}
|
|
2652
|
+
if (!nextPlanningOnlyRetryInstruction && nextReasoningOnlyRetryInstruction && reasoningOnlyRetryAttempts < maxReasoningOnlyRetryAttempts) {
|
|
2653
|
+
reasoningOnlyRetryAttempts += 1;
|
|
2654
|
+
reasoningOnlyRetryInstruction = nextReasoningOnlyRetryInstruction;
|
|
2655
|
+
log.warn(`reasoning-only assistant turn detected: runId=${params.runId} sessionId=${params.sessionId} provider=${activeErrorContext.provider}/${activeErrorContext.model} — retrying ${reasoningOnlyRetryAttempts}/${maxReasoningOnlyRetryAttempts} with visible-answer continuation`);
|
|
2656
|
+
continue;
|
|
2657
|
+
}
|
|
2658
|
+
const reasoningOnlyRetriesExhausted = !nextPlanningOnlyRetryInstruction && nextReasoningOnlyRetryInstruction && reasoningOnlyRetryAttempts >= maxReasoningOnlyRetryAttempts;
|
|
2659
|
+
if (!nextPlanningOnlyRetryInstruction && !nextReasoningOnlyRetryInstruction && nextEmptyResponseRetryInstruction && emptyResponseRetryAttempts < maxEmptyResponseRetryAttempts) {
|
|
2660
|
+
emptyResponseRetryAttempts += 1;
|
|
2661
|
+
emptyResponseRetryInstruction = nextEmptyResponseRetryInstruction;
|
|
2662
|
+
log.warn(`empty response detected: runId=${params.runId} sessionId=${params.sessionId} provider=${activeErrorContext.provider}/${activeErrorContext.model} — retrying ${emptyResponseRetryAttempts}/${maxEmptyResponseRetryAttempts} with visible-answer continuation`);
|
|
2663
|
+
continue;
|
|
2664
|
+
}
|
|
2665
|
+
const incompleteTurnText = resolveIncompleteTurnPayloadText({
|
|
2666
|
+
payloadCount,
|
|
2667
|
+
aborted,
|
|
2668
|
+
timedOut,
|
|
2669
|
+
attempt
|
|
2670
|
+
});
|
|
2671
|
+
if (reasoningOnlyRetriesExhausted && !finalAssistantVisibleText) log.warn(`reasoning-only retries exhausted: runId=${params.runId} sessionId=${params.sessionId} provider=${activeErrorContext.provider}/${activeErrorContext.model} attempts=${reasoningOnlyRetryAttempts}/${maxReasoningOnlyRetryAttempts} — surfacing incomplete-turn error`);
|
|
2672
|
+
if (!incompleteTurnText && nextPlanningOnlyRetryInstruction && strictAgenticActive) {
|
|
2673
|
+
log.warn(`strict-agentic run exhausted planning-only retries: runId=${params.runId} sessionId=${params.sessionId} provider=${provider}/${modelId} configured=${configuredExecutionContract} — surfacing blocked state`);
|
|
2674
|
+
const replayInvalid = resolveReplayInvalidForAttempt(null);
|
|
2675
|
+
const livenessState = "blocked";
|
|
2676
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2677
|
+
replayInvalid,
|
|
2678
|
+
livenessState
|
|
2679
|
+
});
|
|
2680
|
+
return {
|
|
2681
|
+
payloads: [{
|
|
2682
|
+
text: STRICT_AGENTIC_BLOCKED_TEXT,
|
|
2683
|
+
isError: true
|
|
2684
|
+
}],
|
|
2685
|
+
meta: {
|
|
2686
|
+
durationMs: Date.now() - started,
|
|
2687
|
+
agentMeta,
|
|
2688
|
+
aborted,
|
|
2689
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2690
|
+
finalPromptText: attempt.finalPromptText,
|
|
2691
|
+
finalAssistantVisibleText,
|
|
2692
|
+
finalAssistantRawText,
|
|
2693
|
+
replayInvalid,
|
|
2694
|
+
livenessState,
|
|
2695
|
+
toolSummary: attemptToolSummary,
|
|
2696
|
+
agentHarnessResultClassification: attempt.agentHarnessResultClassification
|
|
2697
|
+
},
|
|
2698
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2699
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt,
|
|
2700
|
+
messagingToolSentTexts: attempt.messagingToolSentTexts,
|
|
2701
|
+
messagingToolSentMediaUrls: attempt.messagingToolSentMediaUrls,
|
|
2702
|
+
messagingToolSentTargets: attempt.messagingToolSentTargets,
|
|
2703
|
+
successfulCronAdds: attempt.successfulCronAdds
|
|
2704
|
+
};
|
|
2705
|
+
}
|
|
2706
|
+
if (reasoningOnlyRetriesExhausted && !finalAssistantVisibleText) {
|
|
2707
|
+
const replayInvalid = resolveReplayInvalidForAttempt("⚠️ Agent couldn't generate a response. Please try again.");
|
|
2708
|
+
const livenessState = resolveRunLivenessState({
|
|
2709
|
+
payloadCount: 0,
|
|
2710
|
+
aborted,
|
|
2711
|
+
timedOut,
|
|
2712
|
+
attempt,
|
|
2713
|
+
incompleteTurnText: "⚠️ Agent couldn't generate a response. Please try again."
|
|
2714
|
+
});
|
|
2715
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2716
|
+
replayInvalid,
|
|
2717
|
+
livenessState
|
|
2718
|
+
});
|
|
2719
|
+
if (lastProfileId) await maybeMarkAuthProfileFailure({
|
|
2720
|
+
profileId: lastProfileId,
|
|
2721
|
+
reason: resolveAuthProfileFailureReason(assistantFailoverReason)
|
|
2722
|
+
});
|
|
2723
|
+
return {
|
|
2724
|
+
payloads: [{
|
|
2725
|
+
text: "⚠️ Agent couldn't generate a response. Please try again.",
|
|
2726
|
+
isError: true
|
|
2727
|
+
}],
|
|
2728
|
+
meta: {
|
|
2729
|
+
durationMs: Date.now() - started,
|
|
2730
|
+
agentMeta,
|
|
2731
|
+
aborted,
|
|
2732
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2733
|
+
finalPromptText: attempt.finalPromptText,
|
|
2734
|
+
finalAssistantVisibleText,
|
|
2735
|
+
finalAssistantRawText,
|
|
2736
|
+
replayInvalid,
|
|
2737
|
+
livenessState,
|
|
2738
|
+
toolSummary: attemptToolSummary,
|
|
2739
|
+
agentHarnessResultClassification: attempt.agentHarnessResultClassification
|
|
2740
|
+
},
|
|
2741
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2742
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt,
|
|
2743
|
+
messagingToolSentTexts: attempt.messagingToolSentTexts,
|
|
2744
|
+
messagingToolSentMediaUrls: attempt.messagingToolSentMediaUrls,
|
|
2745
|
+
messagingToolSentTargets: attempt.messagingToolSentTargets,
|
|
2746
|
+
successfulCronAdds: attempt.successfulCronAdds
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
if (!nextPlanningOnlyRetryInstruction && !nextReasoningOnlyRetryInstruction && nextEmptyResponseRetryInstruction && emptyResponseRetryAttempts >= maxEmptyResponseRetryAttempts) log.warn(`empty response retries exhausted: runId=${params.runId} sessionId=${params.sessionId} provider=${activeErrorContext.provider}/${activeErrorContext.model} attempts=${emptyResponseRetryAttempts}/${maxEmptyResponseRetryAttempts} — surfacing incomplete-turn error`);
|
|
2750
|
+
const silentErrorContent = sessionLastAssistant?.content;
|
|
2751
|
+
if (incompleteTurnText && !aborted && !promptError && !timedOut && sessionLastAssistant?.stopReason === "error" && ((sessionLastAssistant?.usage)?.output ?? 0) === 0 && (silentErrorContent?.length ?? 0) === 0 && !attempt.replayMetadata.hadPotentialSideEffects && emptyErrorRetries < MAX_EMPTY_ERROR_RETRIES) {
|
|
2752
|
+
emptyErrorRetries += 1;
|
|
2753
|
+
log.warn(`[empty-error-retry] stopReason=error output=0; resubmitting attempt=${emptyErrorRetries}/${MAX_EMPTY_ERROR_RETRIES} provider=${sessionLastAssistant?.provider ?? provider} model=${sessionLastAssistant?.model ?? model.id} sessionKey=${params.sessionKey ?? params.sessionId}`);
|
|
2754
|
+
continue;
|
|
2755
|
+
}
|
|
2756
|
+
if (incompleteTurnText) {
|
|
2757
|
+
const replayInvalid = resolveReplayInvalidForAttempt(incompleteTurnText);
|
|
2758
|
+
const livenessState = resolveRunLivenessState({
|
|
2759
|
+
payloadCount: payloads.length,
|
|
2760
|
+
aborted,
|
|
2761
|
+
timedOut,
|
|
2762
|
+
attempt,
|
|
2763
|
+
incompleteTurnText
|
|
2764
|
+
});
|
|
2765
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2766
|
+
replayInvalid,
|
|
2767
|
+
livenessState
|
|
2768
|
+
});
|
|
2769
|
+
const incompleteStopReason = attempt.lastAssistant?.stopReason;
|
|
2770
|
+
log.warn(`incomplete turn detected: runId=${params.runId} sessionId=${params.sessionId} stopReason=${incompleteStopReason} payloads=0 — surfacing error to user`);
|
|
2771
|
+
if (lastProfileId) await maybeMarkAuthProfileFailure({
|
|
2772
|
+
profileId: lastProfileId,
|
|
2773
|
+
reason: resolveAuthProfileFailureReason(assistantFailoverReason)
|
|
2774
|
+
});
|
|
2775
|
+
return {
|
|
2776
|
+
payloads: [{
|
|
2777
|
+
text: incompleteTurnText,
|
|
2778
|
+
isError: true
|
|
2779
|
+
}],
|
|
2780
|
+
meta: {
|
|
2781
|
+
durationMs: Date.now() - started,
|
|
2782
|
+
agentMeta,
|
|
2783
|
+
aborted,
|
|
2784
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2785
|
+
finalPromptText: attempt.finalPromptText,
|
|
2786
|
+
finalAssistantVisibleText,
|
|
2787
|
+
finalAssistantRawText,
|
|
2788
|
+
replayInvalid,
|
|
2789
|
+
livenessState,
|
|
2790
|
+
toolSummary: attemptToolSummary,
|
|
2791
|
+
agentHarnessResultClassification: attempt.agentHarnessResultClassification
|
|
2792
|
+
},
|
|
2793
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2794
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt,
|
|
2795
|
+
messagingToolSentTexts: attempt.messagingToolSentTexts,
|
|
2796
|
+
messagingToolSentMediaUrls: attempt.messagingToolSentMediaUrls,
|
|
2797
|
+
messagingToolSentTargets: attempt.messagingToolSentTargets,
|
|
2798
|
+
successfulCronAdds: attempt.successfulCronAdds
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
log.debug(`embedded run done: runId=${params.runId} sessionId=${params.sessionId} durationMs=${Date.now() - started} aborted=${aborted}`);
|
|
2802
|
+
if (lastProfileId) {
|
|
2803
|
+
await markAuthProfileGood({
|
|
2804
|
+
store: authStore,
|
|
2805
|
+
provider,
|
|
2806
|
+
profileId: lastProfileId,
|
|
2807
|
+
agentDir: params.agentDir
|
|
2808
|
+
});
|
|
2809
|
+
await markAuthProfileUsed({
|
|
2810
|
+
store: authStore,
|
|
2811
|
+
profileId: lastProfileId,
|
|
2812
|
+
agentDir: params.agentDir
|
|
2813
|
+
});
|
|
2814
|
+
}
|
|
2815
|
+
const replayInvalid = resolveReplayInvalidForAttempt(null);
|
|
2816
|
+
const livenessState = resolveRunLivenessState({
|
|
2817
|
+
payloadCount: payloads.length,
|
|
2818
|
+
aborted,
|
|
2819
|
+
timedOut,
|
|
2820
|
+
attempt,
|
|
2821
|
+
incompleteTurnText: null
|
|
2822
|
+
});
|
|
2823
|
+
const stopReason = attempt.clientToolCall ? "tool_calls" : attempt.yieldDetected ? "end_turn" : sessionLastAssistant?.stopReason;
|
|
2824
|
+
attempt.setTerminalLifecycleMeta?.({
|
|
2825
|
+
replayInvalid,
|
|
2826
|
+
livenessState
|
|
2827
|
+
});
|
|
2828
|
+
return {
|
|
2829
|
+
payloads: payloadsWithToolMedia?.length ? payloadsWithToolMedia : void 0,
|
|
2830
|
+
...attempt.diagnosticTrace ? { diagnosticTrace: freezeDiagnosticTraceContext(attempt.diagnosticTrace) } : {},
|
|
2831
|
+
meta: {
|
|
2832
|
+
durationMs: Date.now() - started,
|
|
2833
|
+
agentMeta,
|
|
2834
|
+
aborted,
|
|
2835
|
+
systemPromptReport: attempt.systemPromptReport,
|
|
2836
|
+
finalPromptText: attempt.finalPromptText,
|
|
2837
|
+
finalAssistantVisibleText,
|
|
2838
|
+
finalAssistantRawText,
|
|
2839
|
+
replayInvalid,
|
|
2840
|
+
livenessState,
|
|
2841
|
+
agentHarnessResultClassification: attempt.agentHarnessResultClassification,
|
|
2842
|
+
stopReason,
|
|
2843
|
+
pendingToolCalls: attempt.clientToolCall ? [{
|
|
2844
|
+
id: randomBytes(5).toString("hex").slice(0, 9),
|
|
2845
|
+
name: attempt.clientToolCall.name,
|
|
2846
|
+
arguments: JSON.stringify(attempt.clientToolCall.params)
|
|
2847
|
+
}] : void 0,
|
|
2848
|
+
executionTrace: {
|
|
2849
|
+
winnerProvider: sessionLastAssistant?.provider ?? provider,
|
|
2850
|
+
winnerModel: sessionLastAssistant?.model ?? model.id,
|
|
2851
|
+
attempts: traceAttempts.length > 0 || sessionLastAssistant?.provider || sessionLastAssistant?.model ? [...traceAttempts, {
|
|
2852
|
+
provider: sessionLastAssistant?.provider ?? provider,
|
|
2853
|
+
model: sessionLastAssistant?.model ?? model.id,
|
|
2854
|
+
result: "success",
|
|
2855
|
+
stage: "assistant"
|
|
2856
|
+
}] : void 0,
|
|
2857
|
+
fallbackUsed: traceAttempts.length > 0,
|
|
2858
|
+
runner: "embedded"
|
|
2859
|
+
},
|
|
2860
|
+
requestShaping: {
|
|
2861
|
+
...lastProfileId ? { authMode: "auth-profile" } : {},
|
|
2862
|
+
...thinkLevel ? { thinking: thinkLevel } : {},
|
|
2863
|
+
...params.reasoningLevel ? { reasoning: params.reasoningLevel } : {},
|
|
2864
|
+
...params.verboseLevel ? { verbose: params.verboseLevel } : {},
|
|
2865
|
+
...params.blockReplyBreak ? { blockStreaming: params.blockReplyBreak } : {}
|
|
2866
|
+
},
|
|
2867
|
+
toolSummary: attemptToolSummary,
|
|
2868
|
+
completion: {
|
|
2869
|
+
...stopReason ? { stopReason } : {},
|
|
2870
|
+
...stopReason ? { finishReason: stopReason } : {},
|
|
2871
|
+
...stopReason?.toLowerCase().includes("refusal") ? { refusal: true } : {}
|
|
2872
|
+
},
|
|
2873
|
+
contextManagement: autoCompactionCount > 0 ? { lastTurnCompactions: autoCompactionCount } : void 0
|
|
2874
|
+
},
|
|
2875
|
+
didSendViaMessagingTool: attempt.didSendViaMessagingTool,
|
|
2876
|
+
didSendDeterministicApprovalPrompt: attempt.didSendDeterministicApprovalPrompt,
|
|
2877
|
+
messagingToolSentTexts: attempt.messagingToolSentTexts,
|
|
2878
|
+
messagingToolSentMediaUrls: attempt.messagingToolSentMediaUrls,
|
|
2879
|
+
messagingToolSentTargets: attempt.messagingToolSentTargets,
|
|
2880
|
+
successfulCronAdds: attempt.successfulCronAdds
|
|
2881
|
+
};
|
|
2882
|
+
}
|
|
2883
|
+
} finally {
|
|
2884
|
+
await contextEngine.dispose?.();
|
|
2885
|
+
stopRuntimeAuthRefreshTimer();
|
|
2886
|
+
if (params.cleanupBundleMcpOnRunEnd === true) {
|
|
2887
|
+
const onError = (error, sessionId) => {
|
|
2888
|
+
log.warn(`bundle-mcp cleanup failed after run for ${sessionId}: ${formatErrorMessage(error)}`);
|
|
2889
|
+
};
|
|
2890
|
+
if (!await retireSessionMcpRuntimeForSessionKey({
|
|
2891
|
+
sessionKey: params.sessionKey,
|
|
2892
|
+
reason: "embedded-run-end",
|
|
2893
|
+
onError
|
|
2894
|
+
})) await retireSessionMcpRuntime({
|
|
2895
|
+
sessionId: params.sessionId,
|
|
2896
|
+
reason: "embedded-run-end",
|
|
2897
|
+
onError
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
//#endregion
|
|
2905
|
+
export { compactEmbeddedPiSession as n, runEmbeddedPiAgent as t };
|