@agimon-ai/po-cloudflare 0.0.2-alpha.2 → 0.0.2-alpha.4
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 +4 -3
- package/dist/abort-signals-Bkmp_euQ.js +34 -0
- package/dist/anthropic-messages-CkYm8M3V.js +14317 -0
- package/dist/{approval-BMXqnTYd.js → approval-Eu7UgGL-.js} +1 -1
- package/dist/assets/assets/{CodeEditorView-BnyZHaYM.js → CodeEditorView-rEfljuRK.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-muME0eCj.js → abnfDiagram-WEYOIA3C-J6Iu5p17.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-DMnhK1WH.js → architecture-WOLXFQ4H-DKj_xMR1.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DKn7XGP7.js → architectureDiagram-ZHVYKT53--D1MzuBo.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-DtDctXZg.js → blockDiagram-RJAE7QA3-CrWO0t-Q.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-23pGLJeP.js → c4Diagram-XDPPPE54-CBMOJREz.js} +2 -2
- package/dist/assets/assets/channel-CNegK3Rr.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-BZ2nGNPa.js → chunk-2E7WHVMD-CR9NMk46.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-Dui1SYFi.js → chunk-4EMNKR2T-B4D0falO.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-CUB92Evl.js → chunk-55XCU76K-CKrttFen.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-CVayPHfE.js → chunk-7S6XSTFO-BPNrdjSb.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB---wakYqY.js → chunk-AQDTSKZB-Ddx2gPU_.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-DfbdohUR.js → chunk-DSNLSHJZ-iQg3RbZ_.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-Dr4KRh-b.js → chunk-HAGFOTED-CGlDRwnk.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-D06cR91Z.js → chunk-HNE4Q36P-CN7VMEsn.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-Ca4gLeDb.js → chunk-NQOKRVIF-DQKmIS4j.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-DmL638jN.js → chunk-UHW7PFBP-BKSG_d1a.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-pkxSW5Zj.js → chunk-VQ5W62QI-AbFHiDOg.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-Dcc8hV4U.js → chunk-WQQL4CDK-C5a4DmCb.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-BbVKQGnw.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-B_HKcFrw.js → chunk-YZO67HFG-UbKezTdY.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-DAzZUysS.js → chunk-ZAUX2LTX-BShGGpRc.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-DAVgjymL.js → chunk-ZCHMQSOR-BmV-PDP0.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-Fsw8TGPu.js → classDiagram-v2-4MYWR3UA-DB-cfBNq.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-CgUbISYV.js → cose-bilkent-JH36ORCC-Dprqh48h.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-D1LxAU2x.js → cynefin-EF2NZ3EQ-Bz4CND4n.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-D54I1jil.js → cynefinDiagram-WF24UDRP-Cv0Tq-0q.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-DC7zL16U.js → dagre-NK4GIZVX-H4d8oeNm.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-DB0ptUdz.js → diagram-CBK3MWTC-D75OthTM.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-CozSftPJ.js → diagram-I5XIIV2D-CB_W2jXU.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-g3WOEWDS.js → diagram-ODIL2UCW-DPO0lYZ-.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-CFxGeOYi.js → diagram-PFBEJUXE-DJ9olXAC.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-BQBsLche.js → diagram-RJA3I4VV-DL3974PI.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-DrjpW2yq.js → diagram-TYUNFSNR-ZuYESp4p.js} +2 -2
- package/dist/assets/assets/{dist-B3JXhDWV.js → dist-BnkGKHOV.js} +2 -2
- package/dist/assets/assets/{dist-1-mhYUBH.js → dist-C8iSs-hT.js} +2 -2
- package/dist/assets/assets/{dist-XIZum9n5.js → dist-CXqaT1wB.js} +2 -2
- package/dist/assets/assets/{dist-gfbb4ygy.js → dist-CdrEbsAL.js} +2 -2
- package/dist/assets/assets/{dist-h6SOnP8-.js → dist-CeotBqYt.js} +2 -2
- package/dist/assets/assets/{dist-DvgCCshF.js → dist-D2iSi_lg.js} +2 -2
- package/dist/assets/assets/{dist-DjL8d1jZ.js → dist-DvCNYjgK.js} +2 -2
- package/dist/assets/assets/{dist-BabjcJ3j.js → dist-G3vL_xw7.js} +2 -2
- package/dist/assets/assets/{dist-Izr2SB3q.js → dist-zXhaMKmO.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-BZS_aAve.js → ebnfDiagram-V4P3TTPT-DNfHKEsm.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-B2ksVmMA.js → elk-QONTBCTQ-C0FX9D60.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-7P6zF-Z-.js → erDiagram-KYQIGQAA-BI1O9lW0.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-RoGQoRq-.js → eventmodeling-K75KTNOO-BmWt-aOv.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-DQj3H5a6.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-CTOlRy7M.js → ganttDiagram-R7GPNTJY-pM7PmQ6B.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-CPqytIt0.js → gitGraph-VSP46ZUC-D0QXMQxv.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-BffLxuxg.js → gitGraphDiagram-PDYL7XHY-BsMltgt3.js} +2 -2
- package/dist/assets/assets/index-BTHzc8EN.js +155 -0
- package/dist/assets/assets/{info-OHQRW6UA-BI8RK0Ow.js → info-OHQRW6UA-Dp5Eu5PX.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-DUIst1FB.js → infoDiagram-MVDRKAX5-TgXRfZiq.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-CA17Eho5.js → ishikawaDiagram-HPEHV2GE-Qzrmih4p.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CNri5Ap9.js → journeyDiagram-BOSHW7O7-BksI3QOT.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-DnXna7jO.js → kanban-definition-FNSA4HC5-l_IuN5_k.js} +2 -2
- package/dist/assets/assets/{line-BsXJZn93.js → line-BDKssGoM.js} +2 -2
- package/dist/assets/assets/{linear-BHYaD5T0.js → linear-C9vmtzBC.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-B64Eo-8a.js → mermaid-parser.core-O1yFX7K_.js} +4 -4
- package/dist/assets/assets/{mermaid.core-Zw9qmTzg.js → mermaid.core-CIq57361.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-E5qz4KNc.js → mindmap-definition-6OY57UG3-BkVuZ010.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DgfizTr3.js → packet-JDAUHWVQ-PPNcSWeV.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-D0WK_agM.js → pegDiagram-ECIUJNBX-ClwrHXhM.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-PJR1sXD4.js → pie-XZMESJXO-BAE4Cy9j.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-CPuU-NTs.js → pieDiagram-GNMPY74T-CvQ62Knb.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-5C9yjM1b.js → quadrantDiagram-D57K4MC3-CzAyT5ZB.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-BspdXgl0.js → radar-ABXABTNO-CoEe8B7b.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-Ct0a6hLD.js → railroad-I3PHUGI6-BbK5J8H5.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-fduYB4SA.js → railroad-abnf-LNEFI6M7-DlGngfop.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-CTQa8Sww.js → railroad-ebnf-DWYD2UWJ-BRk4ifMx.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-DatoH3GJ.js → railroad-peg-JR7BVNR7-Rz-3vbj2.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-C8sWN8l2.js → railroadDiagram-Y72NRBL7-DQISBRHH.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-CqRz4RcT.js → requirementDiagram-EQYSW5RA-DcK4FnTB.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-bdiuKKlX.js → sankeyDiagram-SY24JHO5-N2EXBOYb.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-Zy-8I0Hy.js → sequenceDiagram-BLEHNHQU-CMJ2EqC_.js} +2 -2
- package/dist/assets/assets/{src-gihY33R9.js → src-Df9VBjd7.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-DXQERPvz.js → stateDiagram-v2-A6IESKWZ-D6Cxm8wj.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-1gjZQElg.js → swimlanes-B3ENRKFQ-BybuzSPd.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-CXJkO6sc.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-CTeYEw-9.js → timeline-definition-JXYKGLGB-BzjkWUdz.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-DD-EsLLT.js → treeView-D4JQ5SDB-DIDWwDtU.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-BLdFeS5J.js → treemap-SAJKECNS-SWP4JszI.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-C1GikSSP.js → usecaseDiagram-WPOLBNNX-ZfCxSJdE.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-B1FoA3g8.js → vennDiagram-Q3Y3IDCW-o44wkgGH.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-BrHb5Bjf.js → wardley-7MLQ67FV-0zKRsI4Z.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-CmPLD1X4.js → wardleyDiagram-IVAIDKWA-CyBVyB40.js} +2 -2
- package/dist/assets/assets/{webpack-BYWDFj_R.js → webpack-C4nkEwJD.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-DR5pfEjl.js → xychartDiagram-4URNHDU4-BMvRihYC.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +1 -1
- package/dist/assets/plugins/assets/base-B5jpmLBl.css +2 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-D4qQFtJO.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -0
- package/dist/assets/plugins/slots/approval.09e72f36-Cck_K9ex.js +2 -0
- package/dist/assets/plugins/slots/artifacts.50b639bb-BZM7uEbe.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.75108f21-EWWGTveL.js +7 -0
- package/dist/assets/plugins/slots/codemode.c58fb583-CgfTL6kt.js +9 -0
- package/dist/assets/plugins/slots/domain.753f9f92-BU0ilfwM.js +1 -0
- package/dist/assets/plugins/slots/mcp.82cc1ff5-BaCD2xZB.js +109 -0
- package/dist/assets/plugins/slots/profile.ab16dcec-Cu6ev2uW.js +1 -0
- package/dist/assets/plugins/slots/skill.62a0a1b3-Bz20F1eA.js +4 -0
- package/dist/{atomicJson-BJfPFSYF.js → atomicJson-DwSqByUJ.js} +3 -3
- package/dist/azure-openai-config-DHMgdIa-.js +55 -0
- package/dist/azure-openai-responses-CTgRdQ4m.js +183 -0
- package/dist/backgroundWork-bE3pc-R9.js +25 -0
- package/dist/classifier-shared-jXm-plIK.js +106 -0
- package/dist/cloudflare-workers-ai-system-one-B0wH6HU5.js +52 -0
- package/dist/{codemode-DbPu0yJN.js → codemode-yHAHBZO-.js} +1 -1
- package/dist/diagnostics-DPTP-yrt.js +131 -0
- package/dist/dist-Dvx5mlIR.js +50 -0
- package/dist/{domains-BNjGTOPj.js → domains-dHfk2U8X.js} +4 -4
- package/dist/env-api-keys-CAnjjnsR.js +32 -0
- package/dist/error-body-DQZRsyL5.js +102 -0
- package/dist/{exports-BNZz2DNU.js → exports-CrJqsTU6.js} +8 -8
- package/dist/{extensionFile-CXOa5G4C.js → extensionFile-CY4EFNHQ.js} +1 -1
- package/dist/github-copilot-headers-DpQQAh-s.js +22 -0
- package/dist/google-generative-ai-BTTOo5RQ.js +328 -0
- package/dist/google-shared-S7bqOccz.js +19588 -0
- package/dist/google-vertex-BcMU_DMb.js +374 -0
- package/dist/{harnessStore-BT706Ly6.js → harnessStore-CRtlTdbI.js} +4 -4
- package/dist/harnessStore-DZ4lDIq6.js +1 -0
- package/dist/hash-B3RRpLS2.js +16 -0
- package/dist/headers-BEuxFxDI.js +17 -0
- package/dist/{hubChannel-BHQyzcOo.js → hubChannel-Cj1iF847.js} +1 -1
- package/dist/identity-BIeAyilV.js +165 -0
- package/dist/{layeredConfig-DPQAnlXD.js → layeredConfig-BqIwPJ-I.js} +3 -3
- package/dist/majorModes-AYZvnOpU.js +1 -0
- package/dist/{majorModes-DbCfLZH3.js → majorModes-C-OD4PBc.js} +4 -4
- package/dist/mistral-conversations-DN8VSERk.js +689 -0
- package/dist/models-D6d73jcW.js +1511 -0
- package/dist/node-DytJOfYf.js +23 -0
- package/dist/node-UuMT2C3q.js +2479 -0
- package/dist/openai-bt3ZRBZv.js +17357 -0
- package/dist/openai-codex-responses-cL36x0ml.js +1210 -0
- package/dist/openai-completions-BWsTNYyT.js +984 -0
- package/dist/openai-decisions-Dfn_KgQd.js +142 -0
- package/dist/openai-prompt-cache-Bc6qNWt0.js +8 -0
- package/dist/openai-responses-aa0LoyCJ.js +281 -0
- package/dist/openai-responses-shared-H-jH5SlM.js +661 -0
- package/dist/openrouter-cost-D99Qqcs6.js +30 -0
- package/dist/openrouter-images-BpwVpALC.js +124 -0
- package/dist/pi-messages-BHAIkYBj.js +312 -0
- package/dist/{platform-B4AAgwJ0.js → platform-CNhm9zLi.js} +1 -1
- package/dist/{platformFiles-C_bXo4Ig.js → platformFiles-3rzOh9cg.js} +1 -1
- package/dist/provider-env-DgfpjgTa.js +38 -0
- package/dist/provider-retry-ChD-K2Gv.js +79 -0
- package/dist/{remoteMcp-CMqZldeA.js → remoteMcp-Ci8crSU9.js} +1 -1
- package/dist/sanitize-unicode-Dl4ROF7y.js +26 -0
- package/dist/{server-BZh1ZXz_.js → server-B2xd7WTP.js} +4 -4
- package/dist/{server-DJAanjoI.js → server-BPvd3Ya5.js} +6 -6
- package/dist/{server-D4W7EdJY.js → server-BccTx_r6.js} +11 -10
- package/dist/{server-BZaPPoQp.js → server-Bf3_VTkt.js} +9 -9
- package/dist/{server-tvgQ99rv.js → server-BmAziQml.js} +4 -4
- package/dist/{server-r358hzQg.js → server-BvV-GqDO.js} +3 -3
- package/dist/{server-BAAL9-NA.js → server-C1ijZQp4.js} +2 -2
- package/dist/{server-BE6VqEiA.js → server-CUvohcAm.js} +4 -4
- package/dist/{server-D8ndq0wL.js → server-CYQHzqaQ.js} +2 -2
- package/dist/{server-Dt4y1rZD.js → server-De_PIOty.js} +5 -5
- package/dist/{server-A-_GFpPr.js → server-DrZBZ17y.js} +7 -7
- package/dist/{server-Dpgh8PDh.js → server-DwWTQg1J.js} +4 -4
- package/dist/{server-D75MWDhB.js → server-xiuzwJ1C.js} +2 -2
- package/dist/{server-D3PQk1Gt.js → server-y9pjeHJM.js} +3 -3
- package/dist/{serverPlugin-BOI6c6s5.js → serverPlugin-H4T49sac.js} +4 -50
- package/dist/{sessionConfig-rBQgzXlT.js → sessionConfig-2a4LWInR.js} +8 -8
- package/dist/simple-options-DWrW31_K.js +156 -0
- package/dist/streaming-json-t4rzNHEp.js +858 -0
- package/dist/system-one-shared-DLVLdzYL.js +132 -0
- package/dist/transform-messages-CjTSwW9q.js +356 -0
- package/dist/typesafe-system-one-DBVcjcUQ.js +37 -0
- package/dist/uuid-mkNGilLv.js +31 -0
- package/dist/worker.js +56113 -21793
- package/package.json +22 -22
- package/dist/assets/assets/channel-CMrEzemr.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-CFf0S6bN.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-BhGbWVf0.js +0 -1
- package/dist/assets/assets/index-Bx_K4Joy.js +0 -155
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-q91tR8ri.js +0 -9
- package/dist/backgroundWork-CeFrbRnj.js +0 -43
- package/dist/harnessStore-BiH9vSuD.js +0 -1
- package/dist/majorModes-BvWNqoHt.js +0 -1
- package/dist/server-36iuA3MI.js +0 -343
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { n as getIdentityHeaders } from "./identity-BIeAyilV.js";
|
|
2
|
+
import { n as providerHeadersToRecord, t as headersToRecord } from "./headers-BEuxFxDI.js";
|
|
3
|
+
import { t as retryProviderRequest } from "./provider-retry-ChD-K2Gv.js";
|
|
4
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-Dl4ROF7y.js";
|
|
5
|
+
import { n as OpenAI } from "./openai-bt3ZRBZv.js";
|
|
6
|
+
import { n as normalizeProviderError, t as formatProviderError } from "./error-body-DQZRsyL5.js";
|
|
7
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_cbd356c737d8e30c7d704b4728fb9233/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js
|
|
8
|
+
/** Image generation over OpenRouter's chat completions endpoint. */
|
|
9
|
+
const generateImages = async (model, context, options) => {
|
|
10
|
+
const output = {
|
|
11
|
+
api: model.api,
|
|
12
|
+
provider: model.provider,
|
|
13
|
+
model: model.id,
|
|
14
|
+
output: [],
|
|
15
|
+
stopReason: "stop",
|
|
16
|
+
timestamp: Date.now()
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
const apiKey = options?.apiKey;
|
|
20
|
+
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
21
|
+
const client = createClient(model, apiKey, options?.headers, options?.fetch, options?.identity);
|
|
22
|
+
let params = buildParams(model, context);
|
|
23
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
24
|
+
if (nextParams !== void 0) params = nextParams;
|
|
25
|
+
const requestOptions = {
|
|
26
|
+
...options?.signal ? { signal: options.signal } : {},
|
|
27
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
28
|
+
maxRetries: 0
|
|
29
|
+
};
|
|
30
|
+
const { data: response, response: rawResponse } = await retryProviderRequest(() => client.chat.completions.create(params, requestOptions).withResponse(), {
|
|
31
|
+
maxRetries: options?.maxRetries,
|
|
32
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
33
|
+
signal: options?.signal
|
|
34
|
+
});
|
|
35
|
+
await options?.onResponse?.({
|
|
36
|
+
status: rawResponse.status,
|
|
37
|
+
headers: headersToRecord(rawResponse.headers)
|
|
38
|
+
}, model);
|
|
39
|
+
const imageResponse = response;
|
|
40
|
+
output.responseId = imageResponse.id;
|
|
41
|
+
if (imageResponse.usage) output.usage = parseUsage(imageResponse.usage, model);
|
|
42
|
+
const choice = imageResponse.choices[0];
|
|
43
|
+
if (choice) {
|
|
44
|
+
const content = choice.message.content;
|
|
45
|
+
if (typeof content === "string" && content.length > 0) output.output.push({
|
|
46
|
+
type: "text",
|
|
47
|
+
text: content
|
|
48
|
+
});
|
|
49
|
+
for (const image of choice.message.images ?? []) {
|
|
50
|
+
const imageUrl = typeof image.image_url === "string" ? image.image_url : image.image_url?.url;
|
|
51
|
+
if (!imageUrl?.startsWith("data:")) continue;
|
|
52
|
+
const matches = imageUrl.match(/^data:([^;]+);base64,(.+)$/);
|
|
53
|
+
if (!matches) continue;
|
|
54
|
+
output.output.push({
|
|
55
|
+
type: "image",
|
|
56
|
+
mimeType: matches[1],
|
|
57
|
+
data: matches[2]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
64
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
65
|
+
return output;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
function createClient(model, apiKey, optionsHeaders, fetch, identity) {
|
|
69
|
+
return new OpenAI({
|
|
70
|
+
apiKey,
|
|
71
|
+
baseURL: model.baseUrl,
|
|
72
|
+
dangerouslyAllowBrowser: true,
|
|
73
|
+
fetch,
|
|
74
|
+
defaultHeaders: providerHeadersToRecord(getIdentityHeaders(model, identity), model.headers, optionsHeaders)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function buildParams(model, context) {
|
|
78
|
+
const content = context.input.map((item) => {
|
|
79
|
+
if (item.type === "text") return {
|
|
80
|
+
type: "text",
|
|
81
|
+
text: sanitizeSurrogates(item.text)
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
type: "image_url",
|
|
85
|
+
image_url: { url: `data:${item.mimeType};base64,${item.data}` }
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
model: model.id,
|
|
90
|
+
messages: [{
|
|
91
|
+
role: "user",
|
|
92
|
+
content
|
|
93
|
+
}],
|
|
94
|
+
stream: false,
|
|
95
|
+
modalities: model.output.includes("text") ? ["image", "text"] : ["image"]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function parseUsage(rawUsage, model) {
|
|
99
|
+
const promptTokens = rawUsage.prompt_tokens || 0;
|
|
100
|
+
const reportedCachedTokens = rawUsage.prompt_tokens_details?.cached_tokens || 0;
|
|
101
|
+
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
102
|
+
const cacheReadTokens = cacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;
|
|
103
|
+
const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
104
|
+
const output = rawUsage.completion_tokens || 0;
|
|
105
|
+
const usage = {
|
|
106
|
+
input,
|
|
107
|
+
output,
|
|
108
|
+
cacheRead: cacheReadTokens,
|
|
109
|
+
cacheWrite: cacheWriteTokens,
|
|
110
|
+
totalTokens: input + output + cacheReadTokens + cacheWriteTokens,
|
|
111
|
+
cost: {
|
|
112
|
+
input: model.cost.input / 1e6 * input,
|
|
113
|
+
output: model.cost.output / 1e6 * output,
|
|
114
|
+
cacheRead: model.cost.cacheRead / 1e6 * cacheReadTokens,
|
|
115
|
+
cacheWrite: model.cost.cacheWrite / 1e6 * cacheWriteTokens,
|
|
116
|
+
total: 0,
|
|
117
|
+
totalFromProvider: false
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
121
|
+
return usage;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { generateImages };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { c as ownedSlice, n as getIdentityHeaders } from "./identity-BIeAyilV.js";
|
|
2
|
+
import { n as ToolCallArgumentsStream } from "./streaming-json-t4rzNHEp.js";
|
|
3
|
+
import { i as AssistantMessageEventStream, n as createAssistantMessageDiagnostic, t as appendAssistantMessageDiagnostic } from "./diagnostics-DPTP-yrt.js";
|
|
4
|
+
import { t as getProviderEnvValue } from "./provider-env-DgfpjgTa.js";
|
|
5
|
+
import { n as providerHeadersToRecord, t as headersToRecord } from "./headers-BEuxFxDI.js";
|
|
6
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_cbd356c737d8e30c7d704b4728fb9233/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js
|
|
7
|
+
/**
|
|
8
|
+
* pi-messages API implementation.
|
|
9
|
+
*
|
|
10
|
+
* Streams pi's own message protocol directly to a backend: the request is a
|
|
11
|
+
* single POST of `{ model, context, options }` to `<baseUrl>/messages`, the
|
|
12
|
+
* response is an SSE stream of serialized assistant-message events plus a
|
|
13
|
+
* terminal `done`/`error` event. This is the wire protocol spoken by the
|
|
14
|
+
* Radius gateway, but any backend implementing it can be used, e.g. via a
|
|
15
|
+
* models.json custom provider with `"api": "pi-messages"`.
|
|
16
|
+
*/
|
|
17
|
+
var PiMessagesResponseError = class extends Error {
|
|
18
|
+
code;
|
|
19
|
+
diagnosticDetails;
|
|
20
|
+
constructor(message, code, diagnosticDetails) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "PiMessagesResponseError";
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.diagnosticDetails = diagnosticDetails;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function parsePiMessagesErrorBody(body) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(body);
|
|
30
|
+
const error = parsed?.error;
|
|
31
|
+
return parsed && typeof error === "object" && error !== null && !Array.isArray(error) ? parsed : void 0;
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function truncateDiagnosticString(value) {
|
|
37
|
+
const maxLength = 8192;
|
|
38
|
+
return value.length > maxLength ? `${ownedSlice(value, 0, maxLength)}…` : value;
|
|
39
|
+
}
|
|
40
|
+
function formatPiMessagesResponseError(response, body, errorBody) {
|
|
41
|
+
const message = typeof errorBody?.error?.message === "string" ? errorBody.error.message : void 0;
|
|
42
|
+
const code = typeof errorBody?.error?.code === "string" ? errorBody.error.code : void 0;
|
|
43
|
+
const suffix = message ?? body;
|
|
44
|
+
const codeSuffix = code ? ` (${code})` : "";
|
|
45
|
+
return `${response.status} ${response.statusText}: ${suffix}${codeSuffix}`;
|
|
46
|
+
}
|
|
47
|
+
function createPiMessagesResponseError(model, url, response, body) {
|
|
48
|
+
const errorBody = parsePiMessagesErrorBody(body);
|
|
49
|
+
const code = typeof errorBody?.error?.code === "string" ? errorBody.error.code : void 0;
|
|
50
|
+
return new PiMessagesResponseError(formatPiMessagesResponseError(response, body, errorBody), code, {
|
|
51
|
+
version: 1,
|
|
52
|
+
provider: model.provider,
|
|
53
|
+
model: model.id,
|
|
54
|
+
url: url.toString(),
|
|
55
|
+
status: response.status,
|
|
56
|
+
statusText: response.statusText,
|
|
57
|
+
...errorBody?.error === void 0 ? {} : { error: errorBody.error },
|
|
58
|
+
...errorBody ? {} : { body: truncateDiagnosticString(body) },
|
|
59
|
+
timestampMs: Date.now()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function createEmptyUsage() {
|
|
63
|
+
return {
|
|
64
|
+
input: 0,
|
|
65
|
+
output: 0,
|
|
66
|
+
cacheRead: 0,
|
|
67
|
+
cacheWrite: 0,
|
|
68
|
+
totalTokens: 0,
|
|
69
|
+
cost: {
|
|
70
|
+
input: 0,
|
|
71
|
+
output: 0,
|
|
72
|
+
cacheRead: 0,
|
|
73
|
+
cacheWrite: 0,
|
|
74
|
+
total: 0
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function appendRewriteDiagnostic(message, rewrite) {
|
|
79
|
+
if (!rewrite) return;
|
|
80
|
+
appendAssistantMessageDiagnostic(message, {
|
|
81
|
+
type: "pi_messages_rewrite",
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
details: { ...rewrite }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function createEventConverter(model) {
|
|
87
|
+
const partial = {
|
|
88
|
+
role: "assistant",
|
|
89
|
+
content: [],
|
|
90
|
+
api: model.api,
|
|
91
|
+
provider: model.provider,
|
|
92
|
+
model: model.id,
|
|
93
|
+
usage: createEmptyUsage(),
|
|
94
|
+
stopReason: "pending",
|
|
95
|
+
timestamp: Date.now()
|
|
96
|
+
};
|
|
97
|
+
const toolArguments = /* @__PURE__ */ new Map();
|
|
98
|
+
return (event) => {
|
|
99
|
+
if ("contentIndex" in event) {
|
|
100
|
+
const index = event.contentIndex;
|
|
101
|
+
const limit = event.type.endsWith("_start") ? partial.content.length : partial.content.length - 1;
|
|
102
|
+
if (typeof index !== "number" || !Number.isInteger(index) || index < 0 || index > limit) throw new Error(`Invalid contentIndex ${JSON.stringify(index)} in pi-messages ${event.type} event`);
|
|
103
|
+
}
|
|
104
|
+
switch (event.type) {
|
|
105
|
+
case "done":
|
|
106
|
+
Object.assign(partial, {
|
|
107
|
+
stopReason: event.reason,
|
|
108
|
+
usage: event.usage,
|
|
109
|
+
responseId: event.responseId
|
|
110
|
+
});
|
|
111
|
+
if (event.responseModel !== void 0) partial.responseModel = event.responseModel;
|
|
112
|
+
if (event.providerThinkingLevel !== void 0) partial.providerThinkingLevel = event.providerThinkingLevel;
|
|
113
|
+
appendRewriteDiagnostic(partial, event.rewrite);
|
|
114
|
+
return {
|
|
115
|
+
type: "done",
|
|
116
|
+
reason: event.reason,
|
|
117
|
+
message: partial
|
|
118
|
+
};
|
|
119
|
+
case "error":
|
|
120
|
+
Object.assign(partial, {
|
|
121
|
+
stopReason: event.reason,
|
|
122
|
+
usage: event.usage,
|
|
123
|
+
errorMessage: event.errorMessage,
|
|
124
|
+
responseId: event.responseId
|
|
125
|
+
});
|
|
126
|
+
if (event.responseModel !== void 0) partial.responseModel = event.responseModel;
|
|
127
|
+
if (event.providerThinkingLevel !== void 0) partial.providerThinkingLevel = event.providerThinkingLevel;
|
|
128
|
+
appendRewriteDiagnostic(partial, event.rewrite);
|
|
129
|
+
return {
|
|
130
|
+
type: "error",
|
|
131
|
+
reason: event.reason,
|
|
132
|
+
error: partial
|
|
133
|
+
};
|
|
134
|
+
case "start": break;
|
|
135
|
+
case "text_start":
|
|
136
|
+
partial.content[event.contentIndex] = {
|
|
137
|
+
type: "text",
|
|
138
|
+
text: ""
|
|
139
|
+
};
|
|
140
|
+
break;
|
|
141
|
+
case "text_delta":
|
|
142
|
+
partial.content[event.contentIndex].text += event.delta;
|
|
143
|
+
break;
|
|
144
|
+
case "text_end":
|
|
145
|
+
Object.assign(partial.content[event.contentIndex], {
|
|
146
|
+
text: event.content,
|
|
147
|
+
textSignature: event.contentSignature
|
|
148
|
+
});
|
|
149
|
+
break;
|
|
150
|
+
case "thinking_start":
|
|
151
|
+
partial.content[event.contentIndex] = {
|
|
152
|
+
type: "thinking",
|
|
153
|
+
thinking: ""
|
|
154
|
+
};
|
|
155
|
+
break;
|
|
156
|
+
case "thinking_delta":
|
|
157
|
+
partial.content[event.contentIndex].thinking += event.delta;
|
|
158
|
+
break;
|
|
159
|
+
case "thinking_end":
|
|
160
|
+
Object.assign(partial.content[event.contentIndex], {
|
|
161
|
+
thinking: event.content,
|
|
162
|
+
thinkingSignature: event.contentSignature,
|
|
163
|
+
redacted: event.redacted
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
case "toolcall_start":
|
|
167
|
+
partial.content[event.contentIndex] = {
|
|
168
|
+
type: "toolCall",
|
|
169
|
+
id: event.id,
|
|
170
|
+
name: event.toolName,
|
|
171
|
+
arguments: {}
|
|
172
|
+
};
|
|
173
|
+
toolArguments.set(event.contentIndex, new ToolCallArgumentsStream());
|
|
174
|
+
break;
|
|
175
|
+
case "toolcall_delta": {
|
|
176
|
+
const args = toolArguments.get(event.contentIndex);
|
|
177
|
+
if (args !== void 0) partial.content[event.contentIndex].arguments = args.append(event.delta);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "toolcall_end":
|
|
181
|
+
Object.assign(partial.content[event.contentIndex], event.toolCall);
|
|
182
|
+
toolArguments.delete(event.contentIndex);
|
|
183
|
+
return {
|
|
184
|
+
type: "toolcall_end",
|
|
185
|
+
contentIndex: event.contentIndex,
|
|
186
|
+
toolCall: partial.content[event.contentIndex],
|
|
187
|
+
partial
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
...event,
|
|
192
|
+
partial
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function* readPiMessagesEvents(stream) {
|
|
197
|
+
const decoder = new TextDecoder();
|
|
198
|
+
const reader = stream.getReader();
|
|
199
|
+
let buffer = "";
|
|
200
|
+
try {
|
|
201
|
+
while (true) {
|
|
202
|
+
const { done, value } = await reader.read();
|
|
203
|
+
buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
|
|
204
|
+
buffer = buffer.replace(/\r\n/g, "\n");
|
|
205
|
+
let split = buffer.indexOf("\n\n");
|
|
206
|
+
while (split !== -1) {
|
|
207
|
+
const event = parsePiMessagesEvent(buffer.slice(0, split));
|
|
208
|
+
if (event) yield event;
|
|
209
|
+
buffer = buffer.slice(split + 2);
|
|
210
|
+
split = buffer.indexOf("\n\n");
|
|
211
|
+
}
|
|
212
|
+
if (done) break;
|
|
213
|
+
}
|
|
214
|
+
if (buffer.trim()) {
|
|
215
|
+
const event = parsePiMessagesEvent(buffer);
|
|
216
|
+
if (event) yield event;
|
|
217
|
+
}
|
|
218
|
+
} finally {
|
|
219
|
+
reader.releaseLock();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function parsePiMessagesEvent(raw) {
|
|
223
|
+
const data = raw.split("\n").find((line) => line.startsWith("data:"))?.slice(5).trim();
|
|
224
|
+
return data && data !== "[DONE]" ? JSON.parse(data) : void 0;
|
|
225
|
+
}
|
|
226
|
+
function createErrorEvent(model, error, aborted) {
|
|
227
|
+
const reason = aborted ? "aborted" : "error";
|
|
228
|
+
const assistantMessage = {
|
|
229
|
+
role: "assistant",
|
|
230
|
+
content: [],
|
|
231
|
+
api: model.api,
|
|
232
|
+
provider: model.provider,
|
|
233
|
+
model: model.id,
|
|
234
|
+
usage: createEmptyUsage(),
|
|
235
|
+
stopReason: reason,
|
|
236
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
237
|
+
timestamp: Date.now()
|
|
238
|
+
};
|
|
239
|
+
if (!aborted && error instanceof PiMessagesResponseError) appendAssistantMessageDiagnostic(assistantMessage, createAssistantMessageDiagnostic("pi_messages_response_failure", error, error.diagnosticDetails));
|
|
240
|
+
return {
|
|
241
|
+
type: "error",
|
|
242
|
+
reason,
|
|
243
|
+
error: assistantMessage
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
247
|
+
if (cacheRetention) return cacheRetention;
|
|
248
|
+
return getProviderEnvValue("PI_CACHE_RETENTION", env) === "long" ? "long" : void 0;
|
|
249
|
+
}
|
|
250
|
+
const stream = (model, context, options) => {
|
|
251
|
+
const eventStream = new AssistantMessageEventStream();
|
|
252
|
+
const convertEvent = createEventConverter(model);
|
|
253
|
+
(async () => {
|
|
254
|
+
try {
|
|
255
|
+
const apiKey = options?.apiKey;
|
|
256
|
+
if (!apiKey) throw new Error(`No API key provided for provider "${model.provider}"`);
|
|
257
|
+
const url = new URL(`${model.baseUrl.replace(/\/+$/u, "")}/messages`);
|
|
258
|
+
if (options?.debug) url.searchParams.set("debug", "1");
|
|
259
|
+
let payload = {
|
|
260
|
+
model: model.id,
|
|
261
|
+
context,
|
|
262
|
+
options: {
|
|
263
|
+
temperature: options?.temperature,
|
|
264
|
+
maxTokens: options?.maxTokens,
|
|
265
|
+
reasoning: options?.reasoning,
|
|
266
|
+
cacheRetention: resolveCacheRetention(options?.cacheRetention, options?.env),
|
|
267
|
+
sessionId: options?.sessionId,
|
|
268
|
+
toolChoice: options?.toolChoice
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const nextPayload = await options?.onPayload?.(payload, model);
|
|
272
|
+
if (nextPayload !== void 0) payload = nextPayload;
|
|
273
|
+
const response = await (options?.fetch ?? globalThis.fetch)(url, {
|
|
274
|
+
method: "POST",
|
|
275
|
+
headers: providerHeadersToRecord(getIdentityHeaders(model, options?.identity), {
|
|
276
|
+
authorization: `Bearer ${apiKey}`,
|
|
277
|
+
accept: "text/event-stream",
|
|
278
|
+
"content-type": "application/json"
|
|
279
|
+
}, options?.headers),
|
|
280
|
+
body: JSON.stringify(payload),
|
|
281
|
+
signal: options?.signal
|
|
282
|
+
});
|
|
283
|
+
await options?.onResponse?.({
|
|
284
|
+
status: response.status,
|
|
285
|
+
headers: headersToRecord(response.headers)
|
|
286
|
+
}, model);
|
|
287
|
+
if (!response.ok) throw createPiMessagesResponseError(model, url, response, await response.text());
|
|
288
|
+
if (!response.body) throw new Error(`${model.provider} response has no body`);
|
|
289
|
+
for await (const piEvent of readPiMessagesEvents(response.body)) {
|
|
290
|
+
await options?.onProviderStreamEvent?.(piEvent, model);
|
|
291
|
+
const event = convertEvent(piEvent);
|
|
292
|
+
eventStream.push(event);
|
|
293
|
+
if (event.type === "done" || event.type === "error") return;
|
|
294
|
+
}
|
|
295
|
+
throw new Error(`${model.provider} stream ended without a terminal event`);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
eventStream.push(createErrorEvent(model, error, options?.signal?.aborted ?? false));
|
|
298
|
+
}
|
|
299
|
+
})();
|
|
300
|
+
return eventStream;
|
|
301
|
+
};
|
|
302
|
+
const streamSimple = (model, context, options) => {
|
|
303
|
+
const extra = options;
|
|
304
|
+
return stream(model, context, {
|
|
305
|
+
...options,
|
|
306
|
+
reasoning: options?.reasoning,
|
|
307
|
+
toolChoice: options?.toolChoice,
|
|
308
|
+
debug: extra?.debug
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
//#endregion
|
|
312
|
+
export { PiMessagesResponseError, stream, streamSimple };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { v as SessionIdentityDoc } from "./serverPlugin-
|
|
1
|
+
import { v as SessionIdentityDoc } from "./serverPlugin-H4T49sac.js";
|
|
2
2
|
//#region ../../core/po-core/src/services/durableSession/index.ts
|
|
3
3
|
/** Stamps a new session's identity, or checks an existing one matches the requested id. */
|
|
4
4
|
async function initializeSessionIdentity(session, request, context) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as __poBuiltin0 from "node:fs";
|
|
2
|
+
import "./rolldown-runtime-B-lAHAz2.js";
|
|
3
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_cbd356c737d8e30c7d704b4728fb9233/node_modules/@earendil-works/pi-ai/dist/utils/provider-env.js
|
|
4
|
+
let procEnvCache = null;
|
|
5
|
+
/**
|
|
6
|
+
* Fallback for https://github.com/oven-sh/bun/issues/27802.
|
|
7
|
+
* Bun compiled binaries can expose an empty process.env inside Linux sandboxes
|
|
8
|
+
* even though /proc/self/environ contains the environment.
|
|
9
|
+
*
|
|
10
|
+
* This intentionally duplicates restoreSandboxEnv() in
|
|
11
|
+
* packages/coding-agent/src/bun/restore-sandbox-env.ts. The ai package can be
|
|
12
|
+
* used directly, without going through that entrypoint, so provider env lookup
|
|
13
|
+
* must not depend on process.env having been patched.
|
|
14
|
+
*/
|
|
15
|
+
function getBunSandboxEnvValue(name) {
|
|
16
|
+
if (typeof process === "undefined" || !process.versions?.bun || Object.keys(process.env).length > 0) return;
|
|
17
|
+
if (procEnvCache === null) {
|
|
18
|
+
procEnvCache = /* @__PURE__ */ new Map();
|
|
19
|
+
try {
|
|
20
|
+
const { readFileSync } = __poBuiltin0;
|
|
21
|
+
const data = readFileSync("/proc/self/environ", "utf-8");
|
|
22
|
+
for (const entry of data.split("\0")) {
|
|
23
|
+
const idx = entry.indexOf("=");
|
|
24
|
+
if (idx > 0) procEnvCache.set(entry.slice(0, idx), entry.slice(idx + 1));
|
|
25
|
+
}
|
|
26
|
+
} catch {}
|
|
27
|
+
}
|
|
28
|
+
return procEnvCache.get(name);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve a provider env value from scoped overrides, normal process.env, then
|
|
32
|
+
* the duplicated Bun sandbox fallback for direct pi-ai consumers.
|
|
33
|
+
*/
|
|
34
|
+
function getProviderEnvValue(name, env) {
|
|
35
|
+
return env?.[name] || (typeof process !== "undefined" ? process.env[name] : void 0) || getBunSandboxEnvValue(name) || void 0;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { getProviderEnvValue as t };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_cbd356c737d8e30c7d704b4728fb9233/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js
|
|
2
|
+
const DEFAULT_MAX_RETRY_DELAY_MS = 6e4;
|
|
3
|
+
function isProviderError(error) {
|
|
4
|
+
if (!(error instanceof Error) || !("status" in error) || !("headers" in error)) return false;
|
|
5
|
+
return (error.status === void 0 || typeof error.status === "number") && (error.headers === void 0 || error.headers instanceof Headers);
|
|
6
|
+
}
|
|
7
|
+
/** Mirrors the pinned OpenAI/Anthropic SDK retry policy; review when either SDK is upgraded. */
|
|
8
|
+
function isRetryableProviderError(error) {
|
|
9
|
+
const shouldRetry = error.headers?.get("x-should-retry");
|
|
10
|
+
if (shouldRetry === "true") return true;
|
|
11
|
+
if (shouldRetry === "false") return false;
|
|
12
|
+
if (error.status === void 0) return true;
|
|
13
|
+
return error.status === 408 || error.status === 409 || error.status === 429 || typeof error.status === "number" && error.status >= 500;
|
|
14
|
+
}
|
|
15
|
+
function validateServerRetryDelayMs(delayMs, maxRetryDelayMs, providerErrorMessage) {
|
|
16
|
+
const maxDelayMs = maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
|
|
17
|
+
if (maxDelayMs > 0 && delayMs > maxDelayMs) throw new Error(`Server requested ${Math.ceil(delayMs / 1e3)}s retry delay (max: ${Math.ceil(maxDelayMs / 1e3)}s). ${providerErrorMessage}`);
|
|
18
|
+
return delayMs;
|
|
19
|
+
}
|
|
20
|
+
function getRetryDelayMs(error, retryIndex, maxRetryDelayMs) {
|
|
21
|
+
const retryAfterMs = error.headers?.get("retry-after-ms");
|
|
22
|
+
if (retryAfterMs) {
|
|
23
|
+
const value = Number.parseFloat(retryAfterMs);
|
|
24
|
+
if (Number.isFinite(value)) return validateServerRetryDelayMs(value, maxRetryDelayMs, error.message);
|
|
25
|
+
}
|
|
26
|
+
const retryAfter = error.headers?.get("retry-after");
|
|
27
|
+
if (retryAfter) {
|
|
28
|
+
const seconds = Number.parseFloat(retryAfter);
|
|
29
|
+
const delayMs = Number.isNaN(seconds) ? Date.parse(retryAfter) - Date.now() : seconds * 1e3;
|
|
30
|
+
if (Number.isFinite(delayMs)) return validateServerRetryDelayMs(delayMs, maxRetryDelayMs, error.message);
|
|
31
|
+
}
|
|
32
|
+
return Math.min(.5 * 2 ** retryIndex, 8) * 1e3 * (1 - Math.random() * .25);
|
|
33
|
+
}
|
|
34
|
+
function createAbortError() {
|
|
35
|
+
const error = /* @__PURE__ */ new Error("Request aborted");
|
|
36
|
+
error.name = "AbortError";
|
|
37
|
+
return error;
|
|
38
|
+
}
|
|
39
|
+
function abortableSleep(ms, signal) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
if (signal?.aborted) {
|
|
42
|
+
reject(createAbortError());
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const onAbort = () => {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
reject(createAbortError());
|
|
48
|
+
};
|
|
49
|
+
const timeout = setTimeout(() => {
|
|
50
|
+
signal?.removeEventListener("abort", onAbort);
|
|
51
|
+
resolve();
|
|
52
|
+
}, Math.max(0, ms));
|
|
53
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reproduce the retry behavior used by the OpenAI and Anthropic SDKs while making
|
|
58
|
+
* their backoff sleep interruptible. Their built-in retry timers ignore the
|
|
59
|
+
* request AbortSignal, so callers must invoke the SDK with `maxRetries: 0` and
|
|
60
|
+
* wrap the request with this helper. Provider-requested delays above
|
|
61
|
+
* `maxRetryDelayMs` fail immediately (60 seconds by default); set it to zero to
|
|
62
|
+
* disable the limit.
|
|
63
|
+
*/
|
|
64
|
+
async function retryProviderRequest(request, options = {}) {
|
|
65
|
+
const maxRetries = options.maxRetries ?? 0;
|
|
66
|
+
let retriesRemaining = maxRetries;
|
|
67
|
+
for (;;) try {
|
|
68
|
+
return await request();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (options.signal?.aborted) throw createAbortError();
|
|
71
|
+
if (retriesRemaining <= 0 || !isProviderError(error) || !isRetryableProviderError(error)) throw error;
|
|
72
|
+
if (error.status !== void 0 && options.noRetryStatuses?.includes(error.status)) throw error;
|
|
73
|
+
const retryIndex = maxRetries - retriesRemaining;
|
|
74
|
+
retriesRemaining--;
|
|
75
|
+
await abortableSleep(getRetryDelayMs(error, retryIndex, options.maxRetryDelayMs), options.signal);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { retryProviderRequest as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pt as defineServiceContract } from "./serverPlugin-H4T49sac.js";
|
|
2
2
|
import { n as Check } from "./value-Djvc2foV.js";
|
|
3
3
|
import { A as string$1, B as _isoDate, C as looseObject, D as preprocess, E as optional, F as safeParse, I as toJSONSchema, L as _coercedBoolean, M as unknown, N as url, O as record$1, R as _coercedNumber, S as literal, T as object, U as NEVER, V as _isoDateTime, _ as intersection, c as _enum, d as any, f as array, g as email, h as discriminatedUnion, i as ZodNumber, j as union, l as _null, n as ZodISODate, p as boolean$1, r as ZodISODateTime, s as ZodString, t as ZodBoolean, w as number$1, x as lazy, z as _coercedString } from "./schemas-Vj8-rCR4.js";
|
|
4
4
|
//#region ../../core/po-web-security/src/services/outboundHost/index.ts
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_cbd356c737d8e30c7d704b4728fb9233/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.js
|
|
2
|
+
/**
|
|
3
|
+
* Removes unpaired Unicode surrogate characters from a string.
|
|
4
|
+
*
|
|
5
|
+
* Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,
|
|
6
|
+
* or vice versa) cause JSON serialization errors in many API providers.
|
|
7
|
+
*
|
|
8
|
+
* Valid emoji and other characters outside the Basic Multilingual Plane use properly paired
|
|
9
|
+
* surrogates and will NOT be affected by this function.
|
|
10
|
+
*
|
|
11
|
+
* @param text - The text to sanitize
|
|
12
|
+
* @returns The sanitized text with unpaired surrogates removed
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Valid emoji (properly paired surrogates) are preserved
|
|
16
|
+
* sanitizeSurrogates("Hello 🙈 World") // => "Hello 🙈 World"
|
|
17
|
+
*
|
|
18
|
+
* // Unpaired high surrogate is removed
|
|
19
|
+
* const unpaired = String.fromCharCode(0xD83D); // high surrogate without low
|
|
20
|
+
* sanitizeSurrogates(`Text ${unpaired} here`) // => "Text here"
|
|
21
|
+
*/
|
|
22
|
+
function sanitizeSurrogates(text) {
|
|
23
|
+
return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { sanitizeSurrogates as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { B as requirePoFs, ct as withAbortSignal, ot as BACKGROUND_CONTEXT, rt as composeServerProviderOverrides } from "./serverPlugin-
|
|
2
|
-
import { f as defineServerPlugin, l as defineRoutedContribution, n as composeRootInjects, o as defineResource, s as defineRoot, t as composeRootHooks } from "./extensionFile-
|
|
1
|
+
import { B as requirePoFs, ct as withAbortSignal, ot as BACKGROUND_CONTEXT, rt as composeServerProviderOverrides } from "./serverPlugin-H4T49sac.js";
|
|
2
|
+
import { f as defineServerPlugin, l as defineRoutedContribution, n as composeRootInjects, o as defineResource, s as defineRoot, t as composeRootHooks } from "./extensionFile-CY4EFNHQ.js";
|
|
3
3
|
import { n as readPackageResource, t as packageResourcePath } from "./index.edge-BgSx_gRO.js";
|
|
4
4
|
import { a as readPoNotificationService, n as createPoTelemetryService } from "./notification-D76PSL7r.js";
|
|
5
|
-
import "./platform-
|
|
6
|
-
import { i as createSettingsApi, n as providePoConfigContext, t as createNativePoConfigContext } from "./sessionConfig-
|
|
5
|
+
import "./platform-CNhm9zLi.js";
|
|
6
|
+
import { i as createSettingsApi, n as providePoConfigContext, t as createNativePoConfigContext } from "./sessionConfig-2a4LWInR.js";
|
|
7
7
|
import { a as createPoMcpProjectionService, i as createDisabledPoMcpProjection, n as PO_MCP_PROJECTION_SERVICE, o as isPoMcpProjection } from "./mcpProjection-BsP0IEnb.js";
|
|
8
8
|
//#region ../../core/po-core/src/schemas/readiness.ts
|
|
9
9
|
/** Cordis service name for session-scoped package initialization. */
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { B as requirePoFs, F as PO_SQLITE_SERVICE, G as PoHeadlessPromptAdmissionError, N as PO_FS_SERVICE, V as requirePoSqlite, X as isPoHeadlessPromptAdmissionError,
|
|
1
|
+
import { B as requirePoFs, F as PO_SQLITE_SERVICE, G as PoHeadlessPromptAdmissionError, N as PO_FS_SERVICE, V as requirePoSqlite, X as isPoHeadlessPromptAdmissionError, c as nodeHost, f as getOrThrow, ft as PO_SERVER_SCOPE_SERVICE, mt as requirePoServerScope, o as poHomeDirectory, ot as BACKGROUND_CONTEXT, pt as defineServiceContract, q as PoSessionSetupError, rt as composeServerProviderOverrides } from "./serverPlugin-H4T49sac.js";
|
|
2
2
|
import { C as Null, G as _Object_, Q as _Array_, _ as Union, k as Literal, q as Optional, y as String$1 } from "./build-2gFaVEfG.js";
|
|
3
3
|
import { n as Check } from "./value-Djvc2foV.js";
|
|
4
4
|
import { m as jsonApiResponses, t as defineApiContract } from "./apiContracts-CHOiCbS_.js";
|
|
5
|
-
import { c as defineRoute, f as defineServerPlugin, i as defineHook, l as defineRoutedContribution, n as composeRootInjects, o as defineResource, p as runCleanups, s as defineRoot, t as composeRootHooks } from "./extensionFile-
|
|
5
|
+
import { c as defineRoute, f as defineServerPlugin, i as defineHook, l as defineRoutedContribution, n as composeRootInjects, o as defineResource, p as runCleanups, s as defineRoot, t as composeRootHooks } from "./extensionFile-CY4EFNHQ.js";
|
|
6
6
|
import { n as readPackageResource, t as packageResourcePath } from "./index.edge-BgSx_gRO.js";
|
|
7
7
|
import { o as PO_PROFILE_IDENTITY_ENTRY_TYPE } from "./contextProjection-DVP2Vc5j.js";
|
|
8
|
-
import "./platform-
|
|
8
|
+
import "./platform-CNhm9zLi.js";
|
|
9
9
|
import "./piSettings-B6fsgIBA.js";
|
|
10
|
-
import { a as loadProfilesAsync, c as inlineProfile, l as parseProfileBinding, o as buildPersonaPrompt, r as PO_CONFIG_SERVICE, s as loadProfiles } from "./sessionConfig-
|
|
11
|
-
import "./exports-
|
|
12
|
-
import { i as readPoCodemode, n as PO_CODEMODE_SERVICE } from "./codemode-
|
|
10
|
+
import { a as loadProfilesAsync, c as inlineProfile, l as parseProfileBinding, o as buildPersonaPrompt, r as PO_CONFIG_SERVICE, s as loadProfiles } from "./sessionConfig-2a4LWInR.js";
|
|
11
|
+
import "./exports-CrJqsTU6.js";
|
|
12
|
+
import { i as readPoCodemode, n as PO_CODEMODE_SERVICE } from "./codemode-yHAHBZO-.js";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
//#region ../../foundations/po-profile/src/constants/profileMemory.ts
|
|
15
15
|
const PROFILE_MEMORY_STORE_SERVICE = "po/profile-memory-store";
|