@agimon-ai/po-cloudflare 0.0.2-alpha.2 → 0.0.2-alpha.21
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-2GUraIGq.js +34 -0
- package/dist/agent-DZ-OKOHn.js +6850 -0
- package/dist/anthropic-messages-5ODquUB-.js +14317 -0
- package/dist/{apiContracts-CHOiCbS_.js → apiContracts-b33nSAAI.js} +18 -81
- package/dist/{approval-BMXqnTYd.js → approval-r3NnI1VC.js} +19 -3
- package/dist/{approvalPrompt-Bg1JrEEY.js → approvalPrompt-DWoXxu3S.js} +2 -2
- package/dist/artifactFiles-DLCReI0-.js +1 -0
- package/dist/assets/assets/{CodeEditorView-BnyZHaYM.js → CodeEditorView-XeNS0L9M.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-muME0eCj.js → abnfDiagram-WEYOIA3C-B6ZW0nkR.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-DMnhK1WH.js → architecture-WOLXFQ4H-bVR64sHO.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DKn7XGP7.js → architectureDiagram-ZHVYKT53-D7tZz3io.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-DtDctXZg.js → blockDiagram-RJAE7QA3-DdwScfiX.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-23pGLJeP.js → c4Diagram-XDPPPE54-DgSxZJCV.js} +2 -2
- package/dist/assets/assets/channel-TPcVvp_3.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-BZ2nGNPa.js → chunk-2E7WHVMD-D5TXC2SM.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-Dui1SYFi.js → chunk-4EMNKR2T-BWhOSvo1.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-CUB92Evl.js → chunk-55XCU76K-HkkBzLtZ.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-CVayPHfE.js → chunk-7S6XSTFO-CBnjycLU.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB---wakYqY.js → chunk-AQDTSKZB-75lIIq8T.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-DfbdohUR.js → chunk-DSNLSHJZ-D8PpnXMk.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-Dr4KRh-b.js → chunk-HAGFOTED-CXRS2NIN.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-D06cR91Z.js → chunk-HNE4Q36P-BocUqS94.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-Ca4gLeDb.js → chunk-NQOKRVIF-CHf_ogYT.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-DmL638jN.js → chunk-UHW7PFBP-DrW1PaIv.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-pkxSW5Zj.js → chunk-VQ5W62QI-CLoA7bFm.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-Dcc8hV4U.js → chunk-WQQL4CDK-BmBsrj9I.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-iFE4Tl8c.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-B_HKcFrw.js → chunk-YZO67HFG-DShE_cgv.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-DAzZUysS.js → chunk-ZAUX2LTX-B3oLvSXy.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-DAVgjymL.js → chunk-ZCHMQSOR-B14vKK7C.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-Fsw8TGPu.js → classDiagram-v2-4MYWR3UA-Da8elIW2.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-CgUbISYV.js → cose-bilkent-JH36ORCC-Du4tGtiJ.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-D1LxAU2x.js → cynefin-EF2NZ3EQ-Cyj6i_WI.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-D54I1jil.js → cynefinDiagram-WF24UDRP-DFWXwO7A.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-DC7zL16U.js → dagre-NK4GIZVX-C1wB_cf-.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-DB0ptUdz.js → diagram-CBK3MWTC-MYCOBYl6.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-CozSftPJ.js → diagram-I5XIIV2D-BFYbKUFf.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-g3WOEWDS.js → diagram-ODIL2UCW-6siqTpv_.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-CFxGeOYi.js → diagram-PFBEJUXE-CaBr9CoB.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-BQBsLche.js → diagram-RJA3I4VV-DAvmuDpc.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-DrjpW2yq.js → diagram-TYUNFSNR-CJnhgCpo.js} +2 -2
- package/dist/assets/assets/{dist-DjL8d1jZ.js → dist-BQ4W1R18.js} +2 -2
- package/dist/assets/assets/{dist-DvgCCshF.js → dist-BnzFckPF.js} +2 -2
- package/dist/assets/assets/{dist-gfbb4ygy.js → dist-CFtBpcYL.js} +2 -2
- package/dist/assets/assets/{dist-BabjcJ3j.js → dist-CIQX1z4W.js} +2 -2
- package/dist/assets/assets/{dist-XIZum9n5.js → dist-ChHYoe9_.js} +2 -2
- package/dist/assets/assets/{dist-1-mhYUBH.js → dist-DKxZO8d9.js} +2 -2
- package/dist/assets/assets/{dist-h6SOnP8-.js → dist-DL6z28wl.js} +2 -2
- package/dist/assets/assets/{dist-B3JXhDWV.js → dist-DNyn1p9Z.js} +2 -2
- package/dist/assets/assets/{dist-Izr2SB3q.js → dist-qYlLXIa8.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-BZS_aAve.js → ebnfDiagram-V4P3TTPT-AUcqDTM3.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-B2ksVmMA.js → elk-QONTBCTQ-aA10PEHJ.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-7P6zF-Z-.js → erDiagram-KYQIGQAA-hhYiqA-x.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-RoGQoRq-.js → eventmodeling-K75KTNOO-BQZqbRo5.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-BuyysPYC.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-CTOlRy7M.js → ganttDiagram-R7GPNTJY-CLON1GpW.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-CPqytIt0.js → gitGraph-VSP46ZUC-DbmvNwR2.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-BffLxuxg.js → gitGraphDiagram-PDYL7XHY-DJVO0WlL.js} +2 -2
- package/dist/assets/assets/index-BiTVAj5E.js +155 -0
- package/dist/assets/assets/index-CBNQEGK3.css +1 -0
- package/dist/assets/assets/{info-OHQRW6UA-BI8RK0Ow.js → info-OHQRW6UA-CAt3Nt3g.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-DUIst1FB.js → infoDiagram-MVDRKAX5-DTuqH-Zb.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-CA17Eho5.js → ishikawaDiagram-HPEHV2GE-BnWvdonT.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CNri5Ap9.js → journeyDiagram-BOSHW7O7-Btxtcgvl.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-DnXna7jO.js → kanban-definition-FNSA4HC5-q7ek9o_H.js} +2 -2
- package/dist/assets/assets/{line-BsXJZn93.js → line-B7yLilmC.js} +2 -2
- package/dist/assets/assets/{linear-BHYaD5T0.js → linear-y8aSKEli.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-B64Eo-8a.js → mermaid-parser.core-B4rH50nD.js} +4 -4
- package/dist/assets/assets/{mermaid.core-Zw9qmTzg.js → mermaid.core-DnRVHTjE.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-E5qz4KNc.js → mindmap-definition-6OY57UG3-DT9Afs2v.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DgfizTr3.js → packet-JDAUHWVQ-CnqNbu4p.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-D0WK_agM.js → pegDiagram-ECIUJNBX-cvxdBBFq.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-PJR1sXD4.js → pie-XZMESJXO-etXMNsaL.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-CPuU-NTs.js → pieDiagram-GNMPY74T-CBN-R3_j.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-5C9yjM1b.js → quadrantDiagram-D57K4MC3-C5jjVPIH.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-BspdXgl0.js → radar-ABXABTNO-CAMd_mrV.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-Ct0a6hLD.js → railroad-I3PHUGI6-DIs3auoe.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-fduYB4SA.js → railroad-abnf-LNEFI6M7-CJXr1qWy.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-CTQa8Sww.js → railroad-ebnf-DWYD2UWJ-DfwtykqI.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-DatoH3GJ.js → railroad-peg-JR7BVNR7-B8beAhTs.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-C8sWN8l2.js → railroadDiagram-Y72NRBL7-BDcQE-EL.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-CqRz4RcT.js → requirementDiagram-EQYSW5RA-KJ4-QjZM.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-bdiuKKlX.js → sankeyDiagram-SY24JHO5-VjIB-Ybr.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-Zy-8I0Hy.js → sequenceDiagram-BLEHNHQU-MfMuWq1M.js} +2 -2
- package/dist/assets/assets/{src-gihY33R9.js → src-BAxIj8GJ.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-DXQERPvz.js → stateDiagram-v2-A6IESKWZ-mHwLRRCY.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-1gjZQElg.js → swimlanes-B3ENRKFQ-PArlYoqV.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-The09-5S.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-CTeYEw-9.js → timeline-definition-JXYKGLGB-B2nKiNFU.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-DD-EsLLT.js → treeView-D4JQ5SDB-gU23_RuI.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-BLdFeS5J.js → treemap-SAJKECNS-CiqoMvZa.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-C1GikSSP.js → usecaseDiagram-WPOLBNNX-DpeoWpMK.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-B1FoA3g8.js → vennDiagram-Q3Y3IDCW-C31iGKvM.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-BrHb5Bjf.js → wardley-7MLQ67FV-CIzHhzNw.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-CmPLD1X4.js → wardleyDiagram-IVAIDKWA-DIIkoezc.js} +2 -2
- package/dist/assets/assets/{webpack-BYWDFj_R.js → webpack-RFseiMZW.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-DR5pfEjl.js → xychartDiagram-4URNHDU4-QiHL91kC.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +2 -2
- package/dist/assets/plugins/assets/base-CKKRZ7-h.css +2 -0
- package/dist/assets/plugins/assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js +13 -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/assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs +110 -0
- package/dist/assets/plugins/assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-BJDT6Lbw.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -0
- package/dist/assets/plugins/slots/approval.293d9a00-BXIhaPlQ.js +2 -0
- package/dist/assets/plugins/slots/artifacts.24567664-ZzR0gbvy.js +1 -0
- package/dist/assets/plugins/slots/author.0998a880-DAbA-7rb.js +93 -0
- package/dist/assets/plugins/slots/autocompact.dd97d013-IVq4Z6qm.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.36d7400b-CpCLjRRN.js +7 -0
- package/dist/assets/plugins/slots/codemode.8eaee717-VWt9PqsU.js +10 -0
- package/dist/assets/plugins/slots/domain.5e95fc37-5PIUBqDe.js +1 -0
- package/dist/assets/plugins/slots/edit.385c9aa9-DNAjPNG5.js +7 -0
- package/dist/assets/plugins/slots/files.daf34ed8-CQaTz0i1.js +2 -0
- package/dist/assets/plugins/slots/goal.77ec9930-B8EkarBq.js +1 -0
- package/dist/assets/plugins/slots/grep.02052cdc-CIRhO2gY.js +1 -0
- package/dist/assets/plugins/slots/help.ecd4c0f9-naMF9NN1.js +3 -0
- package/dist/assets/plugins/slots/log.a86eb6d0-D5__rAZJ.js +4 -0
- package/dist/assets/plugins/slots/mcp.974af249-DPNHn9XH.js +109 -0
- package/dist/assets/plugins/slots/plan.bafb8f68-C5GEpybF.js +3 -0
- package/dist/assets/plugins/slots/profile.48851a1d-yX6tzV3x.js +1 -0
- package/dist/assets/plugins/slots/prompts.723d7748-B7zpPeoF.js +3 -0
- package/dist/assets/plugins/slots/read.46bf6536-Cw5Z5z5T.js +1 -0
- package/dist/assets/plugins/slots/runner.53e9bd76-CiQR_FPX.js +8 -0
- package/dist/assets/plugins/slots/skill.086701a4-CL6h_F-x.js +4 -0
- package/dist/assets/plugins/slots/vault.ac9935c8-DKERQYg4.js +1 -0
- package/dist/assets/plugins/slots/voice.e85ca7f9-DEgb-U9m.js +1 -0
- package/dist/assets/pwa/pwa.js +12 -12
- package/dist/assets/pwa/sw.js +4 -4
- package/dist/{atomicJson-BJfPFSYF.js → atomicJson-C_7F2zD1.js} +2 -3
- package/dist/azure-openai-config-COZUaRzM.js +55 -0
- package/dist/azure-openai-responses-Cs4k2HOd.js +183 -0
- package/dist/{backgroundWork-CeFrbRnj.js → backgroundWork-B1mPDYlf.js} +1 -1
- package/dist/browser-BWf8OMfl.js +3 -0
- package/dist/childSession-Cf2-kH4O.js +22 -0
- package/dist/classifier-shared-IhSH9hhh.js +106 -0
- package/dist/cloudflare-workers-ai-system-one-BNnc8MuH.js +52 -0
- package/dist/{codemode-DbPu0yJN.js → codemode-DQFmrosw.js} +5 -2
- package/dist/contracts-DD3f1Lpn.js +19 -0
- package/dist/diagnostics-1lYFeSJe.js +131 -0
- package/dist/{server-D3PQk1Gt.js → dist-B-vqs6tA.js} +1 -546
- package/dist/dist-Dvx5mlIR.js +50 -0
- package/dist/env-api-keys-Bow6MJe2.js +32 -0
- package/dist/error-body-CJk7jMUh.js +102 -0
- package/dist/esm-BKJy3O9-.js +1553 -0
- package/dist/exports-B0WMEXCP.js +34 -0
- package/dist/{remoteMcp-CMqZldeA.js → exports-D09VsUk-.js} +1153 -175
- package/dist/{exports-BNZz2DNU.js → exports-nV43ShA7.js} +25 -9
- package/dist/{extensionFile-CXOa5G4C.js → extensionFile-DNM4xsje.js} +26 -2
- package/dist/github-copilot-headers-D1RedfLn.js +22 -0
- package/dist/google-generative-ai-DXTILNT0.js +328 -0
- package/dist/google-shared-e4JDCTVP.js +19588 -0
- package/dist/google-vertex-a1lzvJfq.js +374 -0
- package/dist/{domains-BNjGTOPj.js → harnessState-Dwrk3lfv.js} +175 -16
- package/dist/{harnessStore-BT706Ly6.js → harnessStore-Z7yDLO45.js} +4 -5
- package/dist/hash-Dt6RIbkn.js +16 -0
- package/dist/headers-CwtEVQvr.js +17 -0
- package/dist/help-w6vVEZGL.js +101 -0
- package/dist/hubChannel-Cm-sxOvU.js +21 -0
- package/dist/hubRevisions-58pU2dW5.js +363 -0
- package/dist/identity-BgfHobJH.js +165 -0
- package/dist/index.edge-COJJ_Dv2.js +937 -0
- package/dist/index.edge-ChYa2LU4.js +14 -0
- package/dist/index.edge-ClLTmPFz.js +191 -0
- package/dist/index.edge-DyYmurS7.js +62 -0
- package/dist/index.edge-K0w5auwG.js +56 -0
- package/dist/index.edge-Xa5LLtxz.js +67 -0
- package/dist/iso-BPQViXM8.js +10 -0
- package/dist/{layeredConfig-DPQAnlXD.js → layeredConfig-CUkYUs1f.js} +193 -15
- package/dist/{majorModes-DbCfLZH3.js → majorModes-BB0PXgFn.js} +4 -14
- package/dist/majorModes-C7vtBs4D.js +1 -0
- package/dist/{mcpProjection-BsP0IEnb.js → mcpProjection-BtKzB6oK.js} +2 -2
- package/dist/migrations-5gbLIQIc.js +32 -0
- package/dist/mistral-conversations-CLwhVDjA.js +689 -0
- package/dist/modeDefinition-C3Zbrw48.js +44 -0
- package/dist/models-Chzm15vC.js +1511 -0
- package/dist/narration-CpRurWLO.js +127 -0
- package/dist/node-BT4GsJQp.js +2479 -0
- package/dist/node-DytJOfYf.js +23 -0
- package/dist/notification-kckG3leF.js +102 -0
- package/dist/openai-codex-responses-DRMONxDE.js +1210 -0
- package/dist/openai-completions-CcNhAv8l.js +984 -0
- package/dist/openai-decisions-BsFjaAGw.js +142 -0
- package/dist/openai-kPrtlgjl.js +17357 -0
- package/dist/openai-prompt-cache-Bc6qNWt0.js +8 -0
- package/dist/openai-responses-C5Gp2UOV.js +281 -0
- package/dist/openai-responses-shared-BbSi-wBR.js +661 -0
- package/dist/openrouter-cost-CvC52g3b.js +30 -0
- package/dist/openrouter-images-BoHl8g8p.js +124 -0
- package/dist/{hubChannel-BHQyzcOo.js → packageApi-t1oCjNDU.js} +4 -41
- package/dist/photon_rs_bg.wasm +0 -0
- package/dist/pi-messages-BXfrZLC7.js +312 -0
- package/dist/piConfig-DQzlbPY4.js +126 -0
- package/dist/piSettings-Cf1QofNe.js +1 -0
- package/dist/platform-BIEiM4TG.js +113 -0
- package/dist/pluginContributions-Be9EnCAW.js +16 -0
- package/dist/pluginProtocol-BqXXyI4z.js +80 -0
- package/dist/{protocol-Xpm_mCNN.js → protocol-DDL8geoS.js} +2 -2
- package/dist/provider-env-CxhHUFiF.js +38 -0
- package/dist/provider-retry-BUoezuw8.js +79 -0
- package/dist/sanitize-unicode-C3Ec8oL6.js +26 -0
- package/dist/sealedChannel-BeWNTWys.js +27 -0
- package/dist/server-AbXyhXlY.js +217 -0
- package/dist/server-B6dqQoh2.js +1518 -0
- package/dist/server-BIHo9TFu.js +505 -0
- package/dist/{server-BZh1ZXz_.js → server-BJ7DNzCp.js} +8 -19
- package/dist/server-BO-j_GbD.js +15106 -0
- package/dist/{server-D4W7EdJY.js → server-BQzAiMns.js} +16 -16
- package/dist/server-BR7SZtj7.js +3125 -0
- package/dist/{server-BE6VqEiA.js → server-BT2ORK83.js} +20 -12
- package/dist/server-BbSHYRnY.js +295 -0
- package/dist/server-BqoKlEGk.js +1806 -0
- package/dist/{server-tvgQ99rv.js → server-Busl0pQI.js} +370 -120
- package/dist/server-CIHM4jqu.js +1116 -0
- package/dist/server-CgWSSdvd.js +576 -0
- package/dist/{server-Dpgh8PDh.js → server-Co_UWKrR.js} +14 -5
- package/dist/{server-BAAL9-NA.js → server-CuEPb7u-.js} +3 -10
- package/dist/{server-Dt4y1rZD.js → server-D40q2Jpx.js} +47 -27
- package/dist/server-DCyf2Asb.js +679 -0
- package/dist/server-DH7PfLln.js +148 -0
- package/dist/server-DJ8bc89M.js +934 -0
- package/dist/server-DYdp0W9v.js +489 -0
- package/dist/server-DsdPEYGu.js +639 -0
- package/dist/server-DymH4Ucq.js +189 -0
- package/dist/server-IqECnUrb.js +834 -0
- package/dist/{server-36iuA3MI.js → server-KBgW77zh.js} +3 -3
- package/dist/server-RW_9R3R3.js +1522 -0
- package/dist/server-aUit8j6r.js +1028 -0
- package/dist/{server-DJAanjoI.js → server-gifRriZK.js} +491 -103
- package/dist/server-nkUlqnAL.js +2658 -0
- package/dist/server-oxyEbv1a.js +1256 -0
- package/dist/{server-D8ndq0wL.js → server-ub3s16Mc.js} +11 -9
- package/dist/{build-2gFaVEfG.js → serverPlugin-CELT6P0Q.js} +3946 -3
- package/dist/{sessionConfig-rBQgzXlT.js → sessionConfig-RQGvfm6E.js} +550 -760
- package/dist/simple-options-CFzI5Pd_.js +156 -0
- package/dist/streaming-json-BWTHTwz-.js +858 -0
- package/dist/system-one-shared-CiIrx29d.js +132 -0
- package/dist/{notification-D76PSL7r.js → telemetry-Csv1ZxAn.js} +1 -92
- package/dist/transform-messages-D77af7Bx.js +356 -0
- package/dist/truncate-M3KbFyVj.js +89 -0
- package/dist/{server-A-_GFpPr.js → type-ASYnCGVW.js} +10 -1031
- package/dist/typesafe-system-one-DGxeggJh.js +37 -0
- package/dist/uuid-B0QJx6Kr.js +31 -0
- package/dist/{validation-D77NZBrx.js → validation-BJxVSAwx.js} +8 -3
- package/dist/{value-Djvc2foV.js → value-_W31So3B.js} +1 -1
- package/dist/vaultSettings-Di3n5YIg.js +328 -0
- package/dist/voiceTools-RMn4HvWo.js +246 -0
- package/dist/web-DCP7ELJj.js +3 -0
- package/dist/worker.js +95288 -49863
- package/dist/workflow-B7qx0Vv9.js +79 -0
- package/package.json +37 -22
- package/wrangler.jsonc +4 -2
- 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/index-DZM68mTk.css +0 -1
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-q91tR8ri.js +0 -9
- package/dist/contextProjection-DVP2Vc5j.js +0 -188
- package/dist/harnessState-gmzJcPGt.js +0 -88
- package/dist/harnessStore-BiH9vSuD.js +0 -1
- package/dist/index.edge-BgSx_gRO.js +0 -45
- package/dist/majorModes-BvWNqoHt.js +0 -1
- package/dist/piSettings-B6fsgIBA.js +0 -1
- package/dist/platform-B4AAgwJ0.js +0 -16
- package/dist/platformFiles-C_bXo4Ig.js +0 -39
- package/dist/server-BZaPPoQp.js +0 -592
- package/dist/server-D75MWDhB.js +0 -118
- package/dist/server-r358hzQg.js +0 -280
- package/dist/serverPlugin-BOI6c6s5.js +0 -3393
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
import { h as getDeclaredTools, n as clampThinkingLevel, t as calculateCost, v as resolveTranscript, y as resolveTranscriptTools } from "./models-Chzm15vC.js";
|
|
2
|
+
import { l as renderSystemMessageUpdate, n as getIdentityHeaders, s as getSystemMessageText } from "./identity-BgfHobJH.js";
|
|
3
|
+
import { a as resolveSamplingParams, i as clampThinkingBudgetToAnswerRoom, n as buildBaseOptions, o as thinkingBudgetForLevel } from "./simple-options-CFzI5Pd_.js";
|
|
4
|
+
import { n as ToolCallArgumentsStream } from "./streaming-json-BWTHTwz-.js";
|
|
5
|
+
import { i as AssistantMessageEventStream } from "./diagnostics-1lYFeSJe.js";
|
|
6
|
+
import { t as getProviderEnvValue } from "./provider-env-CxhHUFiF.js";
|
|
7
|
+
import { t as headersToRecord } from "./headers-CwtEVQvr.js";
|
|
8
|
+
import { n as isOpenRouterModel, t as applyOpenRouterReportedCost } from "./openrouter-cost-CvC52g3b.js";
|
|
9
|
+
import { t as retryProviderRequest } from "./provider-retry-BUoezuw8.js";
|
|
10
|
+
import { t as sanitizeSurrogates } from "./sanitize-unicode-C3Ec8oL6.js";
|
|
11
|
+
import { a as createGrammarToolInputProperties, d as resolveJsonSchemaStrictSampling, i as closeGrammarToolInputJson, n as transformMessages, o as getGrammarToolInput, r as appendGrammarToolInputJsonDelta, s as getJsonSchemaToolParameters, u as resolveGrammarConstrainedSampling } from "./transform-messages-D77af7Bx.js";
|
|
12
|
+
import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-D1RedfLn.js";
|
|
13
|
+
import { n as OpenAI } from "./openai-kPrtlgjl.js";
|
|
14
|
+
import { n as normalizeProviderError, t as formatProviderError } from "./error-body-CJk7jMUh.js";
|
|
15
|
+
import { t as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-Bc6qNWt0.js";
|
|
16
|
+
import { t as shortHash } from "./hash-Dt6RIbkn.js";
|
|
17
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-ai@1.5.0_@aws-sdk+credential-provider-node@3.972.86_@modelcontextpro_018b33d3c6d4455b3921fdf11f2d0b63/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js
|
|
18
|
+
/**
|
|
19
|
+
* Check if conversation messages contain tool calls or tool results.
|
|
20
|
+
* This is needed because Anthropic (via proxy) requires the tools param
|
|
21
|
+
* to be present when messages include tool_calls or tool role messages.
|
|
22
|
+
*/
|
|
23
|
+
function hasHeader(headers, name) {
|
|
24
|
+
if (!headers) return false;
|
|
25
|
+
const expected = name.toLowerCase();
|
|
26
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === expected && value !== null && value.trim().length > 0) return true;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function getClientApiKey(provider, apiKey, headers) {
|
|
30
|
+
if (apiKey) return apiKey;
|
|
31
|
+
if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization")) return "unused";
|
|
32
|
+
throw new Error(`No API key for provider: ${provider}`);
|
|
33
|
+
}
|
|
34
|
+
function hasToolHistory(messages) {
|
|
35
|
+
for (const msg of messages) {
|
|
36
|
+
if (msg.role === "toolResult") return true;
|
|
37
|
+
if (msg.role === "assistant") {
|
|
38
|
+
if (msg.content.some((block) => block.type === "toolCall")) return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function isTextContentBlock(block) {
|
|
44
|
+
return block.type === "text";
|
|
45
|
+
}
|
|
46
|
+
function isThinkingContentBlock(block) {
|
|
47
|
+
return block.type === "thinking";
|
|
48
|
+
}
|
|
49
|
+
function isToolCallBlock(block) {
|
|
50
|
+
return block.type === "toolCall";
|
|
51
|
+
}
|
|
52
|
+
function isImageContentBlock(block) {
|
|
53
|
+
return block.type === "image";
|
|
54
|
+
}
|
|
55
|
+
function isReasoningDetailObject(detail) {
|
|
56
|
+
return typeof detail === "object" && detail !== null && !Array.isArray(detail);
|
|
57
|
+
}
|
|
58
|
+
function hasValidCommonReasoningDetailFields(candidate) {
|
|
59
|
+
return (candidate.id === void 0 || candidate.id === null || typeof candidate.id === "string") && (candidate.format === void 0 || typeof candidate.format === "string") && (candidate.index === void 0 || typeof candidate.index === "number");
|
|
60
|
+
}
|
|
61
|
+
function isOpenAIReasoningDetail(detail) {
|
|
62
|
+
if (!isReasoningDetailObject(detail) || !hasValidCommonReasoningDetailFields(detail)) return false;
|
|
63
|
+
switch (detail.type) {
|
|
64
|
+
case "reasoning.summary": return typeof detail.summary === "string";
|
|
65
|
+
case "reasoning.encrypted": return typeof detail.data === "string";
|
|
66
|
+
case "reasoning.text": return typeof detail.text === "string" && (detail.signature === void 0 || detail.signature === null || typeof detail.signature === "string");
|
|
67
|
+
default: return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function parseOpenAIReasoningDetails(signature) {
|
|
71
|
+
if (!signature) return void 0;
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(signature);
|
|
74
|
+
return Array.isArray(parsed) && parsed.length > 0 && parsed.every(isOpenAIReasoningDetail) ? parsed : void 0;
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function parseLegacyEncryptedReasoningDetail(signature) {
|
|
80
|
+
if (!signature) return void 0;
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(signature);
|
|
83
|
+
return isOpenAIReasoningDetail(parsed) && parsed.type === "reasoning.encrypted" && typeof parsed.id === "string" && parsed.id.length > 0 && parsed.data.length > 0 ? parsed : void 0;
|
|
84
|
+
} catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function fillMissingCommonReasoningDetailFields(target, source) {
|
|
89
|
+
target.id ??= source.id;
|
|
90
|
+
target.format ||= source.format;
|
|
91
|
+
target.index ??= source.index;
|
|
92
|
+
}
|
|
93
|
+
function appendOpenAIReasoningDetail(details, detail) {
|
|
94
|
+
const lastDetail = details[details.length - 1];
|
|
95
|
+
if (detail.type === "reasoning.text" && lastDetail?.type === "reasoning.text") {
|
|
96
|
+
lastDetail.text += detail.text;
|
|
97
|
+
lastDetail.signature ||= detail.signature;
|
|
98
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (detail.type === "reasoning.summary" && lastDetail?.type === "reasoning.summary") {
|
|
102
|
+
lastDetail.summary += detail.summary;
|
|
103
|
+
fillMissingCommonReasoningDetailFields(lastDetail, detail);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
details.push({ ...detail });
|
|
107
|
+
}
|
|
108
|
+
const OPENAI_COMPLETIONS_REASONING_FIELDS = [
|
|
109
|
+
"reasoning",
|
|
110
|
+
"reasoning_content",
|
|
111
|
+
"reasoning_text"
|
|
112
|
+
];
|
|
113
|
+
function isOpenAICompletionsReasoningField(field) {
|
|
114
|
+
return OPENAI_COMPLETIONS_REASONING_FIELDS.includes(field);
|
|
115
|
+
}
|
|
116
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
117
|
+
if (cacheRetention) return cacheRetention;
|
|
118
|
+
if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") return "long";
|
|
119
|
+
return "short";
|
|
120
|
+
}
|
|
121
|
+
const stream = (model, context, options) => {
|
|
122
|
+
const stream = new AssistantMessageEventStream();
|
|
123
|
+
const normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
|
|
124
|
+
(async () => {
|
|
125
|
+
const output = {
|
|
126
|
+
role: "assistant",
|
|
127
|
+
content: [],
|
|
128
|
+
api: model.api,
|
|
129
|
+
provider: model.provider,
|
|
130
|
+
model: model.id,
|
|
131
|
+
usage: {
|
|
132
|
+
input: 0,
|
|
133
|
+
output: 0,
|
|
134
|
+
cacheRead: 0,
|
|
135
|
+
cacheWrite: 0,
|
|
136
|
+
totalTokens: 0,
|
|
137
|
+
cost: {
|
|
138
|
+
input: 0,
|
|
139
|
+
output: 0,
|
|
140
|
+
cacheRead: 0,
|
|
141
|
+
cacheWrite: 0,
|
|
142
|
+
total: 0
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
stopReason: "pending",
|
|
146
|
+
timestamp: Date.now()
|
|
147
|
+
};
|
|
148
|
+
let streamedReasoningDetails;
|
|
149
|
+
const applyStreamedReasoningDetails = (block) => {
|
|
150
|
+
if (streamedReasoningDetails !== void 0) block.thinkingSignature = JSON.stringify(streamedReasoningDetails);
|
|
151
|
+
};
|
|
152
|
+
try {
|
|
153
|
+
const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
154
|
+
const compat = getCompat(model);
|
|
155
|
+
const grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(normalizedContext.messages), compat.supportsOpenAIGrammarTools);
|
|
156
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
157
|
+
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
158
|
+
const client = createClient(model, normalizedContext, apiKey, options?.headers, options?.identity, options?.fetch, cacheSessionId, compat);
|
|
159
|
+
let params = buildParams(model, normalizedContext, options, compat, cacheRetention, grammarToolInputProperties);
|
|
160
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
161
|
+
if (nextParams !== void 0) params = nextParams;
|
|
162
|
+
const requestOptions = {
|
|
163
|
+
...options?.signal ? { signal: options.signal } : {},
|
|
164
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
165
|
+
maxRetries: 0
|
|
166
|
+
};
|
|
167
|
+
const { data: openaiStream, response } = await retryProviderRequest(() => client.chat.completions.create(params, requestOptions).withResponse(), {
|
|
168
|
+
maxRetries: options?.maxRetries,
|
|
169
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
170
|
+
signal: options?.signal
|
|
171
|
+
});
|
|
172
|
+
await options?.onResponse?.({
|
|
173
|
+
status: response.status,
|
|
174
|
+
headers: headersToRecord(response.headers)
|
|
175
|
+
}, model);
|
|
176
|
+
stream.push({
|
|
177
|
+
type: "start",
|
|
178
|
+
partial: output
|
|
179
|
+
});
|
|
180
|
+
let textBlock = null;
|
|
181
|
+
let thinkingBlock = null;
|
|
182
|
+
let hasFinishReason = false;
|
|
183
|
+
const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
|
|
184
|
+
const toolCallBlocksById = /* @__PURE__ */ new Map();
|
|
185
|
+
const toolCallStates = /* @__PURE__ */ new Map();
|
|
186
|
+
const blocks = output.content;
|
|
187
|
+
const getContentIndex = (block) => blocks.indexOf(block);
|
|
188
|
+
const customInput = (property) => ({
|
|
189
|
+
kind: "custom",
|
|
190
|
+
property,
|
|
191
|
+
buffer: {
|
|
192
|
+
input: "",
|
|
193
|
+
started: false,
|
|
194
|
+
closed: false
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const finishBlock = (block) => {
|
|
198
|
+
const contentIndex = getContentIndex(block);
|
|
199
|
+
if (contentIndex === -1) return;
|
|
200
|
+
if (block.type === "text") stream.push({
|
|
201
|
+
type: "text_end",
|
|
202
|
+
contentIndex,
|
|
203
|
+
content: block.text,
|
|
204
|
+
partial: output
|
|
205
|
+
});
|
|
206
|
+
else if (block.type === "thinking") {
|
|
207
|
+
applyStreamedReasoningDetails(block);
|
|
208
|
+
stream.push({
|
|
209
|
+
type: "thinking_end",
|
|
210
|
+
contentIndex,
|
|
211
|
+
content: block.thinking,
|
|
212
|
+
partial: output
|
|
213
|
+
});
|
|
214
|
+
} else if (block.type === "toolCall") {
|
|
215
|
+
const input = toolCallStates.get(block).input;
|
|
216
|
+
toolCallStates.delete(block);
|
|
217
|
+
if (input.kind === "custom") {
|
|
218
|
+
const delta = closeGrammarToolInputJson(input.buffer, input.property, void 0);
|
|
219
|
+
if (delta !== void 0) stream.push({
|
|
220
|
+
type: "toolcall_delta",
|
|
221
|
+
contentIndex,
|
|
222
|
+
delta,
|
|
223
|
+
partial: output
|
|
224
|
+
});
|
|
225
|
+
} else Object.assign(block, input.arguments.finish());
|
|
226
|
+
stream.push({
|
|
227
|
+
type: "toolcall_end",
|
|
228
|
+
contentIndex,
|
|
229
|
+
toolCall: block,
|
|
230
|
+
partial: output
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const ensureTextBlock = () => {
|
|
235
|
+
if (!textBlock) {
|
|
236
|
+
textBlock = {
|
|
237
|
+
type: "text",
|
|
238
|
+
text: ""
|
|
239
|
+
};
|
|
240
|
+
blocks.push(textBlock);
|
|
241
|
+
stream.push({
|
|
242
|
+
type: "text_start",
|
|
243
|
+
contentIndex: getContentIndex(textBlock),
|
|
244
|
+
partial: output
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return textBlock;
|
|
248
|
+
};
|
|
249
|
+
const ensureThinkingBlock = (thinkingSignature) => {
|
|
250
|
+
if (!thinkingBlock) {
|
|
251
|
+
thinkingBlock = {
|
|
252
|
+
type: "thinking",
|
|
253
|
+
thinking: "",
|
|
254
|
+
thinkingSignature
|
|
255
|
+
};
|
|
256
|
+
blocks.push(thinkingBlock);
|
|
257
|
+
stream.push({
|
|
258
|
+
type: "thinking_start",
|
|
259
|
+
contentIndex: getContentIndex(thinkingBlock),
|
|
260
|
+
partial: output
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return thinkingBlock;
|
|
264
|
+
};
|
|
265
|
+
const ensureToolCallBlock = (toolCall) => {
|
|
266
|
+
const streamIndex = typeof toolCall.index === "number" ? toolCall.index : void 0;
|
|
267
|
+
const name = toolCall.function?.name ?? toolCall.custom?.name ?? "";
|
|
268
|
+
let block = streamIndex !== void 0 ? toolCallBlocksByIndex.get(streamIndex) : void 0;
|
|
269
|
+
if (!block && toolCall.id) block = toolCallBlocksById.get(toolCall.id);
|
|
270
|
+
if (!block) {
|
|
271
|
+
const customInputProperty = toolCall.custom && !toolCall.function ? grammarToolInputProperties.get(name) ?? "input" : void 0;
|
|
272
|
+
block = {
|
|
273
|
+
type: "toolCall",
|
|
274
|
+
id: toolCall.id || "",
|
|
275
|
+
name,
|
|
276
|
+
arguments: customInputProperty !== void 0 ? { [customInputProperty]: "" } : {}
|
|
277
|
+
};
|
|
278
|
+
toolCallStates.set(block, {
|
|
279
|
+
streamIndex,
|
|
280
|
+
input: customInputProperty !== void 0 ? customInput(customInputProperty) : {
|
|
281
|
+
kind: "json",
|
|
282
|
+
arguments: new ToolCallArgumentsStream()
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
if (streamIndex !== void 0) toolCallBlocksByIndex.set(streamIndex, block);
|
|
286
|
+
if (toolCall.id) toolCallBlocksById.set(toolCall.id, block);
|
|
287
|
+
blocks.push(block);
|
|
288
|
+
stream.push({
|
|
289
|
+
type: "toolcall_start",
|
|
290
|
+
contentIndex: getContentIndex(block),
|
|
291
|
+
partial: output
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
const state = toolCallStates.get(block);
|
|
295
|
+
if (streamIndex !== void 0 && state.streamIndex === void 0) {
|
|
296
|
+
state.streamIndex = streamIndex;
|
|
297
|
+
toolCallBlocksByIndex.set(streamIndex, block);
|
|
298
|
+
}
|
|
299
|
+
if (toolCall.id) toolCallBlocksById.set(toolCall.id, block);
|
|
300
|
+
if (!block.name && name) block.name = name;
|
|
301
|
+
if (toolCall.custom && !toolCall.function && state.input.kind !== "custom") {
|
|
302
|
+
const customInputProperty = grammarToolInputProperties.get(block.name) ?? "input";
|
|
303
|
+
block.arguments = { [customInputProperty]: "" };
|
|
304
|
+
state.input = customInput(customInputProperty);
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
block,
|
|
308
|
+
state
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
for await (const chunk of openaiStream) {
|
|
312
|
+
await options?.onProviderStreamEvent?.(chunk, model);
|
|
313
|
+
if (!chunk || typeof chunk !== "object") continue;
|
|
314
|
+
output.responseId ||= chunk.id;
|
|
315
|
+
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) output.responseModel ||= chunk.model;
|
|
316
|
+
if (chunk.usage) output.usage = parseChunkUsage(chunk.usage, model);
|
|
317
|
+
const choice = Array.isArray(chunk.choices) ? chunk.choices[0] : void 0;
|
|
318
|
+
if (!choice) continue;
|
|
319
|
+
if (!chunk.usage && choice.usage) output.usage = parseChunkUsage(choice.usage, model);
|
|
320
|
+
if (choice.finish_reason) {
|
|
321
|
+
output.rawStopReason = choice.finish_reason;
|
|
322
|
+
const finishReasonResult = mapStopReason(choice.finish_reason);
|
|
323
|
+
output.stopReason = finishReasonResult.stopReason;
|
|
324
|
+
if (finishReasonResult.errorMessage) output.errorMessage = finishReasonResult.errorMessage;
|
|
325
|
+
hasFinishReason = true;
|
|
326
|
+
}
|
|
327
|
+
if (choice.delta) {
|
|
328
|
+
const reasoningFields = [
|
|
329
|
+
"reasoning_content",
|
|
330
|
+
"reasoning",
|
|
331
|
+
"reasoning_text"
|
|
332
|
+
];
|
|
333
|
+
const deltaFields = choice.delta;
|
|
334
|
+
let foundReasoningField = null;
|
|
335
|
+
for (const field of reasoningFields) {
|
|
336
|
+
const value = deltaFields[field];
|
|
337
|
+
if (typeof value === "string" && value.length > 0) {
|
|
338
|
+
foundReasoningField = field;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (foundReasoningField) {
|
|
343
|
+
const delta = deltaFields[foundReasoningField];
|
|
344
|
+
if (typeof delta === "string" && delta.length > 0) {
|
|
345
|
+
const block = ensureThinkingBlock(model.provider === "opencode-go" && foundReasoningField === "reasoning" ? "reasoning_content" : foundReasoningField);
|
|
346
|
+
block.thinking += delta;
|
|
347
|
+
stream.push({
|
|
348
|
+
type: "thinking_delta",
|
|
349
|
+
contentIndex: getContentIndex(block),
|
|
350
|
+
delta,
|
|
351
|
+
partial: output
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const reasoningDetails = choice.delta.reasoning_details;
|
|
356
|
+
if (Array.isArray(reasoningDetails)) for (const detail of reasoningDetails) {
|
|
357
|
+
if (!isOpenAIReasoningDetail(detail)) continue;
|
|
358
|
+
ensureThinkingBlock("");
|
|
359
|
+
streamedReasoningDetails ??= [];
|
|
360
|
+
appendOpenAIReasoningDetail(streamedReasoningDetails, detail);
|
|
361
|
+
}
|
|
362
|
+
if (choice.delta.content !== null && choice.delta.content !== void 0 && choice.delta.content.length > 0) {
|
|
363
|
+
const block = ensureTextBlock();
|
|
364
|
+
block.text += choice.delta.content;
|
|
365
|
+
stream.push({
|
|
366
|
+
type: "text_delta",
|
|
367
|
+
contentIndex: getContentIndex(block),
|
|
368
|
+
delta: choice.delta.content,
|
|
369
|
+
partial: output
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
if (choice?.delta?.tool_calls) for (const toolCall of choice.delta.tool_calls) {
|
|
373
|
+
const { block, state } = ensureToolCallBlock(toolCall);
|
|
374
|
+
if (!block.id && toolCall.id) {
|
|
375
|
+
block.id = toolCall.id;
|
|
376
|
+
toolCallBlocksById.set(toolCall.id, block);
|
|
377
|
+
}
|
|
378
|
+
const name = toolCall.function?.name ?? toolCall.custom?.name;
|
|
379
|
+
if (!block.name && name) block.name = name;
|
|
380
|
+
let delta = "";
|
|
381
|
+
const input = state.input;
|
|
382
|
+
if (toolCall.function?.arguments && input.kind === "json") {
|
|
383
|
+
delta = toolCall.function.arguments;
|
|
384
|
+
block.arguments = input.arguments.append(delta);
|
|
385
|
+
} else if (toolCall.custom?.input && input.kind === "custom") {
|
|
386
|
+
delta = appendGrammarToolInputJsonDelta(input.buffer, input.property, toolCall.custom.input) ?? "";
|
|
387
|
+
block.arguments = { [input.property]: input.buffer.input };
|
|
388
|
+
}
|
|
389
|
+
stream.push({
|
|
390
|
+
type: "toolcall_delta",
|
|
391
|
+
contentIndex: getContentIndex(block),
|
|
392
|
+
delta,
|
|
393
|
+
partial: output
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
for (const block of blocks) finishBlock(block);
|
|
399
|
+
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
400
|
+
if (output.stopReason === "aborted") throw new Error("Request was aborted");
|
|
401
|
+
if (!hasFinishReason && !compat.supportsFinishReason) output.stopReason = output.content.some((block) => block.type === "toolCall") ? "toolUse" : "stop";
|
|
402
|
+
if (output.stopReason === "error") throw new Error(output.errorMessage || "Provider returned an error stop reason");
|
|
403
|
+
if (compat.supportsFinishReason && !hasFinishReason || output.stopReason === "pending") throw new Error("Stream ended without finish_reason");
|
|
404
|
+
stream.push({
|
|
405
|
+
type: "done",
|
|
406
|
+
reason: output.stopReason,
|
|
407
|
+
message: output
|
|
408
|
+
});
|
|
409
|
+
stream.end();
|
|
410
|
+
} catch (error) {
|
|
411
|
+
for (const block of output.content) if (block.type === "thinking") applyStreamedReasoningDetails(block);
|
|
412
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
413
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
414
|
+
const rawMetadata = error?.error?.metadata?.raw;
|
|
415
|
+
if (rawMetadata && !output.errorMessage.includes(String(rawMetadata))) output.errorMessage += `\n${rawMetadata}`;
|
|
416
|
+
stream.push({
|
|
417
|
+
type: "error",
|
|
418
|
+
reason: output.stopReason,
|
|
419
|
+
error: output
|
|
420
|
+
});
|
|
421
|
+
stream.end();
|
|
422
|
+
}
|
|
423
|
+
})();
|
|
424
|
+
return stream;
|
|
425
|
+
};
|
|
426
|
+
const streamSimple = (model, context, options) => {
|
|
427
|
+
getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
428
|
+
const base = {
|
|
429
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
430
|
+
toolChoice: options?.toolChoice
|
|
431
|
+
};
|
|
432
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
433
|
+
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
|
|
434
|
+
return stream(model, context, {
|
|
435
|
+
...base,
|
|
436
|
+
reasoningEffort,
|
|
437
|
+
thinkingBudgets: options?.thinkingBudgets
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
function createClient(model, context, apiKey, optionsHeaders, identity, fetch, sessionId, compat = getCompat(model)) {
|
|
441
|
+
const headers = {
|
|
442
|
+
...getIdentityHeaders(model, identity),
|
|
443
|
+
...model.headers
|
|
444
|
+
};
|
|
445
|
+
if (model.provider === "github-copilot") {
|
|
446
|
+
const hasImages = hasCopilotVisionInput(context.messages);
|
|
447
|
+
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
448
|
+
messages: context.messages,
|
|
449
|
+
hasImages
|
|
450
|
+
});
|
|
451
|
+
Object.assign(headers, copilotHeaders);
|
|
452
|
+
}
|
|
453
|
+
if (sessionId && compat.sendSessionAffinityHeaders) {
|
|
454
|
+
if (compat.sessionAffinityFormat === "openrouter") headers["x-session-id"] = sessionId;
|
|
455
|
+
else {
|
|
456
|
+
if (compat.sessionAffinityFormat === "openai") headers.session_id = sessionId;
|
|
457
|
+
headers["x-client-request-id"] = sessionId;
|
|
458
|
+
headers["x-session-affinity"] = sessionId;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
462
|
+
return new OpenAI({
|
|
463
|
+
apiKey,
|
|
464
|
+
baseURL: model.baseUrl,
|
|
465
|
+
dangerouslyAllowBrowser: true,
|
|
466
|
+
fetch,
|
|
467
|
+
defaultHeaders: headers
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
function buildParams(model, context, options, compat = getCompat(model), cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env), grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(context.messages), compat.supportsOpenAIGrammarTools)) {
|
|
471
|
+
const transcriptTools = resolveTranscriptTools(context.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true ? "additions" : "none");
|
|
472
|
+
const messages = convertMessages(model, context, compat, { grammarToolInputProperties });
|
|
473
|
+
const cacheControl = getCompatCacheControl(compat, cacheRetention);
|
|
474
|
+
const params = {
|
|
475
|
+
model: model.id,
|
|
476
|
+
messages,
|
|
477
|
+
stream: true,
|
|
478
|
+
prompt_cache_key: model.baseUrl.includes("api.openai.com") && cacheRetention !== "none" || cacheRetention === "long" && compat.supportsLongCacheRetention ? clampOpenAIPromptCacheKey(options?.sessionId) : void 0,
|
|
479
|
+
prompt_cache_retention: cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
|
|
480
|
+
};
|
|
481
|
+
if (compat.supportsUsageInStreaming !== false) params.stream_options = { include_usage: true };
|
|
482
|
+
if (compat.supportsStore) params.store = false;
|
|
483
|
+
if (options?.maxTokens) {
|
|
484
|
+
if (compat.maxTokensField === "max_tokens") params.max_tokens = options.maxTokens;
|
|
485
|
+
else params.max_completion_tokens = options.maxTokens;
|
|
486
|
+
}
|
|
487
|
+
if (options?.temperature !== void 0) params.temperature = options.temperature;
|
|
488
|
+
if (transcriptTools.requestTools.length > 0) {
|
|
489
|
+
params.tools = convertTools(transcriptTools.requestTools, compat);
|
|
490
|
+
if (compat.zaiToolStream) params.tool_stream = true;
|
|
491
|
+
} else if (hasToolHistory(context.messages)) params.tools = [];
|
|
492
|
+
if (cacheControl) applyAnthropicCacheControl(messages, params.tools, cacheControl);
|
|
493
|
+
if (options?.toolChoice) params.tool_choice = options.toolChoice;
|
|
494
|
+
if (compat.vllmPriority !== void 0) params.priority = compat.vllmPriority;
|
|
495
|
+
const thinkingTokenBudgetField = resolveThinkingTokenBudgetField(compat);
|
|
496
|
+
const thinkingBudget = resolveClampedThinkingBudget(model, options, params);
|
|
497
|
+
if (compat.thinkingFormat === "zai" && model.reasoning) {
|
|
498
|
+
const zaiParams = params;
|
|
499
|
+
zaiParams.thinking = options?.reasoningEffort ? {
|
|
500
|
+
type: "enabled",
|
|
501
|
+
clear_thinking: false
|
|
502
|
+
} : { type: "disabled" };
|
|
503
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) {
|
|
504
|
+
const mappedEffort = model.thinkingLevelMap?.[options.reasoningEffort];
|
|
505
|
+
const effort = mappedEffort === void 0 ? options.reasoningEffort : mappedEffort;
|
|
506
|
+
if (typeof effort === "string") zaiParams.reasoning_effort = effort;
|
|
507
|
+
}
|
|
508
|
+
} else if (compat.thinkingFormat === "qwen" && model.reasoning) {
|
|
509
|
+
params.enable_thinking = !!options?.reasoningEffort;
|
|
510
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) {
|
|
511
|
+
const effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
512
|
+
if (typeof effort === "string") params.reasoning_effort = effort;
|
|
513
|
+
}
|
|
514
|
+
} else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) params.chat_template_kwargs = {
|
|
515
|
+
enable_thinking: !!options?.reasoningEffort,
|
|
516
|
+
preserve_thinking: true
|
|
517
|
+
};
|
|
518
|
+
else if (compat.thinkingFormat === "chat-template" && model.reasoning) {
|
|
519
|
+
const chatTemplateKwargs = buildChatTemplateValues(model, options, compat.chatTemplateKwargs, thinkingBudget);
|
|
520
|
+
if (chatTemplateKwargs) params.chat_template_kwargs = chatTemplateKwargs;
|
|
521
|
+
} else if (compat.thinkingFormat === "baseten" && model.reasoning) {
|
|
522
|
+
const basetenParams = params;
|
|
523
|
+
const chatTemplateArgs = buildChatTemplateValues(model, options, compat.chatTemplateArgs, thinkingBudget);
|
|
524
|
+
if (chatTemplateArgs) basetenParams.chat_template_args = chatTemplateArgs;
|
|
525
|
+
if (compat.supportsReasoningEffort) {
|
|
526
|
+
const requestedEffort = options?.reasoningEffort;
|
|
527
|
+
const mappedEffort = requestedEffort ? model.thinkingLevelMap?.[requestedEffort] : model.thinkingLevelMap?.off;
|
|
528
|
+
const effort = mappedEffort === void 0 ? requestedEffort : mappedEffort;
|
|
529
|
+
if (typeof effort === "string") basetenParams.reasoning_effort = effort;
|
|
530
|
+
}
|
|
531
|
+
} else if (compat.thinkingFormat === "deepseek" && model.reasoning) {
|
|
532
|
+
if (options?.reasoningEffort) params.thinking = { type: "enabled" };
|
|
533
|
+
else if (model.thinkingLevelMap?.off !== null) params.thinking = { type: "disabled" };
|
|
534
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
535
|
+
} else if (compat.thinkingFormat === "openrouter" && model.reasoning) {
|
|
536
|
+
const openRouterParams = params;
|
|
537
|
+
if (options?.reasoningEffort) openRouterParams.reasoning = { effort: model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort };
|
|
538
|
+
else if (model.thinkingLevelMap?.off !== null) openRouterParams.reasoning = { effort: model.thinkingLevelMap?.off ?? "none" };
|
|
539
|
+
} else if (compat.thinkingFormat === "ant-ling" && model.reasoning && options?.reasoningEffort) {
|
|
540
|
+
const effort = model.thinkingLevelMap?.[options.reasoningEffort];
|
|
541
|
+
if (typeof effort === "string") params.reasoning = { effort };
|
|
542
|
+
} else if (compat.thinkingFormat === "together" && model.reasoning) {
|
|
543
|
+
const togetherParams = params;
|
|
544
|
+
togetherParams.reasoning = { enabled: !!options?.reasoningEffort };
|
|
545
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) togetherParams.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
546
|
+
} else if (compat.thinkingFormat === "string-thinking" && model.reasoning) {
|
|
547
|
+
const stringThinkingParams = params;
|
|
548
|
+
if (options?.reasoningEffort) stringThinkingParams.thinking = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
549
|
+
else if (model.thinkingLevelMap?.off !== null) stringThinkingParams.thinking = model.thinkingLevelMap?.off ?? "none";
|
|
550
|
+
} else if (options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) params.reasoning_effort = model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
551
|
+
else if (!options?.reasoningEffort && model.reasoning && compat.supportsReasoningEffort) {
|
|
552
|
+
const offValue = model.thinkingLevelMap?.off;
|
|
553
|
+
if (typeof offValue === "string") params.reasoning_effort = offValue;
|
|
554
|
+
}
|
|
555
|
+
if (thinkingTokenBudgetField && thinkingBudget !== void 0) Object.assign(params, { [thinkingTokenBudgetField]: thinkingBudget });
|
|
556
|
+
if (model.compat?.openRouterRouting) params.provider = model.compat.openRouterRouting;
|
|
557
|
+
if (model.compat?.vercelGatewayRouting) {
|
|
558
|
+
const routing = model.compat.vercelGatewayRouting;
|
|
559
|
+
if (routing.only || routing.order) {
|
|
560
|
+
const gatewayOptions = {};
|
|
561
|
+
if (routing.only) gatewayOptions.only = routing.only;
|
|
562
|
+
if (routing.order) gatewayOptions.order = routing.order;
|
|
563
|
+
params.providerOptions = { gateway: gatewayOptions };
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const samplingParams = resolveSamplingParams(model, options?.reasoningEffort ?? "off", options?.samplingParams);
|
|
567
|
+
if (samplingParams) Object.assign(params, samplingParams);
|
|
568
|
+
return params;
|
|
569
|
+
}
|
|
570
|
+
function resolveThinkingTokenBudgetField(compat) {
|
|
571
|
+
if (compat.thinkingTokenBudgetField) return compat.thinkingTokenBudgetField;
|
|
572
|
+
if (compat.supportsThinkingTokenBudget) return "thinking_token_budget";
|
|
573
|
+
}
|
|
574
|
+
function resolveClampedThinkingBudget(model, options, params) {
|
|
575
|
+
if (!options?.reasoningEffort || !model.reasoning) return void 0;
|
|
576
|
+
const ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;
|
|
577
|
+
const budget = clampThinkingBudgetToAnswerRoom(thinkingBudgetForLevel(options.reasoningEffort, options.thinkingBudgets), ceiling);
|
|
578
|
+
return budget > 0 ? budget : void 0;
|
|
579
|
+
}
|
|
580
|
+
function buildChatTemplateValues(model, options, values, thinkingBudget) {
|
|
581
|
+
const resolvedValues = {};
|
|
582
|
+
for (const [key, value] of Object.entries(values)) {
|
|
583
|
+
const resolved = resolveChatTemplateKwargValue(model, options, value, thinkingBudget);
|
|
584
|
+
if (resolved !== void 0) resolvedValues[key] = resolved;
|
|
585
|
+
}
|
|
586
|
+
return Object.keys(resolvedValues).length > 0 ? resolvedValues : void 0;
|
|
587
|
+
}
|
|
588
|
+
function resolveChatTemplateKwargValue(model, options, value, thinkingBudget) {
|
|
589
|
+
if (typeof value !== "object" || value === null) return value;
|
|
590
|
+
const reasoningEffort = options?.reasoningEffort;
|
|
591
|
+
if (!reasoningEffort && value.omitWhenOff) return;
|
|
592
|
+
if (value.$var === "thinking.enabled") return !!reasoningEffort;
|
|
593
|
+
if (value.$var === "thinking.budget") return thinkingBudget;
|
|
594
|
+
const mappedValue = reasoningEffort ? model.thinkingLevelMap?.[reasoningEffort] : model.thinkingLevelMap?.off;
|
|
595
|
+
return mappedValue === void 0 ? reasoningEffort : typeof mappedValue === "string" ? mappedValue : void 0;
|
|
596
|
+
}
|
|
597
|
+
function getCompatCacheControl(compat, cacheRetention) {
|
|
598
|
+
if (compat.cacheControlFormat !== "anthropic" || cacheRetention === "none") return;
|
|
599
|
+
const ttl = cacheRetention === "long" && compat.supportsLongCacheRetention ? "1h" : void 0;
|
|
600
|
+
return {
|
|
601
|
+
type: "ephemeral",
|
|
602
|
+
...ttl ? { ttl } : {}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function applyAnthropicCacheControl(messages, tools, cacheControl) {
|
|
606
|
+
addCacheControlToSystemPrompt(messages, cacheControl);
|
|
607
|
+
addCacheControlToLastTool(tools, cacheControl);
|
|
608
|
+
addCacheControlToLastConversationMessage(messages, cacheControl);
|
|
609
|
+
}
|
|
610
|
+
function addCacheControlToSystemPrompt(messages, cacheControl) {
|
|
611
|
+
for (const message of messages) if (message.role === "system" || message.role === "developer") {
|
|
612
|
+
addCacheControlToInstructionMessage(message, cacheControl);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function addCacheControlToLastConversationMessage(messages, cacheControl) {
|
|
617
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
618
|
+
const message = messages[i];
|
|
619
|
+
if (message.role === "user" || message.role === "assistant" || message.role === "tool") {
|
|
620
|
+
if (addCacheControlToMessage(message, cacheControl)) return;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function addCacheControlToLastTool(tools, cacheControl) {
|
|
625
|
+
if (!tools || tools.length === 0) return;
|
|
626
|
+
const lastTool = tools[tools.length - 1];
|
|
627
|
+
lastTool.cache_control = cacheControl;
|
|
628
|
+
}
|
|
629
|
+
function addCacheControlToInstructionMessage(message, cacheControl) {
|
|
630
|
+
return addCacheControlToTextContent(message, cacheControl);
|
|
631
|
+
}
|
|
632
|
+
function addCacheControlToMessage(message, cacheControl) {
|
|
633
|
+
if (message.role === "user" || message.role === "assistant" || message.role === "tool") return addCacheControlToTextContent(message, cacheControl);
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
function addCacheControlToTextContent(message, cacheControl) {
|
|
637
|
+
const content = message.content;
|
|
638
|
+
if (typeof content === "string") {
|
|
639
|
+
if (content.length === 0) return false;
|
|
640
|
+
message.content = [{
|
|
641
|
+
type: "text",
|
|
642
|
+
text: content,
|
|
643
|
+
cache_control: cacheControl
|
|
644
|
+
}];
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
if (!Array.isArray(content)) return false;
|
|
648
|
+
for (let i = content.length - 1; i >= 0; i--) {
|
|
649
|
+
const part = content[i];
|
|
650
|
+
if (part?.type === "text") {
|
|
651
|
+
const textPart = part;
|
|
652
|
+
textPart.cache_control = cacheControl;
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
function convertMessages(model, context, compat, options) {
|
|
659
|
+
const normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);
|
|
660
|
+
const params = [];
|
|
661
|
+
const normalizeToolCallId = (id) => {
|
|
662
|
+
if (id.includes("|")) {
|
|
663
|
+
const separatorIndex = id.indexOf("|");
|
|
664
|
+
const callId = id.slice(0, separatorIndex).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
665
|
+
const itemId = id.slice(separatorIndex + 1).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
666
|
+
const combinedId = itemId.length > 0 ? `${callId}_${itemId}` : callId;
|
|
667
|
+
if (combinedId.length <= 40) return combinedId;
|
|
668
|
+
const hash = shortHash(id).slice(0, 8);
|
|
669
|
+
return `${callId.slice(0, Math.max(1, 40 - hash.length - 1))}_${hash}`;
|
|
670
|
+
}
|
|
671
|
+
if (model.provider === "openai") return id.length > 40 ? id.slice(0, 40) : id;
|
|
672
|
+
return id;
|
|
673
|
+
};
|
|
674
|
+
const transformedMessages = transformMessages(normalizedContext.messages, model, (id) => normalizeToolCallId(id));
|
|
675
|
+
const transcriptTools = resolveTranscriptTools(normalizedContext.messages, compat.supportsMidConvoSystemMessages === true && compat.supportsMidConvoToolAdditions === true ? "additions" : "none");
|
|
676
|
+
const instructionRole = model.reasoning && compat.supportsDeveloperRole ? "developer" : "system";
|
|
677
|
+
let lastRole = null;
|
|
678
|
+
let systemIndex = 0;
|
|
679
|
+
for (let i = 0; i < transformedMessages.length; i++) {
|
|
680
|
+
const msg = transformedMessages[i];
|
|
681
|
+
if (compat.requiresAssistantAfterToolResult && lastRole === "toolResult" && msg.role === "user") params.push({
|
|
682
|
+
role: "assistant",
|
|
683
|
+
content: "I have processed the tool results."
|
|
684
|
+
});
|
|
685
|
+
if (msg.role === "system") {
|
|
686
|
+
const addedTools = systemIndex++ >= transcriptTools.foldedSystemMessages ? msg.toolsAdded ?? [] : [];
|
|
687
|
+
if (addedTools.length > 0) {
|
|
688
|
+
const kimiToolMessage = {
|
|
689
|
+
role: "system",
|
|
690
|
+
tools: convertTools(addedTools, compat)
|
|
691
|
+
};
|
|
692
|
+
params.push(kimiToolMessage);
|
|
693
|
+
}
|
|
694
|
+
const text = i === 0 ? getSystemMessageText(msg) : renderSystemMessageUpdate(msg);
|
|
695
|
+
if (text.length > 0) params.push({
|
|
696
|
+
role: instructionRole,
|
|
697
|
+
content: sanitizeSurrogates(text)
|
|
698
|
+
});
|
|
699
|
+
} else if (msg.role === "user") {
|
|
700
|
+
if (typeof msg.content === "string") params.push({
|
|
701
|
+
role: "user",
|
|
702
|
+
content: sanitizeSurrogates(msg.content)
|
|
703
|
+
});
|
|
704
|
+
else {
|
|
705
|
+
const content = msg.content.filter((item) => item.type !== "text" || item.text.length > 0).map((item) => {
|
|
706
|
+
if (item.type === "text") return {
|
|
707
|
+
type: "text",
|
|
708
|
+
text: sanitizeSurrogates(item.text)
|
|
709
|
+
};
|
|
710
|
+
else return {
|
|
711
|
+
type: "image_url",
|
|
712
|
+
image_url: { url: `data:${item.mimeType};base64,${item.data}` }
|
|
713
|
+
};
|
|
714
|
+
});
|
|
715
|
+
if (content.length === 0) continue;
|
|
716
|
+
params.push({
|
|
717
|
+
role: "user",
|
|
718
|
+
content
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
} else if (msg.role === "assistant") {
|
|
722
|
+
const assistantMsg = {
|
|
723
|
+
role: "assistant",
|
|
724
|
+
content: compat.requiresAssistantAfterToolResult ? "" : null
|
|
725
|
+
};
|
|
726
|
+
const assistantTextParts = msg.content.filter(isTextContentBlock).filter((block) => block.text.trim().length > 0).map((block) => ({
|
|
727
|
+
type: "text",
|
|
728
|
+
text: sanitizeSurrogates(block.text)
|
|
729
|
+
}));
|
|
730
|
+
const assistantText = assistantTextParts.map((part) => part.text).join("");
|
|
731
|
+
const thinkingBlocks = msg.content.filter(isThinkingContentBlock);
|
|
732
|
+
const toolCalls = msg.content.filter(isToolCallBlock);
|
|
733
|
+
const signedReasoningDetails = thinkingBlocks.map((block) => parseOpenAIReasoningDetails(block.thinkingSignature)).find((details) => details !== void 0);
|
|
734
|
+
const legacyReasoningDetails = toolCalls.map((toolCall) => parseLegacyEncryptedReasoningDetail(toolCall.thoughtSignature)).filter((detail) => detail !== void 0);
|
|
735
|
+
const preservedReasoningDetails = signedReasoningDetails ?? (legacyReasoningDetails.length > 0 ? legacyReasoningDetails : void 0);
|
|
736
|
+
const nonEmptyThinkingBlocks = thinkingBlocks.filter((block) => block.thinking.trim().length > 0);
|
|
737
|
+
if (nonEmptyThinkingBlocks.length > 0) {
|
|
738
|
+
if (compat.requiresThinkingAsText) assistantMsg.content = [{
|
|
739
|
+
type: "text",
|
|
740
|
+
text: nonEmptyThinkingBlocks.map((block) => sanitizeSurrogates(block.thinking)).join("\n\n")
|
|
741
|
+
}, ...assistantTextParts];
|
|
742
|
+
else {
|
|
743
|
+
if (assistantText.length > 0) assistantMsg.content = assistantText;
|
|
744
|
+
if (!preservedReasoningDetails) {
|
|
745
|
+
let signature = nonEmptyThinkingBlocks[0].thinkingSignature;
|
|
746
|
+
if (model.provider === "opencode-go" && signature === "reasoning") signature = "reasoning_content";
|
|
747
|
+
if (signature && isOpenAICompletionsReasoningField(signature)) assistantMsg[signature] = nonEmptyThinkingBlocks.map((block) => block.thinking).join("\n");
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
} else if (assistantText.length > 0) assistantMsg.content = assistantText;
|
|
751
|
+
if (toolCalls.length > 0) assistantMsg.tool_calls = toolCalls.map((tc) => {
|
|
752
|
+
const customInputProperty = options?.grammarToolInputProperties?.get(tc.name);
|
|
753
|
+
if (customInputProperty !== void 0) return {
|
|
754
|
+
id: tc.id,
|
|
755
|
+
type: "custom",
|
|
756
|
+
custom: {
|
|
757
|
+
name: tc.name,
|
|
758
|
+
input: sanitizeSurrogates(getGrammarToolInput(tc.name, tc.arguments, customInputProperty))
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
return {
|
|
762
|
+
id: tc.id,
|
|
763
|
+
type: "function",
|
|
764
|
+
function: {
|
|
765
|
+
name: tc.name,
|
|
766
|
+
arguments: JSON.stringify(tc.arguments)
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
});
|
|
770
|
+
if (preservedReasoningDetails) assistantMsg.reasoning_details = preservedReasoningDetails;
|
|
771
|
+
if (compat.requiresReasoningContentOnAssistantMessages && model.reasoning && assistantMsg.reasoning_content === void 0) assistantMsg.reasoning_content = "";
|
|
772
|
+
const content = assistantMsg.content;
|
|
773
|
+
if (!(content !== null && content !== void 0 && (typeof content === "string" ? content.length > 0 : content.length > 0)) && !assistantMsg.tool_calls) continue;
|
|
774
|
+
params.push(assistantMsg);
|
|
775
|
+
} else if (msg.role === "toolResult") {
|
|
776
|
+
const imageBlocks = [];
|
|
777
|
+
let j = i;
|
|
778
|
+
for (; j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
|
|
779
|
+
const toolMsg = transformedMessages[j];
|
|
780
|
+
const textResult = toolMsg.content.filter(isTextContentBlock).map((block) => block.text).join("\n");
|
|
781
|
+
const hasImages = toolMsg.content.some((c) => c.type === "image");
|
|
782
|
+
const toolResultText = textResult.trim().length > 0 ? textResult : hasImages ? "(see attached image)" : "(no tool output)";
|
|
783
|
+
const toolResultMsg = {
|
|
784
|
+
role: "tool",
|
|
785
|
+
content: sanitizeSurrogates(toolResultText),
|
|
786
|
+
tool_call_id: toolMsg.toolCallId
|
|
787
|
+
};
|
|
788
|
+
if (compat.requiresToolResultName && toolMsg.toolName) toolResultMsg.name = toolMsg.toolName;
|
|
789
|
+
params.push(toolResultMsg);
|
|
790
|
+
if (hasImages && model.input.includes("image")) {
|
|
791
|
+
for (const block of toolMsg.content) if (isImageContentBlock(block)) imageBlocks.push({
|
|
792
|
+
type: "image_url",
|
|
793
|
+
image_url: { url: `data:${block.mimeType};base64,${block.data}` }
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
i = j - 1;
|
|
798
|
+
if (imageBlocks.length > 0) {
|
|
799
|
+
if (compat.requiresAssistantAfterToolResult) params.push({
|
|
800
|
+
role: "assistant",
|
|
801
|
+
content: "I have processed the tool results."
|
|
802
|
+
});
|
|
803
|
+
params.push({
|
|
804
|
+
role: "user",
|
|
805
|
+
content: [{
|
|
806
|
+
type: "text",
|
|
807
|
+
text: "Attached image(s) from tool result:"
|
|
808
|
+
}, ...imageBlocks]
|
|
809
|
+
});
|
|
810
|
+
lastRole = "user";
|
|
811
|
+
} else lastRole = "toolResult";
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
lastRole = msg.role;
|
|
815
|
+
}
|
|
816
|
+
return params;
|
|
817
|
+
}
|
|
818
|
+
function convertTools(tools, compat) {
|
|
819
|
+
return tools.map((tool) => {
|
|
820
|
+
const grammar = resolveGrammarConstrainedSampling(tool, compat.supportsOpenAIGrammarTools);
|
|
821
|
+
if (grammar) return {
|
|
822
|
+
type: "custom",
|
|
823
|
+
custom: {
|
|
824
|
+
name: tool.name,
|
|
825
|
+
description: tool.description,
|
|
826
|
+
format: {
|
|
827
|
+
type: "grammar",
|
|
828
|
+
grammar: {
|
|
829
|
+
syntax: grammar.format,
|
|
830
|
+
definition: grammar.definition
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
const strict = resolveJsonSchemaStrictSampling(tool, compat.supportsStrictMode !== false);
|
|
836
|
+
return {
|
|
837
|
+
type: "function",
|
|
838
|
+
function: {
|
|
839
|
+
name: tool.name,
|
|
840
|
+
description: tool.description,
|
|
841
|
+
parameters: getJsonSchemaToolParameters(tool, strict),
|
|
842
|
+
...compat.supportsStrictMode !== false && { strict: strict ?? false }
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
function parseChunkUsage(rawUsage, model) {
|
|
848
|
+
const promptTokens = rawUsage.prompt_tokens || 0;
|
|
849
|
+
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? 0;
|
|
850
|
+
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
851
|
+
const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
|
|
852
|
+
const outputTokens = rawUsage.completion_tokens || 0;
|
|
853
|
+
const usage = {
|
|
854
|
+
input,
|
|
855
|
+
output: outputTokens,
|
|
856
|
+
cacheRead: cacheReadTokens,
|
|
857
|
+
cacheWrite: cacheWriteTokens,
|
|
858
|
+
reasoning: rawUsage.completion_tokens_details?.reasoning_tokens || 0,
|
|
859
|
+
totalTokens: input + outputTokens + cacheReadTokens + cacheWriteTokens,
|
|
860
|
+
cost: {
|
|
861
|
+
input: 0,
|
|
862
|
+
output: 0,
|
|
863
|
+
cacheRead: 0,
|
|
864
|
+
cacheWrite: 0,
|
|
865
|
+
total: 0
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
calculateCost(model, usage);
|
|
869
|
+
if (isOpenRouterModel(model)) applyOpenRouterReportedCost(usage, rawUsage);
|
|
870
|
+
return usage;
|
|
871
|
+
}
|
|
872
|
+
function mapStopReason(reason) {
|
|
873
|
+
if (reason === null) return { stopReason: "stop" };
|
|
874
|
+
switch (reason) {
|
|
875
|
+
case "stop":
|
|
876
|
+
case "end": return { stopReason: "stop" };
|
|
877
|
+
case "length": return { stopReason: "length" };
|
|
878
|
+
case "function_call":
|
|
879
|
+
case "tool_calls": return { stopReason: "toolUse" };
|
|
880
|
+
case "content_filter": return {
|
|
881
|
+
stopReason: "error",
|
|
882
|
+
errorMessage: "Provider finish_reason: content_filter"
|
|
883
|
+
};
|
|
884
|
+
case "network_error": return {
|
|
885
|
+
stopReason: "error",
|
|
886
|
+
errorMessage: "Provider finish_reason: network_error"
|
|
887
|
+
};
|
|
888
|
+
default: return {
|
|
889
|
+
stopReason: "error",
|
|
890
|
+
errorMessage: `Provider finish_reason: ${reason}`
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Auto-detect compatibility settings from provider name and baseUrl.
|
|
896
|
+
* Used as the base when model.compat is not set; explicit model.compat
|
|
897
|
+
* entries override these detected values.
|
|
898
|
+
*/
|
|
899
|
+
function detectCompat(model) {
|
|
900
|
+
const provider = model.provider;
|
|
901
|
+
const baseUrl = model.baseUrl;
|
|
902
|
+
const isZai = provider === "zai" || provider === "zai-coding-cn" || baseUrl.includes("api.z.ai") || baseUrl.includes("open.bigmodel.cn");
|
|
903
|
+
const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
|
|
904
|
+
const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
|
|
905
|
+
const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
|
|
906
|
+
const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
|
|
907
|
+
const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
|
|
908
|
+
const isNvidia = provider === "nvidia" || baseUrl.includes("integrate.api.nvidia.com");
|
|
909
|
+
const isAntLing = provider === "ant-ling" || baseUrl.includes("api.ant-ling.com");
|
|
910
|
+
const isCerebras = provider === "cerebras" || baseUrl.includes("cerebras.ai");
|
|
911
|
+
const isDeepSeek = provider === "deepseek" || baseUrl.toLowerCase().includes("deepseek.com");
|
|
912
|
+
const isNonStandard = isNvidia || isCerebras || provider === "xai" || baseUrl.includes("api.x.ai") || isTogether || baseUrl.includes("chutes.ai") || isDeepSeek || isZai || isMoonshot || provider === "opencode" || baseUrl.includes("opencode.ai") || isCloudflareWorkersAI || isCloudflareAiGateway || isAntLing;
|
|
913
|
+
const useMaxTokens = baseUrl.includes("chutes.ai") || isDeepSeek || isMoonshot || isCloudflareAiGateway || isTogether || isNvidia || isAntLing || isZai;
|
|
914
|
+
const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
|
|
915
|
+
const isOpenRouterDeveloperRoleModel = isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
|
|
916
|
+
const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : void 0;
|
|
917
|
+
return {
|
|
918
|
+
supportsStore: !isNonStandard,
|
|
919
|
+
supportsDeveloperRole: isOpenRouterDeveloperRoleModel || !isNonStandard && !isOpenRouter,
|
|
920
|
+
supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
|
|
921
|
+
supportsUsageInStreaming: true,
|
|
922
|
+
supportsFinishReason: true,
|
|
923
|
+
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
|
924
|
+
requiresToolResultName: false,
|
|
925
|
+
requiresAssistantAfterToolResult: false,
|
|
926
|
+
requiresThinkingAsText: false,
|
|
927
|
+
requiresReasoningContentOnAssistantMessages: isDeepSeek,
|
|
928
|
+
thinkingFormat: isDeepSeek ? "deepseek" : isZai ? "zai" : isTogether ? "together" : isAntLing ? "ant-ling" : isOpenRouter ? "openrouter" : "openai",
|
|
929
|
+
openRouterRouting: {},
|
|
930
|
+
vercelGatewayRouting: {},
|
|
931
|
+
chatTemplateKwargs: {},
|
|
932
|
+
chatTemplateArgs: {},
|
|
933
|
+
zaiToolStream: false,
|
|
934
|
+
supportsThinkingTokenBudget: false,
|
|
935
|
+
thinkingTokenBudgetField: void 0,
|
|
936
|
+
supportsStrictMode: false,
|
|
937
|
+
supportsOpenAIGrammarTools: false,
|
|
938
|
+
supportsMidConvoSystemMessages: false,
|
|
939
|
+
supportsMidConvoToolAdditions: false,
|
|
940
|
+
cacheControlFormat,
|
|
941
|
+
sendSessionAffinityHeaders: isOpenRouter,
|
|
942
|
+
sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
|
|
943
|
+
supportsLongCacheRetention: !(isTogether || isCloudflareWorkersAI || isCloudflareAiGateway || isNvidia || isAntLing)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Get resolved compatibility settings for a model.
|
|
948
|
+
* Auto-detects from provider/URL then overrides with explicit model.compat.
|
|
949
|
+
*/
|
|
950
|
+
function getCompat(model) {
|
|
951
|
+
const detected = detectCompat(model);
|
|
952
|
+
if (!model.compat) return detected;
|
|
953
|
+
return {
|
|
954
|
+
supportsStore: model.compat.supportsStore ?? detected.supportsStore,
|
|
955
|
+
supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
|
956
|
+
supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
|
957
|
+
supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
|
958
|
+
supportsFinishReason: model.compat.supportsFinishReason ?? detected.supportsFinishReason,
|
|
959
|
+
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
|
960
|
+
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
|
961
|
+
requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
962
|
+
requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
|
|
963
|
+
requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ?? detected.requiresReasoningContentOnAssistantMessages,
|
|
964
|
+
thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
|
|
965
|
+
openRouterRouting: model.compat.openRouterRouting ?? {},
|
|
966
|
+
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
|
|
967
|
+
chatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,
|
|
968
|
+
chatTemplateArgs: model.compat.chatTemplateArgs ?? detected.chatTemplateArgs,
|
|
969
|
+
zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
|
|
970
|
+
supportsThinkingTokenBudget: model.compat.supportsThinkingTokenBudget ?? detected.supportsThinkingTokenBudget,
|
|
971
|
+
thinkingTokenBudgetField: model.compat.thinkingTokenBudgetField ?? detected.thinkingTokenBudgetField,
|
|
972
|
+
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
|
|
973
|
+
supportsOpenAIGrammarTools: model.compat.supportsOpenAIGrammarTools ?? detected.supportsOpenAIGrammarTools,
|
|
974
|
+
supportsMidConvoSystemMessages: model.compat.supportsMidConvoSystemMessages ?? detected.supportsMidConvoSystemMessages,
|
|
975
|
+
supportsMidConvoToolAdditions: model.compat.supportsMidConvoToolAdditions ?? detected.supportsMidConvoToolAdditions,
|
|
976
|
+
cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
|
|
977
|
+
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
978
|
+
sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
|
|
979
|
+
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
980
|
+
vllmPriority: model.compat.vllmPriority
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
//#endregion
|
|
984
|
+
export { convertMessages, stream, streamSimple };
|