@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.js
CHANGED
|
@@ -1036,6 +1036,12 @@ function parseToolArguments(argsJson) {
|
|
|
1036
1036
|
// src/providers/anthropic.ts
|
|
1037
1037
|
var anthropicClientCache = /* @__PURE__ */ new Map();
|
|
1038
1038
|
var NON_STREAMING_REQUEST_TIMEOUT_MS = 6e5;
|
|
1039
|
+
function fineGrainedToolStreamingEnabled() {
|
|
1040
|
+
const raw = process.env.GG_FINE_GRAINED_TOOL_STREAMING ?? process.env.CLAUDE_CODE_ENABLE_FINE_GRAINED_TOOL_STREAMING;
|
|
1041
|
+
if (!raw) return false;
|
|
1042
|
+
const v = raw.trim().toLowerCase();
|
|
1043
|
+
return v === "1" || v === "true" || v === "yes" || v === "on";
|
|
1044
|
+
}
|
|
1039
1045
|
function createClient(options) {
|
|
1040
1046
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
1041
1047
|
const userAgent = isOAuth ? options.userAgent ?? "claude-cli/2.1.75 (external, cli)" : "";
|
|
@@ -1090,7 +1096,9 @@ async function prewarmAnthropicCache(options) {
|
|
|
1090
1096
|
] : system;
|
|
1091
1097
|
const tools = options.tools?.length ? toAnthropicTools(options.tools, {
|
|
1092
1098
|
cacheControl,
|
|
1093
|
-
|
|
1099
|
+
// Keep the serialized tool bytes identical to runStream so the
|
|
1100
|
+
// prewarmed prompt cache actually hits — both are gated by the flag.
|
|
1101
|
+
enableFineGrainedToolStreaming: fineGrainedToolStreamingEnabled()
|
|
1094
1102
|
}) : void 0;
|
|
1095
1103
|
await client.messages.create(
|
|
1096
1104
|
{
|
|
@@ -1170,7 +1178,7 @@ async function* runStream(options) {
|
|
|
1170
1178
|
options.tools.filter((t) => !reservedServerNames.has(t.name)),
|
|
1171
1179
|
{
|
|
1172
1180
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
1173
|
-
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
1181
|
+
...supportsFirstPartyToolExtras && fineGrainedToolStreamingEnabled() ? { enableFineGrainedToolStreaming: true } : {}
|
|
1174
1182
|
}
|
|
1175
1183
|
) : [];
|
|
1176
1184
|
return {
|
|
@@ -1196,7 +1204,10 @@ async function* runStream(options) {
|
|
|
1196
1204
|
...isOAuth ? ["claude-code-20250219", "oauth-2025-04-20"] : [],
|
|
1197
1205
|
...options.compaction ? ["compact-2026-01-12"] : [],
|
|
1198
1206
|
...options.clearToolUses ? ["context-management-2025-06-27"] : [],
|
|
1199
|
-
|
|
1207
|
+
// Eager tool-input streaming beta — opt-in only (see
|
|
1208
|
+
// fineGrainedToolStreamingEnabled). Off by default: the un-buffered stream
|
|
1209
|
+
// truncates large tool payloads into malformed JSON → phantom empty calls.
|
|
1210
|
+
...fineGrainedToolStreamingEnabled() ? ["fine-grained-tool-streaming-2025-05-14"] : [],
|
|
1200
1211
|
...!hasAdaptiveThinking ? ["interleaved-thinking-2025-05-14"] : [],
|
|
1201
1212
|
// The 1-h cache TTL (cacheRetention "long") is gated behind this beta. Without
|
|
1202
1213
|
// it Anthropic silently ignores ttl:"1h" and falls back to the 5-min default,
|
|
@@ -1331,7 +1342,14 @@ async function* runStream(options) {
|
|
|
1331
1342
|
try {
|
|
1332
1343
|
const parsed = JSON.parse(accum.argsJson);
|
|
1333
1344
|
args = isJsonObject(parsed) ? parsed : {};
|
|
1334
|
-
} catch {
|
|
1345
|
+
} catch (parseErr) {
|
|
1346
|
+
const rawPartial = accum.argsJson;
|
|
1347
|
+
const snippet = rawPartial.length > 200 ? `${rawPartial.slice(0, 200)}\u2026` : rawPartial;
|
|
1348
|
+
throw new ProviderError(
|
|
1349
|
+
"anthropic",
|
|
1350
|
+
`Tool "${accum.toolName}" input JSON was truncated in the stream (${rawPartial.length} bytes): ${snippet}; ${parseErr.message}`,
|
|
1351
|
+
{ cause: parseErr }
|
|
1352
|
+
);
|
|
1335
1353
|
}
|
|
1336
1354
|
}
|
|
1337
1355
|
const tc = {
|
|
@@ -1552,6 +1570,7 @@ function readUnifiedRateLimit(headers) {
|
|
|
1552
1570
|
return { rejected: status === "rejected", ...resetsAt ? { resetsAt } : {} };
|
|
1553
1571
|
}
|
|
1554
1572
|
function toError(err) {
|
|
1573
|
+
if (err instanceof ProviderError) return err;
|
|
1555
1574
|
if (err instanceof Anthropic.APIError) {
|
|
1556
1575
|
const errorBody = err.error;
|
|
1557
1576
|
const nestedError = errorBody?.error;
|