@code-yeongyu/senpi-ai 2026.8.24 → 2026.8.26
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/api/anthropic-messages.d.ts +1 -5
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +25 -13
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +2 -1
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +91 -5
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +4 -2
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +4 -2
- package/dist/api/google-vertex.js.map +1 -1
- package/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/api/mistral-conversations.js +2 -0
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +93 -54
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses.js +2 -5
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/transform-messages.js +1 -1
- package/dist/api/transform-messages.js.map +1 -1
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +97 -46
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/dist/auth/oauth/kimi-coding.js +1 -14
- package/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/dist/auth/pool/slots.d.ts +50 -0
- package/dist/auth/pool/slots.d.ts.map +1 -0
- package/dist/auth/pool/slots.js +129 -0
- package/dist/auth/pool/slots.js.map +1 -0
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +3 -1
- package/dist/auth/resolve.js.map +1 -1
- package/dist/models.d.ts +8 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +16 -3
- package/dist/models.js.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts +3 -1
- package/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
- package/dist/providers/cloudflare-ai-gateway.js +10 -1
- package/dist/providers/cloudflare-ai-gateway.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/azure-openai-responses.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/nvidia.json +1 -1
- package/dist/providers/data/openai.json +1 -1
- package/dist/providers/data/opencode-go.json +1 -1
- package/dist/providers/data/opencode.json +1 -1
- package/dist/providers/data/opengateway.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/data/zai.json +1 -1
- package/dist/providers/faux.d.ts +1 -0
- package/dist/providers/faux.d.ts.map +1 -1
- package/dist/providers/faux.js +1 -0
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +4 -0
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/overflow.d.ts +16 -0
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +17 -1
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/retry-profile/backoff.d.ts +14 -0
- package/dist/utils/retry-profile/backoff.d.ts.map +1 -0
- package/dist/utils/retry-profile/backoff.js +24 -0
- package/dist/utils/retry-profile/backoff.js.map +1 -0
- package/dist/utils/retry-profile/classifiers.d.ts +36 -0
- package/dist/utils/retry-profile/classifiers.d.ts.map +1 -0
- package/dist/utils/retry-profile/classifiers.js +109 -0
- package/dist/utils/retry-profile/classifiers.js.map +1 -0
- package/dist/utils/retry-profile/failure.d.ts +12 -0
- package/dist/utils/retry-profile/failure.d.ts.map +1 -0
- package/dist/utils/retry-profile/failure.js +109 -0
- package/dist/utils/retry-profile/failure.js.map +1 -0
- package/dist/utils/retry-profile/index.d.ts +9 -0
- package/dist/utils/retry-profile/index.d.ts.map +1 -0
- package/dist/utils/retry-profile/index.js +6 -0
- package/dist/utils/retry-profile/index.js.map +1 -0
- package/dist/utils/retry-profile/planner.d.ts +46 -0
- package/dist/utils/retry-profile/planner.d.ts.map +1 -0
- package/dist/utils/retry-profile/planner.js +41 -0
- package/dist/utils/retry-profile/planner.js.map +1 -0
- package/dist/utils/retry-profile/profiles.d.ts +4 -0
- package/dist/utils/retry-profile/profiles.d.ts.map +1 -0
- package/dist/utils/retry-profile/profiles.js +93 -0
- package/dist/utils/retry-profile/profiles.js.map +1 -0
- package/dist/utils/retry-profile/types.d.ts +121 -0
- package/dist/utils/retry-profile/types.d.ts.map +1 -0
- package/dist/utils/retry-profile/types.js +11 -0
- package/dist/utils/retry-profile/types.js.map +1 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +25 -5
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +15 -0
- package/dist/utils/sleep.js.map +1 -0
- package/package.json +19 -15
|
@@ -52,11 +52,7 @@ export interface AnthropicOptions extends StreamOptions {
|
|
|
52
52
|
* Default: true.
|
|
53
53
|
*/
|
|
54
54
|
interleavedThinking?: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Anthropic refusal fallback. When set, the request includes the server-side
|
|
57
|
-
* fallback beta and Anthropic retries eligible refusals on the configured
|
|
58
|
-
* fallback target before returning a final response.
|
|
59
|
-
*/
|
|
55
|
+
/** Anthropic server-side fallback for eligible refusal stop reasons. */
|
|
60
56
|
refusalFallbacks?: AnthropicRefusalFallback;
|
|
61
57
|
/**
|
|
62
58
|
* Anthropic tool choice behavior. String values map to Anthropic's built-in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAGX,+BAA+B,EAK/B,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACX,wBAAwB,EAKxB,OAAO,EAGP,KAAK,EAGL,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAOb,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAGX,+BAA+B,EAK/B,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACX,wBAAwB,EAKxB,OAAO,EAGP,KAAK,EAGL,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAOb,MAAM,aAAa,CAAC;AAqCrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA6JlE,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAyEhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAC5C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AAy1BD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAqbzE,CAAC;AA0FF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CA+ClF,CAAC;AA6IF,wBAAgB,mCAAmC,CAClD,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC,EAClC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACxB,+BAA+B,CAkBjC"}
|
|
@@ -3,6 +3,7 @@ import { calculateCost } from "../models.js";
|
|
|
3
3
|
import { isVideoMimeType } from "../types.js";
|
|
4
4
|
import { combineAbortSignals } from "../utils/abort-signals.js";
|
|
5
5
|
import { splitDeferredTools } from "../utils/deferred-tools.js";
|
|
6
|
+
import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
|
|
6
7
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
7
8
|
import { headersToRecord, providerHeadersToRecord } from "../utils/headers.js";
|
|
8
9
|
import { parseJsonWithRepair, parseStreamingJson } from "../utils/json-parse.js";
|
|
@@ -11,6 +12,7 @@ import { getAnthropicCompat, isAnthropicApiBaseUrl } from "../utils/prompt-cache
|
|
|
11
12
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
12
13
|
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
13
14
|
import { appendRetryAfterMsMarker, extract429RetryAfterMs } from "../utils/retry-hint.js";
|
|
15
|
+
import { normalizeAnthropicRetryFailure } from "../utils/retry-profile/failure.js";
|
|
14
16
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
15
17
|
import { applyServerFallbackAbort, parseServerFallbackReceipt, parseStickyFallbackReceipt, } from "../utils/server-fallback-receipt.js";
|
|
16
18
|
import { normalizeToolCallId } from "../utils/tool-call-id.js";
|
|
@@ -199,15 +201,8 @@ function mergeHeaders(...headerSources) {
|
|
|
199
201
|
}
|
|
200
202
|
return merged;
|
|
201
203
|
}
|
|
202
|
-
function mergeClientHeaders(
|
|
203
|
-
const merged = mergeHeaders(...headerSources);
|
|
204
|
-
if (model.provider === "kimi-coding") {
|
|
205
|
-
for (const name of Object.keys(merged)) {
|
|
206
|
-
if (name.toLowerCase() === "user-agent")
|
|
207
|
-
delete merged[name];
|
|
208
|
-
}
|
|
209
|
-
merged["User-Agent"] = getPiUserAgent();
|
|
210
|
-
}
|
|
204
|
+
function mergeClientHeaders(_model, ...headerSources) {
|
|
205
|
+
const merged = mergeHeaders({ "User-Agent": getPiUserAgent() }, ...headerSources);
|
|
211
206
|
return merged;
|
|
212
207
|
}
|
|
213
208
|
function hasHeader(headers, name) {
|
|
@@ -924,6 +919,7 @@ export const stream = (model, context, options) => {
|
|
|
924
919
|
try {
|
|
925
920
|
let client;
|
|
926
921
|
let isOAuth;
|
|
922
|
+
let usageModel = model;
|
|
927
923
|
if (options?.client) {
|
|
928
924
|
client = options.client;
|
|
929
925
|
isOAuth = false;
|
|
@@ -1007,6 +1003,13 @@ export const stream = (model, context, options) => {
|
|
|
1007
1003
|
if (event.type === "message_start") {
|
|
1008
1004
|
output.responseId = event.message.id;
|
|
1009
1005
|
output.model = event.message.model;
|
|
1006
|
+
const fallback = output.model === model.id
|
|
1007
|
+
? undefined
|
|
1008
|
+
: model.compat?.allowedFallbackModels?.find((candidate) => typeof candidate !== "string" &&
|
|
1009
|
+
candidate.provider === model.provider &&
|
|
1010
|
+
candidate.model === output.model);
|
|
1011
|
+
const fallbackCost = typeof fallback === "string" ? undefined : fallback?.cost;
|
|
1012
|
+
usageModel = fallbackCost ? { ...model, id: output.model, cost: fallbackCost } : model;
|
|
1010
1013
|
// Capture initial token usage from message_start event
|
|
1011
1014
|
// This ensures we have input token counts even if the stream is aborted early
|
|
1012
1015
|
output.usage.input = event.message.usage.input_tokens || 0;
|
|
@@ -1228,7 +1231,7 @@ export const stream = (model, context, options) => {
|
|
|
1228
1231
|
// Anthropic doesn't provide total_tokens, compute from components
|
|
1229
1232
|
output.usage.totalTokens =
|
|
1230
1233
|
output.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;
|
|
1231
|
-
calculateCost(
|
|
1234
|
+
calculateCost(usageModel, output.usage);
|
|
1232
1235
|
}
|
|
1233
1236
|
}
|
|
1234
1237
|
if (options?.signal?.aborted) {
|
|
@@ -1279,6 +1282,18 @@ export const stream = (model, context, options) => {
|
|
|
1279
1282
|
}
|
|
1280
1283
|
}
|
|
1281
1284
|
}
|
|
1285
|
+
const failure = normalizeAnthropicRetryFailure(error);
|
|
1286
|
+
appendAssistantMessageDiagnostic(output, {
|
|
1287
|
+
type: "provider_retry_failure",
|
|
1288
|
+
timestamp: Date.now(),
|
|
1289
|
+
details: {
|
|
1290
|
+
kind: failure.kind,
|
|
1291
|
+
...(failure.statusCode !== undefined ? { statusCode: failure.statusCode } : {}),
|
|
1292
|
+
...(failure.providerCodes !== undefined ? { providerCodes: failure.providerCodes } : {}),
|
|
1293
|
+
...(failure.retryAfterMs !== undefined ? { retryAfterMs: failure.retryAfterMs } : {}),
|
|
1294
|
+
...(failure.shouldRetry !== undefined ? { shouldRetry: failure.shouldRetry } : {}),
|
|
1295
|
+
},
|
|
1296
|
+
});
|
|
1282
1297
|
output.errorMessage = errorMessage;
|
|
1283
1298
|
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
1284
1299
|
stream.end();
|
|
@@ -1366,7 +1381,6 @@ export const streamSimple = (model, context, options) => {
|
|
|
1366
1381
|
if (!options?.reasoning) {
|
|
1367
1382
|
return stream(model, context, {
|
|
1368
1383
|
...base,
|
|
1369
|
-
refusalFallbacks: options?.refusalFallbacks,
|
|
1370
1384
|
thinkingEnabled: false,
|
|
1371
1385
|
});
|
|
1372
1386
|
}
|
|
@@ -1376,7 +1390,6 @@ export const streamSimple = (model, context, options) => {
|
|
|
1376
1390
|
const effort = mapThinkingLevelToEffort(model, options.reasoning);
|
|
1377
1391
|
return stream(model, context, {
|
|
1378
1392
|
...base,
|
|
1379
|
-
refusalFallbacks: options?.refusalFallbacks,
|
|
1380
1393
|
thinkingEnabled: true,
|
|
1381
1394
|
effort,
|
|
1382
1395
|
});
|
|
@@ -1387,7 +1400,6 @@ export const streamSimple = (model, context, options) => {
|
|
|
1387
1400
|
const maxTokens = clampMaxTokensToContext(model, context, adjusted.maxTokens);
|
|
1388
1401
|
return stream(model, context, {
|
|
1389
1402
|
...base,
|
|
1390
|
-
refusalFallbacks: options?.refusalFallbacks,
|
|
1391
1403
|
maxTokens,
|
|
1392
1404
|
thinkingEnabled: true,
|
|
1393
1405
|
thinkingBudgetTokens: Math.min(adjusted.thinkingBudget, Math.max(0, maxTokens - 1024)),
|