@oh-my-pi/pi-ai 13.4.0 → 13.4.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-ai",
4
- "version": "13.4.0",
4
+ "version": "13.4.1",
5
5
  "description": "Unified LLM API with automatic model discovery and provider configuration",
6
6
  "homepage": "https://github.com/can1357/oh-my-pi",
7
7
  "author": "Can Boluk",
@@ -41,7 +41,7 @@
41
41
  "@aws-sdk/client-bedrock-runtime": "^3.998",
42
42
  "@bufbuild/protobuf": "^2.11",
43
43
  "@google/genai": "^1.43",
44
- "@oh-my-pi/pi-utils": "13.4.0",
44
+ "@oh-my-pi/pi-utils": "13.4.1",
45
45
  "@sinclair/typebox": "^0.34",
46
46
  "@smithy/node-http-handler": "^4.4",
47
47
  "ajv": "^8.18",
@@ -1232,6 +1232,27 @@ function inferCopilotApi(modelId: string): Api {
1232
1232
  return "openai-completions";
1233
1233
  }
1234
1234
 
1235
+ function extractCopilotLimits(entry: OpenAICompatibleModelRecord): {
1236
+ maxPromptTokens?: number;
1237
+ maxContextWindowTokens?: number;
1238
+ maxOutputTokens?: number;
1239
+ maxNonStreamingOutputTokens?: number;
1240
+ } {
1241
+ if (!isRecord(entry.capabilities)) {
1242
+ return {};
1243
+ }
1244
+ const limitsValue = entry.capabilities.limits;
1245
+ if (!isRecord(limitsValue)) {
1246
+ return {};
1247
+ }
1248
+ return {
1249
+ maxPromptTokens: toNumber(limitsValue.max_prompt_tokens),
1250
+ maxContextWindowTokens: toNumber(limitsValue.max_context_window_tokens),
1251
+ maxOutputTokens: toNumber(limitsValue.max_output_tokens),
1252
+ maxNonStreamingOutputTokens: toNumber(limitsValue.max_non_streaming_output_tokens),
1253
+ };
1254
+ }
1255
+
1235
1256
  export function githubCopilotModelManagerOptions(config?: GithubCopilotModelManagerConfig): ModelManagerOptions<Api> {
1236
1257
  const apiKey = config?.apiKey;
1237
1258
  const baseUrl = config?.baseUrl ?? "https://api.individual.githubcopilot.com";
@@ -1260,14 +1281,30 @@ export function githubCopilotModelManagerOptions(config?: GithubCopilotModelMana
1260
1281
  ? providerReference
1261
1282
  : globalReference
1262
1283
  : (providerReference ?? globalReference);
1263
- const contextWindow =
1264
- typeof entry.context_length === "number"
1265
- ? entry.context_length
1266
- : (reference?.contextWindow ?? defaults.contextWindow);
1267
- const maxTokens =
1268
- typeof entry.max_completion_tokens === "number"
1269
- ? entry.max_completion_tokens
1270
- : (reference?.maxTokens ?? defaults.maxTokens);
1284
+ const copilotLimits = extractCopilotLimits(entry);
1285
+ // Copilot currently exposes token limits under capabilities.limits.*.
1286
+ // Keep OpenAI-compatible fields as outer fallbacks for forward compatibility if
1287
+ // `/models` starts returning context_length/max_completion_tokens in the future.
1288
+ const contextWindow = toPositiveNumber(
1289
+ entry.context_length,
1290
+ toPositiveNumber(
1291
+ copilotLimits.maxPromptTokens,
1292
+ toPositiveNumber(
1293
+ copilotLimits.maxContextWindowTokens,
1294
+ reference?.contextWindow ?? defaults.contextWindow,
1295
+ ),
1296
+ ),
1297
+ );
1298
+ const maxTokens = toPositiveNumber(
1299
+ entry.max_completion_tokens,
1300
+ toPositiveNumber(
1301
+ copilotLimits.maxOutputTokens,
1302
+ toPositiveNumber(
1303
+ copilotLimits.maxNonStreamingOutputTokens,
1304
+ reference?.maxTokens ?? defaults.maxTokens,
1305
+ ),
1306
+ ),
1307
+ );
1271
1308
  const name =
1272
1309
  typeof entry.name === "string" && entry.name.trim().length > 0
1273
1310
  ? entry.name