@nervekit/desktop 0.40.1 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/THIRD-PARTY-LICENSES.txt +968 -30
- package/dist/bin.js +1 -0
- package/dist/{chunk-OY6PIAR7.js → chunk-2ICPO4UM.js} +5 -5
- package/dist/{chunk-SQ7CWNIT.js → chunk-3CZXUKLG.js} +1 -1
- package/dist/{chunk-QFXKQNMT.js → chunk-4OCDR4DU.js} +14 -17
- package/dist/chunk-62DQXVPO.js +69 -0
- package/dist/chunk-6GUJQURI.js +142 -0
- package/dist/{chunk-CEX2GWGZ.js → chunk-6IHXVT5H.js} +1 -1
- package/dist/{chunk-MH3SUHI2.js → chunk-6ZS7TA6E.js} +2 -2
- package/dist/chunk-7FSH3ABG.js +249 -0
- package/dist/chunk-7HGFEQSD.js +224 -0
- package/dist/chunk-7RPHIJT3.js +153 -0
- package/dist/{chunk-5Y3NEEOK.js → chunk-AAEIGAGD.js} +9 -9
- package/dist/{chunk-HKLAYK2Z.js → chunk-APY4TUR3.js} +210 -0
- package/dist/chunk-BACYVEE6.js +128 -0
- package/dist/chunk-BG2KGLIA.js +783 -0
- package/dist/{chunk-XBHEYY65.js → chunk-BN5YDZUZ.js} +1205 -326
- package/dist/chunk-BUD4JHBZ.js +7017 -0
- package/dist/{chunk-MN7PZ2PH.js → chunk-DDBE2VLT.js} +2 -2
- package/dist/chunk-EF7ZZKA3.js +168 -0
- package/dist/{chunk-TJR6ASRW.js → chunk-EUT45AKW.js} +22 -24
- package/dist/{chunk-L3YB2QLN.js → chunk-FCAIYPDJ.js} +2 -2
- package/dist/{chunk-AJGPULMX.js → chunk-FZ557YWE.js} +47603 -55411
- package/dist/chunk-HPINJGBO.js +359 -0
- package/dist/{chunk-H5UKINTD.js → chunk-IRRR3PWN.js} +68 -65
- package/dist/{chunk-CWHAK2HX.js → chunk-IVBMHEPK.js} +33 -55
- package/dist/{chunk-FESN7DND.js → chunk-JBEWFFOK.js} +1 -1
- package/dist/{chunk-CKVFGRVV.js → chunk-KEXKZKN4.js} +54 -7
- package/dist/{chunk-UGDIHDAR.js → chunk-KUFIFCB4.js} +1 -1
- package/dist/chunk-L5WGVYXM.js +42 -0
- package/dist/{chunk-ONWQH2W6.js → chunk-LGIIT2NF.js} +15 -18
- package/dist/{chunk-KSZJ3HGD.js → chunk-LP4APBBQ.js} +1 -1
- package/dist/{chunk-DBXMYYPJ.js → chunk-M3ELKCNA.js} +1 -1
- package/dist/chunk-MI6L5CEA.js +183 -0
- package/dist/chunk-N4OXAS3A.js +40 -0
- package/dist/chunk-N6BUYKF3.js +340 -0
- package/dist/{chunk-KIGB3FK6.js → chunk-NVVW3MWJ.js} +9 -8
- package/dist/{chunk-V53CETNZ.js → chunk-O5JHHRFN.js} +242 -105
- package/dist/{chunk-KQPEOUCA.js → chunk-O6FDXE54.js} +19 -23
- package/dist/{chunk-QWTKCUIZ.js → chunk-OMCM3MHS.js} +11 -9
- package/dist/{chunk-55OGZFNA.js → chunk-P72Y5ZBH.js} +31 -15
- package/dist/{chunk-AON37AL2.js → chunk-PVPJAGWR.js} +29 -4
- package/dist/{chunk-24GQ74HM.js → chunk-Q3C7TQ2M.js} +3 -3
- package/dist/chunk-Q5E4ZL2R.js +14 -0
- package/dist/chunk-QFK2SWD2.js +258 -0
- package/dist/chunk-RJR7DJJK.js +32 -0
- package/dist/{chunk-BXVRC3HF.js → chunk-RL52LSTV.js} +1 -1
- package/dist/{chunk-KAZFF2RD.js → chunk-RTB6CF7F.js} +137 -113
- package/dist/{chunk-TW6FURZ7.js → chunk-SDDKYMIP.js} +18313 -4317
- package/dist/{chunk-S2PITDVA.js → chunk-TQURLRHD.js} +1 -1
- package/dist/{chunk-2Z5FLMLE.js → chunk-TSAUBRRU.js} +1 -1
- package/dist/chunk-U3TEC52G.js +64 -0
- package/dist/chunk-U5KGV63C.js +39 -0
- package/dist/{chunk-FOFVPPPV.js → chunk-UVRULOOP.js} +10 -9
- package/dist/{chunk-QVHYARC2.js → chunk-VOATSLRG.js} +5 -1
- package/dist/{chunk-WXRYBXYR.js → chunk-W7LEYYFH.js} +53 -65
- package/dist/chunk-WC5HHPPM.js +22 -0
- package/dist/{chunk-3DGBM7UW.js → chunk-WG62RHZ2.js} +3 -3
- package/dist/{chunk-D7WIIZAV.js → chunk-WIQEPAUG.js} +10 -9
- package/dist/chunk-XM27UVWN.js +250 -0
- package/dist/{chunk-4MMJDHFX.js → chunk-XTUSLUQ7.js} +70 -71
- package/dist/{chunk-N5B2RRSS.js → chunk-Z6AY5VOZ.js} +47 -26
- package/dist/{chunk-I6NVW4NX.js → chunk-ZGWXLG5X.js} +29 -33
- package/dist/{chunk-XNYZEQ3U.js → chunk-ZUWBEV2O.js} +1 -1
- package/dist/chunk-ZVH6EB7S.js +29 -0
- package/dist/daemon.js +65 -26
- package/dist/extension-assets/atlassian/docs/confluence-raw.md +31 -0
- package/dist/extension-assets/atlassian/docs/confluence-writing.md +101 -0
- package/dist/extension-assets/atlassian/docs/jira-raw.md +16 -0
- package/dist/extension-assets/atlassian/docs/jira-workflows.md +77 -0
- package/dist/extension-assets/atlassian/docs/project-knowledge.md +25 -0
- package/dist/extension-assets/atlassian/docs/storage.md +58 -0
- package/dist/extension-assets/atlassian/icon.svg +20 -0
- package/dist/extension-assets/diagram/docs/diagrams.md +12 -0
- package/dist/extension-assets/imagegen/docs/imagegen.md +17 -0
- package/dist/extension-assets/web-search/icon.svg +1 -0
- package/dist/git-isolated-reader-helper.js +1 -1
- package/dist/html-to-markdown.worker.js +6 -7028
- package/dist/main.js +583 -164
- package/dist/preload.cjs +45 -2
- package/dist/quick-script-docs/runtime/documents.md +54 -0
- package/dist/quick-script-docs/runtime/files.md +11 -0
- package/dist/quick-script-docs/runtime/images.md +10 -0
- package/dist/sandbox-libraries/docx.LICENSE +21 -0
- package/dist/sandbox-libraries/docx.min.js +9 -0
- package/dist/sandbox-libraries/jszip.LICENSE +651 -0
- package/dist/sandbox-libraries/jszip.min.js +13 -0
- package/dist/sandbox-libraries/mammoth.LICENSE +22 -0
- package/dist/sandbox-libraries/mammoth.browser.min.js +13 -0
- package/dist/sandbox-libraries/papaparse.LICENSE +20 -0
- package/dist/sandbox-libraries/papaparse.min.js +7 -0
- package/dist/sandbox-libraries/pptxgen.bundle.js +96 -0
- package/dist/sandbox-libraries/pptxgenjs.LICENSE +21 -0
- package/dist/sandbox-libraries/xlsx.LICENSE +201 -0
- package/dist/sandbox-libraries/xlsx.full.min.js +24 -0
- package/dist/web/assets/{AsyncBashCenterHost-HGsdxUJ3.js → AsyncBashCenterHost-D2Sy43Ub.js} +1 -1
- package/dist/web/assets/ConversationListItem-DvxCcAYm.js +3 -0
- package/dist/web/assets/ConversationsWorkbenchPanel-YeNq9LRn.js +1 -0
- package/dist/web/assets/DiscoverCenterHost-B6K-QnBF.js +1 -0
- package/dist/web/assets/{FileCenterHost-DigJOU5M.js → FileCenterHost-Dlk53K5G.js} +1 -1
- package/dist/web/assets/FilesWorkbenchPanel-PeCu12oU.js +12 -0
- package/dist/web/assets/{GitDiffCenterHost-IuZfF3hG.js → GitDiffCenterHost-3_Ea0RyG.js} +1 -1
- package/dist/web/assets/{GitWorkbenchPanel-CScC0CfH.js → GitWorkbenchPanel-CYvCkOAW.js} +1 -1
- package/dist/web/assets/{LaunchCenterHost-CIu7bcoZ.js → LaunchCenterHost-CP773N_3.js} +1 -1
- package/dist/web/assets/LaunchConfigurationNotice-CtmZ1uIQ.js +1 -0
- package/dist/web/assets/{LaunchesWorkbenchPanel-Vy0Gm7gg.js → LaunchesWorkbenchPanel-DP3yVfkO.js} +1 -1
- package/dist/web/assets/LogsCenterHost-BFP0doQf.js +1 -0
- package/dist/web/assets/{MermaidCenterHost-DDh4ArdK.js → MermaidCenterHost-Bjl6Dvrq.js} +1 -1
- package/dist/web/assets/MobileFilesBody-CDp21MGZ.js +1 -0
- package/dist/web/assets/{MobileFilesHost-C1jev2Un.js → MobileFilesHost-DlJI_yau.js} +1 -1
- package/dist/web/assets/MobileLaunchOutputHost-y3TehLWF.js +1 -0
- package/dist/web/assets/MobileLaunchesHost-CBNtDTrs.js +2 -0
- package/dist/web/assets/MobileLogsHost-BSb2lydK.js +1 -0
- package/dist/web/assets/MobileNoteEditorHost-7yW7hIC2.js +1 -0
- package/dist/web/assets/{MobileNotesHost-BZeYpK9H.js → MobileNotesHost-CvDHzpAh.js} +1 -1
- package/dist/web/assets/{MobileProjectSettingsHost-U3Mx3EN8.js → MobileProjectSettingsHost-CjtPfyKT.js} +1 -1
- package/dist/web/assets/{MobileProjectSettingsPageHost-CMvxbjfs.js → MobileProjectSettingsPageHost-j_7N-B9L.js} +1 -1
- package/dist/web/assets/{MobileSettingsHost-CP8Z_-gH.js → MobileSettingsHost-DXIKNF01.js} +1 -1
- package/dist/web/assets/{MobileSettingsPageHost-BPjXKTMV.js → MobileSettingsPageHost-CEzo7J9p.js} +1 -1
- package/dist/web/assets/MobileSettingsPageScreen-99wMLRsn.js +1 -0
- package/dist/web/assets/NotesWorkbenchPanel-DqTwXBBv.js +1 -0
- package/dist/web/assets/ProjectSettingsCenterHost-D96cL0uH.js +1 -0
- package/dist/web/assets/{PullRequestCenterHost-CZhXfCX2.js → PullRequestCenterHost-DY0yPDK2.js} +1 -1
- package/dist/web/assets/PullRequestsWorkbenchPanel-D07LE8vJ.js +1 -0
- package/dist/web/assets/{SearchWorkbenchPanel-qLgszneN.js → SearchWorkbenchPanel-D2_3iXo8.js} +1 -1
- package/dist/web/assets/SettingsCenter-BQWc24di.js +1 -0
- package/dist/web/assets/SettingsCenterHost-BvgNfeZN.js +1 -0
- package/dist/web/assets/{SystemPromptCenterHost-ya5AvXsd.js → SystemPromptCenterHost-BLHkB7lp.js} +1 -1
- package/dist/web/assets/activity-notices-C9aphS1s.js +1 -0
- package/dist/web/assets/adapters-DNU88KT0.js +1 -0
- package/dist/web/assets/agent-profiles.svelte-DgI8wSS2.js +1 -0
- package/dist/web/assets/api-CHNbLvvY.js +1 -0
- package/dist/web/assets/center-tabs.svelte-CyhCD_6b.js +1 -0
- package/dist/web/assets/channel-6wGoOwGx.js +57 -0
- package/dist/web/assets/circle-question-mark-C7NgqbLL.js +1 -0
- package/dist/web/assets/code-DJR0pnqV.js +7 -0
- package/dist/web/assets/{confirm-dialog-Bw_IxcZD.js → confirm-dialog-BDjzMiC4.js} +1 -1
- package/dist/web/assets/{conversation-connection-3GxIuhbS.js → conversation-connection-mLNyfV2d.js} +1 -1
- package/dist/web/assets/dialog-CkRcLEJT.js +1 -0
- package/dist/web/assets/discover-Dh4m7djO.js +4 -0
- package/dist/web/assets/dist-DSApqEag.js +1 -0
- package/dist/web/assets/file-tabs.svelte-cX3MMyG6.js +2 -0
- package/dist/web/assets/filesystem-BbIXrkGB.js +1 -0
- package/dist/web/assets/{git-store.svelte-CM5k7yRU.js → git-store.svelte-D3uwRVnj.js} +1 -1
- package/dist/web/assets/{git.api-D2CfUXZW.js → git.api-CTu-tG8A.js} +1 -1
- package/dist/web/assets/index-BrxjAwg0.js +46 -0
- package/dist/web/assets/index-yEOHI1Z7.css +1 -0
- package/dist/web/assets/launches-CC4gLnSa.js +5 -0
- package/dist/web/assets/{launches.api-BZxyWF8t.js → launches.api-CaotSs6l.js} +1 -1
- package/dist/web/assets/launches.svelte-DDA5J-RZ.js +2 -0
- package/dist/web/assets/{message-square-CqLxHJuW.js → list-checks-zV9Dp7Cu.js} +1 -1
- package/dist/web/assets/{logs.api-Coi8HJuy.js → logs.api-DMmVlkSz.js} +1 -1
- package/dist/web/assets/{maintenance-state.svelte-CDO9i4dk.js → maintenance-state.svelte-l9v7Hg3i.js} +2 -2
- package/dist/web/assets/notify.svelte-BTEXJZ8P.js +1 -0
- package/dist/web/assets/popover-panel-C-weKOk3.js +5 -0
- package/dist/web/assets/pr-view-loader.svelte-C0NClMS6.js +1 -0
- package/dist/web/assets/progress-CKEsTSOk.js +1 -0
- package/dist/web/assets/scratch-notes-state.svelte-B_rY_-9q.js +1 -0
- package/dist/web/assets/{scratch-notes.api-Cbvag3bv.js → scratch-notes.api-B2gOOK6Z.js} +1 -1
- package/dist/web/assets/search-input-CEr0SmAB.js +1 -0
- package/dist/web/assets/settings-2-CWd8Y06n.js +1 -0
- package/dist/web/assets/settings-CRmC19nG.js +1 -0
- package/dist/web/assets/settings-CXoAzSmm.js +1 -0
- package/dist/web/assets/settings-actions.svelte-BB6u_lQ0.js +1 -0
- package/dist/web/assets/settings-page-controllers.svelte-al78EDTL.js +29 -0
- package/dist/web/assets/sheet-content-DauQ7hPL.js +1 -0
- package/dist/web/assets/shell-CYbWnH52.js +4 -0
- package/dist/web/assets/shell-layout.svelte-CmEWk428.js +2 -0
- package/dist/web/assets/textarea-BEZ65po_.js +1 -0
- package/dist/web/assets/views-BumCSQ3W.js +2 -0
- package/dist/web/assets/{workbench-connection-gGGv4o8i.js → workbench-connection-CGHdORw3.js} +1 -1
- package/dist/web/assets/{workspace-Cc47dGjw.js → workspace-CW738NJG.js} +1 -1
- package/dist/web/assets/{workspace-actions.svelte-B3oum_9S.js → workspace-actions.svelte-DL9xv7lJ.js} +1 -1
- package/dist/web/assets/workspace-selectors.svelte-BRJvPEBh.js +105 -0
- package/dist/web/index.html +142 -83
- package/dist/web/sw.js +1 -1
- package/dist/worker.js +14 -9
- package/package.json +8 -9
- package/dist/chunk-RUZ2UAYH.js +0 -365
- package/dist/guides/confluence/SKILL.md +0 -36
- package/dist/guides/jira/SKILL.md +0 -34
- package/dist/resize-worker.js +0 -168
- package/dist/web/assets/ConversationListItem-Caz2KiJH.js +0 -3
- package/dist/web/assets/ConversationsWorkbenchPanel-B6dzWkG1.js +0 -1
- package/dist/web/assets/DiscoverCenterHost-B186WBRA.js +0 -1
- package/dist/web/assets/FilesWorkbenchPanel-VPvx3Bmi.js +0 -12
- package/dist/web/assets/LaunchConfigurationNotice-5yb4cH27.js +0 -1
- package/dist/web/assets/LogsCenterHost-BXBozCYw.js +0 -1
- package/dist/web/assets/MobileFilesBody-Cda_7gDp.js +0 -1
- package/dist/web/assets/MobileLaunchOutputHost-Bsv12o2H.js +0 -1
- package/dist/web/assets/MobileLaunchesHost-C9VH-2bn.js +0 -2
- package/dist/web/assets/MobileLogsHost-BMDXc-WC.js +0 -1
- package/dist/web/assets/MobileNoteEditorHost-BA6WIY1Y.js +0 -1
- package/dist/web/assets/MobileSettingsPageScreen-C5rHdrUU.js +0 -1
- package/dist/web/assets/NotesWorkbenchPanel-Bf6rySTL.js +0 -1
- package/dist/web/assets/ProjectSettingsCenterHost-BVXpBixy.js +0 -1
- package/dist/web/assets/PullRequestsWorkbenchPanel-BBnZJVnI.js +0 -1
- package/dist/web/assets/SettingsCenter-7BfrBfiy.js +0 -1
- package/dist/web/assets/SettingsCenterHost-Ck5uHILP.js +0 -1
- package/dist/web/assets/adapters-DxJoo6Za.js +0 -1
- package/dist/web/assets/agent-profiles.svelte-D5YHPc90.js +0 -1
- package/dist/web/assets/api-eaGLre0q.js +0 -1
- package/dist/web/assets/center-tabs.svelte-JJGozG_H.js +0 -1
- package/dist/web/assets/channel-B503YLZR.js +0 -57
- package/dist/web/assets/chevron-left-DPEFG6UJ.js +0 -1
- package/dist/web/assets/circle-alert-Cp2l2jcj.js +0 -5
- package/dist/web/assets/clock-Db6f9HtS.js +0 -1
- package/dist/web/assets/code-BRQC0Tpn.js +0 -7
- package/dist/web/assets/dialog-DU4gXD1J.js +0 -1
- package/dist/web/assets/discover-B3I5g1_G.js +0 -4
- package/dist/web/assets/dist-B_NFPhKV.js +0 -1
- package/dist/web/assets/file-tabs.svelte-DKtVVVCq.js +0 -2
- package/dist/web/assets/filesystem-ReGivxAC.js +0 -1
- package/dist/web/assets/index-DIQuyMVT.css +0 -1
- package/dist/web/assets/index-FJEmK_L5.js +0 -48
- package/dist/web/assets/launches-DiAl56ED.js +0 -5
- package/dist/web/assets/launches.svelte-BVs1pAhl.js +0 -2
- package/dist/web/assets/notebook-pen-lVsLYSe4.js +0 -1
- package/dist/web/assets/notify.svelte-BKVBraTJ.js +0 -1
- package/dist/web/assets/pencil-BrlypebI.js +0 -1
- package/dist/web/assets/pr-view-loader.svelte-DcIwqDJV.js +0 -1
- package/dist/web/assets/progress-DBCSpVPn.js +0 -1
- package/dist/web/assets/scratch-notes-state.svelte-Br_WiMEp.js +0 -1
- package/dist/web/assets/search-input-zU4WCZiz.js +0 -1
- package/dist/web/assets/settings-2-8MSBUGAl.js +0 -1
- package/dist/web/assets/settings-9LBrw4Nv.js +0 -1
- package/dist/web/assets/settings-B7uXsflY.js +0 -1
- package/dist/web/assets/settings-actions.svelte-B8psX3cj.js +0 -1
- package/dist/web/assets/settings-page-controllers.svelte-CU0i08wo.js +0 -30
- package/dist/web/assets/shell-DB5Db5-E.js +0 -4
- package/dist/web/assets/shell-layout.svelte-BT2508sa.js +0 -2
- package/dist/web/assets/textarea-CeoFJ0-t.js +0 -1
- package/dist/web/assets/views-Z-n-GTYY.js +0 -2
- package/dist/web/assets/workspace-selectors.svelte-DLUlSgEE.js +0 -131
- /package/dist/{html-to-markdown.worker.js.LEGAL.txt → chunk-BUD4JHBZ.js.LEGAL.txt} +0 -0
- /package/dist/{chunk-CKVFGRVV.js.LEGAL.txt → chunk-KEXKZKN4.js.LEGAL.txt} +0 -0
- /package/dist/{chunk-TW6FURZ7.js.LEGAL.txt → chunk-SDDKYMIP.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createRequire as __nerveCreateRequire } from "node:module";
|
|
2
|
+
const require = __nerveCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
generatePKCE,
|
|
5
|
+
oauthErrorHtml,
|
|
6
|
+
oauthSuccessHtml
|
|
7
|
+
} from "./chunk-BACYVEE6.js";
|
|
8
|
+
import {
|
|
9
|
+
getProviderEnvValue
|
|
10
|
+
} from "./chunk-JBEWFFOK.js";
|
|
11
|
+
import "./chunk-CWESUMYQ.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/.pnpm/@earendil-works+pi-ai@1.5.2_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_b842a8cec34a633ed5f728049ae89b72/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-chatgpt.js
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
import { createServer } from "node:http";
|
|
16
|
+
var DYNAMIC_CLIENT_ID = "dynamic_agent_client";
|
|
17
|
+
var AGENT_NAME_HINT = "Pi";
|
|
18
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19
|
+
var AUTHORIZE_URL = "https://auth.openai.com/api/accounts/authorize";
|
|
20
|
+
var TOKEN_URL = "https://auth.openai.com/api/accounts/oauth/token";
|
|
21
|
+
var RESOURCE = "https://api.openai.com/v1";
|
|
22
|
+
var CALLBACK_HOST = getProviderEnvValue("PI_OAUTH_CALLBACK_HOST") || "127.0.0.1";
|
|
23
|
+
var CALLBACK_PORT = 1455;
|
|
24
|
+
var CALLBACK_PATH = "/auth/callback";
|
|
25
|
+
var REDIRECT_URI = `http://127.0.0.1:${CALLBACK_PORT}${CALLBACK_PATH}`;
|
|
26
|
+
var DIRECT_TOKEN_SCOPE = "chatgpt.tokens.use.direct";
|
|
27
|
+
var SCOPE = `openid profile email offline_access resource.invoke ${DIRECT_TOKEN_SCOPE}`;
|
|
28
|
+
var EXPIRY_MARGIN_MS = 3 * 60 * 1e3;
|
|
29
|
+
function randomValue() {
|
|
30
|
+
return randomBytes(32).toString("base64url");
|
|
31
|
+
}
|
|
32
|
+
function authorizationResultFromCallback(url, expectedState) {
|
|
33
|
+
const code = url.searchParams.get("code");
|
|
34
|
+
if (!code)
|
|
35
|
+
throw new Error("Missing authorization code");
|
|
36
|
+
const state = url.searchParams.get("state");
|
|
37
|
+
if (!state)
|
|
38
|
+
throw new Error("Missing OAuth state");
|
|
39
|
+
if (state !== expectedState)
|
|
40
|
+
throw new Error("OAuth state mismatch");
|
|
41
|
+
const clientId = url.searchParams.get("client_id")?.trim();
|
|
42
|
+
if (!clientId)
|
|
43
|
+
throw new Error("OpenAI OAuth registration callback did not contain an issued client ID");
|
|
44
|
+
return { code, clientId };
|
|
45
|
+
}
|
|
46
|
+
function authorizationResultFromManualInput(input, expectedState) {
|
|
47
|
+
let url;
|
|
48
|
+
try {
|
|
49
|
+
url = new URL(input.trim());
|
|
50
|
+
} catch {
|
|
51
|
+
throw new Error("Paste the full callback URL from the browser");
|
|
52
|
+
}
|
|
53
|
+
const expected = new URL(REDIRECT_URI);
|
|
54
|
+
if (url.origin !== expected.origin || url.pathname !== expected.pathname) {
|
|
55
|
+
throw new Error(`The pasted callback URL must start with ${REDIRECT_URI}`);
|
|
56
|
+
}
|
|
57
|
+
const error = url.searchParams.get("error");
|
|
58
|
+
if (error)
|
|
59
|
+
throw new Error(`ChatGPT authorization failed: ${error}`);
|
|
60
|
+
return authorizationResultFromCallback(url, expectedState);
|
|
61
|
+
}
|
|
62
|
+
function sendHtml(response, status, body) {
|
|
63
|
+
response.writeHead(status, { "Content-Type": "text/html; charset=utf-8" });
|
|
64
|
+
response.end(body);
|
|
65
|
+
}
|
|
66
|
+
function startCallbackServer(expectedState) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
let resolveResult;
|
|
69
|
+
let rejectResult;
|
|
70
|
+
const result = new Promise((resolveAuthorization, rejectAuthorization) => {
|
|
71
|
+
resolveResult = resolveAuthorization;
|
|
72
|
+
rejectResult = rejectAuthorization;
|
|
73
|
+
});
|
|
74
|
+
const server = createServer((request, response) => {
|
|
75
|
+
try {
|
|
76
|
+
const url = new URL(request.url || "", REDIRECT_URI);
|
|
77
|
+
if (url.pathname !== CALLBACK_PATH) {
|
|
78
|
+
sendHtml(response, 404, oauthErrorHtml("Callback route not found."));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const error = url.searchParams.get("error");
|
|
82
|
+
if (error) {
|
|
83
|
+
sendHtml(response, 400, oauthErrorHtml("ChatGPT was not connected.", `Error: ${error}`));
|
|
84
|
+
rejectResult(new Error(`ChatGPT authorization failed: ${error}`));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
let authorizationResult;
|
|
88
|
+
try {
|
|
89
|
+
authorizationResult = authorizationResultFromCallback(url, expectedState);
|
|
90
|
+
} catch (error2) {
|
|
91
|
+
const message = error2 instanceof Error ? error2.message : "Invalid callback";
|
|
92
|
+
sendHtml(response, 400, oauthErrorHtml(message));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
sendHtml(response, 200, oauthSuccessHtml("ChatGPT authentication completed. You can close this window."));
|
|
96
|
+
resolveResult(authorizationResult);
|
|
97
|
+
} catch {
|
|
98
|
+
sendHtml(response, 500, oauthErrorHtml("Internal error while processing the callback."));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
server.once("error", reject);
|
|
102
|
+
server.listen(CALLBACK_PORT, CALLBACK_HOST, () => {
|
|
103
|
+
server.removeListener("error", reject);
|
|
104
|
+
server.on("error", rejectResult);
|
|
105
|
+
resolve({ server, result });
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function requestToken(body, signal) {
|
|
110
|
+
const response = await fetch(TOKEN_URL, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: {
|
|
113
|
+
accept: "application/json",
|
|
114
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
115
|
+
},
|
|
116
|
+
body,
|
|
117
|
+
signal
|
|
118
|
+
});
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
const responseBody = await response.text().catch(() => "");
|
|
121
|
+
throw new Error(`OpenAI OAuth token request failed (${response.status}): ${responseBody || response.statusText}`);
|
|
122
|
+
}
|
|
123
|
+
const data = await response.json();
|
|
124
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
125
|
+
throw new Error("OpenAI OAuth token response must be an object");
|
|
126
|
+
}
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
function requireTokenString(value, field) {
|
|
130
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
131
|
+
throw new Error(`OpenAI OAuth token response has invalid ${field}`);
|
|
132
|
+
}
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
function credentialFromTokenResponse(token, clientId) {
|
|
136
|
+
const access = requireTokenString(token.access_token, "access_token");
|
|
137
|
+
const refresh = requireTokenString(token.refresh_token, "refresh_token");
|
|
138
|
+
const scope = requireTokenString(token.scope, "scope");
|
|
139
|
+
if (typeof token.expires_in !== "number" || !Number.isFinite(token.expires_in) || token.expires_in <= 0) {
|
|
140
|
+
throw new Error("OpenAI OAuth token response has invalid expires_in");
|
|
141
|
+
}
|
|
142
|
+
const scopes = scope.trim().split(/\s+/).filter(Boolean);
|
|
143
|
+
if (!scopes.includes(DIRECT_TOKEN_SCOPE)) {
|
|
144
|
+
throw new Error(`OpenAI OAuth grant did not include ${DIRECT_TOKEN_SCOPE}`);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
type: "oauth",
|
|
148
|
+
access,
|
|
149
|
+
refresh,
|
|
150
|
+
expires: Date.now() + token.expires_in * 1e3 - EXPIRY_MARGIN_MS,
|
|
151
|
+
clientId,
|
|
152
|
+
scopes
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async function exchangeAuthorizationCode(code, verifier, clientId, signal) {
|
|
156
|
+
const token = await requestToken(new URLSearchParams({
|
|
157
|
+
grant_type: "authorization_code",
|
|
158
|
+
client_id: clientId,
|
|
159
|
+
code,
|
|
160
|
+
code_verifier: verifier,
|
|
161
|
+
redirect_uri: REDIRECT_URI,
|
|
162
|
+
resource: RESOURCE
|
|
163
|
+
}), signal);
|
|
164
|
+
if (typeof token.id_token !== "string" || token.id_token.trim().length === 0) {
|
|
165
|
+
throw new Error("OpenAI OAuth token response did not contain an ID token");
|
|
166
|
+
}
|
|
167
|
+
return credentialFromTokenResponse(token, clientId);
|
|
168
|
+
}
|
|
169
|
+
async function refreshAccessToken(credential, signal) {
|
|
170
|
+
const clientId = credential.clientId;
|
|
171
|
+
if (typeof clientId !== "string" || clientId.trim().length === 0) {
|
|
172
|
+
throw new Error("Stored OpenAI OAuth credential does not contain an issued client ID; reconnect ChatGPT");
|
|
173
|
+
}
|
|
174
|
+
const token = await requestToken(new URLSearchParams({
|
|
175
|
+
grant_type: "refresh_token",
|
|
176
|
+
client_id: clientId,
|
|
177
|
+
refresh_token: credential.refresh,
|
|
178
|
+
resource: RESOURCE
|
|
179
|
+
}), signal);
|
|
180
|
+
return credentialFromTokenResponse(token, clientId);
|
|
181
|
+
}
|
|
182
|
+
function agentHostId(deviceId) {
|
|
183
|
+
if (!deviceId || !UUID_PATTERN.test(deviceId)) {
|
|
184
|
+
throw new Error("Sign in with ChatGPT requires a device ID (UUID) for this installation");
|
|
185
|
+
}
|
|
186
|
+
return `urn:uuid:${deviceId.toLowerCase()}`;
|
|
187
|
+
}
|
|
188
|
+
async function loginOpenAIChatGPT(interaction, options) {
|
|
189
|
+
const hostId = agentHostId(options?.getDeviceId?.());
|
|
190
|
+
const { verifier, challenge } = await generatePKCE();
|
|
191
|
+
const state = randomValue();
|
|
192
|
+
const nonce = randomValue();
|
|
193
|
+
const callback = await startCallbackServer(state).catch((error) => {
|
|
194
|
+
if (!(error instanceof Error && "code" in error && error.code === "EADDRINUSE"))
|
|
195
|
+
throw error;
|
|
196
|
+
throw new Error(`Port ${CALLBACK_PORT} is in use, probably by an unfinished login in another pi session or by the Codex CLI. Cancel that login and try again.`);
|
|
197
|
+
});
|
|
198
|
+
const authorizationUrl = new URL(AUTHORIZE_URL);
|
|
199
|
+
authorizationUrl.search = new URLSearchParams({
|
|
200
|
+
client_id: DYNAMIC_CLIENT_ID,
|
|
201
|
+
agent_name_hint: options?.agentName ?? AGENT_NAME_HINT,
|
|
202
|
+
ext_agent_host_id: hostId,
|
|
203
|
+
response_type: "code",
|
|
204
|
+
redirect_uri: REDIRECT_URI,
|
|
205
|
+
resource: RESOURCE,
|
|
206
|
+
scope: SCOPE,
|
|
207
|
+
state,
|
|
208
|
+
code_challenge: challenge,
|
|
209
|
+
code_challenge_method: "S256",
|
|
210
|
+
nonce
|
|
211
|
+
}).toString();
|
|
212
|
+
interaction.notify({
|
|
213
|
+
type: "auth_url",
|
|
214
|
+
url: authorizationUrl.toString(),
|
|
215
|
+
instructions: "Complete sign-in in your browser. If the callback does not complete, paste the final redirect URL here."
|
|
216
|
+
});
|
|
217
|
+
const manualAbort = new AbortController();
|
|
218
|
+
const manualCode = interaction.prompt({
|
|
219
|
+
type: "manual_code",
|
|
220
|
+
message: "Complete login in your browser, or paste the final redirect URL here:",
|
|
221
|
+
placeholder: REDIRECT_URI,
|
|
222
|
+
signal: AbortSignal.any([manualAbort.signal, interaction.signal])
|
|
223
|
+
}).then((input) => authorizationResultFromManualInput(input, state));
|
|
224
|
+
try {
|
|
225
|
+
const result = await Promise.race([callback.result, manualCode]);
|
|
226
|
+
interaction.notify({ type: "progress", message: "Exchanging authorization code for tokens..." });
|
|
227
|
+
return await exchangeAuthorizationCode(result.code, verifier, result.clientId, interaction.signal);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (interaction.signal.aborted)
|
|
230
|
+
throw new Error("Login cancelled");
|
|
231
|
+
throw error;
|
|
232
|
+
} finally {
|
|
233
|
+
manualAbort.abort();
|
|
234
|
+
callback.server.close();
|
|
235
|
+
callback.server.closeAllConnections();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
var openaiChatGPTOAuth = {
|
|
239
|
+
name: "OpenAI (ChatGPT subscription)",
|
|
240
|
+
isSubscription: true,
|
|
241
|
+
loginLabel: "Sign in with ChatGPT",
|
|
242
|
+
login: loginOpenAIChatGPT,
|
|
243
|
+
refresh: refreshAccessToken,
|
|
244
|
+
async toAuth(credential) {
|
|
245
|
+
return { apiKey: credential.access };
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
export {
|
|
249
|
+
openaiChatGPTOAuth
|
|
250
|
+
};
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { createRequire as __nerveCreateRequire } from "node:module";
|
|
2
2
|
const require = __nerveCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
applyOpenRouterReportedCost,
|
|
5
|
+
isOpenRouterModel
|
|
6
|
+
} from "./chunk-N4OXAS3A.js";
|
|
3
7
|
import {
|
|
4
8
|
buildCopilotDynamicHeaders,
|
|
5
9
|
hasCopilotVisionInput
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TQURLRHD.js";
|
|
7
11
|
import {
|
|
8
12
|
clampOpenAIPromptCacheKey
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import {
|
|
11
|
-
shortHash
|
|
12
|
-
} from "./chunk-KSZJ3HGD.js";
|
|
13
|
+
} from "./chunk-KUFIFCB4.js";
|
|
13
14
|
import {
|
|
14
15
|
OpenAI
|
|
15
16
|
} from "./chunk-NW3DH7IK.js";
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from "./chunk-RUZ2UAYH.js";
|
|
18
|
+
shortHash
|
|
19
|
+
} from "./chunk-LP4APBBQ.js";
|
|
20
20
|
import {
|
|
21
21
|
appendGrammarToolInputJsonDelta,
|
|
22
22
|
buildBaseOptions,
|
|
23
23
|
clampThinkingBudgetToAnswerRoom,
|
|
24
|
+
closeGrammarToolInputJson,
|
|
24
25
|
createGrammarToolInputProperties,
|
|
25
26
|
getGrammarToolInput,
|
|
26
27
|
getJsonSchemaToolParameters,
|
|
@@ -29,41 +30,46 @@ import {
|
|
|
29
30
|
resolveSamplingParams,
|
|
30
31
|
thinkingBudgetForLevel,
|
|
31
32
|
transformMessages
|
|
32
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-Z6AY5VOZ.js";
|
|
33
34
|
import {
|
|
34
35
|
sanitizeSurrogates
|
|
35
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-TSAUBRRU.js";
|
|
37
|
+
import {
|
|
38
|
+
retryProviderRequest
|
|
39
|
+
} from "./chunk-3CZXUKLG.js";
|
|
36
40
|
import {
|
|
37
41
|
formatProviderError,
|
|
38
42
|
normalizeProviderError
|
|
39
|
-
} from "./chunk-
|
|
40
|
-
import {
|
|
41
|
-
retryProviderRequest
|
|
42
|
-
} from "./chunk-SQ7CWNIT.js";
|
|
43
|
+
} from "./chunk-PVPJAGWR.js";
|
|
43
44
|
import {
|
|
44
45
|
headersToRecord
|
|
45
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-6IHXVT5H.js";
|
|
46
47
|
import {
|
|
47
48
|
getProviderEnvValue
|
|
48
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-JBEWFFOK.js";
|
|
50
|
+
import {
|
|
51
|
+
ToolCallArgumentsStream
|
|
52
|
+
} from "./chunk-BG2KGLIA.js";
|
|
49
53
|
import {
|
|
50
54
|
calculateCost,
|
|
51
55
|
clampThinkingLevel,
|
|
52
56
|
getDeclaredTools,
|
|
53
|
-
getSystemMessageText,
|
|
54
|
-
renderSystemMessageUpdate,
|
|
55
57
|
resolveTranscript,
|
|
56
58
|
resolveTranscriptTools
|
|
57
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-W7LEYYFH.js";
|
|
58
60
|
import {
|
|
59
61
|
AssistantMessageEventStream
|
|
60
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-DDBE2VLT.js";
|
|
61
63
|
import {
|
|
62
64
|
getIdentityHeaders
|
|
63
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-Q3C7TQ2M.js";
|
|
66
|
+
import {
|
|
67
|
+
getSystemMessageText,
|
|
68
|
+
renderSystemMessageUpdate
|
|
69
|
+
} from "./chunk-U5KGV63C.js";
|
|
64
70
|
import "./chunk-CWESUMYQ.js";
|
|
65
71
|
|
|
66
|
-
// node_modules/.pnpm/@earendil-works+pi-ai@1.
|
|
72
|
+
// node_modules/.pnpm/@earendil-works+pi-ai@1.5.2_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_b842a8cec34a633ed5f728049ae89b72/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js
|
|
67
73
|
function hasHeader(headers, name) {
|
|
68
74
|
if (!headers)
|
|
69
75
|
return false;
|
|
@@ -236,23 +242,14 @@ var stream = (model, context, options) => {
|
|
|
236
242
|
let hasFinishReason = false;
|
|
237
243
|
const toolCallBlocksByIndex = /* @__PURE__ */ new Map();
|
|
238
244
|
const toolCallBlocksById = /* @__PURE__ */ new Map();
|
|
245
|
+
const toolCallStates = /* @__PURE__ */ new Map();
|
|
239
246
|
const blocks = output.content;
|
|
240
247
|
const getContentIndex = (block) => blocks.indexOf(block);
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return typeof value === "string" ? value : "";
|
|
247
|
-
};
|
|
248
|
-
const appendCustomToolCallInput = (block, nextInput, close) => {
|
|
249
|
-
const customInput = block.customInput;
|
|
250
|
-
if (!customInput)
|
|
251
|
-
return void 0;
|
|
252
|
-
const delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);
|
|
253
|
-
block.arguments = { [customInput.property]: nextInput };
|
|
254
|
-
return delta;
|
|
255
|
-
};
|
|
248
|
+
const customInput = (property) => ({
|
|
249
|
+
kind: "custom",
|
|
250
|
+
property,
|
|
251
|
+
buffer: { input: "", started: false, closed: false }
|
|
252
|
+
});
|
|
256
253
|
const finishBlock = (block) => {
|
|
257
254
|
const contentIndex = getContentIndex(block);
|
|
258
255
|
if (contentIndex === -1) {
|
|
@@ -274,8 +271,10 @@ var stream = (model, context, options) => {
|
|
|
274
271
|
partial: output
|
|
275
272
|
});
|
|
276
273
|
} else if (block.type === "toolCall") {
|
|
277
|
-
|
|
278
|
-
|
|
274
|
+
const input = toolCallStates.get(block).input;
|
|
275
|
+
toolCallStates.delete(block);
|
|
276
|
+
if (input.kind === "custom") {
|
|
277
|
+
const delta = closeGrammarToolInputJson(input.buffer, input.property, void 0);
|
|
279
278
|
if (delta !== void 0) {
|
|
280
279
|
stream2.push({
|
|
281
280
|
type: "toolcall_delta",
|
|
@@ -285,11 +284,8 @@ var stream = (model, context, options) => {
|
|
|
285
284
|
});
|
|
286
285
|
}
|
|
287
286
|
} else {
|
|
288
|
-
Object.assign(block,
|
|
287
|
+
Object.assign(block, input.arguments.finish());
|
|
289
288
|
}
|
|
290
|
-
delete block.partialArgs;
|
|
291
|
-
delete block.customInput;
|
|
292
|
-
delete block.streamIndex;
|
|
293
289
|
stream2.push({
|
|
294
290
|
type: "toolcall_end",
|
|
295
291
|
contentIndex,
|
|
@@ -327,16 +323,16 @@ var stream = (model, context, options) => {
|
|
|
327
323
|
}
|
|
328
324
|
if (!block) {
|
|
329
325
|
const customInputProperty = toolCall.custom && !toolCall.function ? grammarToolInputProperties.get(name) ?? "input" : void 0;
|
|
330
|
-
const hasCustomInput = customInputProperty !== void 0;
|
|
331
326
|
block = {
|
|
332
327
|
type: "toolCall",
|
|
333
328
|
id: toolCall.id || "",
|
|
334
329
|
name,
|
|
335
|
-
arguments:
|
|
336
|
-
partialArgs: hasCustomInput ? void 0 : "",
|
|
337
|
-
customInput: hasCustomInput ? { property: customInputProperty, jsonBuffer: { input: "", started: false, closed: false } } : void 0,
|
|
338
|
-
streamIndex
|
|
330
|
+
arguments: customInputProperty !== void 0 ? { [customInputProperty]: "" } : {}
|
|
339
331
|
};
|
|
332
|
+
toolCallStates.set(block, {
|
|
333
|
+
streamIndex,
|
|
334
|
+
input: customInputProperty !== void 0 ? customInput(customInputProperty) : { kind: "json", arguments: new ToolCallArgumentsStream() }
|
|
335
|
+
});
|
|
340
336
|
if (streamIndex !== void 0) {
|
|
341
337
|
toolCallBlocksByIndex.set(streamIndex, block);
|
|
342
338
|
}
|
|
@@ -350,8 +346,9 @@ var stream = (model, context, options) => {
|
|
|
350
346
|
partial: output
|
|
351
347
|
});
|
|
352
348
|
}
|
|
353
|
-
|
|
354
|
-
|
|
349
|
+
const state = toolCallStates.get(block);
|
|
350
|
+
if (streamIndex !== void 0 && state.streamIndex === void 0) {
|
|
351
|
+
state.streamIndex = streamIndex;
|
|
355
352
|
toolCallBlocksByIndex.set(streamIndex, block);
|
|
356
353
|
}
|
|
357
354
|
if (toolCall.id) {
|
|
@@ -360,16 +357,12 @@ var stream = (model, context, options) => {
|
|
|
360
357
|
if (!block.name && name) {
|
|
361
358
|
block.name = name;
|
|
362
359
|
}
|
|
363
|
-
if (toolCall.custom && !toolCall.function &&
|
|
360
|
+
if (toolCall.custom && !toolCall.function && state.input.kind !== "custom") {
|
|
364
361
|
const customInputProperty = grammarToolInputProperties.get(block.name) ?? "input";
|
|
365
362
|
block.arguments = { [customInputProperty]: "" };
|
|
366
|
-
|
|
367
|
-
property: customInputProperty,
|
|
368
|
-
jsonBuffer: { input: "", started: false, closed: false }
|
|
369
|
-
};
|
|
370
|
-
delete block.partialArgs;
|
|
363
|
+
state.input = customInput(customInputProperty);
|
|
371
364
|
}
|
|
372
|
-
return block;
|
|
365
|
+
return { block, state };
|
|
373
366
|
};
|
|
374
367
|
for await (const chunk of openaiStream) {
|
|
375
368
|
await options?.onProviderStreamEvent?.(chunk, model);
|
|
@@ -444,7 +437,7 @@ var stream = (model, context, options) => {
|
|
|
444
437
|
}
|
|
445
438
|
if (choice?.delta?.tool_calls) {
|
|
446
439
|
for (const toolCall of choice.delta.tool_calls) {
|
|
447
|
-
const block = ensureToolCallBlock(toolCall);
|
|
440
|
+
const { block, state } = ensureToolCallBlock(toolCall);
|
|
448
441
|
if (!block.id && toolCall.id) {
|
|
449
442
|
block.id = toolCall.id;
|
|
450
443
|
toolCallBlocksById.set(toolCall.id, block);
|
|
@@ -454,13 +447,13 @@ var stream = (model, context, options) => {
|
|
|
454
447
|
block.name = name;
|
|
455
448
|
}
|
|
456
449
|
let delta = "";
|
|
457
|
-
|
|
450
|
+
const input = state.input;
|
|
451
|
+
if (toolCall.function?.arguments && input.kind === "json") {
|
|
458
452
|
delta = toolCall.function.arguments;
|
|
459
|
-
block.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
delta = appendCustomToolCallInput(block, nextInput, false) ?? "";
|
|
453
|
+
block.arguments = input.arguments.append(delta);
|
|
454
|
+
} else if (toolCall.custom?.input && input.kind === "custom") {
|
|
455
|
+
delta = appendGrammarToolInputJsonDelta(input.buffer, input.property, toolCall.custom.input) ?? "";
|
|
456
|
+
block.arguments = { [input.property]: input.buffer.input };
|
|
464
457
|
}
|
|
465
458
|
stream2.push({
|
|
466
459
|
type: "toolcall_delta",
|
|
@@ -497,10 +490,6 @@ var stream = (model, context, options) => {
|
|
|
497
490
|
if (block.type === "thinking") {
|
|
498
491
|
applyStreamedReasoningDetails(block);
|
|
499
492
|
}
|
|
500
|
-
delete block.index;
|
|
501
|
-
delete block.partialArgs;
|
|
502
|
-
delete block.customInput;
|
|
503
|
-
delete block.streamIndex;
|
|
504
493
|
}
|
|
505
494
|
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
506
495
|
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
@@ -567,11 +556,13 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
567
556
|
grammarToolInputProperties
|
|
568
557
|
});
|
|
569
558
|
const cacheControl = getCompatCacheControl(compat, cacheRetention);
|
|
559
|
+
const promptCacheKeyMode = compat.promptCacheKeyMode ?? "auto";
|
|
560
|
+
const supportsPromptCacheKey = promptCacheKeyMode === "enabled" || promptCacheKeyMode === "auto" && (model.baseUrl.includes("api.openai.com") || cacheRetention === "long" && compat.supportsLongCacheRetention);
|
|
570
561
|
const params = {
|
|
571
562
|
model: model.id,
|
|
572
563
|
messages,
|
|
573
564
|
stream: true,
|
|
574
|
-
prompt_cache_key:
|
|
565
|
+
prompt_cache_key: cacheRetention !== "none" && supportsPromptCacheKey ? clampOpenAIPromptCacheKey(options?.sessionId) : void 0,
|
|
575
566
|
prompt_cache_retention: cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0
|
|
576
567
|
};
|
|
577
568
|
if (compat.supportsUsageInStreaming !== false) {
|
|
@@ -595,7 +586,7 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
595
586
|
if (compat.zaiToolStream) {
|
|
596
587
|
params.tool_stream = true;
|
|
597
588
|
}
|
|
598
|
-
} else if (hasToolHistory(context.messages)) {
|
|
589
|
+
} else if (compat.requiresToolsWithToolHistory && hasToolHistory(context.messages)) {
|
|
599
590
|
params.tools = [];
|
|
600
591
|
}
|
|
601
592
|
if (cacheControl) {
|
|
@@ -911,7 +902,7 @@ function convertMessages(model, context, compat, options) {
|
|
|
911
902
|
} else if (msg.role === "assistant") {
|
|
912
903
|
const assistantMsg = {
|
|
913
904
|
role: "assistant",
|
|
914
|
-
content: compat.requiresAssistantAfterToolResult ? "" : null
|
|
905
|
+
content: compat.requiresAssistantAfterToolResult || compat.requiresNonNullAssistantContent ? "" : null
|
|
915
906
|
};
|
|
916
907
|
const assistantTextParts = msg.content.filter(isTextContentBlock).filter((block) => block.text.trim().length > 0).map((block) => ({
|
|
917
908
|
type: "text",
|
|
@@ -1087,6 +1078,9 @@ function parseChunkUsage(rawUsage, model) {
|
|
|
1087
1078
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
1088
1079
|
};
|
|
1089
1080
|
calculateCost(model, usage);
|
|
1081
|
+
if (isOpenRouterModel(model)) {
|
|
1082
|
+
applyOpenRouterReportedCost(usage, rawUsage);
|
|
1083
|
+
}
|
|
1090
1084
|
return usage;
|
|
1091
1085
|
}
|
|
1092
1086
|
function mapStopReason(reason) {
|
|
@@ -1139,6 +1133,8 @@ function detectCompat(model) {
|
|
|
1139
1133
|
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
|
1140
1134
|
requiresToolResultName: false,
|
|
1141
1135
|
requiresAssistantAfterToolResult: false,
|
|
1136
|
+
requiresNonNullAssistantContent: false,
|
|
1137
|
+
requiresToolsWithToolHistory: false,
|
|
1142
1138
|
requiresThinkingAsText: false,
|
|
1143
1139
|
requiresReasoningContentOnAssistantMessages: isDeepSeek,
|
|
1144
1140
|
thinkingFormat: isDeepSeek ? "deepseek" : isZai ? "zai" : isTogether ? "together" : isAntLing ? "ant-ling" : isOpenRouter ? "openrouter" : "openai",
|
|
@@ -1173,6 +1169,8 @@ function getCompat(model) {
|
|
|
1173
1169
|
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
|
1174
1170
|
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
|
1175
1171
|
requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
1172
|
+
requiresNonNullAssistantContent: model.compat.requiresNonNullAssistantContent ?? detected.requiresNonNullAssistantContent,
|
|
1173
|
+
requiresToolsWithToolHistory: model.compat.requiresToolsWithToolHistory ?? detected.requiresToolsWithToolHistory,
|
|
1176
1174
|
requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
|
|
1177
1175
|
requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ?? detected.requiresReasoningContentOnAssistantMessages,
|
|
1178
1176
|
thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
|
|
@@ -1191,6 +1189,7 @@ function getCompat(model) {
|
|
|
1191
1189
|
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
1192
1190
|
sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
|
|
1193
1191
|
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
1192
|
+
promptCacheKeyMode: model.compat.promptCacheKeyMode,
|
|
1194
1193
|
vllmPriority: model.compat.vllmPriority
|
|
1195
1194
|
};
|
|
1196
1195
|
}
|