@kenkaiiii/gg-ai 5.87.1 → 5.87.2
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/index.cjs +23 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -286,6 +286,10 @@ interface StreamOptions {
|
|
|
286
286
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
287
287
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
288
288
|
streaming?: boolean;
|
|
289
|
+
/** Called whenever response body bytes arrive, including SSE pings the SDK
|
|
290
|
+
* swallows. Lets the agent loop's watchdog see a live connection while the
|
|
291
|
+
* model thinks silently (Anthropic sends only a ping every 30s then). */
|
|
292
|
+
onTransportActivity?: () => void;
|
|
289
293
|
/** Cache prewarm (Anthropic only; other providers ignore it). Sends the exact
|
|
290
294
|
* same request prefix (system, tools, messages, thinking, betas) with
|
|
291
295
|
* `max_tokens: 1` over a non-streaming request so the prompt cache is written
|
package/dist/index.d.ts
CHANGED
|
@@ -286,6 +286,10 @@ interface StreamOptions {
|
|
|
286
286
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
287
287
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
288
288
|
streaming?: boolean;
|
|
289
|
+
/** Called whenever response body bytes arrive, including SSE pings the SDK
|
|
290
|
+
* swallows. Lets the agent loop's watchdog see a live connection while the
|
|
291
|
+
* model thinks silently (Anthropic sends only a ping every 30s then). */
|
|
292
|
+
onTransportActivity?: () => void;
|
|
289
293
|
/** Cache prewarm (Anthropic only; other providers ignore it). Sends the exact
|
|
290
294
|
* same request prefix (system, tools, messages, thinking, betas) with
|
|
291
295
|
* `max_tokens: 1` over a non-streaming request so the prompt cache is written
|
package/dist/index.js
CHANGED
|
@@ -1721,7 +1721,7 @@ function parseToolArguments(argsJson) {
|
|
|
1721
1721
|
|
|
1722
1722
|
// src/utils/provider-fetch.ts
|
|
1723
1723
|
import { Agent, EnvHttpProxyAgent, fetch as undiciFetch } from "undici";
|
|
1724
|
-
var PROVIDER_TRANSPORT_TIMEOUT_MS =
|
|
1724
|
+
var PROVIDER_TRANSPORT_TIMEOUT_MS = 45 * 6e4;
|
|
1725
1725
|
function nodeUsesEnvProxy({
|
|
1726
1726
|
env = process.env,
|
|
1727
1727
|
execArgv = process.execArgv,
|
|
@@ -1749,6 +1749,25 @@ function createProviderFetch(timeoutMs, { useEnvProxy = nodeUsesEnvProxy() } = {
|
|
|
1749
1749
|
};
|
|
1750
1750
|
return Object.assign(providerFetch2, { Response: globalThis.Response });
|
|
1751
1751
|
}
|
|
1752
|
+
function withBodyActivity(fetchImpl, onActivity) {
|
|
1753
|
+
return async (input, init2) => {
|
|
1754
|
+
const response = await fetchImpl(input, init2);
|
|
1755
|
+
if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
1756
|
+
return response;
|
|
1757
|
+
}
|
|
1758
|
+
const tap = new TransformStream({
|
|
1759
|
+
transform(chunk, controller) {
|
|
1760
|
+
onActivity();
|
|
1761
|
+
controller.enqueue(chunk);
|
|
1762
|
+
}
|
|
1763
|
+
});
|
|
1764
|
+
return new Response(response.body.pipeThrough(tap), {
|
|
1765
|
+
status: response.status,
|
|
1766
|
+
statusText: response.statusText,
|
|
1767
|
+
headers: response.headers
|
|
1768
|
+
});
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1752
1771
|
var providerFetch = createProviderFetch(
|
|
1753
1772
|
PROVIDER_TRANSPORT_TIMEOUT_MS
|
|
1754
1773
|
);
|
|
@@ -2049,8 +2068,10 @@ async function* runStream(options) {
|
|
|
2049
2068
|
const keepalive = { type: "keepalive" };
|
|
2050
2069
|
let receivedAnyEvent = false;
|
|
2051
2070
|
try {
|
|
2071
|
+
const onActivity = options.onTransportActivity;
|
|
2072
|
+
const streamClient = onActivity ? client.withOptions({ fetch: withBodyActivity(options.fetch ?? providerFetch, onActivity) }) : client;
|
|
2052
2073
|
const stream2 = await send(
|
|
2053
|
-
(p, o) =>
|
|
2074
|
+
(p, o) => streamClient.messages.create(p, o)
|
|
2054
2075
|
);
|
|
2055
2076
|
for await (const event of stream2) {
|
|
2056
2077
|
receivedAnyEvent = true;
|