@code-yeongyu/senpi-ai 2026.7.31 → 2026.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/README.md +2 -1
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +56 -25
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/anthropic-tool-pairs.d.ts +3 -0
- package/dist/api/anthropic-tool-pairs.d.ts.map +1 -0
- package/dist/api/anthropic-tool-pairs.js +134 -0
- package/dist/api/anthropic-tool-pairs.js.map +1 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +7 -3
- 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 +64 -4
- 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 +12 -2
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +13 -6
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +12 -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 +19 -10
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses/fallback-state.d.ts +24 -0
- package/dist/api/openai-codex-responses/fallback-state.d.ts.map +1 -0
- package/dist/api/openai-codex-responses/fallback-state.js +70 -0
- package/dist/api/openai-codex-responses/fallback-state.js.map +1 -0
- package/dist/api/openai-codex-responses.d.ts +2 -16
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +94 -105
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +19 -10
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-prompt-cache.d.ts +1 -0
- package/dist/api/openai-prompt-cache.d.ts.map +1 -1
- package/dist/api/openai-prompt-cache.js +7 -0
- package/dist/api/openai-prompt-cache.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +11 -1
- package/dist/api/openai-responses-shared.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +9 -5
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/openrouter-images.js +3 -2
- package/dist/api/openrouter-images.js.map +1 -1
- package/dist/api/pi-messages.js +2 -2
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +1 -0
- package/dist/api/simple-options.js.map +1 -1
- package/dist/auth/oauth/openrouter.d.ts +3 -1
- package/dist/auth/oauth/openrouter.d.ts.map +1 -1
- package/dist/auth/oauth/openrouter.js +81 -26
- package/dist/auth/oauth/openrouter.js.map +1 -1
- package/dist/auth/resolve.d.ts +2 -0
- package/dist/auth/resolve.d.ts.map +1 -1
- package/dist/auth/resolve.js +16 -8
- package/dist/auth/resolve.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +2 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +95 -19
- package/dist/models.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.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/fireworks.json +1 -1
- package/dist/providers/data/github-copilot.json +1 -1
- package/dist/providers/data/huggingface.json +1 -1
- package/dist/providers/data/mistral.json +1 -1
- package/dist/providers/data/openai-codex.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/openrouter.json +1 -1
- package/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/providers/data/together.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.map +1 -1
- package/dist/providers/faux.js +4 -1
- package/dist/providers/faux.js.map +1 -1
- package/dist/providers/opencode-go.js +1 -1
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/types.d.ts +18 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/error-body.d.ts.map +1 -1
- package/dist/utils/error-body.js +23 -4
- package/dist/utils/error-body.js.map +1 -1
- package/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
- package/dist/utils/prompt-cache-ttl.js +10 -1
- package/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/dist/utils/provider-retry.d.ts +3 -0
- package/dist/utils/provider-retry.d.ts.map +1 -1
- package/dist/utils/provider-retry.js +13 -12
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry-hint.d.ts +24 -0
- package/dist/utils/retry-hint.d.ts.map +1 -0
- package/dist/utils/retry-hint.js +233 -0
- package/dist/utils/retry-hint.js.map +1 -0
- package/dist/utils/unavailable-tool-text.d.ts +3 -0
- package/dist/utils/unavailable-tool-text.d.ts.map +1 -0
- package/dist/utils/unavailable-tool-text.js +36 -0
- package/dist/utils/unavailable-tool-text.js.map +1 -0
- package/package.json +10 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import { calculateCost, clampThinkingLevel, supportsXhigh } from "../models.js";
|
|
2
|
+
import { calculateCost, clampThinkingLevel, supportsMax, supportsXhigh } from "../models.js";
|
|
3
3
|
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
4
4
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
5
5
|
import { shortHash } from "../utils/hash.js";
|
|
@@ -197,7 +197,7 @@ export const stream = (model, context, options) => {
|
|
|
197
197
|
totalTokens: 0,
|
|
198
198
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
199
199
|
},
|
|
200
|
-
stopReason: "
|
|
200
|
+
stopReason: "pending",
|
|
201
201
|
timestamp: Date.now(),
|
|
202
202
|
};
|
|
203
203
|
try {
|
|
@@ -206,7 +206,7 @@ export const stream = (model, context, options) => {
|
|
|
206
206
|
const grammarToolInputProperties = createGrammarToolInputProperties(context.tools, compat.supportsOpenAIGrammarTools);
|
|
207
207
|
const cacheRetention = resolveCacheRetention(options?.cacheRetention ?? model.cacheRetention, options?.env);
|
|
208
208
|
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
209
|
-
const client = createClient(model, context, clientAuth.apiKey, clientAuth.headers, cacheSessionId, compat);
|
|
209
|
+
const client = createClient(model, context, clientAuth.apiKey, clientAuth.headers, options?.fetch, cacheSessionId, compat);
|
|
210
210
|
let params = buildParams(model, context, options, compat, cacheRetention, grammarToolInputProperties);
|
|
211
211
|
const nextParams = await options?.onPayload?.(params, model);
|
|
212
212
|
if (nextParams !== undefined) {
|
|
@@ -384,9 +384,7 @@ export const stream = (model, context, options) => {
|
|
|
384
384
|
}
|
|
385
385
|
// Note: the "input" fallback here should/must not be taken. in case the LLM makes up
|
|
386
386
|
// a tool we don't knwo about, we at least have a place to stash our stuff.
|
|
387
|
-
const customInputProperty = toolCall.custom
|
|
388
|
-
? (grammarToolInputProperties.get(name) ?? "input")
|
|
389
|
-
: undefined;
|
|
387
|
+
const customInputProperty = toolCall.custom && !toolCall.function ? (grammarToolInputProperties.get(name) ?? "input") : undefined;
|
|
390
388
|
const hasCustomInput = customInputProperty !== undefined;
|
|
391
389
|
block = {
|
|
392
390
|
type: "toolCall",
|
|
@@ -425,7 +423,7 @@ export const stream = (model, context, options) => {
|
|
|
425
423
|
if (!block.name && name) {
|
|
426
424
|
block.name = name;
|
|
427
425
|
}
|
|
428
|
-
if (toolCall.custom && !block.customInput) {
|
|
426
|
+
if (toolCall.custom && !toolCall.function && !block.customInput) {
|
|
429
427
|
const customInputProperty = grammarToolInputProperties.get(block.name) ?? "input";
|
|
430
428
|
block.arguments = { [customInputProperty]: "" };
|
|
431
429
|
block.customInput = {
|
|
@@ -483,6 +481,7 @@ export const stream = (model, context, options) => {
|
|
|
483
481
|
output.usage = parseChunkUsage(choiceUsage, model);
|
|
484
482
|
}
|
|
485
483
|
if (choice.finish_reason) {
|
|
484
|
+
output.rawStopReason = choice.finish_reason;
|
|
486
485
|
const finishReasonResult = mapStopReason(choice.finish_reason);
|
|
487
486
|
output.stopReason = finishReasonResult.stopReason;
|
|
488
487
|
if (finishReasonResult.errorMessage) {
|
|
@@ -610,10 +609,13 @@ export const stream = (model, context, options) => {
|
|
|
610
609
|
if (output.stopReason === "aborted") {
|
|
611
610
|
throw new Error("Request was aborted");
|
|
612
611
|
}
|
|
612
|
+
if (!hasFinishReason && !compat.supportsFinishReason) {
|
|
613
|
+
output.stopReason = output.content.some((block) => block.type === "toolCall") ? "toolUse" : "stop";
|
|
614
|
+
}
|
|
613
615
|
if (output.stopReason === "error") {
|
|
614
616
|
throw new Error(output.errorMessage || "Provider returned an error stop reason");
|
|
615
617
|
}
|
|
616
|
-
if (!hasFinishReason) {
|
|
618
|
+
if ((compat.supportsFinishReason && !hasFinishReason) || output.stopReason === "pending") {
|
|
617
619
|
throw new Error("Stream ended without finish_reason");
|
|
618
620
|
}
|
|
619
621
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
@@ -652,7 +654,7 @@ export const streamSimple = (model, context, options) => {
|
|
|
652
654
|
const clampedReasoning = options?.reasoning ? clampThinkingLevel(thinkingModel, options.reasoning) : undefined;
|
|
653
655
|
const reasoningEffort = clampedReasoning === "off"
|
|
654
656
|
? undefined
|
|
655
|
-
: clampedReasoning === "max" &&
|
|
657
|
+
: clampedReasoning === "max" && supportsMax(thinkingModel)
|
|
656
658
|
? "max"
|
|
657
659
|
: clampMaxForOpenAI(clampedReasoning, supportsXhigh(thinkingModel));
|
|
658
660
|
const toolChoice = options?.toolChoice;
|
|
@@ -662,7 +664,7 @@ export const streamSimple = (model, context, options) => {
|
|
|
662
664
|
toolChoice,
|
|
663
665
|
});
|
|
664
666
|
};
|
|
665
|
-
function createClient(model, context, apiKey, optionsHeaders, sessionId, compat = getCompat(model)) {
|
|
667
|
+
function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId, compat = getCompat(model)) {
|
|
666
668
|
const headers = { ...model.headers };
|
|
667
669
|
if (model.provider === "github-copilot") {
|
|
668
670
|
const hasImages = hasCopilotVisionInput(context.messages);
|
|
@@ -692,6 +694,7 @@ function createClient(model, context, apiKey, optionsHeaders, sessionId, compat
|
|
|
692
694
|
apiKey,
|
|
693
695
|
baseURL: model.baseUrl,
|
|
694
696
|
dangerouslyAllowBrowser: true,
|
|
697
|
+
fetch,
|
|
695
698
|
defaultHeaders: headers,
|
|
696
699
|
});
|
|
697
700
|
}
|
|
@@ -759,6 +762,12 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
759
762
|
}
|
|
760
763
|
else if (compat.thinkingFormat === "qwen" && model.reasoning) {
|
|
761
764
|
params.enable_thinking = !!options?.reasoningEffort;
|
|
765
|
+
if (options?.reasoningEffort && compat.supportsReasoningEffort) {
|
|
766
|
+
const effort = resolveReasoningEffort(thinkingLevelMap, options.reasoningEffort);
|
|
767
|
+
if (effort !== undefined) {
|
|
768
|
+
params.reasoning_effort = effort;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
762
771
|
}
|
|
763
772
|
else if (compat.thinkingFormat === "qwen-chat-template" && model.reasoning) {
|
|
764
773
|
params.chat_template_kwargs = {
|