@code-yeongyu/senpi-ai 2026.7.25-2 → 2026.7.28
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 -0
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +296 -66
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/azure-openai-responses.js +4 -2
- package/dist/api/azure-openai-responses.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts +1 -0
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +3 -47
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/google-shared.d.ts.map +1 -1
- package/dist/api/google-shared.js +4 -3
- package/dist/api/google-shared.js.map +1 -1
- package/dist/api/openai-codex-responses/reasoning.d.ts +14 -0
- package/dist/api/openai-codex-responses/reasoning.d.ts.map +1 -0
- package/dist/api/openai-codex-responses/reasoning.js +27 -0
- package/dist/api/openai-codex-responses/reasoning.js.map +1 -0
- package/dist/api/openai-codex-responses.d.ts +2 -1
- package/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/api/openai-codex-responses.js +4 -12
- package/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/api/openai-completions.d.ts +3 -8
- package/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/api/openai-completions.js +8 -122
- package/dist/api/openai-completions.js.map +1 -1
- package/dist/api/openai-responses-shared.d.ts +1 -0
- package/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/dist/api/openai-responses-shared.js +67 -31
- 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 +2 -1
- package/dist/api/openai-responses.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 +7 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js.map +1 -1
- package/dist/oauth.d.ts +2 -1
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +2 -1
- package/dist/oauth.js.map +1 -1
- package/dist/openai-responses-compat.d.ts +24 -0
- package/dist/openai-responses-compat.d.ts.map +1 -0
- package/dist/openai-responses-compat.js +2 -0
- package/dist/openai-responses-compat.js.map +1 -0
- package/dist/providers/data/.manifest.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/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.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/together.json +1 -1
- package/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/types.d.ts +8 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/prompt-cache-ttl.d.ts +32 -0
- package/dist/utils/prompt-cache-ttl.d.ts.map +1 -0
- package/dist/utils/prompt-cache-ttl.js +294 -0
- package/dist/utils/prompt-cache-ttl.js.map +1 -0
- package/dist/utils/provider-retry.d.ts +5 -0
- package/dist/utils/provider-retry.d.ts.map +1 -1
- package/dist/utils/provider-retry.js +46 -1
- package/dist/utils/provider-retry.js.map +1 -1
- package/dist/utils/retry.d.ts +7 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +24 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/stop-details.d.ts +1 -1
- package/dist/utils/stop-details.d.ts.map +1 -1
- package/dist/utils/stop-details.js +7 -3
- package/dist/utils/stop-details.js.map +1 -1
- package/dist/utils/tool-call-id.d.ts +9 -0
- package/dist/utils/tool-call-id.d.ts.map +1 -0
- package/dist/utils/tool-call-id.js +16 -0
- package/dist/utils/tool-call-id.js.map +1 -0
- package/package.json +2 -2
|
@@ -5,8 +5,9 @@ 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 { getOpenAICompletionsCompat as getCompat, } from "../utils/prompt-cache-ttl.js";
|
|
8
9
|
import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
9
|
-
import {
|
|
10
|
+
import { retryProviderStreamRequest } from "../utils/provider-retry.js";
|
|
10
11
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
11
12
|
import { isForcedToolChoiceUnsupportedError, omitToolChoiceParam } from "../utils/tool-choice-fallback.js";
|
|
12
13
|
import { normalizeToolParametersForMoonshot, normalizeToolParametersForOpenAICompat, } from "../utils/tool-schema-compat.js";
|
|
@@ -15,6 +16,7 @@ import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copi
|
|
|
15
16
|
import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
|
|
16
17
|
import { applyExtraBody, buildBaseOptions, clampMaxForOpenAI, OPENAI_COMPLETIONS_RESERVED_BODY_KEYS, } from "./simple-options.js";
|
|
17
18
|
import { transformMessages } from "./transform-messages.js";
|
|
19
|
+
export { getOpenAICompletionsCompat as getCompat, } from "../utils/prompt-cache-ttl.js";
|
|
18
20
|
const KIMI_K3_THINKING_LEVEL_MAP = {
|
|
19
21
|
off: null,
|
|
20
22
|
minimal: null,
|
|
@@ -246,12 +248,11 @@ export const stream = (model, context, options) => {
|
|
|
246
248
|
throw error;
|
|
247
249
|
}
|
|
248
250
|
};
|
|
249
|
-
const {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
});
|
|
254
|
-
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
251
|
+
const { stream: openaiStream } = await retryProviderStreamRequest(async () => {
|
|
252
|
+
const { data, response } = await createRequest();
|
|
253
|
+
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
254
|
+
return { stream: data, metadata: response };
|
|
255
|
+
}, { maxRetries: options?.maxRetries, maxRetryDelayMs: options?.maxRetryDelayMs, signal: options?.signal });
|
|
255
256
|
stream.push({ type: "start", partial: output });
|
|
256
257
|
let textBlock = null;
|
|
257
258
|
let thinkingBlock = null;
|
|
@@ -1266,119 +1267,4 @@ function mapStopReason(reason) {
|
|
|
1266
1267
|
};
|
|
1267
1268
|
}
|
|
1268
1269
|
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Detect compatibility settings from provider and baseUrl for known providers.
|
|
1271
|
-
* Provider takes precedence over URL-based detection since it's explicitly configured.
|
|
1272
|
-
* Returns a fully resolved OpenAICompletionsCompat object with all fields set.
|
|
1273
|
-
*/
|
|
1274
|
-
function detectCompat(model) {
|
|
1275
|
-
const provider = model.provider;
|
|
1276
|
-
const baseUrl = model.baseUrl;
|
|
1277
|
-
const isZai = provider === "zai" ||
|
|
1278
|
-
provider === "zai-coding-cn" ||
|
|
1279
|
-
baseUrl.includes("api.z.ai") ||
|
|
1280
|
-
baseUrl.includes("open.bigmodel.cn");
|
|
1281
|
-
const isTogether = provider === "together" || baseUrl.includes("api.together.ai") || baseUrl.includes("api.together.xyz");
|
|
1282
|
-
const isMoonshot = provider === "moonshotai" || provider === "moonshotai-cn" || baseUrl.includes("api.moonshot.");
|
|
1283
|
-
const isOpenRouter = provider === "openrouter" || baseUrl.includes("openrouter.ai");
|
|
1284
|
-
const isCloudflareWorkersAI = provider === "cloudflare-workers-ai" || baseUrl.includes("api.cloudflare.com");
|
|
1285
|
-
const isCloudflareAiGateway = provider === "cloudflare-ai-gateway" || baseUrl.includes("gateway.ai.cloudflare.com");
|
|
1286
|
-
const isNvidia = provider === "nvidia" || baseUrl.includes("integrate.api.nvidia.com");
|
|
1287
|
-
const isAntLing = provider === "ant-ling" || baseUrl.includes("api.ant-ling.com");
|
|
1288
|
-
const isNonStandard = isNvidia ||
|
|
1289
|
-
provider === "cerebras" ||
|
|
1290
|
-
baseUrl.includes("cerebras.ai") ||
|
|
1291
|
-
provider === "xai" ||
|
|
1292
|
-
baseUrl.includes("api.x.ai") ||
|
|
1293
|
-
isTogether ||
|
|
1294
|
-
baseUrl.includes("chutes.ai") ||
|
|
1295
|
-
baseUrl.includes("deepseek.com") ||
|
|
1296
|
-
isZai ||
|
|
1297
|
-
isMoonshot ||
|
|
1298
|
-
provider === "opencode" ||
|
|
1299
|
-
baseUrl.includes("opencode.ai") ||
|
|
1300
|
-
isCloudflareWorkersAI ||
|
|
1301
|
-
isCloudflareAiGateway ||
|
|
1302
|
-
isAntLing;
|
|
1303
|
-
const useMaxTokens = baseUrl.includes("chutes.ai") || isMoonshot || isCloudflareAiGateway || isTogether || isNvidia || isAntLing;
|
|
1304
|
-
const isGrok = provider === "xai" || baseUrl.includes("api.x.ai");
|
|
1305
|
-
const isDeepSeek = provider === "deepseek" || baseUrl.includes("deepseek.com");
|
|
1306
|
-
const isOpenRouterDeveloperRoleModel = isOpenRouter && (model.id.startsWith("anthropic/") || model.id.startsWith("openai/"));
|
|
1307
|
-
const cacheControlFormat = provider === "openrouter" && model.id.startsWith("anthropic/") ? "anthropic" : undefined;
|
|
1308
|
-
return {
|
|
1309
|
-
supportsStore: !isNonStandard,
|
|
1310
|
-
supportsDeveloperRole: isOpenRouterDeveloperRoleModel || (!isNonStandard && !isOpenRouter),
|
|
1311
|
-
supportsReasoningEffort: !isGrok && !isZai && !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia && !isAntLing,
|
|
1312
|
-
supportsUsageInStreaming: true,
|
|
1313
|
-
maxTokensField: useMaxTokens ? "max_tokens" : "max_completion_tokens",
|
|
1314
|
-
requiresToolResultName: false,
|
|
1315
|
-
requiresAssistantAfterToolResult: false,
|
|
1316
|
-
requiresThinkingAsText: false,
|
|
1317
|
-
requiresReasoningContentOnAssistantMessages: isDeepSeek,
|
|
1318
|
-
thinkingFormat: isDeepSeek
|
|
1319
|
-
? "deepseek"
|
|
1320
|
-
: isZai
|
|
1321
|
-
? "zai"
|
|
1322
|
-
: isTogether
|
|
1323
|
-
? "together"
|
|
1324
|
-
: isAntLing
|
|
1325
|
-
? "ant-ling"
|
|
1326
|
-
: isOpenRouter
|
|
1327
|
-
? "openrouter"
|
|
1328
|
-
: "openai",
|
|
1329
|
-
openRouterRouting: {},
|
|
1330
|
-
vercelGatewayRouting: {},
|
|
1331
|
-
chatTemplateKwargs: {},
|
|
1332
|
-
zaiToolStream: false,
|
|
1333
|
-
supportsStrictMode: !isMoonshot && !isTogether && !isCloudflareAiGateway && !isNvidia,
|
|
1334
|
-
toolSchemaFlavor: isMoonshot ? "moonshot-mfjs" : undefined,
|
|
1335
|
-
supportsDisabledThinking: true,
|
|
1336
|
-
toolCallFormat: undefined,
|
|
1337
|
-
supportsOpenAIGrammarTools: false,
|
|
1338
|
-
cacheControlFormat,
|
|
1339
|
-
sendSessionAffinityHeaders: false,
|
|
1340
|
-
deferredToolsMode: undefined,
|
|
1341
|
-
sessionAffinityFormat: isOpenRouter ? "openrouter" : "openai",
|
|
1342
|
-
supportsLongCacheRetention: !(isTogether ||
|
|
1343
|
-
isCloudflareWorkersAI ||
|
|
1344
|
-
isCloudflareAiGateway ||
|
|
1345
|
-
isNvidia ||
|
|
1346
|
-
isAntLing),
|
|
1347
|
-
};
|
|
1348
|
-
}
|
|
1349
|
-
/**
|
|
1350
|
-
* Get resolved compatibility settings for a model.
|
|
1351
|
-
* Auto-detects from provider/URL then overrides with explicit model.compat.
|
|
1352
|
-
*/
|
|
1353
|
-
function getCompat(model) {
|
|
1354
|
-
const detected = detectCompat(model);
|
|
1355
|
-
if (!model.compat)
|
|
1356
|
-
return detected;
|
|
1357
|
-
return {
|
|
1358
|
-
supportsStore: model.compat.supportsStore ?? detected.supportsStore,
|
|
1359
|
-
supportsDeveloperRole: model.compat.supportsDeveloperRole ?? detected.supportsDeveloperRole,
|
|
1360
|
-
supportsReasoningEffort: model.compat.supportsReasoningEffort ?? detected.supportsReasoningEffort,
|
|
1361
|
-
supportsUsageInStreaming: model.compat.supportsUsageInStreaming ?? detected.supportsUsageInStreaming,
|
|
1362
|
-
maxTokensField: model.compat.maxTokensField ?? detected.maxTokensField,
|
|
1363
|
-
requiresToolResultName: model.compat.requiresToolResultName ?? detected.requiresToolResultName,
|
|
1364
|
-
requiresAssistantAfterToolResult: model.compat.requiresAssistantAfterToolResult ?? detected.requiresAssistantAfterToolResult,
|
|
1365
|
-
requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
|
|
1366
|
-
requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ??
|
|
1367
|
-
detected.requiresReasoningContentOnAssistantMessages,
|
|
1368
|
-
thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
|
|
1369
|
-
supportsDisabledThinking: model.compat.supportsDisabledThinking ?? detected.supportsDisabledThinking,
|
|
1370
|
-
openRouterRouting: model.compat.openRouterRouting ?? detected.openRouterRouting,
|
|
1371
|
-
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
|
|
1372
|
-
chatTemplateKwargs: model.compat.chatTemplateKwargs ?? detected.chatTemplateKwargs,
|
|
1373
|
-
zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
|
|
1374
|
-
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
|
|
1375
|
-
toolCallFormat: model.compat.toolCallFormat ?? detected.toolCallFormat,
|
|
1376
|
-
supportsOpenAIGrammarTools: model.compat.supportsOpenAIGrammarTools ?? detected.supportsOpenAIGrammarTools,
|
|
1377
|
-
cacheControlFormat: model.compat.cacheControlFormat ?? detected.cacheControlFormat,
|
|
1378
|
-
sendSessionAffinityHeaders: model.compat.sendSessionAffinityHeaders ?? detected.sendSessionAffinityHeaders,
|
|
1379
|
-
deferredToolsMode: model.compat.deferredToolsMode ?? detected.deferredToolsMode,
|
|
1380
|
-
sessionAffinityFormat: model.compat.sessionAffinityFormat ?? detected.sessionAffinityFormat,
|
|
1381
|
-
supportsLongCacheRetention: model.compat.supportsLongCacheRetention ?? detected.supportsLongCacheRetention,
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
1270
|
//# sourceMappingURL=openai-completions.js.map
|