pi-nvidia-nim 1.1.20 → 1.1.22
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 +1 -1
- package/index.ts +46 -8
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-nvidia-nim
|
|
2
2
|
|
|
3
|
-
NVIDIA NIM API provider extension for [pi coding agent](https://github.com/
|
|
3
|
+
NVIDIA NIM API provider extension for [pi coding agent](https://github.com/earendil-works/pi-mono) - access 100+ models from [build.nvidia.com](https://build.nvidia.com) including DeepSeek V4 Flash/Pro, DeepSeek V3.2, Kimi K2.6, MiniMax M2.1, GLM-5, GLM-4.7, Qwen3, Llama 4, and many more.
|
|
4
4
|
|
|
5
5
|
https://github.com/user-attachments/assets/f44773e4-9bf8-4bb5-a9c0-d5938030701c
|
|
6
6
|
|
package/index.ts
CHANGED
|
@@ -42,9 +42,9 @@ import type {
|
|
|
42
42
|
Context,
|
|
43
43
|
Model,
|
|
44
44
|
SimpleStreamOptions,
|
|
45
|
-
} from "@
|
|
46
|
-
import { streamSimpleOpenAICompletions } from "@
|
|
47
|
-
import { getAgentDir, type ExtensionAPI } from "@
|
|
45
|
+
} from "@earendil-works/pi-ai";
|
|
46
|
+
import { streamSimpleOpenAICompletions } from "@earendil-works/pi-ai";
|
|
47
|
+
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
48
48
|
|
|
49
49
|
// =============================================================================
|
|
50
50
|
// Constants
|
|
@@ -498,10 +498,29 @@ function getNimApiKey(): string | undefined {
|
|
|
498
498
|
return apiKey?.trim() || undefined;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
+
function getNimProviderApiKeyConfig(): string {
|
|
502
|
+
return `$${getNimApiKeyEnv() ?? NVIDIA_NIM_API_KEY_ENV}`;
|
|
503
|
+
}
|
|
504
|
+
|
|
501
505
|
function isNimApiKeyEnvName(value: string): value is NimApiKeyEnvName {
|
|
502
506
|
return NVIDIA_API_KEY_ENV_NAMES.includes(value as NimApiKeyEnvName);
|
|
503
507
|
}
|
|
504
508
|
|
|
509
|
+
function isNimApiKeyEnvReference(value: string): boolean {
|
|
510
|
+
return value.startsWith("$") && isNimApiKeyEnvName(value.slice(1));
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function isNimApiKeyEnvPlaceholder(value: string): boolean {
|
|
514
|
+
return isNimApiKeyEnvName(value) || isNimApiKeyEnvReference(value);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function resolveNimApiKeyEnvReference(value: string): string | undefined {
|
|
518
|
+
if (!isNimApiKeyEnvReference(value)) return undefined;
|
|
519
|
+
|
|
520
|
+
const envValue = process.env[value.slice(1)]?.trim();
|
|
521
|
+
return envValue || undefined;
|
|
522
|
+
}
|
|
523
|
+
|
|
505
524
|
function isNimApiKeyEnvValue(value: string): boolean {
|
|
506
525
|
return NVIDIA_API_KEY_ENV_NAMES.some((envName) => process.env[envName]?.trim() === value);
|
|
507
526
|
}
|
|
@@ -570,15 +589,19 @@ function resolveNimApiKey(apiKey: string | undefined, authStorage?: AuthStorageL
|
|
|
570
589
|
|
|
571
590
|
if (
|
|
572
591
|
hasStoredCommandCredential &&
|
|
573
|
-
(!resolvedApiKey ||
|
|
592
|
+
(!resolvedApiKey || isNimApiKeyEnvPlaceholder(resolvedApiKey) || isNimApiKeyEnvValue(resolvedApiKey))
|
|
574
593
|
) {
|
|
575
594
|
throw new Error("NVIDIA NIM API key command resolved to an empty value.");
|
|
576
595
|
}
|
|
577
596
|
|
|
578
597
|
const storedApiKey = getStoredResolvedNimApiKey(authStorage);
|
|
579
|
-
if (storedApiKey && (!resolvedApiKey ||
|
|
598
|
+
if (storedApiKey && (!resolvedApiKey || isNimApiKeyEnvPlaceholder(resolvedApiKey))) return storedApiKey;
|
|
580
599
|
|
|
581
|
-
if (resolvedApiKey
|
|
600
|
+
if (resolvedApiKey) {
|
|
601
|
+
const envReferenceApiKey = resolveNimApiKeyEnvReference(resolvedApiKey);
|
|
602
|
+
if (envReferenceApiKey) return envReferenceApiKey;
|
|
603
|
+
if (!isNimApiKeyEnvPlaceholder(resolvedApiKey)) return resolvedApiKey;
|
|
604
|
+
}
|
|
582
605
|
|
|
583
606
|
return getNimApiKey();
|
|
584
607
|
}
|
|
@@ -615,6 +638,20 @@ function buildThinkingKwargs(
|
|
|
615
638
|
return kwargs;
|
|
616
639
|
}
|
|
617
640
|
|
|
641
|
+
function buildNimRequestHeaders(headers: SimpleStreamOptions["headers"], apiKey: string): Record<string, string> {
|
|
642
|
+
const resolvedHeaders: Record<string, string> = {};
|
|
643
|
+
|
|
644
|
+
for (const [key, value] of Object.entries(headers ?? {})) {
|
|
645
|
+
if (key.toLowerCase() === "authorization") continue;
|
|
646
|
+
resolvedHeaders[key] = value;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
return {
|
|
650
|
+
...resolvedHeaders,
|
|
651
|
+
Authorization: `Bearer ${apiKey}`,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
618
655
|
function nimStreamSimple(
|
|
619
656
|
model: Model<Api>,
|
|
620
657
|
context: Context,
|
|
@@ -654,6 +691,7 @@ function nimStreamSimple(
|
|
|
654
691
|
...options,
|
|
655
692
|
reasoning: effectiveReasoning,
|
|
656
693
|
apiKey: nimApiKey,
|
|
694
|
+
headers: buildNimRequestHeaders(options?.headers, nimApiKey),
|
|
657
695
|
onPayload: (params: unknown) => {
|
|
658
696
|
const p = params as Record<string, unknown>;
|
|
659
697
|
|
|
@@ -834,7 +872,7 @@ async function fetchNimModels(apiKey: string): Promise<NimModelFetchResult> {
|
|
|
834
872
|
// =============================================================================
|
|
835
873
|
|
|
836
874
|
export default function (pi: ExtensionAPI) {
|
|
837
|
-
const providerApiKeyConfig =
|
|
875
|
+
const providerApiKeyConfig = getNimProviderApiKeyConfig();
|
|
838
876
|
|
|
839
877
|
// Always register the curated model list. The request path resolves credentials
|
|
840
878
|
// through pi first (CLI override, auth.json, shell command), then falls back to
|
|
@@ -897,7 +935,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
897
935
|
const allModels = Array.from(modelMap.values());
|
|
898
936
|
ctx.modelRegistry.registerProvider(PROVIDER_NAME, {
|
|
899
937
|
baseUrl: NVIDIA_NIM_BASE_URL,
|
|
900
|
-
apiKey:
|
|
938
|
+
apiKey: getNimProviderApiKeyConfig(),
|
|
901
939
|
api: "openai-completions",
|
|
902
940
|
authHeader: true,
|
|
903
941
|
models: allModels,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-nvidia-nim",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.22",
|
|
4
4
|
"description": "NVIDIA NIM API provider extension for pi coding agent — access 100+ models from build.nvidia.com",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"test": "node --test test/*.test.mjs"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@types/node": "^22.0.0"
|
|
26
|
+
"@earendil-works/pi-ai": "^0.74.0",
|
|
27
|
+
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"typescript": "^6.0.3"
|
|
29
30
|
},
|
|
30
31
|
"repository": {
|
|
31
32
|
"type": "git",
|