privateer-agent 0.15.4 → 0.15.6
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 +11 -0
- package/bin/boot-bundle.d.mts +2 -0
- package/bin/boot-bundle.mjs +44 -0
- package/bin/fresh-supervisor.d.mts +5 -1
- package/bin/fresh-supervisor.mjs +47 -10
- package/bin/privateer-launch.mjs +27 -3
- package/bin/privateer-subagent.mjs +5 -2
- package/bin/privateer-verify.mjs +12 -0
- package/bin/session-recovery.d.mts +53 -0
- package/bin/session-recovery.mjs +240 -0
- package/bin/session-seal-preload.mjs +17 -0
- package/bin/session-seal.d.mts +25 -0
- package/bin/session-seal.mjs +242 -0
- package/dist-boot/boot.mjs +3 -0
- package/dist-boot/c-27JKSMWL.mjs +1460 -0
- package/dist-boot/c-2BMRFV24.mjs +269 -0
- package/dist-boot/c-2CTF6JA3.mjs +166 -0
- package/dist-boot/c-2G3BBHRJ.mjs +84 -0
- package/dist-boot/c-2IDLKXX6.mjs +250 -0
- package/dist-boot/c-2NJD5VYM.mjs +8 -0
- package/dist-boot/c-2S5EEQPW.mjs +1602 -0
- package/dist-boot/c-2WRDCUVI.mjs +25 -0
- package/dist-boot/c-2YN3M256.mjs +14 -0
- package/dist-boot/c-37GM3GMU.mjs +187 -0
- package/dist-boot/c-3STKRSVO.mjs +2480 -0
- package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
- package/dist-boot/c-3UVHLQDJ.mjs +225 -0
- package/dist-boot/c-42PUUZYC.mjs +697 -0
- package/dist-boot/c-4D5UMWVW.mjs +683 -0
- package/dist-boot/c-4ETZRMTA.mjs +46 -0
- package/dist-boot/c-4QT25BD5.mjs +1482 -0
- package/dist-boot/c-4WVR32AP.mjs +2579 -0
- package/dist-boot/c-5EMM567G.mjs +152 -0
- package/dist-boot/c-5FA4CV63.mjs +145 -0
- package/dist-boot/c-5GV3X3RB.mjs +14 -0
- package/dist-boot/c-5JCEPRIY.mjs +52 -0
- package/dist-boot/c-5NDKIIWT.mjs +16 -0
- package/dist-boot/c-5QL3AR26.mjs +4665 -0
- package/dist-boot/c-5XY6MFKN.mjs +5142 -0
- package/dist-boot/c-65UZIZC7.mjs +2897 -0
- package/dist-boot/c-6FUXKHOK.mjs +1969 -0
- package/dist-boot/c-6JHWQE4V.mjs +18242 -0
- package/dist-boot/c-6LOBR4I6.mjs +5280 -0
- package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
- package/dist-boot/c-6ZO2SADQ.mjs +178 -0
- package/dist-boot/c-6ZORVVZP.mjs +1449 -0
- package/dist-boot/c-76QH4UCP.mjs +2441 -0
- package/dist-boot/c-77GO5L5Y.mjs +20982 -0
- package/dist-boot/c-7M23XFTN.mjs +5052 -0
- package/dist-boot/c-7TC367E2.mjs +32 -0
- package/dist-boot/c-7UOG7POX.mjs +1524 -0
- package/dist-boot/c-7VHP3FLN.mjs +376 -0
- package/dist-boot/c-A73JHZP2.mjs +13207 -0
- package/dist-boot/c-ABXULAFL.mjs +71 -0
- package/dist-boot/c-ANDD2AQO.mjs +74 -0
- package/dist-boot/c-AOY77AZL.mjs +1430 -0
- package/dist-boot/c-AXEPZ22I.mjs +108 -0
- package/dist-boot/c-B2Y7VNHU.mjs +427 -0
- package/dist-boot/c-B7VJUH73.mjs +77 -0
- package/dist-boot/c-BFW6CDVL.mjs +24 -0
- package/dist-boot/c-BHNIF2AR.mjs +188 -0
- package/dist-boot/c-BKF2O6BL.mjs +23 -0
- package/dist-boot/c-BOZXFTZN.mjs +8 -0
- package/dist-boot/c-BRNYJWZL.mjs +28 -0
- package/dist-boot/c-C3N4Z2HO.mjs +93 -0
- package/dist-boot/c-C4IV7ZFG.mjs +717 -0
- package/dist-boot/c-C5NK6UYV.mjs +793 -0
- package/dist-boot/c-C67644MB.mjs +1659 -0
- package/dist-boot/c-C6S2YB53.mjs +620 -0
- package/dist-boot/c-CDBEJSBF.mjs +37 -0
- package/dist-boot/c-CG47HBKU.mjs +435 -0
- package/dist-boot/c-CKCTWCT5.mjs +51 -0
- package/dist-boot/c-CN77DCGF.mjs +60 -0
- package/dist-boot/c-CRBXNKFO.mjs +1795 -0
- package/dist-boot/c-CRIHASQ6.mjs +973 -0
- package/dist-boot/c-CU4NGAUO.mjs +3786 -0
- package/dist-boot/c-CWRFLGQU.mjs +1883 -0
- package/dist-boot/c-CYQB2USO.mjs +32 -0
- package/dist-boot/c-DEE67DJO.mjs +379 -0
- package/dist-boot/c-DIFDBYOP.mjs +1258 -0
- package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
- package/dist-boot/c-DR7XQI32.mjs +381 -0
- package/dist-boot/c-DTGPSB46.mjs +14666 -0
- package/dist-boot/c-DTHDNA4P.mjs +320 -0
- package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
- package/dist-boot/c-E66Z2TI7.mjs +203 -0
- package/dist-boot/c-EBU6RLRV.mjs +1527 -0
- package/dist-boot/c-EBZZNGSF.mjs +432 -0
- package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
- package/dist-boot/c-EQBKXWNX.mjs +15829 -0
- package/dist-boot/c-EUEPIW4S.mjs +574 -0
- package/dist-boot/c-EX4YVWAT.mjs +378 -0
- package/dist-boot/c-EYZGSAJU.mjs +98 -0
- package/dist-boot/c-F75VRKY4.mjs +172 -0
- package/dist-boot/c-FH4NXKHV.mjs +177 -0
- package/dist-boot/c-FHNUCTEM.mjs +140 -0
- package/dist-boot/c-FJ5T42DS.mjs +5349 -0
- package/dist-boot/c-FPCNRL7G.mjs +1728 -0
- package/dist-boot/c-G4DLN7Q4.mjs +8 -0
- package/dist-boot/c-G56GYQFZ.mjs +2507 -0
- package/dist-boot/c-GLIOERDQ.mjs +1200 -0
- package/dist-boot/c-GMJ5HUBM.mjs +14 -0
- package/dist-boot/c-H3HSGMAQ.mjs +461 -0
- package/dist-boot/c-HIKTO6P7.mjs +275 -0
- package/dist-boot/c-I2MCJ34O.mjs +464 -0
- package/dist-boot/c-I3C6LBW4.mjs +765 -0
- package/dist-boot/c-I54OKQHW.mjs +387 -0
- package/dist-boot/c-IFSP3R4D.mjs +80 -0
- package/dist-boot/c-IZK77VB7.mjs +171 -0
- package/dist-boot/c-J3Y25UGE.mjs +54 -0
- package/dist-boot/c-J5IESS7W.mjs +27750 -0
- package/dist-boot/c-JJWZBY7L.mjs +254 -0
- package/dist-boot/c-JKTFXTGF.mjs +463 -0
- package/dist-boot/c-JN57AXQ4.mjs +77 -0
- package/dist-boot/c-KFIO6LUW.mjs +1096 -0
- package/dist-boot/c-KIEMEFWW.mjs +478 -0
- package/dist-boot/c-KIVXWBYD.mjs +28 -0
- package/dist-boot/c-KP6CRIP4.mjs +580 -0
- package/dist-boot/c-L26VOJX4.mjs +11558 -0
- package/dist-boot/c-L5GHWG5G.mjs +5988 -0
- package/dist-boot/c-M7NSQAKK.mjs +353 -0
- package/dist-boot/c-MCEWOPBW.mjs +56 -0
- package/dist-boot/c-MGPIEG7I.mjs +20 -0
- package/dist-boot/c-NREXJV3M.mjs +393 -0
- package/dist-boot/c-O5PP6CTX.mjs +162 -0
- package/dist-boot/c-OBQDHSXM.mjs +1774 -0
- package/dist-boot/c-OLQHHDD4.mjs +21 -0
- package/dist-boot/c-OXW4JQQH.mjs +319 -0
- package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
- package/dist-boot/c-P4PQZVV5.mjs +948 -0
- package/dist-boot/c-P63T3XL2.mjs +26373 -0
- package/dist-boot/c-P6N5DQGZ.mjs +194 -0
- package/dist-boot/c-P7MLKQFC.mjs +58 -0
- package/dist-boot/c-PB3PZJL5.mjs +1276 -0
- package/dist-boot/c-PTN4S6G2.mjs +1259 -0
- package/dist-boot/c-PYCE5J7U.mjs +1083 -0
- package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
- package/dist-boot/c-QUXMETGG.mjs +68 -0
- package/dist-boot/c-RDMJZCOX.mjs +356 -0
- package/dist-boot/c-ROGJK76M.mjs +17 -0
- package/dist-boot/c-RQJJ26T4.mjs +708 -0
- package/dist-boot/c-RSKCUPJF.mjs +7559 -0
- package/dist-boot/c-RVJU4O6P.mjs +37 -0
- package/dist-boot/c-S2RVHR3M.mjs +165 -0
- package/dist-boot/c-SKMK3PEE.mjs +91120 -0
- package/dist-boot/c-TI7SM4EG.mjs +20 -0
- package/dist-boot/c-TILJ6GXD.mjs +1235 -0
- package/dist-boot/c-TT6BCUJD.mjs +114 -0
- package/dist-boot/c-U4ITOXAN.mjs +2107 -0
- package/dist-boot/c-UGERXVO2.mjs +7120 -0
- package/dist-boot/c-UPBH5AXY.mjs +1363 -0
- package/dist-boot/c-US2PUNZL.mjs +597 -0
- package/dist-boot/c-UU4WZPPE.mjs +20 -0
- package/dist-boot/c-UWVIYPQS.mjs +39 -0
- package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
- package/dist-boot/c-V5MRVK47.mjs +351 -0
- package/dist-boot/c-V6CL266R.mjs +1755 -0
- package/dist-boot/c-VJTMFKYE.mjs +14975 -0
- package/dist-boot/c-VJTRUKIB.mjs +773 -0
- package/dist-boot/c-W4IFSHPW.mjs +43 -0
- package/dist-boot/c-WETGB2CF.mjs +113 -0
- package/dist-boot/c-WO3QSZUU.mjs +1337 -0
- package/dist-boot/c-WQLH73TY.mjs +242 -0
- package/dist-boot/c-XL735JW5.mjs +500 -0
- package/dist-boot/c-Y7HADL5B.mjs +1107 -0
- package/dist-boot/c-YGQHSVSK.mjs +41 -0
- package/dist-boot/c-YMP2AMEB.mjs +10350 -0
- package/dist-boot/c-YRDO2WEF.mjs +12012 -0
- package/dist-boot/c-YUSTRATJ.mjs +8 -0
- package/dist-boot/c-Z2262R22.mjs +2697 -0
- package/dist-boot/c-Z4ALQMJC.mjs +709 -0
- package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
- package/dist-boot/c-ZDZUKXF7.mjs +874 -0
- package/dist-boot/c-ZJYLGIC3.mjs +32 -0
- package/dist-boot/c-ZNA5CDMI.mjs +77 -0
- package/dist-boot/c-ZSO6DI3M.mjs +204 -0
- package/dist-boot/c-ZWUVHKMK.mjs +100 -0
- package/dist-boot/c-ZY4MESEW.mjs +832 -0
- package/dist-boot/c-ZZ5REI4L.mjs +329 -0
- package/dist-boot/cli.mjs +51 -0
- package/dist-boot/ext-anthropic-attribution.mjs +207 -0
- package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
- package/dist-boot/ext-pi-subagents.mjs +37 -0
- package/dist-boot/ext-privateer-account.mjs +4426 -0
- package/dist-boot/ext-privateer-brand.mjs +5274 -0
- package/dist-boot/ext-privateer-codemode.mjs +37 -0
- package/dist-boot/ext-privateer-computer.mjs +626 -0
- package/dist-boot/ext-privateer-connect.mjs +1862 -0
- package/dist-boot/ext-privateer-context.mjs +323 -0
- package/dist-boot/ext-privateer-desktop.mjs +92 -0
- package/dist-boot/ext-privateer-final-audit.mjs +48 -0
- package/dist-boot/ext-privateer-fresh.mjs +81 -0
- package/dist-boot/ext-privateer-gate.mjs +5959 -0
- package/dist-boot/ext-privateer-hints.mjs +236 -0
- package/dist-boot/ext-privateer-media.mjs +2626 -0
- package/dist-boot/ext-privateer-models.mjs +3397 -0
- package/dist-boot/ext-privateer-posture.mjs +3006 -0
- package/dist-boot/ext-privateer-privacy.mjs +4578 -0
- package/dist-boot/ext-privateer-recovery.mjs +287 -0
- package/dist-boot/ext-privateer-speak.mjs +4754 -0
- package/dist-boot/ext-privateer-terminals.mjs +725 -0
- package/dist-boot/ext-privateer-tools.mjs +528 -0
- package/dist-boot/ext-privateer-truncation.mjs +74 -0
- package/dist-boot/ext-privateer-update.mjs +210 -0
- package/dist-boot/ext-privateer-vision.mjs +148 -0
- package/dist-boot/ext-privateer-web.mjs +543 -0
- package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
- package/dist-boot/manifest.json +9 -0
- package/extensions/privateer-brand.ts +3 -1
- package/extensions/privateer-context.ts +4 -2
- package/extensions/privateer-final-audit.ts +17 -0
- package/extensions/privateer-gate.ts +55 -9
- package/extensions/privateer-recovery.ts +175 -0
- package/extensions/privateer-web.ts +4 -4
- package/package.json +3 -1
- package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
- package/patches/pi-background-tasks+2.6.10.patch +91 -7
- package/src/cli/chat.ts +7 -1
- package/src/config/moatManifest.json +2 -0
- package/src/config/whatsNew.json +4 -4
- package/src/context.ts +33 -5
- package/src/engine/finalAudit.ts +38 -0
- package/src/engine/stallWatchdog.ts +8 -1
- package/src/providers/account.ts +34 -3
- package/src/remote/attentionPush.ts +40 -0
- package/src/remote/liveTaskSession.ts +7 -1
- package/src/remote/relayClient.ts +38 -4
- package/src/remote/remoteBridge.ts +17 -0
- package/src/remote/transcriptSnapshot.ts +104 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
convertResponsesMessages,
|
|
4
|
+
convertResponsesTools,
|
|
5
|
+
processResponsesStream
|
|
6
|
+
} from "./c-4D5UMWVW.mjs";
|
|
7
|
+
import {
|
|
8
|
+
clampOpenAIPromptCacheKey
|
|
9
|
+
} from "./c-UU4WZPPE.mjs";
|
|
10
|
+
import "./c-BKF2O6BL.mjs";
|
|
11
|
+
import {
|
|
12
|
+
OpenAI
|
|
13
|
+
} from "./c-Q4HYCRLB.mjs";
|
|
14
|
+
import {
|
|
15
|
+
formatProviderError,
|
|
16
|
+
normalizeProviderError
|
|
17
|
+
} from "./c-ZWUVHKMK.mjs";
|
|
18
|
+
import {
|
|
19
|
+
buildCopilotDynamicHeaders,
|
|
20
|
+
hasCopilotVisionInput
|
|
21
|
+
} from "./c-UWVIYPQS.mjs";
|
|
22
|
+
import {
|
|
23
|
+
buildBaseOptions,
|
|
24
|
+
createGrammarToolInputProperties,
|
|
25
|
+
getPiUserAgent,
|
|
26
|
+
resolveSamplingParams
|
|
27
|
+
} from "./c-C6S2YB53.mjs";
|
|
28
|
+
import "./c-5GV3X3RB.mjs";
|
|
29
|
+
import {
|
|
30
|
+
retryProviderRequest
|
|
31
|
+
} from "./c-EYZGSAJU.mjs";
|
|
32
|
+
import {
|
|
33
|
+
headersToRecord
|
|
34
|
+
} from "./c-ZJYLGIC3.mjs";
|
|
35
|
+
import {
|
|
36
|
+
getProviderEnvValue
|
|
37
|
+
} from "./c-CDBEJSBF.mjs";
|
|
38
|
+
import "./c-DEE67DJO.mjs";
|
|
39
|
+
import {
|
|
40
|
+
clampThinkingLevel,
|
|
41
|
+
getDeclaredTools,
|
|
42
|
+
resolveTranscript,
|
|
43
|
+
resolveTranscriptTools
|
|
44
|
+
} from "./c-WO3QSZUU.mjs";
|
|
45
|
+
import {
|
|
46
|
+
AssistantMessageEventStream
|
|
47
|
+
} from "./c-S2RVHR3M.mjs";
|
|
48
|
+
import {
|
|
49
|
+
__name
|
|
50
|
+
} from "./c-CN77DCGF.mjs";
|
|
51
|
+
|
|
52
|
+
// node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js
|
|
53
|
+
var OPENAI_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode"]);
|
|
54
|
+
var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
55
|
+
var CHATGPT_USAGE_URL = "https://chatgpt.com/settings/usage";
|
|
56
|
+
var CONFIGURATION_UPDATE_REQUEST_EFFORT = "medium";
|
|
57
|
+
function isChatGPTSignIn(model, apiKey) {
|
|
58
|
+
return model.provider === "openai" && model.baseUrl === "https://api.openai.com/v1" && apiKey !== void 0 && !apiKey.startsWith("sk-");
|
|
59
|
+
}
|
|
60
|
+
__name(isChatGPTSignIn, "isChatGPTSignIn");
|
|
61
|
+
function hasHeader(headers, name) {
|
|
62
|
+
if (!headers)
|
|
63
|
+
return false;
|
|
64
|
+
const expected = name.toLowerCase();
|
|
65
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
66
|
+
if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
__name(hasHeader, "hasHeader");
|
|
72
|
+
function getClientApiKey(provider, apiKey, headers) {
|
|
73
|
+
if (apiKey)
|
|
74
|
+
return apiKey;
|
|
75
|
+
if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization"))
|
|
76
|
+
return "unused";
|
|
77
|
+
throw new Error(`No API key for provider: ${provider}`);
|
|
78
|
+
}
|
|
79
|
+
__name(getClientApiKey, "getClientApiKey");
|
|
80
|
+
function detectSessionAffinityFormat(model) {
|
|
81
|
+
return model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai") ? "openrouter" : "openai";
|
|
82
|
+
}
|
|
83
|
+
__name(detectSessionAffinityFormat, "detectSessionAffinityFormat");
|
|
84
|
+
function resolveCacheRetention(cacheRetention, env) {
|
|
85
|
+
if (cacheRetention) {
|
|
86
|
+
return cacheRetention;
|
|
87
|
+
}
|
|
88
|
+
if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") {
|
|
89
|
+
return "long";
|
|
90
|
+
}
|
|
91
|
+
return "short";
|
|
92
|
+
}
|
|
93
|
+
__name(resolveCacheRetention, "resolveCacheRetention");
|
|
94
|
+
function getCompat(model) {
|
|
95
|
+
return {
|
|
96
|
+
supportsDeveloperRole: model.compat?.supportsDeveloperRole ?? true,
|
|
97
|
+
supportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,
|
|
98
|
+
sessionAffinityFormat: model.compat?.sessionAffinityFormat ?? detectSessionAffinityFormat(model),
|
|
99
|
+
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
100
|
+
supportsStrictMode: model.compat?.supportsStrictMode ?? false,
|
|
101
|
+
supportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,
|
|
102
|
+
supportsAdditionalTools: model.compat?.supportsAdditionalTools ?? false,
|
|
103
|
+
supportsToolSearch: model.compat?.supportsToolSearch ?? false,
|
|
104
|
+
supportsExplicitPromptCacheMode: model.compat?.supportsExplicitPromptCacheMode ?? false,
|
|
105
|
+
supportsMaxOutputTokens: model.compat?.supportsMaxOutputTokens ?? true,
|
|
106
|
+
supportsMidConvoEffort: model.compat?.supportsMidConvoEffort ?? false
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
__name(getCompat, "getCompat");
|
|
110
|
+
function getConfigurationUpdateEffort(model, options, compat) {
|
|
111
|
+
if (!compat.supportsMidConvoEffort || !options?.reasoningEffort || // Sign in with ChatGPT rejects configuration_update items.
|
|
112
|
+
isChatGPTSignIn(model, options.apiKey)) {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
return model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
116
|
+
}
|
|
117
|
+
__name(getConfigurationUpdateEffort, "getConfigurationUpdateEffort");
|
|
118
|
+
function getPromptCacheRetention(compat, cacheRetention) {
|
|
119
|
+
return cacheRetention === "long" && compat.supportsLongCacheRetention && !compat.supportsExplicitPromptCacheMode ? "24h" : void 0;
|
|
120
|
+
}
|
|
121
|
+
__name(getPromptCacheRetention, "getPromptCacheRetention");
|
|
122
|
+
function getPromptCacheOptions(compat, cacheRetention) {
|
|
123
|
+
if (!compat.supportsExplicitPromptCacheMode)
|
|
124
|
+
return void 0;
|
|
125
|
+
if (cacheRetention === "none")
|
|
126
|
+
return { mode: "explicit" };
|
|
127
|
+
if (cacheRetention === "long" && compat.supportsLongCacheRetention)
|
|
128
|
+
return { ttl: "30m" };
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
__name(getPromptCacheOptions, "getPromptCacheOptions");
|
|
132
|
+
var stream = /* @__PURE__ */ __name((model, context, options) => {
|
|
133
|
+
const stream2 = new AssistantMessageEventStream();
|
|
134
|
+
const normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
|
|
135
|
+
(async () => {
|
|
136
|
+
const compat = getCompat(model);
|
|
137
|
+
const configurationUpdateEffort = getConfigurationUpdateEffort(model, options, compat);
|
|
138
|
+
const output = {
|
|
139
|
+
role: "assistant",
|
|
140
|
+
content: [],
|
|
141
|
+
api: model.api,
|
|
142
|
+
provider: model.provider,
|
|
143
|
+
model: model.id,
|
|
144
|
+
...configurationUpdateEffort === void 0 ? {} : { providerThinkingLevel: configurationUpdateEffort },
|
|
145
|
+
usage: {
|
|
146
|
+
input: 0,
|
|
147
|
+
output: 0,
|
|
148
|
+
cacheRead: 0,
|
|
149
|
+
cacheWrite: 0,
|
|
150
|
+
totalTokens: 0,
|
|
151
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
152
|
+
},
|
|
153
|
+
stopReason: "pending",
|
|
154
|
+
timestamp: Date.now()
|
|
155
|
+
};
|
|
156
|
+
try {
|
|
157
|
+
const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
158
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
159
|
+
const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
|
|
160
|
+
const grammarToolInputProperties = createGrammarToolInputProperties(getDeclaredTools(normalizedContext.messages), compat.supportsOpenAIGrammarTools);
|
|
161
|
+
const client = createClient(model, normalizedContext, apiKey, options?.headers, options?.fetch, cacheSessionId);
|
|
162
|
+
let params = buildParams(model, normalizedContext, options, compat, grammarToolInputProperties, configurationUpdateEffort);
|
|
163
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
164
|
+
if (nextParams !== void 0) {
|
|
165
|
+
params = nextParams;
|
|
166
|
+
}
|
|
167
|
+
const requestOptions = {
|
|
168
|
+
...options?.signal ? { signal: options.signal } : {},
|
|
169
|
+
...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
|
|
170
|
+
maxRetries: 0
|
|
171
|
+
};
|
|
172
|
+
const { data: openaiStream, response } = await retryProviderRequest(() => client.responses.create(params, requestOptions).withResponse(), {
|
|
173
|
+
maxRetries: options?.maxRetries,
|
|
174
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
175
|
+
signal: options?.signal
|
|
176
|
+
});
|
|
177
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
178
|
+
stream2.push({ type: "start", partial: output });
|
|
179
|
+
await processResponsesStream(openaiStream, output, stream2, model, {
|
|
180
|
+
onProviderStreamEvent: options?.onProviderStreamEvent,
|
|
181
|
+
serviceTier: options?.serviceTier,
|
|
182
|
+
grammarToolInputProperties,
|
|
183
|
+
applyServiceTierPricing: /* @__PURE__ */ __name((usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model), "applyServiceTierPricing")
|
|
184
|
+
});
|
|
185
|
+
if (options?.signal?.aborted) {
|
|
186
|
+
throw new Error("Request was aborted");
|
|
187
|
+
}
|
|
188
|
+
if (output.stopReason === "pending") {
|
|
189
|
+
throw new Error("OpenAI Responses stream ended without a stop reason");
|
|
190
|
+
}
|
|
191
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
192
|
+
throw new Error(output.errorMessage || "An unknown error occurred");
|
|
193
|
+
}
|
|
194
|
+
stream2.push({ type: "done", reason: output.stopReason, message: output });
|
|
195
|
+
stream2.end();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
for (const block of output.content) {
|
|
198
|
+
delete block.index;
|
|
199
|
+
delete block.partialJson;
|
|
200
|
+
delete block.customInput;
|
|
201
|
+
}
|
|
202
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
203
|
+
const errorMessage = formatProviderError(normalizeProviderError(error), `${model.provider === "openai" ? "OpenAI" : model.provider} API error`);
|
|
204
|
+
output.errorMessage = errorMessage.includes("subscription_sharing_usage_limit_exceeded") ? `${errorMessage}
|
|
205
|
+
Check your ChatGPT usage: ${CHATGPT_USAGE_URL}` : errorMessage;
|
|
206
|
+
stream2.push({ type: "error", reason: output.stopReason, error: output });
|
|
207
|
+
stream2.end();
|
|
208
|
+
}
|
|
209
|
+
})();
|
|
210
|
+
return stream2;
|
|
211
|
+
}, "stream");
|
|
212
|
+
var streamSimple = /* @__PURE__ */ __name((model, context, options) => {
|
|
213
|
+
getClientApiKey(model.provider, options?.apiKey, options?.headers);
|
|
214
|
+
const base = {
|
|
215
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
216
|
+
toolChoice: options?.toolChoice
|
|
217
|
+
};
|
|
218
|
+
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
|
|
219
|
+
const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
|
|
220
|
+
return stream(model, context, {
|
|
221
|
+
...base,
|
|
222
|
+
reasoningEffort
|
|
223
|
+
});
|
|
224
|
+
}, "streamSimple");
|
|
225
|
+
function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId) {
|
|
226
|
+
const compat = getCompat(model);
|
|
227
|
+
const headers = { "User-Agent": getPiUserAgent(), ...model.headers };
|
|
228
|
+
if (model.provider === "github-copilot") {
|
|
229
|
+
const hasImages = hasCopilotVisionInput(context.messages);
|
|
230
|
+
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
231
|
+
messages: context.messages,
|
|
232
|
+
hasImages
|
|
233
|
+
});
|
|
234
|
+
Object.assign(headers, copilotHeaders);
|
|
235
|
+
}
|
|
236
|
+
if (sessionId) {
|
|
237
|
+
if (compat.sessionAffinityFormat === "openrouter") {
|
|
238
|
+
headers["x-session-id"] = sessionId;
|
|
239
|
+
} else {
|
|
240
|
+
if (compat.sessionAffinityFormat === "openai") {
|
|
241
|
+
headers.session_id = sessionId;
|
|
242
|
+
}
|
|
243
|
+
headers["x-client-request-id"] = sessionId;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (optionsHeaders) {
|
|
247
|
+
Object.assign(headers, optionsHeaders);
|
|
248
|
+
}
|
|
249
|
+
return new OpenAI({
|
|
250
|
+
apiKey,
|
|
251
|
+
baseURL: model.baseUrl,
|
|
252
|
+
dangerouslyAllowBrowser: true,
|
|
253
|
+
fetch,
|
|
254
|
+
defaultHeaders: headers
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
__name(createClient, "createClient");
|
|
258
|
+
function buildParams(model, context, options, compat, grammarToolInputProperties, configurationUpdateEffort) {
|
|
259
|
+
const transcriptTools = resolveTranscriptTools(context.messages, compat.supportsAdditionalTools || compat.supportsToolSearch);
|
|
260
|
+
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
|
|
261
|
+
grammarToolInputProperties,
|
|
262
|
+
supportsMidConvoSystemMessages: compat.supportsMidConvoSystemMessages,
|
|
263
|
+
supportsAdditionalTools: compat.supportsAdditionalTools,
|
|
264
|
+
supportsToolSearch: compat.supportsToolSearch,
|
|
265
|
+
toolOptions: {
|
|
266
|
+
supportsStrictMode: compat.supportsStrictMode,
|
|
267
|
+
supportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools
|
|
268
|
+
},
|
|
269
|
+
configurationUpdateEffort
|
|
270
|
+
});
|
|
271
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
272
|
+
const omitUnsupportedFields = isChatGPTSignIn(model, options?.apiKey);
|
|
273
|
+
const params = {
|
|
274
|
+
model: model.id,
|
|
275
|
+
input: messages,
|
|
276
|
+
stream: true,
|
|
277
|
+
prompt_cache_key: cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.sessionId),
|
|
278
|
+
prompt_cache_retention: omitUnsupportedFields ? void 0 : getPromptCacheRetention(compat, cacheRetention),
|
|
279
|
+
prompt_cache_options: omitUnsupportedFields ? void 0 : getPromptCacheOptions(compat, cacheRetention),
|
|
280
|
+
store: false
|
|
281
|
+
};
|
|
282
|
+
if (options?.maxTokens && compat.supportsMaxOutputTokens && !omitUnsupportedFields) {
|
|
283
|
+
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
|
|
284
|
+
}
|
|
285
|
+
if (options?.temperature !== void 0 && !omitUnsupportedFields) {
|
|
286
|
+
params.temperature = options?.temperature;
|
|
287
|
+
}
|
|
288
|
+
if (options?.serviceTier !== void 0) {
|
|
289
|
+
params.service_tier = options.serviceTier;
|
|
290
|
+
}
|
|
291
|
+
if (transcriptTools.requestTools.length > 0) {
|
|
292
|
+
params.tools = convertResponsesTools(transcriptTools.requestTools, {
|
|
293
|
+
supportsStrictMode: compat.supportsStrictMode,
|
|
294
|
+
supportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (options?.toolChoice !== void 0) {
|
|
298
|
+
params.tool_choice = options.toolChoice;
|
|
299
|
+
}
|
|
300
|
+
const reasoningEffort = options?.reasoningEffort ?? (options?.reasoningSummary ? "medium" : void 0);
|
|
301
|
+
if (model.reasoning) {
|
|
302
|
+
if (reasoningEffort) {
|
|
303
|
+
const requestedEffort = options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : reasoningEffort;
|
|
304
|
+
const effort = configurationUpdateEffort === void 0 ? requestedEffort : CONFIGURATION_UPDATE_REQUEST_EFFORT;
|
|
305
|
+
params.reasoning = {
|
|
306
|
+
effort,
|
|
307
|
+
summary: options?.reasoningSummary || "auto"
|
|
308
|
+
};
|
|
309
|
+
params.include = ["reasoning.encrypted_content"];
|
|
310
|
+
} else if (model.provider !== "github-copilot" && model.thinkingLevelMap?.off !== null) {
|
|
311
|
+
params.reasoning = {
|
|
312
|
+
effort: model.thinkingLevelMap?.off ?? "none"
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (model.provider === "xai")
|
|
316
|
+
params.include = ["reasoning.encrypted_content"];
|
|
317
|
+
}
|
|
318
|
+
const samplingParams = resolveSamplingParams(model, reasoningEffort ?? "off", options?.samplingParams);
|
|
319
|
+
if (samplingParams) {
|
|
320
|
+
Object.assign(params, samplingParams);
|
|
321
|
+
}
|
|
322
|
+
return params;
|
|
323
|
+
}
|
|
324
|
+
__name(buildParams, "buildParams");
|
|
325
|
+
function getServiceTierCostMultiplier(model, serviceTier) {
|
|
326
|
+
switch (serviceTier) {
|
|
327
|
+
case "flex":
|
|
328
|
+
return 0.5;
|
|
329
|
+
case "priority":
|
|
330
|
+
case "fast":
|
|
331
|
+
return model.id === "gpt-5.5" ? 2.5 : 2;
|
|
332
|
+
default:
|
|
333
|
+
return 1;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
__name(getServiceTierCostMultiplier, "getServiceTierCostMultiplier");
|
|
337
|
+
function applyServiceTierPricing(usage, serviceTier, model) {
|
|
338
|
+
const multiplier = getServiceTierCostMultiplier(model, serviceTier);
|
|
339
|
+
if (multiplier === 1)
|
|
340
|
+
return;
|
|
341
|
+
usage.cost.input *= multiplier;
|
|
342
|
+
usage.cost.output *= multiplier;
|
|
343
|
+
usage.cost.cacheRead *= multiplier;
|
|
344
|
+
usage.cost.cacheWrite *= multiplier;
|
|
345
|
+
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
346
|
+
}
|
|
347
|
+
__name(applyServiceTierPricing, "applyServiceTierPricing");
|
|
348
|
+
export {
|
|
349
|
+
stream,
|
|
350
|
+
streamSimple
|
|
351
|
+
};
|