@code-yeongyu/senpi-ai 2026.8.18 → 2026.8.19
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 +5 -3
- package/dist/api/anthropic-messages.d.ts +7 -1
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +21 -4
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.d.ts +2 -0
- package/dist/api/azure-openai-responses.d.ts.map +1 -1
- package/dist/api/azure-openai-responses.js +7 -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 +39 -2
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/cursor-agent/gen/agent_pb.d.ts +22 -1
- package/dist/api/cursor-agent/gen/agent_pb.d.ts.map +1 -1
- package/dist/api/cursor-agent/gen/agent_pb.js +1 -1
- package/dist/api/cursor-agent/gen/agent_pb.js.map +1 -1
- package/dist/api/cursor-agent/reasoning-params.d.ts +20 -0
- package/dist/api/cursor-agent/reasoning-params.d.ts.map +1 -0
- package/dist/api/cursor-agent/reasoning-params.js +26 -0
- package/dist/api/cursor-agent/reasoning-params.js.map +1 -0
- package/dist/api/cursor-agent/types.d.ts +7 -1
- package/dist/api/cursor-agent/types.d.ts.map +1 -1
- package/dist/api/cursor-agent/types.js.map +1 -1
- package/dist/api/cursor-agent.d.ts +5 -3
- package/dist/api/cursor-agent.d.ts.map +1 -1
- package/dist/api/cursor-agent.js +82 -12
- package/dist/api/cursor-agent.js.map +1 -1
- package/dist/api/google-generative-ai.d.ts +2 -2
- package/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/api/google-generative-ai.js +14 -11
- package/dist/api/google-generative-ai.js.map +1 -1
- package/dist/api/google-shared.d.ts +5 -2
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +16 -0
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/google-vertex.d.ts +2 -2
- package/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/api/google-vertex.js +13 -10
- 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 +4 -1
- package/dist/api/mistral-conversations.js.map +1 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +4 -1
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts +1 -1
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +45 -29
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses.d.ts.map +1 -1
- package/dist/api/openai-responses.js +8 -1
- package/dist/api/openai-responses.js.map +1 -1
- package/dist/api/pi-messages.js +1 -1
- package/dist/api/pi-messages.js.map +1 -1
- package/dist/api/simple-options.d.ts +4 -0
- package/dist/api/simple-options.d.ts.map +1 -1
- package/dist/api/simple-options.js +18 -9
- package/dist/api/simple-options.js.map +1 -1
- package/dist/auth/oauth/device-code.d.ts +1 -0
- package/dist/auth/oauth/device-code.d.ts.map +1 -1
- package/dist/auth/oauth/device-code.js +1 -1
- package/dist/auth/oauth/device-code.js.map +1 -1
- package/dist/auth/oauth/github-copilot.d.ts.map +1 -1
- package/dist/auth/oauth/github-copilot.js +22 -9
- package/dist/auth/oauth/github-copilot.js.map +1 -1
- package/dist/cursor/catalog-grouping.d.ts +25 -0
- package/dist/cursor/catalog-grouping.d.ts.map +1 -0
- package/dist/cursor/catalog-grouping.js +134 -0
- package/dist/cursor/catalog-grouping.js.map +1 -0
- package/dist/cursor/cursor-variant-aliases.json +1893 -0
- package/dist/cursor/model-capabilities.d.ts +47 -0
- package/dist/cursor/model-capabilities.d.ts.map +1 -0
- package/dist/cursor/model-capabilities.js +208 -0
- package/dist/cursor/model-capabilities.js.map +1 -0
- package/dist/cursor/selection-descriptor.d.ts +21 -0
- package/dist/cursor/selection-descriptor.d.ts.map +1 -0
- package/dist/cursor/selection-descriptor.js +83 -0
- package/dist/cursor/selection-descriptor.js.map +1 -0
- package/dist/cursor/store-migration.d.ts +8 -0
- package/dist/cursor/store-migration.d.ts.map +1 -0
- package/dist/cursor/store-migration.js +76 -0
- package/dist/cursor/store-migration.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +13 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/models.d.ts +6 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +9 -1
- package/dist/models.js.map +1 -1
- package/dist/providers/cursor.d.ts.map +1 -1
- package/dist/providers/cursor.js +40 -11
- package/dist/providers/cursor.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/anthropic.json +1 -1
- package/dist/providers/data/baseten.json +1 -1
- package/dist/providers/data/github-copilot.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-individual.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/providers/data/xai.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/dist/providers/data/xiaomi.json +1 -1
- package/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/providers/data/zai.json +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js +1 -5
- package/dist/providers/xai.js.map +1 -1
- package/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +1 -1
- package/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +21 -1
- package/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +1 -1
- package/dist/tool-call-middleware/recovery-message-snapshot.d.ts.map +1 -1
- package/dist/tool-call-middleware/recovery-message-snapshot.js +2 -1
- package/dist/tool-call-middleware/recovery-message-snapshot.js.map +1 -1
- package/dist/types.d.ts +45 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/overflow.d.ts.map +1 -1
- package/dist/utils/overflow.js +15 -0
- package/dist/utils/overflow.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +7 -0
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/prompt-cache-ttl.d.ts +2 -1
- package/dist/utils/prompt-cache-ttl.d.ts.map +1 -1
- package/dist/utils/prompt-cache-ttl.js +2 -0
- package/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/package.json +2 -3
|
@@ -5,6 +5,7 @@ import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
|
5
5
|
import { shortHash } from "../utils/hash.js";
|
|
6
6
|
import { headersToRecord } from "../utils/headers.js";
|
|
7
7
|
import { parseStreamingJson } from "../utils/json-parse.js";
|
|
8
|
+
import { forcePiUserAgent } from "../utils/pi-user-agent.js";
|
|
8
9
|
import { getOpenAICompletionsCompat as getCompat, } from "../utils/prompt-cache-ttl.js";
|
|
9
10
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
10
11
|
import { retryProviderStreamRequest } from "../utils/provider-retry.js";
|
|
@@ -15,7 +16,7 @@ import { appendGrammarToolInputJsonDelta, createGrammarToolInputProperties, getG
|
|
|
15
16
|
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
16
17
|
import { resolveOpenAIClientAuth } from "./openai-client-auth.js";
|
|
17
18
|
import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
|
|
18
|
-
import { applyExtraBody, buildBaseOptions, clampMaxForOpenAI,
|
|
19
|
+
import { applyExtraBody, buildBaseOptions, clampMaxForOpenAI, clampThinkingBudgetToAnswerRoom, OPENAI_COMPLETIONS_RESERVED_BODY_KEYS, thinkingBudgetForLevel, } from "./simple-options.js";
|
|
19
20
|
import { transformMessages } from "./transform-messages.js";
|
|
20
21
|
export { getOpenAICompletionsCompat as getCompat, } from "../utils/prompt-cache-ttl.js";
|
|
21
22
|
const KIMI_K3_THINKING_LEVEL_MAP = {
|
|
@@ -647,7 +648,12 @@ export const stream = (model, context, options) => {
|
|
|
647
648
|
};
|
|
648
649
|
export const streamSimple = (model, context, options) => {
|
|
649
650
|
resolveOpenAIClientAuth(model.provider, options?.apiKey, options?.headers);
|
|
650
|
-
const base =
|
|
651
|
+
const base = {
|
|
652
|
+
...buildBaseOptions(model, context, options, options?.apiKey),
|
|
653
|
+
// Adapter-native callers may pass the richer OpenAI tool_choice shape; the
|
|
654
|
+
// provider-neutral SimpleStreamOptions value is the fallback.
|
|
655
|
+
toolChoice: options?.toolChoice ?? options?.toolChoice,
|
|
656
|
+
};
|
|
651
657
|
const compat = getCompat(model);
|
|
652
658
|
const thinkingLevelMap = getThinkingLevelMap(model, compat);
|
|
653
659
|
const thinkingModel = thinkingLevelMap === model.thinkingLevelMap ? model : { ...model, thinkingLevelMap };
|
|
@@ -657,11 +663,9 @@ export const streamSimple = (model, context, options) => {
|
|
|
657
663
|
: clampedReasoning === "max" && supportsMax(thinkingModel)
|
|
658
664
|
? "max"
|
|
659
665
|
: clampMaxForOpenAI(clampedReasoning, supportsXhigh(thinkingModel));
|
|
660
|
-
const toolChoice = options?.toolChoice;
|
|
661
666
|
return stream(model, context, {
|
|
662
667
|
...base,
|
|
663
668
|
reasoningEffort,
|
|
664
|
-
toolChoice,
|
|
665
669
|
thinkingBudgets: options?.thinkingBudgets,
|
|
666
670
|
});
|
|
667
671
|
};
|
|
@@ -691,6 +695,9 @@ function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId,
|
|
|
691
695
|
if (optionsHeaders) {
|
|
692
696
|
Object.assign(headers, optionsHeaders);
|
|
693
697
|
}
|
|
698
|
+
if (model.provider === "xai") {
|
|
699
|
+
forcePiUserAgent(headers);
|
|
700
|
+
}
|
|
694
701
|
return new OpenAI({
|
|
695
702
|
apiKey,
|
|
696
703
|
baseURL: model.baseUrl,
|
|
@@ -755,6 +762,8 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
755
762
|
if (options?.toolChoice) {
|
|
756
763
|
params.tool_choice = options.toolChoice;
|
|
757
764
|
}
|
|
765
|
+
const thinkingTokenBudgetField = resolveThinkingTokenBudgetField(compat);
|
|
766
|
+
const thinkingBudget = resolveClampedThinkingBudget(model, options, params);
|
|
758
767
|
if (compat.thinkingFormat === "zai" && model.reasoning) {
|
|
759
768
|
const isGlm53 = /(?:^|[/:-])glm-5\.3(?:$|[/.:_-])/.test(model.id.toLowerCase());
|
|
760
769
|
const zaiParams = params;
|
|
@@ -783,14 +792,14 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
783
792
|
};
|
|
784
793
|
}
|
|
785
794
|
else if (compat.thinkingFormat === "chat-template" && model.reasoning) {
|
|
786
|
-
const chatTemplateKwargs = buildChatTemplateValues(model, options, compat, compat.chatTemplateKwargs);
|
|
795
|
+
const chatTemplateKwargs = buildChatTemplateValues(model, options, compat, compat.chatTemplateKwargs, thinkingBudget);
|
|
787
796
|
if (chatTemplateKwargs) {
|
|
788
797
|
params.chat_template_kwargs = chatTemplateKwargs;
|
|
789
798
|
}
|
|
790
799
|
}
|
|
791
800
|
else if (compat.thinkingFormat === "baseten" && model.reasoning) {
|
|
792
801
|
const basetenParams = params;
|
|
793
|
-
const chatTemplateArgs = buildChatTemplateValues(model, options, compat, compat.chatTemplateArgs ?? {});
|
|
802
|
+
const chatTemplateArgs = buildChatTemplateValues(model, options, compat, compat.chatTemplateArgs ?? {}, thinkingBudget);
|
|
794
803
|
if (chatTemplateArgs) {
|
|
795
804
|
basetenParams.chat_template_args = chatTemplateArgs;
|
|
796
805
|
}
|
|
@@ -870,25 +879,12 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
870
879
|
params.reasoning_effort = offValue;
|
|
871
880
|
}
|
|
872
881
|
}
|
|
873
|
-
//
|
|
874
|
-
//
|
|
875
|
-
//
|
|
876
|
-
//
|
|
877
|
-
if (
|
|
878
|
-
|
|
879
|
-
const budgets = {
|
|
880
|
-
minimal: 1024,
|
|
881
|
-
low: 2048,
|
|
882
|
-
medium: 8192,
|
|
883
|
-
high: 16384,
|
|
884
|
-
...options.thinkingBudgets,
|
|
885
|
-
};
|
|
886
|
-
const ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;
|
|
887
|
-
// Always leave room for the answer, otherwise the budget recreates the bug it prevents.
|
|
888
|
-
const budget = Math.min(budgets[level], Math.max(0, ceiling - MIN_ANSWER_TOKENS));
|
|
889
|
-
if (budget > 0) {
|
|
890
|
-
params.thinking_token_budget = budget;
|
|
891
|
-
}
|
|
882
|
+
// Cap reasoning with a top-level budget field. Independent of thinkingFormat: the
|
|
883
|
+
// same server can serve zai, qwen or chat-template models. Reasoning and the answer
|
|
884
|
+
// share max_tokens here, so an uncapped reasoning phase can consume the whole
|
|
885
|
+
// response and leave no answer and no tool call.
|
|
886
|
+
if (thinkingTokenBudgetField && thinkingBudget !== undefined) {
|
|
887
|
+
Object.assign(params, { [thinkingTokenBudgetField]: thinkingBudget });
|
|
892
888
|
}
|
|
893
889
|
// OpenRouter provider routing preferences
|
|
894
890
|
if (model.compat?.openRouterRouting) {
|
|
@@ -913,17 +909,31 @@ function buildParams(model, context, options, compat = getCompat(model), cacheRe
|
|
|
913
909
|
}
|
|
914
910
|
return params;
|
|
915
911
|
}
|
|
916
|
-
function
|
|
912
|
+
function resolveThinkingTokenBudgetField(compat) {
|
|
913
|
+
if (compat.thinkingTokenBudgetField)
|
|
914
|
+
return compat.thinkingTokenBudgetField;
|
|
915
|
+
if (compat.supportsThinkingTokenBudget)
|
|
916
|
+
return "thinking_token_budget";
|
|
917
|
+
return undefined;
|
|
918
|
+
}
|
|
919
|
+
function resolveClampedThinkingBudget(model, options, params) {
|
|
920
|
+
if (!options?.reasoningEffort || !model.reasoning)
|
|
921
|
+
return undefined;
|
|
922
|
+
const ceiling = params.max_tokens ?? params.max_completion_tokens ?? model.maxTokens;
|
|
923
|
+
const budget = clampThinkingBudgetToAnswerRoom(thinkingBudgetForLevel(options.reasoningEffort, options.thinkingBudgets), ceiling);
|
|
924
|
+
return budget > 0 ? budget : undefined;
|
|
925
|
+
}
|
|
926
|
+
function buildChatTemplateValues(model, options, compat, values, thinkingBudget) {
|
|
917
927
|
const resolvedValues = {};
|
|
918
928
|
for (const [key, value] of Object.entries(values)) {
|
|
919
|
-
const resolved = resolveChatTemplateKwargValue(model, options, compat, value);
|
|
929
|
+
const resolved = resolveChatTemplateKwargValue(model, options, compat, value, thinkingBudget);
|
|
920
930
|
if (resolved !== undefined) {
|
|
921
931
|
resolvedValues[key] = resolved;
|
|
922
932
|
}
|
|
923
933
|
}
|
|
924
934
|
return Object.keys(resolvedValues).length > 0 ? resolvedValues : undefined;
|
|
925
935
|
}
|
|
926
|
-
function resolveChatTemplateKwargValue(model, options, compat, value) {
|
|
936
|
+
function resolveChatTemplateKwargValue(model, options, compat, value, thinkingBudget) {
|
|
927
937
|
if (typeof value !== "object" || value === null) {
|
|
928
938
|
return value;
|
|
929
939
|
}
|
|
@@ -934,6 +944,9 @@ function resolveChatTemplateKwargValue(model, options, compat, value) {
|
|
|
934
944
|
if (value.$var === "thinking.enabled") {
|
|
935
945
|
return !!reasoningEffort;
|
|
936
946
|
}
|
|
947
|
+
if (value.$var === "thinking.budget") {
|
|
948
|
+
return thinkingBudget;
|
|
949
|
+
}
|
|
937
950
|
const thinkingLevelMap = getThinkingLevelMap(model, compat);
|
|
938
951
|
const mappedValue = reasoningEffort ? thinkingLevelMap?.[reasoningEffort] : thinkingLevelMap?.off;
|
|
939
952
|
return mappedValue === undefined ? reasoningEffort : typeof mappedValue === "string" ? mappedValue : undefined;
|
|
@@ -1349,7 +1362,10 @@ function parseChunkUsage(rawUsage, model) {
|
|
|
1349
1362
|
const cacheReadTokens = rawUsage.prompt_tokens_details?.cached_tokens ?? rawUsage.prompt_cache_hit_tokens ?? rawUsage.cached_tokens ?? 0;
|
|
1350
1363
|
const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
|
|
1351
1364
|
// Follow documented OpenAI/OpenRouter semantics: cached_tokens is cache-read
|
|
1352
|
-
// tokens (hits).
|
|
1365
|
+
// tokens (hits). Providers disagree on placement: OpenAI/OpenRouter use
|
|
1366
|
+
// prompt_tokens_details.cached_tokens, DeepSeek uses prompt_cache_hit_tokens,
|
|
1367
|
+
// and Kimi documents top-level usage.cached_tokens on the final usage chunk.
|
|
1368
|
+
// OpenAI does not document or emit cache_write_tokens, but
|
|
1353
1369
|
// OpenRouter-compatible providers can include it as a separate write count.
|
|
1354
1370
|
// OpenRouter's own provider/tests affirm the separate mapping:
|
|
1355
1371
|
// https://github.com/OpenRouterTeam/ai-sdk-provider/pull/409
|