@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,858 @@
|
|
|
1
|
+
import { t as __commonJSMin } from "./rolldown-runtime-B-lAHAz2.js";
|
|
2
|
+
//#region ../../../node_modules/.pnpm/partial-json@0.1.7/node_modules/partial-json/dist/options.js
|
|
3
|
+
var require_options = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4
|
+
/**
|
|
5
|
+
* Sometimes you don't allow every type to be partially parsed.
|
|
6
|
+
* For example, you may not want a partial number because it may increase its size gradually before it's complete.
|
|
7
|
+
* In this case, you can use the `Allow` object to control what types you allow to be partially parsed.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Allow = exports.ALL = exports.COLLECTION = exports.ATOM = exports.SPECIAL = exports.INF = exports._INFINITY = exports.INFINITY = exports.NAN = exports.BOOL = exports.NULL = exports.OBJ = exports.ARR = exports.NUM = exports.STR = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* allow partial strings like `"hello \u12` to be parsed as `"hello "`
|
|
14
|
+
*/
|
|
15
|
+
exports.STR = 1;
|
|
16
|
+
/**
|
|
17
|
+
* allow partial numbers like `123.` to be parsed as `123`
|
|
18
|
+
*/
|
|
19
|
+
exports.NUM = 2;
|
|
20
|
+
/**
|
|
21
|
+
* allow partial arrays like `[1, 2,` to be parsed as `[1, 2]`
|
|
22
|
+
*/
|
|
23
|
+
exports.ARR = 4;
|
|
24
|
+
/**
|
|
25
|
+
* allow partial objects like `{"a": 1, "b":` to be parsed as `{"a": 1}`
|
|
26
|
+
*/
|
|
27
|
+
exports.OBJ = 8;
|
|
28
|
+
/**
|
|
29
|
+
* allow `nu` to be parsed as `null`
|
|
30
|
+
*/
|
|
31
|
+
exports.NULL = 16;
|
|
32
|
+
/**
|
|
33
|
+
* allow `tr` to be parsed as `true`, and `fa` to be parsed as `false`
|
|
34
|
+
*/
|
|
35
|
+
exports.BOOL = 32;
|
|
36
|
+
/**
|
|
37
|
+
* allow `Na` to be parsed as `NaN`
|
|
38
|
+
*/
|
|
39
|
+
exports.NAN = 64;
|
|
40
|
+
/**
|
|
41
|
+
* allow `Inf` to be parsed as `Infinity`
|
|
42
|
+
*/
|
|
43
|
+
exports.INFINITY = 128;
|
|
44
|
+
/**
|
|
45
|
+
* allow `-Inf` to be parsed as `-Infinity`
|
|
46
|
+
*/
|
|
47
|
+
exports._INFINITY = 256;
|
|
48
|
+
exports.INF = exports.INFINITY | exports._INFINITY;
|
|
49
|
+
exports.SPECIAL = exports.NULL | exports.BOOL | exports.INF | exports.NAN;
|
|
50
|
+
exports.ATOM = exports.STR | exports.NUM | exports.SPECIAL;
|
|
51
|
+
exports.COLLECTION = exports.ARR | exports.OBJ;
|
|
52
|
+
exports.ALL = exports.ATOM | exports.COLLECTION;
|
|
53
|
+
/**
|
|
54
|
+
* Control what types you allow to be partially parsed.
|
|
55
|
+
* The default is to allow all types to be partially parsed, which in most casees is the best option.
|
|
56
|
+
* @example
|
|
57
|
+
* If you don't want to allow partial objects, you can use the following code:
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { Allow, parse } from "partial-json";
|
|
60
|
+
* parse(`[{"a": 1, "b": 2}, {"a": 3,`, Allow.ARR); // [ { a: 1, b: 2 } ]
|
|
61
|
+
* ```
|
|
62
|
+
* Or you can use `~` to disallow a type:
|
|
63
|
+
* ```ts
|
|
64
|
+
* parse(`[{"a": 1, "b": 2}, {"a": 3,`, ~Allow.OBJ); // [ { a: 1, b: 2 } ]
|
|
65
|
+
* ```
|
|
66
|
+
* @example
|
|
67
|
+
* If you don't want to allow partial strings, you can use the following code:
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { Allow, parse } from "partial-json";
|
|
70
|
+
* parse(`["complete string", "incompl`, ~Allow.STR); // [ 'complete string' ]
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
exports.Allow = {
|
|
74
|
+
STR: exports.STR,
|
|
75
|
+
NUM: exports.NUM,
|
|
76
|
+
ARR: exports.ARR,
|
|
77
|
+
OBJ: exports.OBJ,
|
|
78
|
+
NULL: exports.NULL,
|
|
79
|
+
BOOL: exports.BOOL,
|
|
80
|
+
NAN: exports.NAN,
|
|
81
|
+
INFINITY: exports.INFINITY,
|
|
82
|
+
_INFINITY: exports._INFINITY,
|
|
83
|
+
INF: exports.INF,
|
|
84
|
+
SPECIAL: exports.SPECIAL,
|
|
85
|
+
ATOM: exports.ATOM,
|
|
86
|
+
COLLECTION: exports.COLLECTION,
|
|
87
|
+
ALL: exports.ALL
|
|
88
|
+
};
|
|
89
|
+
exports.default = exports.Allow;
|
|
90
|
+
}));
|
|
91
|
+
(/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
92
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
93
|
+
if (k2 === void 0) k2 = k;
|
|
94
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
95
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return m[k];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
Object.defineProperty(o, k2, desc);
|
|
102
|
+
}) : (function(o, m, k, k2) {
|
|
103
|
+
if (k2 === void 0) k2 = k;
|
|
104
|
+
o[k2] = m[k];
|
|
105
|
+
}));
|
|
106
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports$1) {
|
|
107
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
|
|
108
|
+
};
|
|
109
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
110
|
+
exports.Allow = exports.MalformedJSON = exports.PartialJSON = exports.parseJSON = exports.parse = void 0;
|
|
111
|
+
const options_1 = require_options();
|
|
112
|
+
Object.defineProperty(exports, "Allow", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return options_1.Allow;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
__exportStar(require_options(), exports);
|
|
119
|
+
var PartialJSON = class extends Error {};
|
|
120
|
+
exports.PartialJSON = PartialJSON;
|
|
121
|
+
var MalformedJSON = class extends Error {};
|
|
122
|
+
exports.MalformedJSON = MalformedJSON;
|
|
123
|
+
/**
|
|
124
|
+
* Parse incomplete JSON
|
|
125
|
+
* @param {string} jsonString Partial JSON to be parsed
|
|
126
|
+
* @param {number} allowPartial Specify what types are allowed to be partial, see {@link Allow} for details
|
|
127
|
+
* @returns The parsed JSON
|
|
128
|
+
* @throws {PartialJSON} If the JSON is incomplete (related to the `allow` parameter)
|
|
129
|
+
* @throws {MalformedJSON} If the JSON is malformed
|
|
130
|
+
*/
|
|
131
|
+
function parseJSON(jsonString, allowPartial = options_1.Allow.ALL) {
|
|
132
|
+
if (typeof jsonString !== "string") throw new TypeError(`expecting str, got ${typeof jsonString}`);
|
|
133
|
+
if (!jsonString.trim()) throw new Error(`${jsonString} is empty`);
|
|
134
|
+
return _parseJSON(jsonString.trim(), allowPartial);
|
|
135
|
+
}
|
|
136
|
+
exports.parseJSON = parseJSON;
|
|
137
|
+
const _parseJSON = (jsonString, allow) => {
|
|
138
|
+
const length = jsonString.length;
|
|
139
|
+
let index = 0;
|
|
140
|
+
const markPartialJSON = (msg) => {
|
|
141
|
+
throw new PartialJSON(`${msg} at position ${index}`);
|
|
142
|
+
};
|
|
143
|
+
const throwMalformedError = (msg) => {
|
|
144
|
+
throw new MalformedJSON(`${msg} at position ${index}`);
|
|
145
|
+
};
|
|
146
|
+
const parseAny = () => {
|
|
147
|
+
skipBlank();
|
|
148
|
+
if (index >= length) markPartialJSON("Unexpected end of input");
|
|
149
|
+
if (jsonString[index] === "\"") return parseStr();
|
|
150
|
+
if (jsonString[index] === "{") return parseObj();
|
|
151
|
+
if (jsonString[index] === "[") return parseArr();
|
|
152
|
+
if (jsonString.substring(index, index + 4) === "null" || options_1.Allow.NULL & allow && length - index < 4 && "null".startsWith(jsonString.substring(index))) {
|
|
153
|
+
index += 4;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (jsonString.substring(index, index + 4) === "true" || options_1.Allow.BOOL & allow && length - index < 4 && "true".startsWith(jsonString.substring(index))) {
|
|
157
|
+
index += 4;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (jsonString.substring(index, index + 5) === "false" || options_1.Allow.BOOL & allow && length - index < 5 && "false".startsWith(jsonString.substring(index))) {
|
|
161
|
+
index += 5;
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (jsonString.substring(index, index + 8) === "Infinity" || options_1.Allow.INFINITY & allow && length - index < 8 && "Infinity".startsWith(jsonString.substring(index))) {
|
|
165
|
+
index += 8;
|
|
166
|
+
return Infinity;
|
|
167
|
+
}
|
|
168
|
+
if (jsonString.substring(index, index + 9) === "-Infinity" || options_1.Allow._INFINITY & allow && 1 < length - index && length - index < 9 && "-Infinity".startsWith(jsonString.substring(index))) {
|
|
169
|
+
index += 9;
|
|
170
|
+
return -Infinity;
|
|
171
|
+
}
|
|
172
|
+
if (jsonString.substring(index, index + 3) === "NaN" || options_1.Allow.NAN & allow && length - index < 3 && "NaN".startsWith(jsonString.substring(index))) {
|
|
173
|
+
index += 3;
|
|
174
|
+
return NaN;
|
|
175
|
+
}
|
|
176
|
+
return parseNum();
|
|
177
|
+
};
|
|
178
|
+
const parseStr = () => {
|
|
179
|
+
const start = index;
|
|
180
|
+
let escape = false;
|
|
181
|
+
index++;
|
|
182
|
+
while (index < length && (jsonString[index] !== "\"" || escape && jsonString[index - 1] === "\\")) {
|
|
183
|
+
escape = jsonString[index] === "\\" ? !escape : false;
|
|
184
|
+
index++;
|
|
185
|
+
}
|
|
186
|
+
if (jsonString.charAt(index) == "\"") try {
|
|
187
|
+
return JSON.parse(jsonString.substring(start, ++index - Number(escape)));
|
|
188
|
+
} catch (e) {
|
|
189
|
+
throwMalformedError(String(e));
|
|
190
|
+
}
|
|
191
|
+
else if (options_1.Allow.STR & allow) try {
|
|
192
|
+
return JSON.parse(jsonString.substring(start, index - Number(escape)) + "\"");
|
|
193
|
+
} catch (e) {
|
|
194
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("\\")) + "\"");
|
|
195
|
+
}
|
|
196
|
+
markPartialJSON("Unterminated string literal");
|
|
197
|
+
};
|
|
198
|
+
const parseObj = () => {
|
|
199
|
+
index++;
|
|
200
|
+
skipBlank();
|
|
201
|
+
const obj = {};
|
|
202
|
+
try {
|
|
203
|
+
while (jsonString[index] !== "}") {
|
|
204
|
+
skipBlank();
|
|
205
|
+
if (index >= length && options_1.Allow.OBJ & allow) return obj;
|
|
206
|
+
const key = parseStr();
|
|
207
|
+
skipBlank();
|
|
208
|
+
index++;
|
|
209
|
+
try {
|
|
210
|
+
obj[key] = parseAny();
|
|
211
|
+
} catch (e) {
|
|
212
|
+
if (options_1.Allow.OBJ & allow) return obj;
|
|
213
|
+
else throw e;
|
|
214
|
+
}
|
|
215
|
+
skipBlank();
|
|
216
|
+
if (jsonString[index] === ",") index++;
|
|
217
|
+
}
|
|
218
|
+
} catch (e) {
|
|
219
|
+
if (options_1.Allow.OBJ & allow) return obj;
|
|
220
|
+
else markPartialJSON("Expected '}' at end of object");
|
|
221
|
+
}
|
|
222
|
+
index++;
|
|
223
|
+
return obj;
|
|
224
|
+
};
|
|
225
|
+
const parseArr = () => {
|
|
226
|
+
index++;
|
|
227
|
+
const arr = [];
|
|
228
|
+
try {
|
|
229
|
+
while (jsonString[index] !== "]") {
|
|
230
|
+
arr.push(parseAny());
|
|
231
|
+
skipBlank();
|
|
232
|
+
if (jsonString[index] === ",") index++;
|
|
233
|
+
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
if (options_1.Allow.ARR & allow) return arr;
|
|
236
|
+
markPartialJSON("Expected ']' at end of array");
|
|
237
|
+
}
|
|
238
|
+
index++;
|
|
239
|
+
return arr;
|
|
240
|
+
};
|
|
241
|
+
const parseNum = () => {
|
|
242
|
+
if (index === 0) {
|
|
243
|
+
if (jsonString === "-") throwMalformedError("Not sure what '-' is");
|
|
244
|
+
try {
|
|
245
|
+
return JSON.parse(jsonString);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
if (options_1.Allow.NUM & allow) try {
|
|
248
|
+
return JSON.parse(jsonString.substring(0, jsonString.lastIndexOf("e")));
|
|
249
|
+
} catch (e) {}
|
|
250
|
+
throwMalformedError(String(e));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const start = index;
|
|
254
|
+
if (jsonString[index] === "-") index++;
|
|
255
|
+
while (jsonString[index] && ",]}".indexOf(jsonString[index]) === -1) index++;
|
|
256
|
+
if (index == length && !(options_1.Allow.NUM & allow)) markPartialJSON("Unterminated number literal");
|
|
257
|
+
try {
|
|
258
|
+
return JSON.parse(jsonString.substring(start, index));
|
|
259
|
+
} catch (e) {
|
|
260
|
+
if (jsonString.substring(start, index) === "-") markPartialJSON("Not sure what '-' is");
|
|
261
|
+
try {
|
|
262
|
+
return JSON.parse(jsonString.substring(start, jsonString.lastIndexOf("e")));
|
|
263
|
+
} catch (e) {
|
|
264
|
+
throwMalformedError(String(e));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const skipBlank = () => {
|
|
269
|
+
while (index < length && " \n\r ".includes(jsonString[index])) index++;
|
|
270
|
+
};
|
|
271
|
+
return parseAny();
|
|
272
|
+
};
|
|
273
|
+
exports.parse = parseJSON;
|
|
274
|
+
})))();
|
|
275
|
+
const VALID_JSON_ESCAPES = /* @__PURE__ */ new Set([
|
|
276
|
+
"\"",
|
|
277
|
+
"\\",
|
|
278
|
+
"/",
|
|
279
|
+
"b",
|
|
280
|
+
"f",
|
|
281
|
+
"n",
|
|
282
|
+
"r",
|
|
283
|
+
"t"
|
|
284
|
+
]);
|
|
285
|
+
function isControlCharacter(char) {
|
|
286
|
+
const codePoint = char.codePointAt(0);
|
|
287
|
+
return codePoint !== void 0 && codePoint >= 0 && codePoint <= 31;
|
|
288
|
+
}
|
|
289
|
+
function escapeControlCharacter(char) {
|
|
290
|
+
switch (char) {
|
|
291
|
+
case "\b": return "\\b";
|
|
292
|
+
case "\f": return "\\f";
|
|
293
|
+
case "\n": return "\\n";
|
|
294
|
+
case "\r": return "\\r";
|
|
295
|
+
case " ": return "\\t";
|
|
296
|
+
default: return `\\u${char.codePointAt(0)?.toString(16).padStart(4, "0") ?? "0000"}`;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Repairs malformed JSON string literals by:
|
|
301
|
+
* - escaping raw control characters inside strings
|
|
302
|
+
* - doubling backslashes before invalid escape characters
|
|
303
|
+
*/
|
|
304
|
+
function repairJson(json) {
|
|
305
|
+
let repaired = "";
|
|
306
|
+
let inString = false;
|
|
307
|
+
for (let index = 0; index < json.length; index++) {
|
|
308
|
+
const char = json[index];
|
|
309
|
+
if (!inString) {
|
|
310
|
+
repaired += char;
|
|
311
|
+
if (char === "\"") inString = true;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (char === "\"") {
|
|
315
|
+
repaired += char;
|
|
316
|
+
inString = false;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (char === "\\") {
|
|
320
|
+
const nextChar = json[index + 1];
|
|
321
|
+
if (nextChar === void 0) {
|
|
322
|
+
repaired += "\\\\";
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (nextChar === "u") {
|
|
326
|
+
const unicodeDigits = json.slice(index + 2, index + 6);
|
|
327
|
+
if (/^[0-9a-fA-F]{4}$/.test(unicodeDigits)) {
|
|
328
|
+
repaired += `\\u${unicodeDigits}`;
|
|
329
|
+
index += 5;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (VALID_JSON_ESCAPES.has(nextChar)) {
|
|
334
|
+
repaired += `\\${nextChar}`;
|
|
335
|
+
index += 1;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
repaired += "\\\\";
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
repaired += isControlCharacter(char) ? escapeControlCharacter(char) : char;
|
|
342
|
+
}
|
|
343
|
+
return repaired;
|
|
344
|
+
}
|
|
345
|
+
function parseJsonWithRepair(json) {
|
|
346
|
+
try {
|
|
347
|
+
return JSON.parse(json);
|
|
348
|
+
} catch (error) {
|
|
349
|
+
const repairedJson = repairJson(json);
|
|
350
|
+
if (repairedJson !== json) return JSON.parse(repairedJson);
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Parses the model's complete arguments text of a finished tool call.
|
|
356
|
+
*
|
|
357
|
+
* Unlike {@link parseStreamingJson}, this never keeps a partially parsed prefix: once the call is
|
|
358
|
+
* finished, text that is not a valid JSON object means the model sent malformed arguments. In that
|
|
359
|
+
* case `arguments` is `{}` and `argumentsError` describes the problem, including the text the
|
|
360
|
+
* model sent, so tool validation can report it back to the model.
|
|
361
|
+
*/
|
|
362
|
+
function parseToolCallArguments(json) {
|
|
363
|
+
if (!json?.trim()) return { arguments: {} };
|
|
364
|
+
try {
|
|
365
|
+
const parsed = parseJsonWithRepair(json);
|
|
366
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("Tool arguments must be a JSON object");
|
|
367
|
+
return { arguments: parsed };
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return {
|
|
370
|
+
arguments: {},
|
|
371
|
+
argumentsError: `${error instanceof Error ? error.message : String(error)}\n\nReceived arguments:\n${json}`
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//#endregion
|
|
376
|
+
//#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/streaming-json.js
|
|
377
|
+
/**
|
|
378
|
+
* Incremental, tolerant parsing of JSON text that arrives in pieces, such as streamed tool-call arguments.
|
|
379
|
+
*
|
|
380
|
+
* `StreamingJsonParser.append()` reads each piece once, so a stream costs time and memory linear in its length, and
|
|
381
|
+
* `snapshot()` returns the value of the text read so far. Snapshots are plain JSON values and never change once
|
|
382
|
+
* returned: the parser copies the containers that are still open (the "open path") into every new snapshot and shares
|
|
383
|
+
* completed containers and strings. The rules for incomplete text follow `parseStreamingJson()`:
|
|
384
|
+
*
|
|
385
|
+
* - An unterminated string shows the characters read so far; an unterminated escape is held back until complete.
|
|
386
|
+
* - An unterminated container shows the members and elements read so far.
|
|
387
|
+
* - A member whose key or value has not started is omitted.
|
|
388
|
+
* - An unterminated literal shows its value once it is a prefix of `true`, `false` or `null`; an unterminated number
|
|
389
|
+
* shows its value when the digits read so far form a number (an exponent without digits is ignored).
|
|
390
|
+
*
|
|
391
|
+
* Malformed text is read leniently, the way `repairJson()` and `parseStreamingJson()` treat it: raw control characters
|
|
392
|
+
* in strings are kept, an invalid escape such as `\d` stays literal text, missing commas and colons are tolerated,
|
|
393
|
+
* values in invalid positions and unknown words are dropped, and text after the root value is ignored. The parser never
|
|
394
|
+
* throws. Callers that need the exact value of the finished text parse it once, e.g. with `parseToolCallArguments()`.
|
|
395
|
+
*
|
|
396
|
+
* Differences from `parseStreamingJson()` on incomplete text: trailing whitespace inside an unterminated string is
|
|
397
|
+
* kept (it was trimmed), a string that contains a raw control character or an invalid escape stays visible while it
|
|
398
|
+
* streams (it was dropped until the document was complete), and `NaN` and `Infinity` words are dropped.
|
|
399
|
+
*
|
|
400
|
+
* `append()` also returns the changes the piece made, for a writer that keeps its own copy of the value and applies
|
|
401
|
+
* them instead of re-assigning snapshots: `set` when a key, an array item or a finished value appears (a new string is
|
|
402
|
+
* set once with its first text, a container empty), `append` when the piece extended an open string. Unterminated
|
|
403
|
+
* numbers and literals are not reported until they end. A container nested more than 32 levels deep is reported as one
|
|
404
|
+
* `set` of its whole value when it closes, so paths stay short.
|
|
405
|
+
*
|
|
406
|
+
* Cost: copying the open path costs its member and element count. Each `append()` earns copy credit proportional to its
|
|
407
|
+
* length plus a constant; `snapshot()` spends it and returns the previous snapshot while the open path costs more than
|
|
408
|
+
* the credit. So a document that keeps a very large container open (thousands of elements) shows a preview that lags
|
|
409
|
+
* a little behind the text, and no input makes the total work grow faster than the text.
|
|
410
|
+
*/
|
|
411
|
+
const MAX_REPORTED_DEPTH = 32;
|
|
412
|
+
const ROOT_SLOT = { kind: "root" };
|
|
413
|
+
const CREDIT_PER_APPEND = 256;
|
|
414
|
+
const CREDIT_PER_CHARACTER = 8;
|
|
415
|
+
const MAX_PENDING_SCALAR_LENGTH = 64;
|
|
416
|
+
const NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
417
|
+
const NUMBER_WITHOUT_EXPONENT_DIGITS = /^(-?(?:0|[1-9]\d*)(?:\.\d+)?)[eE][+-]?$/;
|
|
418
|
+
const LITERALS = [
|
|
419
|
+
["true", true],
|
|
420
|
+
["false", false],
|
|
421
|
+
["null", null]
|
|
422
|
+
];
|
|
423
|
+
const QUOTE = 34;
|
|
424
|
+
const BACKSLASH = 92;
|
|
425
|
+
/** Incremental, tolerant JSON parser; see the module comment for its rules and costs. */
|
|
426
|
+
var StreamingJsonParser = class {
|
|
427
|
+
#root = void 0;
|
|
428
|
+
#done = false;
|
|
429
|
+
#stack = [];
|
|
430
|
+
#string = void 0;
|
|
431
|
+
#scalar = "";
|
|
432
|
+
#scalarSlot = void 0;
|
|
433
|
+
/** Sum of `size + 1` over the open path: what a fresh snapshot copies. */
|
|
434
|
+
#pathCost = 0;
|
|
435
|
+
#credit = 0;
|
|
436
|
+
#dirty = false;
|
|
437
|
+
#snapshot = void 0;
|
|
438
|
+
/** Changes of the piece being read. */
|
|
439
|
+
#changes = [];
|
|
440
|
+
/**
|
|
441
|
+
* Read the next piece of text; returns the changes it made, in order. Costs time linear in `text.length`.
|
|
442
|
+
*/
|
|
443
|
+
append(text) {
|
|
444
|
+
this.#credit += CREDIT_PER_APPEND + CREDIT_PER_CHARACTER * text.length;
|
|
445
|
+
this.#changes = [];
|
|
446
|
+
if (this.#string !== void 0) this.#string.change = void 0;
|
|
447
|
+
let index = 0;
|
|
448
|
+
while (index < text.length && !this.#done) {
|
|
449
|
+
const open = this.#string;
|
|
450
|
+
if (open !== void 0) index = this.#readString(open, text, index);
|
|
451
|
+
else if (this.#scalar !== "") index = this.#readScalar(text, index);
|
|
452
|
+
else this.#structural(text[index++]);
|
|
453
|
+
}
|
|
454
|
+
return this.#changes;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* The value of the text read so far: `undefined` before a value starts, otherwise a plain JSON value that never
|
|
458
|
+
* changes afterwards. Returns the previous snapshot while the text read since did not change the value, or while a
|
|
459
|
+
* fresh copy of the open path is not yet paid for (see the module comment).
|
|
460
|
+
*/
|
|
461
|
+
snapshot() {
|
|
462
|
+
if (!this.#dirty) return this.#snapshot;
|
|
463
|
+
const pending = this.#pendingScalar();
|
|
464
|
+
const cost = this.#pathCost + (pending === void 0 ? 0 : 1);
|
|
465
|
+
if (cost > this.#credit) return this.#snapshot;
|
|
466
|
+
this.#credit -= cost;
|
|
467
|
+
this.#dirty = false;
|
|
468
|
+
this.#snapshot = this.#copyOpenPath(pending);
|
|
469
|
+
return this.#snapshot;
|
|
470
|
+
}
|
|
471
|
+
/** Read string characters from `start` until the string ends or the text does; returns the next index. */
|
|
472
|
+
#readString(open, text, start) {
|
|
473
|
+
let runStart = start;
|
|
474
|
+
for (let index = start; index < text.length; index++) {
|
|
475
|
+
const code = text.charCodeAt(index);
|
|
476
|
+
if (open.escape !== "") {
|
|
477
|
+
if (this.#continueEscape(open, text[index])) {
|
|
478
|
+
runStart = index + 1;
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
runStart = index;
|
|
482
|
+
}
|
|
483
|
+
if (code === QUOTE) {
|
|
484
|
+
if (index > runStart) this.#appendString(open, text.slice(runStart, index));
|
|
485
|
+
this.#endString(open);
|
|
486
|
+
return index + 1;
|
|
487
|
+
}
|
|
488
|
+
if (code === BACKSLASH) {
|
|
489
|
+
if (index > runStart) this.#appendString(open, text.slice(runStart, index));
|
|
490
|
+
open.escape = "\\";
|
|
491
|
+
runStart = index + 1;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (text.length > runStart) this.#appendString(open, text.slice(runStart));
|
|
495
|
+
return text.length;
|
|
496
|
+
}
|
|
497
|
+
/** Read number or literal characters from `start` up to the next delimiter; returns the delimiter's index. */
|
|
498
|
+
#readScalar(text, start) {
|
|
499
|
+
let end = start;
|
|
500
|
+
while (end < text.length && !isDelimiter(text[end])) end++;
|
|
501
|
+
if (end > start) {
|
|
502
|
+
this.#scalar += text.slice(start, end);
|
|
503
|
+
if (this.#scalarSlot !== void 0) this.#dirty = true;
|
|
504
|
+
}
|
|
505
|
+
if (end < text.length) this.#endScalar();
|
|
506
|
+
return end;
|
|
507
|
+
}
|
|
508
|
+
/** Handle one character outside strings. */
|
|
509
|
+
#structural(char) {
|
|
510
|
+
switch (char) {
|
|
511
|
+
case " ":
|
|
512
|
+
case " ":
|
|
513
|
+
case "\n":
|
|
514
|
+
case "\r": return;
|
|
515
|
+
case "\"":
|
|
516
|
+
this.#startString();
|
|
517
|
+
return;
|
|
518
|
+
case "{":
|
|
519
|
+
case "[":
|
|
520
|
+
this.#openContainer(char === "{" ? {} : []);
|
|
521
|
+
return;
|
|
522
|
+
case "}":
|
|
523
|
+
case "]":
|
|
524
|
+
this.#closeContainer();
|
|
525
|
+
return;
|
|
526
|
+
case ":": {
|
|
527
|
+
const frame = this.#stack.at(-1);
|
|
528
|
+
if (frame !== void 0 && !Array.isArray(frame.container) && frame.phase === "colon") frame.phase = "value";
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
case ",": {
|
|
532
|
+
const frame = this.#stack.at(-1);
|
|
533
|
+
if (frame !== void 0) frame.phase = Array.isArray(frame.container) ? "value" : "key";
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
default:
|
|
537
|
+
this.#scalar = char;
|
|
538
|
+
this.#scalarSlot = this.#valueSlot();
|
|
539
|
+
if (this.#scalarSlot !== void 0) this.#dirty = true;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
/** Where a value starting now goes, or `undefined` when this position takes no value. */
|
|
543
|
+
#valueSlot() {
|
|
544
|
+
const frame = this.#stack.at(-1);
|
|
545
|
+
if (frame === void 0) return this.#root === void 0 ? ROOT_SLOT : void 0;
|
|
546
|
+
if (Array.isArray(frame.container)) return {
|
|
547
|
+
kind: "element",
|
|
548
|
+
index: frame.container.length
|
|
549
|
+
};
|
|
550
|
+
if ((frame.phase === "value" || frame.phase === "colon") && frame.key !== void 0) return {
|
|
551
|
+
kind: "member",
|
|
552
|
+
key: frame.key
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
#startString() {
|
|
556
|
+
const frame = this.#stack.at(-1);
|
|
557
|
+
if (frame !== void 0 && !Array.isArray(frame.container) && (frame.phase === "key" || frame.phase === "comma")) {
|
|
558
|
+
this.#string = {
|
|
559
|
+
target: "key",
|
|
560
|
+
slot: void 0,
|
|
561
|
+
text: "",
|
|
562
|
+
escape: "",
|
|
563
|
+
path: void 0,
|
|
564
|
+
change: void 0
|
|
565
|
+
};
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const slot = this.#valueSlot();
|
|
569
|
+
const path = this.#reportedPath(slot);
|
|
570
|
+
this.#string = {
|
|
571
|
+
target: "value",
|
|
572
|
+
slot,
|
|
573
|
+
text: "",
|
|
574
|
+
escape: "",
|
|
575
|
+
path,
|
|
576
|
+
change: void 0
|
|
577
|
+
};
|
|
578
|
+
this.#place(slot, "");
|
|
579
|
+
if (path !== void 0) this.#string.change = this.#report({
|
|
580
|
+
kind: "set",
|
|
581
|
+
path,
|
|
582
|
+
value: ""
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
/** The path of a value at `slot` in the innermost open container, when its changes are reported. */
|
|
586
|
+
#reportedPath(slot) {
|
|
587
|
+
if (slot === void 0) return void 0;
|
|
588
|
+
if (slot.kind === "root") return [];
|
|
589
|
+
const frame = this.#stack.at(-1);
|
|
590
|
+
if (!frame.reportsInside) return void 0;
|
|
591
|
+
return [...frame.path, slot.kind === "member" ? slot.key : slot.index];
|
|
592
|
+
}
|
|
593
|
+
#report(change) {
|
|
594
|
+
this.#changes.push(change);
|
|
595
|
+
return change;
|
|
596
|
+
}
|
|
597
|
+
/** Continue an escape with `char`; returns false when `char` is not part of it and must be read normally. */
|
|
598
|
+
#continueEscape(open, char) {
|
|
599
|
+
if (open.escape === "\\") {
|
|
600
|
+
const decoded = SIMPLE_ESCAPES[char];
|
|
601
|
+
if (decoded !== void 0) {
|
|
602
|
+
open.escape = "";
|
|
603
|
+
this.#appendString(open, decoded);
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
if (char === "u") {
|
|
607
|
+
open.escape = "\\u";
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
open.escape = "";
|
|
611
|
+
this.#appendString(open, "\\");
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
if (isHexDigit(char)) {
|
|
615
|
+
open.escape += char;
|
|
616
|
+
if (open.escape.length < 6) return true;
|
|
617
|
+
const decoded = String.fromCharCode(Number.parseInt(open.escape.slice(2), 16));
|
|
618
|
+
open.escape = "";
|
|
619
|
+
this.#appendString(open, decoded);
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
const literal = open.escape;
|
|
623
|
+
open.escape = "";
|
|
624
|
+
this.#appendString(open, literal);
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
#appendString(open, text) {
|
|
628
|
+
open.text += text;
|
|
629
|
+
if (open.target !== "value") return;
|
|
630
|
+
this.#place(open.slot, open.text);
|
|
631
|
+
if (open.path === void 0) return;
|
|
632
|
+
const change = open.change;
|
|
633
|
+
if (change !== void 0 && this.#changes.at(-1) === change) {
|
|
634
|
+
if (change.kind === "set") change.value = change.value + text;
|
|
635
|
+
else change.text += text;
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
open.change = this.#report({
|
|
639
|
+
kind: "append",
|
|
640
|
+
path: open.path,
|
|
641
|
+
text
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
#endString(open) {
|
|
645
|
+
this.#string = void 0;
|
|
646
|
+
const frame = this.#stack.at(-1);
|
|
647
|
+
if (open.target === "key") {
|
|
648
|
+
if (frame === void 0) return;
|
|
649
|
+
frame.key = open.text;
|
|
650
|
+
frame.phase = "colon";
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
this.#valueEnded(frame);
|
|
654
|
+
}
|
|
655
|
+
#endScalar() {
|
|
656
|
+
const token = this.#scalar;
|
|
657
|
+
const slot = this.#scalarSlot;
|
|
658
|
+
this.#scalar = "";
|
|
659
|
+
this.#scalarSlot = void 0;
|
|
660
|
+
const value = scalarValue(token);
|
|
661
|
+
if (value !== void 0) {
|
|
662
|
+
this.#place(slot, value);
|
|
663
|
+
const path = this.#reportedPath(slot);
|
|
664
|
+
if (path !== void 0) this.#report({
|
|
665
|
+
kind: "set",
|
|
666
|
+
path,
|
|
667
|
+
value
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
this.#valueEnded(this.#stack.at(-1));
|
|
671
|
+
}
|
|
672
|
+
/** The value of the unterminated scalar at the end of the text, if it shows. */
|
|
673
|
+
#pendingScalar() {
|
|
674
|
+
const slot = this.#scalarSlot;
|
|
675
|
+
const token = this.#scalar;
|
|
676
|
+
if (slot === void 0 || token === "" || token.length > MAX_PENDING_SCALAR_LENGTH) return void 0;
|
|
677
|
+
const value = pendingScalarValue(token);
|
|
678
|
+
return value === void 0 ? void 0 : {
|
|
679
|
+
slot,
|
|
680
|
+
value
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
#openContainer(container) {
|
|
684
|
+
const slot = this.#valueSlot();
|
|
685
|
+
const path = this.#reportedPath(slot);
|
|
686
|
+
this.#place(slot, container);
|
|
687
|
+
this.#stack.push({
|
|
688
|
+
container,
|
|
689
|
+
slot,
|
|
690
|
+
path,
|
|
691
|
+
reportsInside: path !== void 0 && path.length < MAX_REPORTED_DEPTH,
|
|
692
|
+
size: 0,
|
|
693
|
+
key: void 0,
|
|
694
|
+
phase: Array.isArray(container) ? "value" : "key"
|
|
695
|
+
});
|
|
696
|
+
this.#pathCost += 1;
|
|
697
|
+
this.#dirty = true;
|
|
698
|
+
if (path !== void 0) this.#report({
|
|
699
|
+
kind: "set",
|
|
700
|
+
path,
|
|
701
|
+
value: Array.isArray(container) ? [] : {}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
#closeContainer() {
|
|
705
|
+
const frame = this.#stack.pop();
|
|
706
|
+
if (frame === void 0) return;
|
|
707
|
+
this.#pathCost -= frame.size + 1;
|
|
708
|
+
this.#dirty = true;
|
|
709
|
+
if (frame.path !== void 0 && !frame.reportsInside) this.#report({
|
|
710
|
+
kind: "set",
|
|
711
|
+
path: frame.path,
|
|
712
|
+
value: frame.container
|
|
713
|
+
});
|
|
714
|
+
this.#valueEnded(this.#stack.at(-1));
|
|
715
|
+
}
|
|
716
|
+
/** A value in `frame`, or the root value when there is no frame, has ended. */
|
|
717
|
+
#valueEnded(frame) {
|
|
718
|
+
if (frame === void 0) {
|
|
719
|
+
if (this.#root !== void 0) this.#done = true;
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
frame.phase = "comma";
|
|
723
|
+
}
|
|
724
|
+
/** Set the value at `slot` in the open path; nothing for a value in an invalid position. */
|
|
725
|
+
#place(slot, value) {
|
|
726
|
+
if (slot === void 0) return;
|
|
727
|
+
this.#dirty = true;
|
|
728
|
+
if (slot.kind === "root") {
|
|
729
|
+
this.#root = value;
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
const frame = this.#stack.at(-1);
|
|
733
|
+
if (slot.kind === "element") {
|
|
734
|
+
const elements = frame.container;
|
|
735
|
+
if (slot.index === elements.length) {
|
|
736
|
+
frame.size++;
|
|
737
|
+
this.#pathCost++;
|
|
738
|
+
}
|
|
739
|
+
elements[slot.index] = value;
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const members = frame.container;
|
|
743
|
+
if (!Object.hasOwn(members, slot.key)) {
|
|
744
|
+
frame.size++;
|
|
745
|
+
this.#pathCost++;
|
|
746
|
+
}
|
|
747
|
+
setMember(members, slot.key, value);
|
|
748
|
+
}
|
|
749
|
+
/** A fresh snapshot: copies of the open containers, innermost first, each holding the copy of its open child. */
|
|
750
|
+
#copyOpenPath(pending) {
|
|
751
|
+
if (this.#stack.length === 0) return pending?.slot.kind === "root" ? pending.value : this.#root;
|
|
752
|
+
let child;
|
|
753
|
+
let childSlot;
|
|
754
|
+
for (let depth = this.#stack.length - 1; depth >= 0; depth--) {
|
|
755
|
+
const frame = this.#stack[depth];
|
|
756
|
+
const copy = Array.isArray(frame.container) ? frame.container.slice() : { ...frame.container };
|
|
757
|
+
if (depth === this.#stack.length - 1 && pending !== void 0) setSlot(copy, pending.slot, pending.value);
|
|
758
|
+
if (child !== void 0 && childSlot !== void 0) setSlot(copy, childSlot, child);
|
|
759
|
+
child = copy;
|
|
760
|
+
childSlot = frame.slot;
|
|
761
|
+
}
|
|
762
|
+
return childSlot?.kind === "root" ? child : this.#root;
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
/**
|
|
766
|
+
* The arguments of one streaming tool call: the raw text, for the one full parse when the call ends, and a
|
|
767
|
+
* `StreamingJsonParser` for the partial arguments in between. Providers keep one per call in their own stream state,
|
|
768
|
+
* never on the content block, so the raw text never reaches partial messages or transcripts.
|
|
769
|
+
*/
|
|
770
|
+
var ToolCallArgumentsStream = class {
|
|
771
|
+
#text = "";
|
|
772
|
+
#parser = new StreamingJsonParser();
|
|
773
|
+
#snapshot = void 0;
|
|
774
|
+
#arguments = {};
|
|
775
|
+
/** The raw argument text received so far. */
|
|
776
|
+
get text() {
|
|
777
|
+
return this.#text;
|
|
778
|
+
}
|
|
779
|
+
/** Append a piece of argument text; returns the partial arguments, a new object whenever they changed. */
|
|
780
|
+
append(delta) {
|
|
781
|
+
this.#text += delta;
|
|
782
|
+
this.#parser.append(delta);
|
|
783
|
+
return this.#partial();
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Take the provider's complete argument text. When it continues the text so far, returns the missing piece as
|
|
787
|
+
* `delta`; otherwise starts over with `text`. Either way returns the partial arguments of `text`.
|
|
788
|
+
*/
|
|
789
|
+
replace(text) {
|
|
790
|
+
if (text.startsWith(this.#text)) {
|
|
791
|
+
const delta = text.slice(this.#text.length);
|
|
792
|
+
return {
|
|
793
|
+
delta,
|
|
794
|
+
arguments: delta === "" ? this.#partial() : this.append(delta)
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
this.#text = "";
|
|
798
|
+
this.#parser = new StreamingJsonParser();
|
|
799
|
+
return {
|
|
800
|
+
delta: void 0,
|
|
801
|
+
arguments: this.append(text)
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/** The final arguments: one full parse of the complete text, which reports malformed arguments. */
|
|
805
|
+
finish() {
|
|
806
|
+
return parseToolCallArguments(this.#text);
|
|
807
|
+
}
|
|
808
|
+
#partial() {
|
|
809
|
+
const snapshot = this.#parser.snapshot();
|
|
810
|
+
if (snapshot === this.#snapshot) return this.#arguments;
|
|
811
|
+
this.#snapshot = snapshot;
|
|
812
|
+
this.#arguments = typeof snapshot === "object" && snapshot !== null && !Array.isArray(snapshot) ? snapshot : {};
|
|
813
|
+
return this.#arguments;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
const SIMPLE_ESCAPES = {
|
|
817
|
+
"\"": "\"",
|
|
818
|
+
"\\": "\\",
|
|
819
|
+
"/": "/",
|
|
820
|
+
b: "\b",
|
|
821
|
+
f: "\f",
|
|
822
|
+
n: "\n",
|
|
823
|
+
r: "\r",
|
|
824
|
+
t: " "
|
|
825
|
+
};
|
|
826
|
+
function isDelimiter(char) {
|
|
827
|
+
return char === " " || char === " " || char === "\n" || char === "\r" || char === "," || char === ":" || char === "{" || char === "}" || char === "[" || char === "]" || char === "\"";
|
|
828
|
+
}
|
|
829
|
+
function isHexDigit(char) {
|
|
830
|
+
return char >= "0" && char <= "9" || char >= "a" && char <= "f" || char >= "A" && char <= "F";
|
|
831
|
+
}
|
|
832
|
+
/** The value of a complete number or literal token; `undefined` for anything else, which is dropped. */
|
|
833
|
+
function scalarValue(token) {
|
|
834
|
+
for (const [literal, value] of LITERALS) if (token === literal) return value;
|
|
835
|
+
return NUMBER.test(token) ? Number(token) : void 0;
|
|
836
|
+
}
|
|
837
|
+
/** The value an unterminated number or literal token shows. */
|
|
838
|
+
function pendingScalarValue(token) {
|
|
839
|
+
for (const [literal, value] of LITERALS) if (literal.startsWith(token)) return value;
|
|
840
|
+
if (NUMBER.test(token)) return Number(token);
|
|
841
|
+
const mantissa = NUMBER_WITHOUT_EXPONENT_DIGITS.exec(token);
|
|
842
|
+
return mantissa === null ? void 0 : Number(mantissa[1]);
|
|
843
|
+
}
|
|
844
|
+
function setSlot(container, slot, value) {
|
|
845
|
+
if (slot.kind === "element") container[slot.index] = value;
|
|
846
|
+
else if (slot.kind === "member") setMember(container, slot.key, value);
|
|
847
|
+
}
|
|
848
|
+
function setMember(members, key, value) {
|
|
849
|
+
if (key === "__proto__") Object.defineProperty(members, key, {
|
|
850
|
+
value,
|
|
851
|
+
writable: true,
|
|
852
|
+
enumerable: true,
|
|
853
|
+
configurable: true
|
|
854
|
+
});
|
|
855
|
+
else members[key] = value;
|
|
856
|
+
}
|
|
857
|
+
//#endregion
|
|
858
|
+
export { ToolCallArgumentsStream as n, parseJsonWithRepair as r, StreamingJsonParser as t };
|