@f5-sales-demo/pi-ai 21.5.0 → 21.5.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": "@f5-sales-demo/pi-ai",
4
- "version": "21.5.0",
4
+ "version": "21.5.1",
5
5
  "description": "Unified LLM API with automatic model discovery and provider configuration",
6
6
  "homepage": "https://github.com/f5-sales-demo/xcsh",
7
7
  "author": "Can Boluk",
@@ -46,7 +46,7 @@
46
46
  "@anthropic-ai/sdk": "^0.115",
47
47
  "@aws-sdk/client-bedrock-runtime": "^3",
48
48
  "@bufbuild/protobuf": "^2.11",
49
- "@f5-sales-demo/pi-utils": "21.5.0",
49
+ "@f5-sales-demo/pi-utils": "21.5.1",
50
50
  "@google/genai": "^2.15",
51
51
  "@sinclair/typebox": "^0.34",
52
52
  "@smithy/node-http-handler": "^4.4",
@@ -35,8 +35,8 @@ export function googleModelManagerOptions(
35
35
  export function googleVertexModelManagerOptions(
36
36
  _config?: GoogleVertexModelManagerConfig,
37
37
  ): ModelManagerOptions<"google-vertex"> {
38
- // Vertex AI uses Application Default Credentials (ADC) for authentication,
39
- // which is handled at stream time rather than during model discovery.
38
+ // Vertex authentication is handled at stream time rather than during model
39
+ // discovery (standalone OAuth in xcsh, or explicit credentials for SDK users).
40
40
  // Dynamic model discovery is not yet implemented for this provider.
41
41
  return {
42
42
  providerId: "google-vertex",
@@ -106,8 +106,8 @@ export const streamGoogleVertex: StreamFunction<"google-vertex"> = (
106
106
  let rawRequestDump: RawHttpRequestDump | undefined;
107
107
 
108
108
  try {
109
- // Corporate Vertex is deliberately ADC-only. In particular, do not let the
110
- // generic agent API-key plumbing turn this route into Gemini consumer auth.
109
+ // apiKey is an isolated, short-lived OAuth bearer token for the Corporate
110
+ // Vertex route. It is never sourced from Gemini consumer credentials.
111
111
  const project = await resolveGoogleVertexProject(options);
112
112
  const location = resolveGoogleVertexLocation(options);
113
113
  const client = createClient(model, project, location, options?.apiKey);
package/src/stream.ts CHANGED
@@ -1,6 +1,3 @@
1
- import * as fs from "node:fs";
2
- import * as os from "node:os";
3
- import * as path from "node:path";
4
1
  import { $env, $pickenv } from "@f5-sales-demo/pi-utils";
5
2
  import { getCustomApi } from "./api-registry";
6
3
  import type { Effort } from "./model-thinking";
@@ -37,22 +34,6 @@ import type {
37
34
  ToolChoice,
38
35
  } from "./types";
39
36
 
40
- let cachedVertexAdcCredentialsExists: boolean | null = null;
41
-
42
- function hasVertexAdcCredentials(): boolean {
43
- if (cachedVertexAdcCredentialsExists === null) {
44
- const gacPath = $env.GOOGLE_APPLICATION_CREDENTIALS;
45
- if (gacPath) {
46
- cachedVertexAdcCredentialsExists = fs.existsSync(gacPath);
47
- } else {
48
- cachedVertexAdcCredentialsExists = fs.existsSync(
49
- path.join(os.homedir(), ".config", "gcloud", "application_default_credentials.json"),
50
- );
51
- }
52
- }
53
- return cachedVertexAdcCredentialsExists;
54
- }
55
-
56
37
  type KeyResolver = string | (() => string | undefined);
57
38
 
58
39
  function isFoundryEnabled(): boolean {
@@ -97,8 +78,6 @@ const serviceProviderMap: Record<string, KeyResolver> = {
97
78
  ? $pickenv("ANTHROPIC_FOUNDRY_API_KEY", "ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY")
98
79
  : $pickenv("ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"),
99
80
  "gitlab-duo": "GITLAB_TOKEN",
100
- // Corporate Vertex uses Application Default Credentials only.
101
- "google-vertex": () => (hasVertexAdcCredentials() ? "<authenticated>" : undefined),
102
81
  // Amazon Bedrock supports multiple credential sources:
103
82
  // 1. AWS_PROFILE - named profile from ~/.aws/credentials
104
83
  // 2. AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY - standard IAM keys
@@ -402,7 +381,7 @@ function resolveOpenAiReasoningEffort<TApi extends Api>(
402
381
 
403
382
  const castApi = <TApi extends Api>(api: OptionsForApi<TApi>): OptionsForApi<Api> => api as OptionsForApi<Api>;
404
383
 
405
- function mapOptionsForApi<TApi extends Api>(
384
+ export function mapOptionsForApi<TApi extends Api>(
406
385
  model: Model<TApi>,
407
386
  options?: SimpleStreamOptions,
408
387
  apiKey?: string,
@@ -647,11 +626,16 @@ function mapOptionsForApi<TApi extends Api>(
647
626
  }
648
627
 
649
628
  case "google-vertex": {
629
+ const vertexBase = {
630
+ ...base,
631
+ project: options?.project,
632
+ location: options?.location,
633
+ };
650
634
  // Explicitly disable thinking when reasoning is not specified or model doesn't support it
651
635
  const reasoning = options?.reasoning;
652
636
  if (!reasoning || !model.reasoning) {
653
637
  return castApi<"google-vertex">({
654
- ...base,
638
+ ...vertexBase,
655
639
  thinking: { enabled: false },
656
640
  toolChoice: mapGoogleToolChoice(options?.toolChoice),
657
641
  });
@@ -663,7 +647,7 @@ function mapOptionsForApi<TApi extends Api>(
663
647
 
664
648
  if (geminiModel.thinking?.mode === "google-level") {
665
649
  return castApi<"google-vertex">({
666
- ...base,
650
+ ...vertexBase,
667
651
  thinking: {
668
652
  enabled: true,
669
653
  level: mapEffortToGoogleThinkingLevel(geminiModel, effort),
@@ -673,7 +657,7 @@ function mapOptionsForApi<TApi extends Api>(
673
657
  }
674
658
 
675
659
  return castApi<"google-vertex">({
676
- ...base,
660
+ ...vertexBase,
677
661
  thinking: {
678
662
  enabled: true,
679
663
  budgetTokens: getGoogleBudget(geminiModel, effort, options?.thinkingBudgets),
package/src/types.ts CHANGED
@@ -227,6 +227,10 @@ export interface StreamOptions {
227
227
 
228
228
  // Unified options with reasoning passed to streamSimple() and completeSimple()
229
229
  export interface SimpleStreamOptions extends StreamOptions {
230
+ /** Confirmed Google Cloud project for the Corporate Vertex transport. */
231
+ project?: string;
232
+ /** Google Cloud location for the Corporate Vertex transport. */
233
+ location?: string;
230
234
  reasoning?: Effort;
231
235
  /** Custom token budgets for thinking levels (token-based providers only) */
232
236
  thinkingBudgets?: ThinkingBudgets;