@herbertgao/pi-extensions 2026.10.19 → 2026.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/THIRD_PARTY_NOTICES.md +53 -2
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +142 -45
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +17 -7
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +111 -59
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +135 -117
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +41 -14
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +110 -19
- package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +8 -0
- package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +31 -0
- package/node_modules/@tintinweb/pi-tasks/CHANGELOG.md +270 -0
- package/node_modules/@tintinweb/pi-tasks/CONTRIBUTING.md +67 -0
- package/node_modules/@tintinweb/pi-tasks/CUSTOMIZING.md +289 -0
- package/node_modules/@tintinweb/pi-tasks/LICENSE +21 -0
- package/node_modules/@tintinweb/pi-tasks/README.md +417 -0
- package/node_modules/@tintinweb/pi-tasks/SECURITY.md +107 -0
- package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.d.ts +64 -0
- package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.js +129 -0
- package/node_modules/@tintinweb/pi-tasks/dist/index.d.ts +17 -0
- package/node_modules/@tintinweb/pi-tasks/dist/index.js +1338 -0
- package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.d.ts +29 -0
- package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.js +121 -0
- package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.d.ts +39 -0
- package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.js +61 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.d.ts +48 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.js +68 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-paths.d.ts +44 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-paths.js +60 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-sort.d.ts +23 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-sort.js +69 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-store.d.ts +61 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-store.js +397 -0
- package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.d.ts +16 -0
- package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.js +51 -0
- package/node_modules/@tintinweb/pi-tasks/dist/types.d.ts +36 -0
- package/node_modules/@tintinweb/pi-tasks/dist/types.js +4 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.d.ts +15 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.js +140 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.d.ts +69 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.js +278 -0
- package/node_modules/@tintinweb/pi-tasks/package.json +57 -0
- package/node_modules/@tintinweb/pi-tasks/src/auto-clear.ts +134 -0
- package/node_modules/@tintinweb/pi-tasks/src/index.ts +1417 -0
- package/node_modules/@tintinweb/pi-tasks/src/process-tracker.ts +140 -0
- package/node_modules/@tintinweb/pi-tasks/src/reminder-cadence.ts +90 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-glyphs.ts +110 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-paths.ts +65 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-sort.ts +90 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-store.ts +402 -0
- package/node_modules/@tintinweb/pi-tasks/src/tasks-config.ts +77 -0
- package/node_modules/@tintinweb/pi-tasks/src/types.ts +40 -0
- package/node_modules/@tintinweb/pi-tasks/src/ui/settings-menu.ts +174 -0
- package/node_modules/@tintinweb/pi-tasks/src/ui/task-widget.ts +325 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +330 -0
- package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +192 -0
- package/node_modules/pi-commandcode-provider/LICENSE +21 -0
- package/node_modules/pi-commandcode-provider/README.md +243 -0
- package/node_modules/pi-commandcode-provider/RELEASE.md +194 -0
- package/node_modules/pi-commandcode-provider/index.ts +309 -0
- package/node_modules/pi-commandcode-provider/package.json +91 -0
- package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +87 -0
- package/node_modules/pi-commandcode-provider/scripts/pi-authenticated.mjs +50 -0
- package/node_modules/pi-commandcode-provider/scripts/pi-isolated.mjs +79 -0
- package/node_modules/pi-commandcode-provider/src/api-key.ts +69 -0
- package/node_modules/pi-commandcode-provider/src/auth-server.ts +229 -0
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +28 -0
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +260 -0
- package/node_modules/pi-commandcode-provider/src/converters.ts +477 -0
- package/node_modules/pi-commandcode-provider/src/core.ts +836 -0
- package/node_modules/pi-commandcode-provider/src/cost.ts +76 -0
- package/node_modules/pi-commandcode-provider/src/json-schema.ts +417 -0
- package/node_modules/pi-commandcode-provider/src/models.ts +515 -0
- package/node_modules/pi-commandcode-provider/src/oauth.ts +229 -0
- package/node_modules/pi-commandcode-provider/src/overflow.ts +120 -0
- package/node_modules/pi-commandcode-provider/src/pricing.ts +370 -0
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +66 -0
- package/node_modules/pi-commandcode-provider/src/quota-format.ts +143 -0
- package/node_modules/pi-commandcode-provider/src/quota-types.ts +47 -0
- package/node_modules/pi-commandcode-provider/src/quota.ts +357 -0
- package/node_modules/pi-commandcode-provider/src/responses-stream.ts +249 -0
- package/node_modules/pi-commandcode-provider/src/runtime.ts +330 -0
- package/node_modules/pi-commandcode-provider/src/transcript.ts +56 -0
- package/node_modules/pi-commandcode-provider/src/transport.ts +147 -0
- package/node_modules/pi-commandcode-provider/src/types.ts +212 -0
- package/node_modules/pi-commandcode-provider/src/usage.ts +261 -0
- package/node_modules/pi-lens/CHANGELOG.md +149 -0
- package/node_modules/pi-lens/README.md +12 -2
- package/node_modules/pi-lens/config/markdownlint/run-no-fix.mjs +36 -0
- package/node_modules/pi-lens/dist/{chunk-WME2OQST.js → chunk-2453RRJ2.js} +11 -6
- package/node_modules/pi-lens/dist/{chunk-FZKFVUEC.js → chunk-2BKUFQKR.js} +276 -208
- package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +31 -0
- package/node_modules/pi-lens/dist/{chunk-QHSNL7B2.js → chunk-2ZE3AUJQ.js} +12 -14
- package/node_modules/pi-lens/dist/{chunk-MPKRJBPK.js → chunk-35WKJWO5.js} +28 -30
- package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-4LM3VAZH.js → chunk-3O5EII3W.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-447YZL4S.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-H7OR7DFZ.js → chunk-4B2YFN4U.js} +25 -21
- package/node_modules/pi-lens/dist/{chunk-OSTKYB55.js → chunk-4BKU7PV3.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-RRV3FNNM.js → chunk-4LL2VRNY.js} +27 -28
- package/node_modules/pi-lens/dist/{chunk-BZARLRJW.js → chunk-4NBWFYWW.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-KKCK636N.js → chunk-4QG55RRC.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-RQS4QQSD.js → chunk-4W52ZKZX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-Z2XAOKHK.js → chunk-565VRUP4.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-HWDAVBFU.js → chunk-57X2CDRX.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-MB6PXBUA.js → chunk-5F3XF3SX.js} +7 -15
- package/node_modules/pi-lens/dist/{chunk-O4BJFESU.js → chunk-5RNB4HVK.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZMAUPOMG.js → chunk-5T5A6YAJ.js} +35 -34
- package/node_modules/pi-lens/dist/{chunk-4ZYJHQMB.js → chunk-6FIRFP6A.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-4YHYPW2G.js → chunk-6GMGEKQN.js} +9 -5
- package/node_modules/pi-lens/dist/{chunk-4LOE5R5P.js → chunk-6LJOJ6EO.js} +20 -15
- package/node_modules/pi-lens/dist/{chunk-3YY7IXIL.js → chunk-6YUNI7B5.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-PKES3ISE.js → chunk-7ANZ7XDD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-FB5SCCPT.js → chunk-7CGIDRIK.js} +16 -15
- package/node_modules/pi-lens/dist/{chunk-L3CMBQMH.js → chunk-7MAD5ZAY.js} +16 -17
- package/node_modules/pi-lens/dist/{chunk-WDBICWH3.js → chunk-7TNILKGY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-RORGS5II.js → chunk-A5GRLYPZ.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-MNJIXFX4.js → chunk-AGGUWKRK.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ABPKUVA4.js → chunk-BBET6HD6.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-L5JYIU47.js → chunk-BHWW6FAX.js} +14 -13
- package/node_modules/pi-lens/dist/{chunk-URCQWAQ4.js → chunk-BOPDQ7AZ.js} +23 -21
- package/node_modules/pi-lens/dist/{chunk-KDX35VXP.js → chunk-BQG2QFVO.js} +158 -133
- package/node_modules/pi-lens/dist/{chunk-CB4WHS4H.js → chunk-BUZIQDFS.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2PHMIAKO.js → chunk-CM73PPGD.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DH5JPM3K.js → chunk-CUDD35TW.js} +10 -9
- package/node_modules/pi-lens/dist/{chunk-AWDSEDER.js → chunk-CZL44WFN.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-N5WSK2K7.js → chunk-DIWK3LBC.js} +12 -15
- package/node_modules/pi-lens/dist/{chunk-24BILSZW.js → chunk-DYRZGUMA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PR6PO3ES.js → chunk-FHEV6T4L.js} +22 -18
- package/node_modules/pi-lens/dist/{chunk-DQZFQSR5.js → chunk-FRLAUP2B.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-RZOXUSPC.js → chunk-G5GV2Q7K.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-EKWX4WD3.js → chunk-G6JKM4O7.js} +7 -7
- package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-XT2HTCJ5.js → chunk-GIRBSBGL.js} +6 -5
- package/node_modules/pi-lens/dist/{chunk-PQJFG24Z.js → chunk-GMROJJRN.js} +1292 -946
- package/node_modules/pi-lens/dist/{chunk-U6VN4NVL.js → chunk-HHR7WGCI.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-TIQJPRDD.js → chunk-HKIL6DCL.js} +3 -2
- package/node_modules/pi-lens/dist/{chunk-SNDXCFRS.js → chunk-HUAM7QG3.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-QOE342SU.js → chunk-HXFUTMX2.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-U7BD2QL7.js → chunk-I22THIHI.js} +12 -12
- package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +58 -0
- package/node_modules/pi-lens/dist/{chunk-DPGEAHZT.js → chunk-IYVYZQRL.js} +10 -16
- package/node_modules/pi-lens/dist/{chunk-3F6BMY53.js → chunk-JBP7KESM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-U5HPROLA.js → chunk-JE6HKLC7.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-ZE3KXHS7.js → chunk-JPRDTY5S.js} +85 -3
- package/node_modules/pi-lens/dist/{chunk-HO6LWE2E.js → chunk-JYLOYTZD.js} +17 -1
- package/node_modules/pi-lens/dist/{chunk-KW5JQPO5.js → chunk-JZRP4DGP.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CPSR3AVL.js → chunk-KZ4ALBCH.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6IR3ZYIB.js → chunk-L3CLUGDY.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-LV4UMYVH.js → chunk-L4NEVZ4T.js} +28 -27
- package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +22 -0
- package/node_modules/pi-lens/dist/{chunk-WGRJOXED.js → chunk-LSFXZLPW.js} +1016 -636
- package/node_modules/pi-lens/dist/{chunk-LBLBAFG3.js → chunk-MC6VB2E5.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-U2SDMG7C.js → chunk-NM2NWH55.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-T7A2HK2B.js → chunk-NSPVR3FN.js} +19 -18
- package/node_modules/pi-lens/dist/{chunk-ZGSJDWQU.js → chunk-O2ARHQKF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-OXOI55RU.js → chunk-O4N5BQ3T.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-3FRLWYBG.js → chunk-OC7VWJBZ.js} +39 -40
- package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +89 -0
- package/node_modules/pi-lens/dist/{chunk-HR3OJ3TH.js → chunk-OWTG6UMO.js} +21 -21
- package/node_modules/pi-lens/dist/{chunk-75GAYVNO.js → chunk-OY7WZI7Q.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-ZJTT47IG.js → chunk-OZWXLJMX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-F6X3YJWD.js → chunk-PIQQM32Y.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-PKLB2XJL.js +8 -0
- package/node_modules/pi-lens/dist/{chunk-EAOK7MIZ.js → chunk-PKSUMEPT.js} +17 -4
- package/node_modules/pi-lens/dist/{chunk-YISME6ON.js → chunk-PPKECBPP.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-4L36HG27.js → chunk-R2QQC33W.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-LUBPZN36.js → chunk-R4QWJQ2H.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-V63BC55Q.js → chunk-RGGH6M34.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-Y7F7IEE3.js → chunk-RZG472YW.js} +65 -7
- package/node_modules/pi-lens/dist/{chunk-PUZ3E2J4.js → chunk-SDFKOLSF.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-YHC2O2WO.js → chunk-SFLHSL5R.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-CCV2EU7T.js → chunk-SP4TFY5F.js} +14 -13
- package/node_modules/pi-lens/dist/{chunk-J6JP25XU.js → chunk-SQC7K3SP.js} +4 -3
- package/node_modules/pi-lens/dist/{chunk-3K2F6UDZ.js → chunk-T2S3FNNJ.js} +44 -42
- package/node_modules/pi-lens/dist/{chunk-2TF6RXWB.js → chunk-TV6RXRYH.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-GNSIWBAT.js → chunk-U3AS2FR6.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-F7K5IBZG.js → chunk-UHHLR2VY.js} +40 -40
- package/node_modules/pi-lens/dist/chunk-UYXV5NIS.js +20 -0
- package/node_modules/pi-lens/dist/{chunk-VSFLRN5Y.js → chunk-VLQ7UKZH.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VUZWQ7UG.js → chunk-VN3L2JWZ.js} +46 -72
- package/node_modules/pi-lens/dist/{chunk-NA7SEXHE.js → chunk-VOP4PJKA.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-F5Z6URKM.js → chunk-VOXTCULR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-LLS45EWB.js → chunk-VPLBLWFO.js} +6 -8
- package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-ZKXQKGWZ.js → chunk-WC6WRNQT.js} +4 -3
- package/node_modules/pi-lens/dist/{chunk-YVHBNSME.js → chunk-WMDUT4KH.js} +1148 -1132
- package/node_modules/pi-lens/dist/{chunk-KXF5R4UN.js → chunk-WQV6BI4Q.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-WXUDRAG6.js +24 -0
- package/node_modules/pi-lens/dist/{chunk-KPPJTH44.js → chunk-X35S7HSB.js} +28 -10
- package/node_modules/pi-lens/dist/{chunk-JMEKXFOL.js → chunk-X66YJ2SS.js} +40 -34
- package/node_modules/pi-lens/dist/{chunk-CE6VMBCB.js → chunk-XOMGO63G.js} +22 -21
- package/node_modules/pi-lens/dist/{chunk-LS3QJRUB.js → chunk-XWIME22V.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-R5MOQM2H.js → chunk-XYLC35E4.js} +119 -87
- package/node_modules/pi-lens/dist/{chunk-OE5ZBP7F.js → chunk-YHGYAEFH.js} +18 -18
- package/node_modules/pi-lens/dist/{chunk-7E2563GA.js → chunk-ZFORSIED.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-E7HJ56Y7.js → chunk-ZKLTNLAW.js} +64 -73
- package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +74 -0
- package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-RC2Z6K47.js → chunk-ZZDIOAAJ.js} +15 -6
- package/node_modules/pi-lens/dist/index.js +6993 -5396
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -10
- package/node_modules/pi-lens/dist/mcp/cli.js +44 -42
- package/node_modules/pi-lens/dist/mcp/server.js +1627 -504
- package/node_modules/pi-lens/dist/mcp/worker.js +62 -61
- package/node_modules/pi-lens/dist/probes/installer.js +20 -19
- package/node_modules/pi-lens/docs/adr/0003-git-guard-latch-writer.md +11 -6
- package/node_modules/pi-lens/docs/agent-tools.md +18 -8
- package/node_modules/pi-lens/docs/alignment-families.md +29 -0
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +6 -4
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +126 -0
- package/node_modules/pi-lens/docs/configuration.md +99 -3
- package/node_modules/pi-lens/docs/defect-shapes.md +55 -12
- package/node_modules/pi-lens/docs/engineering-principles.md +27 -2
- package/node_modules/pi-lens/docs/features.md +2 -2
- package/node_modules/pi-lens/docs/invariants/git-guard-host.md +7 -3
- package/node_modules/pi-lens/docs/invariants/language-config.md +15 -4
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +16 -2
- package/node_modules/pi-lens/docs/invariants/paths-os.md +4 -2
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +119 -39
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +24 -17
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +20 -11
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +9 -0
- package/node_modules/pi-lens/docs/pi-lens-orchestration.md +4 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +5 -5
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +6 -3
- package/node_modules/pi-lens/docs/public-api-stability.md +18 -2
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +10 -0
- package/node_modules/pi-lens/docs/settings.md +10 -6
- package/node_modules/pi-lens/docs/word-index.md +17 -5
- package/node_modules/pi-lens/package.json +5 -3
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-accumulating-spread-js-test.yml +37 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ts-redundant-filter-map-test.yml +12 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-js-test.yml +12 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-accumulating-spread-js.yml +49 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/ts-redundant-filter-map.yml +9 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map-js.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map.yml +36 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/self-scan-baseline.json +1 -1
- package/node_modules/pi-provider-qoder/README.md +22 -0
- package/node_modules/pi-provider-qoder/dist/index.js +370 -11
- package/node_modules/pi-provider-qoder/package.json +5 -2
- package/package.json +11 -8
- package/node_modules/@tifan/pi-preferred-thinking/README.md +0 -54
- package/node_modules/@tifan/pi-preferred-thinking/package.json +0 -43
- package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +0 -236
- package/node_modules/pi-lens/dist/chunk-46TNM7XZ.js +0 -88
- package/node_modules/pi-lens/dist/chunk-72OKUXSD.js +0 -31
- package/node_modules/pi-lens/dist/chunk-7GLOLOSH.js +0 -57
- package/node_modules/pi-lens/dist/chunk-AKUUMGD5.js +0 -26
- package/node_modules/pi-lens/dist/chunk-ASUXV767.js +0 -22
- package/node_modules/pi-lens/dist/chunk-CTADOKYM.js +0 -25
- package/node_modules/pi-lens/dist/chunk-JJ2RRESP.js +0 -58
- package/node_modules/pi-lens/dist/chunk-LSC3VADM.js +0 -23
- package/node_modules/pi-lens/dist/chunk-SHLDT3OI.js +0 -27
- package/node_modules/pi-lens/dist/chunk-UF7RTZSO.js +0 -27
- package/node_modules/pi-lens/dist/chunk-W4WP2ERB.js +0 -30
- package/node_modules/pi-lens/dist/chunk-YES5CACN.js +0 -73
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { redactCommandCodeErrorText } from "./overflow.ts"
|
|
2
|
+
import type {
|
|
3
|
+
CommandCodeCredits,
|
|
4
|
+
CommandCodeQuotaResult,
|
|
5
|
+
CommandCodeQuotaSection,
|
|
6
|
+
CommandCodeSubscription,
|
|
7
|
+
CommandCodeUsageSummary,
|
|
8
|
+
CommandCodeWindowLimit,
|
|
9
|
+
} from "./quota-types.ts"
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_API_BASE = "https://api.commandcode.ai"
|
|
12
|
+
export const QUOTA_TIMEOUT_MS = 15_000
|
|
13
|
+
|
|
14
|
+
interface FetchOptions {
|
|
15
|
+
apiKey: string
|
|
16
|
+
baseUrl?: string
|
|
17
|
+
fetchImpl?: typeof fetch
|
|
18
|
+
timeoutMs?: number
|
|
19
|
+
extraHeaders?: Record<string, string>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface HttpErrorShape {
|
|
23
|
+
__httpError: true
|
|
24
|
+
message: string
|
|
25
|
+
status: number
|
|
26
|
+
body: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface QuotaErrorShape {
|
|
30
|
+
__quotaError: true
|
|
31
|
+
kind: "timeout" | "network"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function numberValue(value: unknown): number | undefined {
|
|
39
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function stringValue(value: unknown): string | undefined {
|
|
43
|
+
return typeof value === "string" && value.length > 0 ? value : undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function timestampValue(value: unknown): string | undefined {
|
|
47
|
+
const text = stringValue(value)
|
|
48
|
+
if (text) return text
|
|
49
|
+
const number = numberValue(value)
|
|
50
|
+
return number === undefined ? undefined : String(number)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function errorMessage(error: unknown): string {
|
|
54
|
+
return error instanceof Error ? error.message : String(error)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function normalizeResetAt(value: unknown): number | null {
|
|
58
|
+
let timestamp: number | undefined
|
|
59
|
+
if (typeof value === "number" && Number.isFinite(value)) timestamp = value
|
|
60
|
+
if (typeof value === "string" && value.length > 0) {
|
|
61
|
+
const trimmed = value.trim()
|
|
62
|
+
timestamp = /^\d+$/.test(trimmed) ? Number(trimmed) : Date.parse(trimmed)
|
|
63
|
+
}
|
|
64
|
+
if (timestamp === undefined || !Number.isFinite(timestamp) || timestamp < 0) return null
|
|
65
|
+
return timestamp >= 1e12 ? Math.round(timestamp / 1000) : timestamp
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function windowLimitsFromCredits(value: unknown): CommandCodeWindowLimit[] {
|
|
69
|
+
if (!isRecord(value)) return []
|
|
70
|
+
const limits: CommandCodeWindowLimit[] = []
|
|
71
|
+
for (const [window, entry] of [
|
|
72
|
+
["fiveHour", value.fiveHour],
|
|
73
|
+
["weekly", value.weekly],
|
|
74
|
+
] as const) {
|
|
75
|
+
if (!isRecord(entry)) continue
|
|
76
|
+
const used = numberValue(entry.used)
|
|
77
|
+
const cap = numberValue(entry.cap)
|
|
78
|
+
if (used === undefined || cap === undefined || (used === 0 && cap === 0)) continue
|
|
79
|
+
limits.push({ window, used, cap, resetAt: normalizeResetAt(entry.resetAt) })
|
|
80
|
+
}
|
|
81
|
+
return limits
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseCredits(value: unknown): CommandCodeCredits | null {
|
|
85
|
+
if (!isRecord(value) || !isRecord(value.credits)) return null
|
|
86
|
+
const credits = value.credits
|
|
87
|
+
const monthlyCredits = numberValue(credits.monthlyCredits)
|
|
88
|
+
const purchasedCredits = numberValue(credits.purchasedCredits)
|
|
89
|
+
const freeCredits = numberValue(credits.freeCredits)
|
|
90
|
+
if (monthlyCredits === undefined && purchasedCredits === undefined && freeCredits === undefined) {
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
const monthly = monthlyCredits ?? 0
|
|
94
|
+
const purchased = purchasedCredits ?? 0
|
|
95
|
+
const free = freeCredits ?? 0
|
|
96
|
+
return {
|
|
97
|
+
monthlyCredits: monthly,
|
|
98
|
+
purchasedCredits: purchased,
|
|
99
|
+
freeCredits: free,
|
|
100
|
+
remainingCredits: monthly + purchased + free,
|
|
101
|
+
windowLimits: windowLimitsFromCredits(value.windowLimits),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseSubscription(value: unknown): CommandCodeSubscription | null {
|
|
106
|
+
if (!isRecord(value) || !isRecord(value.data)) return null
|
|
107
|
+
const data = value.data
|
|
108
|
+
const planId = stringValue(data.planId)
|
|
109
|
+
const status = stringValue(data.status)
|
|
110
|
+
const currentPeriodStart = timestampValue(data.currentPeriodStart)
|
|
111
|
+
const currentPeriodEnd = timestampValue(data.currentPeriodEnd)
|
|
112
|
+
if (!planId && !status && !currentPeriodStart && !currentPeriodEnd) return null
|
|
113
|
+
return {
|
|
114
|
+
planId: planId ?? null,
|
|
115
|
+
status: status ?? null,
|
|
116
|
+
currentPeriodStart: currentPeriodStart ?? null,
|
|
117
|
+
currentPeriodEnd: currentPeriodEnd ?? null,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseSummary(value: unknown): CommandCodeUsageSummary | null {
|
|
122
|
+
if (!isRecord(value)) return null
|
|
123
|
+
const totalCost = numberValue(value.totalCost)
|
|
124
|
+
const totalCount = numberValue(value.totalCount)
|
|
125
|
+
if (totalCost === undefined || totalCount === undefined) return null
|
|
126
|
+
const totalTokens = numberValue(value.totalTokens) ?? numberValue(value.tokens)
|
|
127
|
+
return { totalCost, totalCount, ...(totalTokens === undefined ? {} : { totalTokens }) }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseWhoami(value: unknown): {
|
|
131
|
+
login: string
|
|
132
|
+
orgId: string | null
|
|
133
|
+
keyName?: string
|
|
134
|
+
} | null {
|
|
135
|
+
if (!isRecord(value)) return null
|
|
136
|
+
const org = isRecord(value.org) ? value.org : undefined
|
|
137
|
+
const user = isRecord(value.user) ? value.user : undefined
|
|
138
|
+
const login =
|
|
139
|
+
(org ? stringValue(org.login) : undefined) ??
|
|
140
|
+
(user ? (stringValue(user.userName) ?? stringValue(user.name)) : undefined)
|
|
141
|
+
if (!login) return null
|
|
142
|
+
const orgId = org ? stringValue(org.id) : undefined
|
|
143
|
+
const keyName = user ? (stringValue(user.keyName) ?? stringValue(user.displayName)) : undefined
|
|
144
|
+
return { login, orgId: orgId ?? null, ...(keyName ? { keyName } : {}) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function buildUrl(path: string, params: Record<string, string | undefined>): string {
|
|
148
|
+
const search = new URLSearchParams()
|
|
149
|
+
for (const [key, value] of Object.entries(params)) {
|
|
150
|
+
if (value) search.set(key, value)
|
|
151
|
+
}
|
|
152
|
+
const query = search.toString()
|
|
153
|
+
return `${path}${query ? `?${query}` : ""}`
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isHttpError(value: unknown): value is HttpErrorShape {
|
|
157
|
+
return (
|
|
158
|
+
isRecord(value) &&
|
|
159
|
+
value.__httpError === true &&
|
|
160
|
+
typeof value.message === "string" &&
|
|
161
|
+
typeof value.status === "number" &&
|
|
162
|
+
typeof value.body === "string"
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isQuotaError(value: unknown): value is QuotaErrorShape {
|
|
167
|
+
return (
|
|
168
|
+
isRecord(value) &&
|
|
169
|
+
value.__quotaError === true &&
|
|
170
|
+
(value.kind === "timeout" || value.kind === "network")
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function isBlockingHttpError(error: HttpErrorShape): boolean {
|
|
175
|
+
return error.status === 401 || error.status === 403
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function httpFailure(error: HttpErrorShape, context: string): CommandCodeQuotaResult {
|
|
179
|
+
const detail = error.body.trim().slice(0, 200)
|
|
180
|
+
return {
|
|
181
|
+
ok: false,
|
|
182
|
+
error: {
|
|
183
|
+
kind: "http",
|
|
184
|
+
message: redactValue(
|
|
185
|
+
`${context} request failed (${error.status}): ${detail || error.message}`,
|
|
186
|
+
),
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
class QuotaTimeoutError extends Error {}
|
|
192
|
+
|
|
193
|
+
export async function fetchCommandCodeQuota(
|
|
194
|
+
options: FetchOptions,
|
|
195
|
+
): Promise<CommandCodeQuotaResult> {
|
|
196
|
+
if (!options.apiKey) {
|
|
197
|
+
return { ok: false, error: { message: "No Command Code API key found", kind: "config" } }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const baseUrl = options.baseUrl ?? DEFAULT_API_BASE
|
|
201
|
+
const fetchImpl = options.fetchImpl ?? fetch
|
|
202
|
+
const timeoutMs = options.timeoutMs ?? QUOTA_TIMEOUT_MS
|
|
203
|
+
const overallController = new AbortController()
|
|
204
|
+
// AbortSignal is cooperative: a custom fetch or stalled response body may ignore it.
|
|
205
|
+
// Race every I/O phase against a single deadline so /commandcode-quota always returns.
|
|
206
|
+
let rejectDeadline: ((error: QuotaTimeoutError) => void) | undefined
|
|
207
|
+
const deadline = new Promise<never>((_resolve, reject) => {
|
|
208
|
+
rejectDeadline = reject
|
|
209
|
+
})
|
|
210
|
+
const overallTimer = setTimeout(() => {
|
|
211
|
+
overallController.abort()
|
|
212
|
+
rejectDeadline?.(new QuotaTimeoutError())
|
|
213
|
+
}, timeoutMs)
|
|
214
|
+
|
|
215
|
+
function withinDeadline<T>(operation: Promise<T>): Promise<T> {
|
|
216
|
+
return Promise.race([operation, deadline])
|
|
217
|
+
}
|
|
218
|
+
const headers = {
|
|
219
|
+
accept: "application/json",
|
|
220
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
221
|
+
...options.extraHeaders,
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const request = async (path: string): Promise<unknown> => {
|
|
225
|
+
if (overallController.signal.aborted) throw new QuotaTimeoutError()
|
|
226
|
+
try {
|
|
227
|
+
const response = await withinDeadline(
|
|
228
|
+
fetchImpl(`${baseUrl}${path}`, {
|
|
229
|
+
method: "GET",
|
|
230
|
+
headers,
|
|
231
|
+
signal: overallController.signal,
|
|
232
|
+
}),
|
|
233
|
+
)
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
return {
|
|
236
|
+
__httpError: true,
|
|
237
|
+
message:
|
|
238
|
+
response.status === 401 || response.status === 403
|
|
239
|
+
? "Command Code rejected the API key"
|
|
240
|
+
: response.statusText,
|
|
241
|
+
status: response.status,
|
|
242
|
+
body: await withinDeadline(response.text().catch(() => "")),
|
|
243
|
+
} satisfies HttpErrorShape
|
|
244
|
+
}
|
|
245
|
+
return await withinDeadline(response.json())
|
|
246
|
+
} catch (error) {
|
|
247
|
+
if (overallController.signal.aborted) throw new QuotaTimeoutError()
|
|
248
|
+
throw error
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const safeRequest = async (path: string): Promise<unknown> => {
|
|
253
|
+
try {
|
|
254
|
+
return await request(path)
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return {
|
|
257
|
+
__quotaError: true,
|
|
258
|
+
kind: error instanceof QuotaTimeoutError ? "timeout" : "network",
|
|
259
|
+
} satisfies QuotaErrorShape
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const whoamiRaw = await request("/alpha/whoami")
|
|
265
|
+
if (isHttpError(whoamiRaw)) return httpFailure(whoamiRaw, "whoami")
|
|
266
|
+
const account = parseWhoami(whoamiRaw)
|
|
267
|
+
if (!account) {
|
|
268
|
+
return {
|
|
269
|
+
ok: false,
|
|
270
|
+
error: { kind: "http", message: "Command Code returned an unrecognized account response" },
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const orgId = account.orgId ?? undefined
|
|
275
|
+
const [creditsRaw, subscriptionRaw] = await Promise.all([
|
|
276
|
+
safeRequest(buildUrl("/alpha/billing/credits", { orgId })),
|
|
277
|
+
safeRequest(buildUrl("/alpha/billing/subscriptions", { orgId })),
|
|
278
|
+
])
|
|
279
|
+
if (isHttpError(creditsRaw) && isBlockingHttpError(creditsRaw)) {
|
|
280
|
+
return httpFailure(creditsRaw, "credits")
|
|
281
|
+
}
|
|
282
|
+
if (isHttpError(subscriptionRaw) && isBlockingHttpError(subscriptionRaw)) {
|
|
283
|
+
return httpFailure(subscriptionRaw, "subscription")
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const unavailable: CommandCodeQuotaSection[] = []
|
|
287
|
+
const credits =
|
|
288
|
+
isHttpError(creditsRaw) || isQuotaError(creditsRaw) ? null : parseCredits(creditsRaw)
|
|
289
|
+
if (!credits) unavailable.push("credits")
|
|
290
|
+
const subscription =
|
|
291
|
+
isHttpError(subscriptionRaw) || isQuotaError(subscriptionRaw)
|
|
292
|
+
? null
|
|
293
|
+
: parseSubscription(subscriptionRaw)
|
|
294
|
+
if (!subscription) unavailable.push("subscription")
|
|
295
|
+
|
|
296
|
+
const summaryRaw = await safeRequest(
|
|
297
|
+
buildUrl("/alpha/usage/summary", {
|
|
298
|
+
orgId,
|
|
299
|
+
since: subscription?.currentPeriodStart ?? undefined,
|
|
300
|
+
}),
|
|
301
|
+
)
|
|
302
|
+
if (isHttpError(summaryRaw) && isBlockingHttpError(summaryRaw)) {
|
|
303
|
+
return httpFailure(summaryRaw, "summary")
|
|
304
|
+
}
|
|
305
|
+
const summary =
|
|
306
|
+
isHttpError(summaryRaw) || isQuotaError(summaryRaw) ? null : parseSummary(summaryRaw)
|
|
307
|
+
if (!summary) unavailable.push("usage")
|
|
308
|
+
|
|
309
|
+
if (!credits && !subscription && !summary) {
|
|
310
|
+
return {
|
|
311
|
+
ok: false,
|
|
312
|
+
error: {
|
|
313
|
+
kind: overallController.signal.aborted ? "timeout" : "http",
|
|
314
|
+
message: overallController.signal.aborted
|
|
315
|
+
? "Command Code quota request timed out"
|
|
316
|
+
: "Command Code returned no recognized usage data for the account",
|
|
317
|
+
},
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
ok: true,
|
|
323
|
+
quota: {
|
|
324
|
+
account,
|
|
325
|
+
credits,
|
|
326
|
+
subscription,
|
|
327
|
+
summary,
|
|
328
|
+
...(unavailable.length > 0 ? { unavailable } : {}),
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error instanceof QuotaTimeoutError || overallController.signal.aborted) {
|
|
333
|
+
return {
|
|
334
|
+
ok: false,
|
|
335
|
+
error: { message: "Command Code quota request timed out", kind: "timeout" },
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
ok: false,
|
|
340
|
+
error: {
|
|
341
|
+
message: redactValue(`Failed to fetch Command Code quota: ${errorMessage(error)}`),
|
|
342
|
+
kind: "network",
|
|
343
|
+
},
|
|
344
|
+
}
|
|
345
|
+
} finally {
|
|
346
|
+
clearTimeout(overallTimer)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function redactValue(value: string): string {
|
|
351
|
+
return redactCommandCodeErrorText(value)
|
|
352
|
+
.replace(
|
|
353
|
+
/("\s*(?:api[-_ ]?key|apikey|access[-_ ]?token|refresh[-_ ]?token|token|secret|password|authorization)\s*"\s*:\s*")([^"]{8,})/gi,
|
|
354
|
+
"$1[redacted]",
|
|
355
|
+
)
|
|
356
|
+
.trim()
|
|
357
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes Command Code's non-standard Responses reasoning deltas.
|
|
3
|
+
*
|
|
4
|
+
* Command Code emits `response.reasoning.delta` while a reasoning item is still
|
|
5
|
+
* streaming, but pi-ai 1.0.3 only understands the canonical
|
|
6
|
+
* `response.reasoning_text.delta`. Without translation the deltas are dropped
|
|
7
|
+
* and the reasoning text only appears at `response.output_item.done`. Rewriting
|
|
8
|
+
* the frame in flight restores incremental thinking without touching any other
|
|
9
|
+
* Responses event.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const SSE_MIME_TYPE = "text/event-stream"
|
|
13
|
+
const REASONING_DELTA_EVENT = "response.reasoning.delta"
|
|
14
|
+
const REASONING_TEXT_DELTA_EVENT = "response.reasoning_text.delta"
|
|
15
|
+
|
|
16
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
17
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SseLine {
|
|
21
|
+
content: string
|
|
22
|
+
ending: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Splits a complete SSE frame into lines, preserving each original ending. */
|
|
26
|
+
function splitSseLines(frame: string): SseLine[] {
|
|
27
|
+
const lines: SseLine[] = []
|
|
28
|
+
let start = 0
|
|
29
|
+
let index = 0
|
|
30
|
+
while (index < frame.length) {
|
|
31
|
+
const code = frame.charCodeAt(index)
|
|
32
|
+
if (code === 0x0a) {
|
|
33
|
+
lines.push({ content: frame.slice(start, index), ending: "\n" })
|
|
34
|
+
index += 1
|
|
35
|
+
start = index
|
|
36
|
+
} else if (code === 0x0d) {
|
|
37
|
+
if (index + 1 < frame.length && frame.charCodeAt(index + 1) === 0x0a) {
|
|
38
|
+
lines.push({ content: frame.slice(start, index), ending: "\r\n" })
|
|
39
|
+
index += 2
|
|
40
|
+
} else {
|
|
41
|
+
lines.push({ content: frame.slice(start, index), ending: "\r" })
|
|
42
|
+
index += 1
|
|
43
|
+
}
|
|
44
|
+
start = index
|
|
45
|
+
} else {
|
|
46
|
+
index += 1
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (start < frame.length) {
|
|
50
|
+
lines.push({ content: frame.slice(start), ending: "" })
|
|
51
|
+
}
|
|
52
|
+
return lines
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface SseField {
|
|
56
|
+
field: string
|
|
57
|
+
value: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Parses one SSE line. Returns undefined for comments and blank lines. */
|
|
61
|
+
function parseSseField(content: string): SseField | undefined {
|
|
62
|
+
if (content.startsWith(":")) return undefined
|
|
63
|
+
const colon = content.indexOf(":")
|
|
64
|
+
if (colon === -1) return { field: content, value: "" }
|
|
65
|
+
const field = content.slice(0, colon)
|
|
66
|
+
let value = content.slice(colon + 1)
|
|
67
|
+
if (value.startsWith(" ")) value = value.slice(1)
|
|
68
|
+
return { field, value }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rewrites `response.reasoning.delta` frames as `response.reasoning_text.delta`
|
|
73
|
+
* frames. Everything else, including malformed JSON, is returned unchanged.
|
|
74
|
+
*/
|
|
75
|
+
function normalizeResponsesSseFrame(frame: string, onSchemaMismatch: () => void): string {
|
|
76
|
+
const lines = splitSseLines(frame)
|
|
77
|
+
const dataValues: string[] = []
|
|
78
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
79
|
+
const content = index === 0 ? stripBom(lines[index].content) : lines[index].content
|
|
80
|
+
const parsed = parseSseField(content)
|
|
81
|
+
if (parsed?.field === "data") dataValues.push(parsed.value)
|
|
82
|
+
}
|
|
83
|
+
if (dataValues.length === 0) return frame
|
|
84
|
+
|
|
85
|
+
let payload: unknown
|
|
86
|
+
try {
|
|
87
|
+
payload = JSON.parse(dataValues.join("\n"))
|
|
88
|
+
} catch {
|
|
89
|
+
return frame
|
|
90
|
+
}
|
|
91
|
+
if (!isRecord(payload)) return frame
|
|
92
|
+
if (payload.type !== REASONING_DELTA_EVENT) return frame
|
|
93
|
+
if (
|
|
94
|
+
typeof payload.delta !== "string" ||
|
|
95
|
+
!Number.isInteger(payload.output_index) ||
|
|
96
|
+
(payload.output_index as number) < 0
|
|
97
|
+
) {
|
|
98
|
+
onSchemaMismatch()
|
|
99
|
+
return frame
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const replacement = { ...payload, type: REASONING_TEXT_DELTA_EVENT }
|
|
103
|
+
const replacementLine = `data: ${JSON.stringify(replacement)}`
|
|
104
|
+
const output: string[] = []
|
|
105
|
+
let replacedData = false
|
|
106
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
107
|
+
const line = lines[index]
|
|
108
|
+
const content = index === 0 ? stripBom(line.content) : line.content
|
|
109
|
+
const bom = index === 0 && line.content.startsWith("\uFEFF") ? "\uFEFF" : ""
|
|
110
|
+
const parsed = parseSseField(content)
|
|
111
|
+
if (parsed?.field === "data") {
|
|
112
|
+
if (!replacedData) {
|
|
113
|
+
output.push(`${bom}${replacementLine}${line.ending}`)
|
|
114
|
+
replacedData = true
|
|
115
|
+
}
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
if (parsed?.field === "event" && parsed.value === REASONING_DELTA_EVENT) {
|
|
119
|
+
output.push(`${bom}event: ${REASONING_TEXT_DELTA_EVENT}${line.ending}`)
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
output.push(`${line.content}${line.ending}`)
|
|
123
|
+
}
|
|
124
|
+
return output.join("")
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Drops a leading UTF-8 BOM for field recognition only, never from output. */
|
|
128
|
+
function stripBom(content: string): string {
|
|
129
|
+
return content.startsWith("\uFEFF") ? content.slice(1) : content
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Stateful splitter that emits one normalized frame per SSE event. */
|
|
133
|
+
class ResponsesSseNormalizer {
|
|
134
|
+
private readonly decoder = new TextDecoder("utf-8", { ignoreBOM: true })
|
|
135
|
+
private readonly encoder = new TextEncoder()
|
|
136
|
+
private buffer = ""
|
|
137
|
+
private scanIndex = 0
|
|
138
|
+
private lineStart = 0
|
|
139
|
+
private warned = false
|
|
140
|
+
|
|
141
|
+
constructor(private readonly onWarning?: (message: string) => void) {}
|
|
142
|
+
|
|
143
|
+
private normalize(frame: string): string {
|
|
144
|
+
return normalizeResponsesSseFrame(frame, () => {
|
|
145
|
+
if (this.warned) return
|
|
146
|
+
this.warned = true
|
|
147
|
+
try {
|
|
148
|
+
this.onWarning?.(
|
|
149
|
+
"Unsupported Command Code response.reasoning.delta shape; incremental reasoning may be unavailable. Original events were preserved.",
|
|
150
|
+
)
|
|
151
|
+
} catch {
|
|
152
|
+
// Diagnostics must not interrupt a usable response stream.
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
push(text: string, emit: (frame: string) => void, flush: boolean): void {
|
|
158
|
+
this.buffer += text
|
|
159
|
+
this.process(emit, flush)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
finish(emit: (frame: string) => void): void {
|
|
163
|
+
if (this.buffer.length === 0) return
|
|
164
|
+
emit(this.normalize(this.buffer))
|
|
165
|
+
this.buffer = ""
|
|
166
|
+
this.scanIndex = 0
|
|
167
|
+
this.lineStart = 0
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private process(emit: (frame: string) => void, flush: boolean): void {
|
|
171
|
+
while (this.scanIndex < this.buffer.length) {
|
|
172
|
+
const code = this.buffer.charCodeAt(this.scanIndex)
|
|
173
|
+
if (code === 0x0a) {
|
|
174
|
+
this.consumeLine(this.scanIndex + 1, this.scanIndex, emit)
|
|
175
|
+
} else if (code === 0x0d) {
|
|
176
|
+
const next = this.scanIndex + 1
|
|
177
|
+
if (next >= this.buffer.length) {
|
|
178
|
+
if (!flush) return
|
|
179
|
+
this.consumeLine(next, this.scanIndex, emit)
|
|
180
|
+
} else if (this.buffer.charCodeAt(next) === 0x0a) {
|
|
181
|
+
this.consumeLine(next + 1, this.scanIndex, emit)
|
|
182
|
+
} else {
|
|
183
|
+
this.consumeLine(next, this.scanIndex, emit)
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
this.scanIndex += 1
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private consumeLine(end: number, lineEnd: number, emit: (frame: string) => void): void {
|
|
192
|
+
if (lineEnd === this.lineStart) {
|
|
193
|
+
const frame = this.buffer.slice(0, end)
|
|
194
|
+
emit(this.normalize(frame))
|
|
195
|
+
this.buffer = this.buffer.slice(end)
|
|
196
|
+
this.scanIndex = 0
|
|
197
|
+
this.lineStart = 0
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
this.lineStart = end
|
|
201
|
+
this.scanIndex = end
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
transform(chunk: Uint8Array, controller: TransformStreamDefaultController<Uint8Array>): void {
|
|
205
|
+
const text = this.decoder.decode(chunk, { stream: true })
|
|
206
|
+
this.push(text, (frame) => controller.enqueue(this.encoder.encode(frame)), false)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
flush(controller: TransformStreamDefaultController<Uint8Array>): void {
|
|
210
|
+
this.push(
|
|
211
|
+
this.decoder.decode(),
|
|
212
|
+
(frame) => controller.enqueue(this.encoder.encode(frame)),
|
|
213
|
+
true,
|
|
214
|
+
)
|
|
215
|
+
this.finish((frame) => controller.enqueue(this.encoder.encode(frame)))
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Wraps a Command Code Responses HTTP response so streaming reasoning deltas
|
|
221
|
+
* reach pi-ai. Returns the original response when it cannot be an SSE stream.
|
|
222
|
+
*/
|
|
223
|
+
export function normalizeCommandCodeResponsesResponse(
|
|
224
|
+
response: Response,
|
|
225
|
+
onWarning?: (message: string) => void,
|
|
226
|
+
): Response {
|
|
227
|
+
if (!response.ok) return response
|
|
228
|
+
if (response.body === null) return response
|
|
229
|
+
const mimeType = response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase()
|
|
230
|
+
if (mimeType !== SSE_MIME_TYPE) return response
|
|
231
|
+
|
|
232
|
+
const normalizer = new ResponsesSseNormalizer(onWarning)
|
|
233
|
+
const body = response.body.pipeThrough(
|
|
234
|
+
new TransformStream<Uint8Array, Uint8Array>({
|
|
235
|
+
transform: (chunk, controller) => normalizer.transform(chunk, controller),
|
|
236
|
+
flush: (controller) => normalizer.flush(controller),
|
|
237
|
+
}),
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
const headers = new Headers(response.headers)
|
|
241
|
+
headers.delete("content-length")
|
|
242
|
+
headers.delete("content-encoding")
|
|
243
|
+
|
|
244
|
+
return new Response(body, {
|
|
245
|
+
status: response.status,
|
|
246
|
+
statusText: response.statusText,
|
|
247
|
+
headers,
|
|
248
|
+
})
|
|
249
|
+
}
|