@desplega.ai/agent-swarm 1.119.4 → 1.119.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/dist/{actions-cvcf510b.js → actions-qe5zjcbr.js} +5 -5
- package/dist/{anthropic-messages-kq3pjhbp.js → anthropic-messages-qjxzsabf.js} +94 -46
- package/dist/{app-05ksvyna.js → app-31x7k3vj.js} +3 -3
- package/dist/{assistant-wqr7nmqv.js → assistant-4crt9dve.js} +8 -8
- package/dist/{azure-openai-responses-f57n5qy7.js → azure-openai-responses-ntfd05zd.js} +10 -7
- package/dist/{boot-reembed-v0q84hej.js → boot-reembed-8g69ttz4.js} +3 -3
- package/dist/{boot-reembed-dx3zweeh.js → boot-reembed-q648j733.js} +4 -4
- package/dist/{boot-scrub-logs-3am4xegg.js → boot-scrub-logs-sfmzd2hj.js} +2 -2
- package/dist/{claude-adapter-3csn5bks.js → claude-adapter-9n3nzt65.js} +2 -2
- package/dist/{claude-managed-adapter-kysmkz89.js → claude-managed-adapter-pv2nbqy4.js} +2 -2
- package/dist/{cli-m6pzzhqr.js → cli-1arw00dp.js} +251 -122
- package/dist/{cli-pc276yqz.js → cli-2gv8ygwr.js} +1 -1
- package/dist/{cli-rk6fkhkk.js → cli-433c0f4b.js} +5 -5
- package/dist/{cli-kmtp1rg9.js → cli-4s84mw72.js} +2 -2
- package/dist/{cli-ttb3pty1.js → cli-59jy217p.js} +16 -16
- package/dist/{cli-qfp17rw8.js → cli-6rvm3jkk.js} +1 -1
- package/dist/{cli-bzjncaf6.js → cli-8hhms4hp.js} +1 -1
- package/dist/{cli-h1bffz9b.js → cli-96feg24n.js} +1 -1
- package/dist/{cli-0y66mw72.js → cli-bpvgs2y6.js} +2 -2
- package/dist/{cli-jfc1jm13.js → cli-d1reabed.js} +1 -1
- package/dist/{cli-dh9eb7tt.js → cli-da3x3btq.js} +5 -3
- package/dist/{cli-bsyka9ta.js → cli-e0y603nn.js} +30 -16
- package/dist/{cli-chfh8r6f.js → cli-fkxxh5d4.js} +2 -2
- package/dist/{cli-7mvmqemc.js → cli-g6qz2kts.js} +1 -1
- package/dist/{cli-pyagab0x.js → cli-gdqdkr3j.js} +2 -2
- package/dist/{cli-67e8g7bj.js → cli-gg5bd32n.js} +4 -4
- package/dist/{cli-zrxpz200.js → cli-h6cf69x5.js} +1 -1
- package/dist/{cli-xw7p4wkq.js → cli-mg280wsv.js} +1 -1
- package/dist/{cli-hcpm1e90.js → cli-n61x2aph.js} +2488 -18718
- package/dist/{cli-4xtzqzv4.js → cli-ner6af7m.js} +18 -18
- package/dist/{cli-zm2jjaq6.js → cli-pasyk3vc.js} +6 -6
- package/dist/{cli-758zm6xy.js → cli-q8dway4w.js} +1 -1
- package/dist/cli-qs7nb3zn.js +76 -0
- package/dist/{cli-fhmhjjh4.js → cli-qw1ccvxm.js} +8 -7
- package/dist/{cli-8jjrc3ww.js → cli-r93nz80j.js} +1 -1
- package/dist/{cli-cs5g429e.js → cli-sbkwvn5e.js} +1 -1
- package/dist/cli-v1mwc5v2.js +68 -0
- package/dist/cli-vfcth11k.js +36 -0
- package/dist/{cli-k0x0fvh5.js → cli-vg1jxfqz.js} +5 -5
- package/dist/{cli-qe43w9a5.js → cli-vx0y68jv.js} +2 -2
- package/dist/{cli-kc3h8mnm.js → cli-w6rhc30s.js} +1 -1
- package/dist/{cli-sdpnhajn.js → cli-wr706gez.js} +56 -7
- package/dist/{cli-1c5zhw9z.js → cli-wxbnjgce.js} +3 -3
- package/dist/{cli-0qy7bk86.js → cli-xeatwfbe.js} +25 -16
- package/dist/{cli-hx1dcevq.js → cli-z9gzq07x.js} +1 -23
- package/dist/cli.js +21 -20
- package/dist/{codex-adapter-efskwfc4.js → codex-adapter-6j2b38tg.js} +8 -6
- package/dist/{codex-session-runner-n7ad0jdv.js → codex-session-runner-vz215wgw.js} +8 -6
- package/dist/{commands-3ke60h4e.js → commands-6xr20jbe.js} +2 -2
- package/dist/{db-a1e1nj43.js → db-1mmvk1z4.js} +2 -2
- package/dist/{google-generative-ai-hyrra2jm.js → google-generative-ai-n1d3xt4n.js} +9 -7
- package/dist/{google-vertex-9hhq68sw.js → google-vertex-mxst23gy.js} +9 -7
- package/dist/{handlers-d86a4ypy.js → handlers-xvrknk8w.js} +8 -8
- package/dist/{hook-teegt6h5.js → hook-qm7he8wn.js} +7 -5
- package/dist/{http-64jvxqnz.js → http-hj08zq67.js} +39 -38
- package/dist/{index-z39ch6n5.js → index-688jph6a.js} +9 -9
- package/dist/{index-a95n0ay5.js → index-etz7d8md.js} +8 -8
- package/dist/{index-hb9j1aqr.js → index-gze4fg2w.js} +6 -6
- package/dist/{index-bndzxk11.js → index-wj8dfpwh.js} +10 -10
- package/dist/{keepalive-ab1qpqrm.js → keepalive-94wn9yxw.js} +4 -4
- package/dist/{lead-852gtrsa.js → lead-rvcqkp11.js} +32 -30
- package/dist/{maintenance-fke93wqq.js → maintenance-qhfc4dnp.js} +4 -4
- package/dist/{mistral-conversations-tn4sj5qv.js → mistral-conversations-ykcg66za.js} +5 -3
- package/dist/{oauth-refresh-sweep-a139pm5w.js → oauth-refresh-sweep-rj8wgvsw.js} +3 -3
- package/dist/{onboard-vcd22m9e.js → onboard-8bv8q1wc.js} +2 -2
- package/dist/{openai-codex-responses-bex0bpn6.js → openai-codex-responses-zy0907j9.js} +68 -39
- package/dist/{openai-completions-gygw5cxt.js → openai-completions-xk4p56n9.js} +73 -14
- package/dist/{openai-responses-8c0dgmty.js → openai-responses-4gv3ca5d.js} +38 -16
- package/dist/{opencode-adapter-p6bxnbm4.js → opencode-adapter-5bwzvbwj.js} +2 -2
- package/dist/{otel-impl-88egk5hc.js → otel-impl-1kf6fr2m.js} +1 -1
- package/dist/pi-messages-zb8v76wx.js +313 -0
- package/dist/{pi-mono-adapter-erghwha0.js → pi-mono-adapter-9sg69kg3.js} +15711 -12608
- package/dist/{pricing-refresh-bbg7s7qs.js → pricing-refresh-e84tar2s.js} +4 -4
- package/dist/{rbac-roles-kc9t08gp.js → rbac-roles-atytq5ch.js} +3 -3
- package/dist/{rbac-roles-e169ndy2.js → rbac-roles-pg0zvnwn.js} +2 -2
- package/dist/{seed-pricing-3zhtw483.js → seed-pricing-xd6nxq7k.js} +3 -3
- package/dist/{setup-6m99ne8y.js → setup-4z389yk0.js} +2 -2
- package/dist/{worker-pwg46aav.js → worker-m61r0t7m.js} +32 -30
- package/openapi.json +1 -1
- package/package.json +6 -6
- package/src/providers/pi-mono-adapter.ts +14 -20
- package/src/tests/internal-ai/credentials.test.ts +22 -0
- package/src/tests/pi-mono-adapter.test.ts +28 -20
- package/src/tests/scripts-only-gating.test.ts +93 -31
- package/src/tests/workflow-engine-v2.test.ts +26 -0
- package/src/utils/internal-ai/credentials.ts +53 -5
- package/src/workflows/engine.ts +12 -2
- package/dist/{cli-sznberje.js → cli-2r7s8jhp.js} +3 -3
- package/dist/{cli-bc89my0z.js → cli-branks1w.js} +3 -3
- package/dist/{cli-mnbgv3w7.js → cli-mw3xpgwb.js} +3 -3
- package/dist/{openrouter-images-537nmn1r.js → openrouter-images-4fsrrzes.js} +3 -3
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerSessionResourceCleanup,
|
|
3
|
+
uuidv7
|
|
4
|
+
} from "./cli-v1mwc5v2.js";
|
|
1
5
|
import {
|
|
2
6
|
appendAssistantMessageDiagnostic,
|
|
3
7
|
createAssistantMessageDiagnostic,
|
|
4
|
-
formatThrownValue
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
formatThrownValue
|
|
9
|
+
} from "./cli-z9gzq07x.js";
|
|
10
|
+
import {
|
|
11
|
+
splitDeferredTools
|
|
12
|
+
} from "./cli-vfcth11k.js";
|
|
7
13
|
import {
|
|
8
14
|
convertResponsesMessages,
|
|
9
15
|
convertResponsesTools,
|
|
10
16
|
processResponsesStream
|
|
11
|
-
} from "./cli-
|
|
12
|
-
import"./cli-5m9j2spm.js";
|
|
17
|
+
} from "./cli-wr706gez.js";
|
|
13
18
|
import {
|
|
14
19
|
clampOpenAIPromptCacheKey
|
|
15
20
|
} from "./cli-mrptpp86.js";
|
|
21
|
+
import"./cli-5m9j2spm.js";
|
|
16
22
|
import {
|
|
17
23
|
resolveHttpProxyUrlForTarget
|
|
18
24
|
} from "./cli-cwy5hqbq.js";
|
|
@@ -24,15 +30,17 @@ import {
|
|
|
24
30
|
} from "./cli-pscrc6tw.js";
|
|
25
31
|
import {
|
|
26
32
|
buildBaseOptions
|
|
27
|
-
} from "./cli-
|
|
33
|
+
} from "./cli-e0y603nn.js";
|
|
34
|
+
import"./cli-y2apkfe2.js";
|
|
28
35
|
import {
|
|
29
36
|
headersToRecord
|
|
30
37
|
} from "./cli-vapyk8sw.js";
|
|
31
|
-
import"./cli-y2apkfe2.js";
|
|
32
38
|
import {
|
|
33
|
-
AssistantMessageEventStream,
|
|
34
39
|
clampThinkingLevel
|
|
35
|
-
} from "./cli-
|
|
40
|
+
} from "./cli-1arw00dp.js";
|
|
41
|
+
import {
|
|
42
|
+
AssistantMessageEventStream
|
|
43
|
+
} from "./cli-qs7nb3zn.js";
|
|
36
44
|
import"./cli-p9swy5t3.js";
|
|
37
45
|
|
|
38
46
|
// node_modules/@earendil-works/pi-ai/dist/utils/abort-signals.js
|
|
@@ -71,28 +79,20 @@ function combineAbortSignals(signals) {
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
// node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js
|
|
74
|
-
|
|
75
|
-
if (typeof
|
|
76
|
-
return
|
|
77
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
|
|
78
|
-
});
|
|
82
|
+
function loadNodeOs() {
|
|
83
|
+
if (typeof process === "undefined" || !(process.versions?.node || process.versions?.bun)) {
|
|
84
|
+
return null;
|
|
79
85
|
}
|
|
80
|
-
return
|
|
81
|
-
};
|
|
82
|
-
var _os = null;
|
|
83
|
-
var dynamicImport = (specifier) => import(__rewriteRelativeImportExtension(specifier));
|
|
84
|
-
var NODE_OS_SPECIFIER = "node:os";
|
|
85
|
-
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
|
|
86
|
-
dynamicImport(NODE_OS_SPECIFIER).then((m) => {
|
|
87
|
-
_os = m;
|
|
88
|
-
});
|
|
86
|
+
return process.getBuiltinModule?.("node:os") ?? null;
|
|
89
87
|
}
|
|
88
|
+
var _os = loadNodeOs();
|
|
90
89
|
var DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
91
90
|
var JWT_CLAIM_PATH = "https://api.openai.com/auth";
|
|
92
91
|
var DEFAULT_MAX_RETRIES = 0;
|
|
93
92
|
var BASE_DELAY_MS = 1000;
|
|
94
93
|
var DEFAULT_MAX_RETRY_DELAY_MS = 60000;
|
|
95
94
|
var DEFAULT_WEBSOCKET_CONNECT_TIMEOUT_MS = 15000;
|
|
95
|
+
var REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
96
96
|
var CODEX_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
97
97
|
var WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
98
98
|
var WEBSOCKET_CONNECTION_LIMIT_REACHED_CODE = "websocket_connection_limit_reached";
|
|
@@ -163,6 +163,26 @@ function normalizeTimeoutMs(value) {
|
|
|
163
163
|
}
|
|
164
164
|
return Math.floor(value);
|
|
165
165
|
}
|
|
166
|
+
function loadNodeZlib() {
|
|
167
|
+
if (typeof process === "undefined" || !(process.versions?.node || process.versions?.bun)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return process.getBuiltinModule?.("node:zlib") ?? null;
|
|
171
|
+
}
|
|
172
|
+
function compressRequestBodyZstd(bodyJson) {
|
|
173
|
+
const zlib = loadNodeZlib();
|
|
174
|
+
if (!zlib || typeof zlib.zstdCompressSync !== "function") {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const compressed = zlib.zstdCompressSync(bodyJson, {
|
|
179
|
+
params: { [zlib.constants.ZSTD_c_compressionLevel]: REQUEST_COMPRESSION_ZSTD_LEVEL }
|
|
180
|
+
});
|
|
181
|
+
return new Uint8Array(compressed.buffer, compressed.byteOffset, compressed.byteLength);
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
166
186
|
var stream = (model, context, options) => {
|
|
167
187
|
const stream2 = new AssistantMessageEventStream;
|
|
168
188
|
(async () => {
|
|
@@ -194,8 +214,9 @@ var stream = (model, context, options) => {
|
|
|
194
214
|
if (nextBody !== undefined) {
|
|
195
215
|
body = nextBody;
|
|
196
216
|
}
|
|
197
|
-
const
|
|
198
|
-
const
|
|
217
|
+
const codexSessionId = clampOpenAIPromptCacheKey(options?.sessionId);
|
|
218
|
+
const websocketRequestId = codexSessionId || uuidv7();
|
|
219
|
+
const sseHeaders = buildSSEHeaders(model.headers, options?.headers, accountId, apiKey, codexSessionId);
|
|
199
220
|
const websocketHeaders = buildWebSocketHeaders(model.headers, options?.headers, accountId, apiKey, websocketRequestId);
|
|
200
221
|
const bodyJson = JSON.stringify(body);
|
|
201
222
|
const httpTimeoutMs = normalizeTimeoutMs(options?.timeoutMs);
|
|
@@ -250,6 +271,11 @@ var stream = (model, context, options) => {
|
|
|
250
271
|
}
|
|
251
272
|
}
|
|
252
273
|
}
|
|
274
|
+
const compressedBody = compressRequestBodyZstd(bodyJson);
|
|
275
|
+
if (compressedBody) {
|
|
276
|
+
sseHeaders.set("content-encoding", "zstd");
|
|
277
|
+
}
|
|
278
|
+
const sseBody = compressedBody ?? bodyJson;
|
|
253
279
|
let response;
|
|
254
280
|
let lastError;
|
|
255
281
|
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
@@ -264,7 +290,7 @@ var stream = (model, context, options) => {
|
|
|
264
290
|
response = await fetch(resolveCodexUrl(model.baseUrl), {
|
|
265
291
|
method: "POST",
|
|
266
292
|
headers: sseHeaders,
|
|
267
|
-
body:
|
|
293
|
+
body: sseBody,
|
|
268
294
|
signal: combinedSignal.signal
|
|
269
295
|
});
|
|
270
296
|
} catch (error) {
|
|
@@ -346,8 +372,10 @@ var streamSimple = (model, context, options) => {
|
|
|
346
372
|
});
|
|
347
373
|
};
|
|
348
374
|
function buildRequestBody(model, context, options) {
|
|
375
|
+
const toolPlacement = splitDeferredTools(context, model.compat?.supportsToolSearch ?? false);
|
|
349
376
|
const messages = convertResponsesMessages(model, context, CODEX_TOOL_CALL_PROVIDERS, {
|
|
350
|
-
includeSystemPrompt: false
|
|
377
|
+
includeSystemPrompt: false,
|
|
378
|
+
deferredTools: toolPlacement.deferred
|
|
351
379
|
});
|
|
352
380
|
const body = {
|
|
353
381
|
model: model.id,
|
|
@@ -358,7 +386,7 @@ function buildRequestBody(model, context, options) {
|
|
|
358
386
|
text: { verbosity: options?.textVerbosity || "low" },
|
|
359
387
|
include: ["reasoning.encrypted_content"],
|
|
360
388
|
prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),
|
|
361
|
-
tool_choice: "auto",
|
|
389
|
+
tool_choice: options?.toolChoice ?? "auto",
|
|
362
390
|
parallel_tool_calls: true
|
|
363
391
|
};
|
|
364
392
|
if (options?.temperature !== undefined) {
|
|
@@ -367,8 +395,8 @@ function buildRequestBody(model, context, options) {
|
|
|
367
395
|
if (options?.serviceTier !== undefined) {
|
|
368
396
|
body.service_tier = options.serviceTier;
|
|
369
397
|
}
|
|
370
|
-
if (
|
|
371
|
-
body.tools = convertResponsesTools(
|
|
398
|
+
if (toolPlacement.immediate.length > 0) {
|
|
399
|
+
body.tools = convertResponsesTools(toolPlacement.immediate, { strict: null });
|
|
372
400
|
}
|
|
373
401
|
if (options?.reasoningEffort !== undefined) {
|
|
374
402
|
const effort = options.reasoningEffort === "none" ? model.thinkingLevelMap?.off ?? "none" : model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort;
|
|
@@ -558,7 +586,8 @@ async function* parseSSE(response, signal) {
|
|
|
558
586
|
}
|
|
559
587
|
}
|
|
560
588
|
var OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
561
|
-
var SESSION_WEBSOCKET_CACHE_TTL_MS =
|
|
589
|
+
var SESSION_WEBSOCKET_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
590
|
+
var SESSION_WEBSOCKET_MAX_AGE_MS = 55 * 60 * 1000;
|
|
562
591
|
var websocketSessionCache = new Map;
|
|
563
592
|
var websocketDebugStats = new Map;
|
|
564
593
|
var websocketSseFallbackSessions = new Set;
|
|
@@ -680,6 +709,9 @@ function isWebSocketReusable(socket) {
|
|
|
680
709
|
const readyState = getWebSocketReadyState(socket);
|
|
681
710
|
return readyState === undefined || readyState === 1;
|
|
682
711
|
}
|
|
712
|
+
function isWebSocketSessionExpired(entry) {
|
|
713
|
+
return Date.now() - entry.createdAt >= SESSION_WEBSOCKET_MAX_AGE_MS;
|
|
714
|
+
}
|
|
683
715
|
function closeWebSocketSilently(socket, code = 1000, reason = "done") {
|
|
684
716
|
try {
|
|
685
717
|
socket.close(code, reason);
|
|
@@ -778,7 +810,10 @@ async function acquireWebSocket(url, headers, sessionId, signal, connectTimeoutM
|
|
|
778
810
|
clearTimeout(cached.idleTimer);
|
|
779
811
|
cached.idleTimer = undefined;
|
|
780
812
|
}
|
|
781
|
-
if (!cached.busy &&
|
|
813
|
+
if (!cached.busy && isWebSocketSessionExpired(cached)) {
|
|
814
|
+
closeWebSocketSilently(cached.socket, 1000, "connection_age_limit");
|
|
815
|
+
websocketSessionCache.delete(sessionId);
|
|
816
|
+
} else if (!cached.busy && isWebSocketReusable(cached.socket)) {
|
|
782
817
|
cached.busy = true;
|
|
783
818
|
return {
|
|
784
819
|
socket: cached.socket,
|
|
@@ -811,7 +846,7 @@ async function acquireWebSocket(url, headers, sessionId, signal, connectTimeoutM
|
|
|
811
846
|
}
|
|
812
847
|
}
|
|
813
848
|
const socket = await connectWebSocket(url, headers, signal, connectTimeoutMs, env);
|
|
814
|
-
const entry = { socket, busy: true };
|
|
849
|
+
const entry = { socket, busy: true, createdAt: Date.now() };
|
|
815
850
|
websocketSessionCache.set(sessionId, entry);
|
|
816
851
|
return {
|
|
817
852
|
socket,
|
|
@@ -1138,12 +1173,6 @@ function extractAccountId(token) {
|
|
|
1138
1173
|
throw new Error("Failed to extract accountId from token");
|
|
1139
1174
|
}
|
|
1140
1175
|
}
|
|
1141
|
-
function createCodexRequestId() {
|
|
1142
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
1143
|
-
return globalThis.crypto.randomUUID();
|
|
1144
|
-
}
|
|
1145
|
-
return `codex_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
1146
|
-
}
|
|
1147
1176
|
function buildBaseCodexHeaders(initHeaders, additionalHeaders, accountId, token) {
|
|
1148
1177
|
const headers = new Headers(initHeaders);
|
|
1149
1178
|
for (const [key, value] of Object.entries(additionalHeaders || {})) {
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
clampOpenAIPromptCacheKey
|
|
7
7
|
} from "./cli-mrptpp86.js";
|
|
8
|
+
import {
|
|
9
|
+
shortHash
|
|
10
|
+
} from "./cli-5m9j2spm.js";
|
|
8
11
|
import {
|
|
9
12
|
OpenAI
|
|
10
13
|
} from "./cli-sajgpkqg.js";
|
|
@@ -21,18 +24,20 @@ import {
|
|
|
21
24
|
import {
|
|
22
25
|
buildBaseOptions,
|
|
23
26
|
transformMessages
|
|
24
|
-
} from "./cli-
|
|
25
|
-
import {
|
|
26
|
-
headersToRecord
|
|
27
|
-
} from "./cli-vapyk8sw.js";
|
|
27
|
+
} from "./cli-e0y603nn.js";
|
|
28
28
|
import {
|
|
29
29
|
sanitizeSurrogates
|
|
30
30
|
} from "./cli-y2apkfe2.js";
|
|
31
31
|
import {
|
|
32
|
-
|
|
32
|
+
headersToRecord
|
|
33
|
+
} from "./cli-vapyk8sw.js";
|
|
34
|
+
import {
|
|
33
35
|
calculateCost,
|
|
34
36
|
clampThinkingLevel
|
|
35
|
-
} from "./cli-
|
|
37
|
+
} from "./cli-1arw00dp.js";
|
|
38
|
+
import {
|
|
39
|
+
AssistantMessageEventStream
|
|
40
|
+
} from "./cli-qs7nb3zn.js";
|
|
36
41
|
import"./cli-p9swy5t3.js";
|
|
37
42
|
|
|
38
43
|
// node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js
|
|
@@ -66,6 +71,23 @@ function hasToolHistory(messages) {
|
|
|
66
71
|
}
|
|
67
72
|
return false;
|
|
68
73
|
}
|
|
74
|
+
function getDeferredToolNames(messages) {
|
|
75
|
+
const names = new Set;
|
|
76
|
+
for (const message of messages) {
|
|
77
|
+
if (message.role === "toolResult") {
|
|
78
|
+
for (const name of message.addedToolNames ?? []) {
|
|
79
|
+
names.add(name);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return names;
|
|
84
|
+
}
|
|
85
|
+
function getToolsByName(tools, names) {
|
|
86
|
+
if (!tools)
|
|
87
|
+
return [];
|
|
88
|
+
const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
89
|
+
return Array.from(names).map((name) => toolsByName.get(name)).filter((tool) => tool !== undefined);
|
|
90
|
+
}
|
|
69
91
|
function isTextContentBlock(block) {
|
|
70
92
|
return block.type === "text";
|
|
71
93
|
}
|
|
@@ -398,9 +420,15 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
398
420
|
Object.assign(headers, copilotHeaders);
|
|
399
421
|
}
|
|
400
422
|
if (sessionId && compat.sendSessionAffinityHeaders) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
423
|
+
if (compat.sessionAffinityFormat === "openrouter") {
|
|
424
|
+
headers["x-session-id"] = sessionId;
|
|
425
|
+
} else {
|
|
426
|
+
if (compat.sessionAffinityFormat === "openai") {
|
|
427
|
+
headers.session_id = sessionId;
|
|
428
|
+
}
|
|
429
|
+
headers["x-client-request-id"] = sessionId;
|
|
430
|
+
headers["x-session-affinity"] = sessionId;
|
|
431
|
+
}
|
|
404
432
|
}
|
|
405
433
|
if (optionsHeaders) {
|
|
406
434
|
Object.assign(headers, optionsHeaders);
|
|
@@ -438,8 +466,10 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
438
466
|
if (options?.temperature !== undefined) {
|
|
439
467
|
params.temperature = options.temperature;
|
|
440
468
|
}
|
|
441
|
-
|
|
442
|
-
|
|
469
|
+
const deferredToolNames = compat.deferredToolsMode === "kimi" ? getDeferredToolNames(context.messages) : new Set;
|
|
470
|
+
const activeTools = context.tools?.filter((tool) => !deferredToolNames.has(tool.name));
|
|
471
|
+
if (activeTools && activeTools.length > 0) {
|
|
472
|
+
params.tools = convertTools(activeTools, compat);
|
|
443
473
|
if (compat.zaiToolStream) {
|
|
444
474
|
params.tool_stream = true;
|
|
445
475
|
}
|
|
@@ -636,8 +666,16 @@ function convertMessages(model, context, compat) {
|
|
|
636
666
|
const params = [];
|
|
637
667
|
const normalizeToolCallId = (id) => {
|
|
638
668
|
if (id.includes("|")) {
|
|
639
|
-
const
|
|
640
|
-
|
|
669
|
+
const separatorIndex = id.indexOf("|");
|
|
670
|
+
const callId = id.slice(0, separatorIndex).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
671
|
+
const itemId = id.slice(separatorIndex + 1).replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
672
|
+
const combinedId = itemId.length > 0 ? `${callId}_${itemId}` : callId;
|
|
673
|
+
if (combinedId.length <= 40) {
|
|
674
|
+
return combinedId;
|
|
675
|
+
}
|
|
676
|
+
const hash = shortHash(id).slice(0, 8);
|
|
677
|
+
const prefix = callId.slice(0, Math.max(1, 40 - hash.length - 1));
|
|
678
|
+
return `${prefix}_${hash}`;
|
|
641
679
|
}
|
|
642
680
|
if (model.provider === "openai")
|
|
643
681
|
return id.length > 40 ? id.slice(0, 40) : id;
|
|
@@ -752,6 +790,7 @@ function convertMessages(model, context, compat) {
|
|
|
752
790
|
params.push(assistantMsg);
|
|
753
791
|
} else if (msg.role === "toolResult") {
|
|
754
792
|
const imageBlocks = [];
|
|
793
|
+
const deferredToolNames = new Set;
|
|
755
794
|
let j = i;
|
|
756
795
|
for (;j < transformedMessages.length && transformedMessages[j].role === "toolResult"; j++) {
|
|
757
796
|
const toolMsg = transformedMessages[j];
|
|
@@ -759,15 +798,21 @@ function convertMessages(model, context, compat) {
|
|
|
759
798
|
`);
|
|
760
799
|
const hasImages = toolMsg.content.some((c) => c.type === "image");
|
|
761
800
|
const hasText = textResult.length > 0;
|
|
801
|
+
const toolResultText = hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)";
|
|
762
802
|
const toolResultMsg = {
|
|
763
803
|
role: "tool",
|
|
764
|
-
content: sanitizeSurrogates(
|
|
804
|
+
content: sanitizeSurrogates(toolResultText),
|
|
765
805
|
tool_call_id: toolMsg.toolCallId
|
|
766
806
|
};
|
|
767
807
|
if (compat.requiresToolResultName && toolMsg.toolName) {
|
|
768
808
|
toolResultMsg.name = toolMsg.toolName;
|
|
769
809
|
}
|
|
770
810
|
params.push(toolResultMsg);
|
|
811
|
+
if (compat.deferredToolsMode === "kimi") {
|
|
812
|
+
for (const name of toolMsg.addedToolNames ?? []) {
|
|
813
|
+
deferredToolNames.add(name);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
771
816
|
if (hasImages && model.input.includes("image")) {
|
|
772
817
|
for (const block of toolMsg.content) {
|
|
773
818
|
if (isImageContentBlock(block)) {
|
|
@@ -803,6 +848,16 @@ function convertMessages(model, context, compat) {
|
|
|
803
848
|
} else {
|
|
804
849
|
lastRole = "toolResult";
|
|
805
850
|
}
|
|
851
|
+
if (deferredToolNames.size > 0) {
|
|
852
|
+
const deferredTools = getToolsByName(context.tools, deferredToolNames);
|
|
853
|
+
if (deferredTools.length > 0) {
|
|
854
|
+
const kimiToolMessage = {
|
|
855
|
+
role: "system",
|
|
856
|
+
tools: convertTools(deferredTools, compat)
|
|
857
|
+
};
|
|
858
|
+
params.push(kimiToolMessage);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
806
861
|
continue;
|
|
807
862
|
}
|
|
808
863
|
lastRole = msg.role;
|
|
@@ -896,6 +951,8 @@ function detectCompat(model) {
|
|
|
896
951
|
supportsStrictMode: !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia,
|
|
897
952
|
cacheControlFormat,
|
|
898
953
|
sendSessionAffinityHeaders: false,
|
|
954
|
+
deferredToolsMode: undefined,
|
|
955
|
+
sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
|
|
899
956
|
supportsLongCacheRetention: !(isTogether || isCloudflareWorkersAI || isCloudflareAiGateway || isNvidia || isAntLing)
|
|
900
957
|
};
|
|
901
958
|
}
|
|
@@ -921,6 +978,8 @@ function getCompat(model) {
|
|
|
921
978
|
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
|
|
922
979
|
cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
|
|
923
980
|
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
981
|
+
deferredToolsMode: model.compat.deferredToolsMode ?? detected.deferredToolsMode,
|
|
982
|
+
sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
|
|
924
983
|
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention
|
|
925
984
|
};
|
|
926
985
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
splitDeferredTools
|
|
3
|
+
} from "./cli-vfcth11k.js";
|
|
1
4
|
import {
|
|
2
5
|
convertResponsesMessages,
|
|
3
6
|
convertResponsesTools,
|
|
4
7
|
processResponsesStream
|
|
5
|
-
} from "./cli-
|
|
6
|
-
import"./cli-5m9j2spm.js";
|
|
8
|
+
} from "./cli-wr706gez.js";
|
|
7
9
|
import {
|
|
8
10
|
buildCopilotDynamicHeaders,
|
|
9
11
|
hasCopilotVisionInput
|
|
@@ -11,6 +13,7 @@ import {
|
|
|
11
13
|
import {
|
|
12
14
|
clampOpenAIPromptCacheKey
|
|
13
15
|
} from "./cli-mrptpp86.js";
|
|
16
|
+
import"./cli-5m9j2spm.js";
|
|
14
17
|
import {
|
|
15
18
|
OpenAI
|
|
16
19
|
} from "./cli-sajgpkqg.js";
|
|
@@ -24,19 +27,22 @@ import {
|
|
|
24
27
|
} from "./cli-pscrc6tw.js";
|
|
25
28
|
import {
|
|
26
29
|
buildBaseOptions
|
|
27
|
-
} from "./cli-
|
|
30
|
+
} from "./cli-e0y603nn.js";
|
|
31
|
+
import"./cli-y2apkfe2.js";
|
|
28
32
|
import {
|
|
29
33
|
headersToRecord
|
|
30
34
|
} from "./cli-vapyk8sw.js";
|
|
31
|
-
import"./cli-y2apkfe2.js";
|
|
32
35
|
import {
|
|
33
|
-
AssistantMessageEventStream,
|
|
34
36
|
clampThinkingLevel
|
|
35
|
-
} from "./cli-
|
|
37
|
+
} from "./cli-1arw00dp.js";
|
|
38
|
+
import {
|
|
39
|
+
AssistantMessageEventStream
|
|
40
|
+
} from "./cli-qs7nb3zn.js";
|
|
36
41
|
import"./cli-p9swy5t3.js";
|
|
37
42
|
|
|
38
43
|
// node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js
|
|
39
44
|
var OPENAI_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
45
|
+
var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
40
46
|
function hasHeader(headers, name) {
|
|
41
47
|
if (!headers)
|
|
42
48
|
return false;
|
|
@@ -54,6 +60,9 @@ function getClientApiKey(provider, apiKey, headers) {
|
|
|
54
60
|
return "unused";
|
|
55
61
|
throw new Error(`No API key for provider: ${provider}`);
|
|
56
62
|
}
|
|
63
|
+
function detectSessionAffinityFormat(model) {
|
|
64
|
+
return model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai") ? "openrouter" : "openai";
|
|
65
|
+
}
|
|
57
66
|
function resolveCacheRetention(cacheRetention, env) {
|
|
58
67
|
if (cacheRetention) {
|
|
59
68
|
return cacheRetention;
|
|
@@ -66,8 +75,9 @@ function resolveCacheRetention(cacheRetention, env) {
|
|
|
66
75
|
function getCompat(model) {
|
|
67
76
|
return {
|
|
68
77
|
supportsDeveloperRole: model.compat?.supportsDeveloperRole ?? true,
|
|
69
|
-
|
|
70
|
-
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true
|
|
78
|
+
sessionAffinityFormat: model.compat?.sessionAffinityFormat ?? detectSessionAffinityFormat(model),
|
|
79
|
+
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
80
|
+
supportsToolSearch: model.compat?.supportsToolSearch ?? false
|
|
71
81
|
};
|
|
72
82
|
}
|
|
73
83
|
function getPromptCacheRetention(compat, cacheRetention) {
|
|
@@ -161,10 +171,14 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
|
161
171
|
Object.assign(headers, copilotHeaders);
|
|
162
172
|
}
|
|
163
173
|
if (sessionId) {
|
|
164
|
-
if (compat.
|
|
165
|
-
headers
|
|
174
|
+
if (compat.sessionAffinityFormat === "openrouter") {
|
|
175
|
+
headers["x-session-id"] = sessionId;
|
|
176
|
+
} else {
|
|
177
|
+
if (compat.sessionAffinityFormat === "openai") {
|
|
178
|
+
headers.session_id = sessionId;
|
|
179
|
+
}
|
|
180
|
+
headers["x-client-request-id"] = sessionId;
|
|
166
181
|
}
|
|
167
|
-
headers["x-client-request-id"] = sessionId;
|
|
168
182
|
}
|
|
169
183
|
if (optionsHeaders) {
|
|
170
184
|
Object.assign(headers, optionsHeaders);
|
|
@@ -177,9 +191,12 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
|
177
191
|
});
|
|
178
192
|
}
|
|
179
193
|
function buildParams(model, context, options) {
|
|
180
|
-
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS);
|
|
181
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
182
194
|
const compat = getCompat(model);
|
|
195
|
+
const toolPlacement = splitDeferredTools(context, compat.supportsToolSearch);
|
|
196
|
+
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
|
|
197
|
+
deferredTools: toolPlacement.deferred
|
|
198
|
+
});
|
|
199
|
+
const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
|
|
183
200
|
const params = {
|
|
184
201
|
model: model.id,
|
|
185
202
|
input: messages,
|
|
@@ -189,7 +206,7 @@ function buildParams(model, context, options) {
|
|
|
189
206
|
store: false
|
|
190
207
|
};
|
|
191
208
|
if (options?.maxTokens) {
|
|
192
|
-
params.max_output_tokens = options
|
|
209
|
+
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
|
|
193
210
|
}
|
|
194
211
|
if (options?.temperature !== undefined) {
|
|
195
212
|
params.temperature = options?.temperature;
|
|
@@ -197,8 +214,11 @@ function buildParams(model, context, options) {
|
|
|
197
214
|
if (options?.serviceTier !== undefined) {
|
|
198
215
|
params.service_tier = options.serviceTier;
|
|
199
216
|
}
|
|
200
|
-
if (
|
|
201
|
-
params.tools = convertResponsesTools(
|
|
217
|
+
if (toolPlacement.immediate.length > 0) {
|
|
218
|
+
params.tools = convertResponsesTools(toolPlacement.immediate);
|
|
219
|
+
}
|
|
220
|
+
if (options?.toolChoice !== undefined) {
|
|
221
|
+
params.tool_choice = options.toolChoice;
|
|
202
222
|
}
|
|
203
223
|
if (model.reasoning) {
|
|
204
224
|
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
@@ -213,6 +233,8 @@ function buildParams(model, context, options) {
|
|
|
213
233
|
effort: model.thinkingLevelMap?.off ?? "none"
|
|
214
234
|
};
|
|
215
235
|
}
|
|
236
|
+
if (model.provider === "xai")
|
|
237
|
+
params.include = ["reasoning.encrypted_content"];
|
|
216
238
|
}
|
|
217
239
|
return params;
|
|
218
240
|
}
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
_setOpenRouterModelCacheRefreshForTests,
|
|
5
5
|
checkOpencodeCredentials,
|
|
6
6
|
resolveContextModePluginPath
|
|
7
|
-
} from "./cli-
|
|
8
|
-
import"./cli-yazx6hap.js";
|
|
7
|
+
} from "./cli-branks1w.js";
|
|
9
8
|
import"./cli-r94z9p1z.js";
|
|
9
|
+
import"./cli-yazx6hap.js";
|
|
10
10
|
import"./cli-d6n0thxw.js";
|
|
11
11
|
import"./cli-tng3131n.js";
|
|
12
12
|
import"./cli-zm7njwzd.js";
|