@kenkaiiii/gg-ai 5.8.2 → 5.8.3
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 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1091,6 +1091,12 @@ function parseToolArguments(argsJson) {
|
|
|
1091
1091
|
// src/providers/anthropic.ts
|
|
1092
1092
|
var anthropicClientCache = /* @__PURE__ */ new Map();
|
|
1093
1093
|
var NON_STREAMING_REQUEST_TIMEOUT_MS = 6e5;
|
|
1094
|
+
function fineGrainedToolStreamingEnabled() {
|
|
1095
|
+
const raw = process.env.GG_FINE_GRAINED_TOOL_STREAMING ?? process.env.CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING;
|
|
1096
|
+
if (!raw) return false;
|
|
1097
|
+
const v = raw.trim().toLowerCase();
|
|
1098
|
+
return v === "1" || v === "true" || v === "yes" || v === "on";
|
|
1099
|
+
}
|
|
1094
1100
|
function createClient(options) {
|
|
1095
1101
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
1096
1102
|
const userAgent = isOAuth ? options.userAgent ?? "claude-cli/2.1.75 (external, cli)" : "";
|
|
@@ -1145,7 +1151,9 @@ async function prewarmAnthropicCache(options) {
|
|
|
1145
1151
|
] : system;
|
|
1146
1152
|
const tools = options.tools?.length ? toAnthropicTools(options.tools, {
|
|
1147
1153
|
cacheControl,
|
|
1148
|
-
|
|
1154
|
+
// Keep the serialized tool bytes identical to runStream so the
|
|
1155
|
+
// prewarmed prompt cache actually hits — both are gated by the flag.
|
|
1156
|
+
enableFineGrainedToolStreaming: fineGrainedToolStreamingEnabled()
|
|
1149
1157
|
}) : void 0;
|
|
1150
1158
|
await client.messages.create(
|
|
1151
1159
|
{
|
|
@@ -1225,7 +1233,7 @@ async function* runStream(options) {
|
|
|
1225
1233
|
options.tools.filter((t) => !reservedServerNames.has(t.name)),
|
|
1226
1234
|
{
|
|
1227
1235
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
1228
|
-
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
1236
|
+
...supportsFirstPartyToolExtras && fineGrainedToolStreamingEnabled() ? { enableFineGrainedToolStreaming: true } : {}
|
|
1229
1237
|
}
|
|
1230
1238
|
) : [];
|
|
1231
1239
|
return {
|
|
@@ -1251,7 +1259,10 @@ async function* runStream(options) {
|
|
|
1251
1259
|
...isOAuth ? ["claude-code-20250219", "oauth-2025-04-20"] : [],
|
|
1252
1260
|
...options.compaction ? ["compact-2026-01-12"] : [],
|
|
1253
1261
|
...options.clearToolUses ? ["context-management-2025-06-27"] : [],
|
|
1254
|
-
|
|
1262
|
+
// Eager tool-input streaming beta — opt-in only (see
|
|
1263
|
+
// fineGrainedToolStreamingEnabled). Off by default: the un-buffered stream
|
|
1264
|
+
// truncates large tool payloads into malformed JSON → phantom empty calls.
|
|
1265
|
+
...fineGrainedToolStreamingEnabled() ? ["fine-grained-tool-streaming-2025-05-14"] : [],
|
|
1255
1266
|
...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : [],
|
|
1256
1267
|
// The 1-h cache TTL (cacheRetention "long") is gated behind this beta. Without
|
|
1257
1268
|
// it Anthropic silently ignores ttl:"1h" and falls back to the 5-min default,
|
|
@@ -1386,7 +1397,14 @@ async function* runStream(options) {
|
|
|
1386
1397
|
try {
|
|
1387
1398
|
const parsed = JSON.parse(accum.argsJson);
|
|
1388
1399
|
args = isJsonObject(parsed) ? parsed : {};
|
|
1389
|
-
} catch {
|
|
1400
|
+
} catch (parseErr) {
|
|
1401
|
+
const rawPartial = accum.argsJson;
|
|
1402
|
+
const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
|
|
1403
|
+
throw new ProviderError(
|
|
1404
|
+
"anthropic",
|
|
1405
|
+
`Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
|
|
1406
|
+
{ cause: parseErr }
|
|
1407
|
+
);
|
|
1390
1408
|
}
|
|
1391
1409
|
}
|
|
1392
1410
|
const tc = {
|
|
@@ -1607,6 +1625,7 @@ function readUnifiedRateLimit(headers) {
|
|
|
1607
1625
|
return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
|
|
1608
1626
|
}
|
|
1609
1627
|
function toError(err) {
|
|
1628
|
+
if (err instanceof ProviderError) return err;
|
|
1610
1629
|
if (err instanceof import_sdk.default.APIError) {
|
|
1611
1630
|
const errorBody = err.error;
|
|
1612
1631
|
const nestedError = errorBody?.error;
|