@jambonz/llm 0.2.7 → 0.3.0

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.
@@ -465,6 +465,9 @@ var OpenAIAdapter = class {
465
465
  async listAvailableModels() {
466
466
  return listOpenAICompatibleModels(this.ensureClient(), openAIManifest.knownModels);
467
467
  }
468
+ async testCredential() {
469
+ await this.ensureClient().models.list();
470
+ }
468
471
  async warmup() {
469
472
  const client = this.ensureClient();
470
473
  await client.models.list().catch(() => void 0);
@@ -891,6 +894,9 @@ var AnthropicAdapter = class {
891
894
  }
892
895
  return models;
893
896
  }
897
+ async testCredential() {
898
+ await this.ensureClient().models.list();
899
+ }
894
900
  async warmup() {
895
901
  const client = this.ensureClient();
896
902
  await client.models.list().catch(() => void 0);
@@ -1317,6 +1323,9 @@ var GoogleAdapter = class {
1317
1323
  async listAvailableModels() {
1318
1324
  return listGeminiModels(this.ensureClient(), googleManifest.knownModels);
1319
1325
  }
1326
+ async testCredential() {
1327
+ await listGeminiModels(this.ensureClient(), googleManifest.knownModels);
1328
+ }
1320
1329
  async warmup() {
1321
1330
  }
1322
1331
  ensureClient() {
@@ -1487,6 +1496,9 @@ var VertexGeminiAdapter = class {
1487
1496
  async listAvailableModels() {
1488
1497
  return listGeminiModels(this.ensureClient(), vertexGeminiManifest.knownModels);
1489
1498
  }
1499
+ async testCredential() {
1500
+ await listGeminiModels(this.ensureClient(), vertexGeminiManifest.knownModels);
1501
+ }
1490
1502
  async warmup() {
1491
1503
  }
1492
1504
  ensureClient() {
@@ -1607,6 +1619,7 @@ var VertexOpenAIAdapter = class {
1607
1619
  vendor = vertexOpenAIManifest.vendor;
1608
1620
  acceptedAuth = ["vertexServiceAccount"];
1609
1621
  client;
1622
+ googleAuth;
1610
1623
  init(auth, client) {
1611
1624
  if (auth.kind !== "vertexServiceAccount") {
1612
1625
  throw new Error(
@@ -1623,12 +1636,12 @@ var VertexOpenAIAdapter = class {
1623
1636
  throw new Error("VertexOpenAIAdapter: location is required");
1624
1637
  }
1625
1638
  const baseURL = `https://${auth.location}-aiplatform.googleapis.com/v1beta1/projects/${auth.projectId}/locations/${auth.location}/endpoints/openapi`;
1626
- const googleAuth = new import_google_auth_library.GoogleAuth({
1639
+ this.googleAuth = new import_google_auth_library.GoogleAuth({
1627
1640
  credentials: auth.credentials,
1628
1641
  scopes: ["https://www.googleapis.com/auth/cloud-platform"]
1629
1642
  });
1630
1643
  const authedFetch = async (input, init2) => {
1631
- const googleClient = await googleAuth.getClient();
1644
+ const googleClient = await this.googleAuth.getClient();
1632
1645
  const token = await googleClient.getAccessToken();
1633
1646
  const headers = new Headers(init2?.headers);
1634
1647
  headers.set("Authorization", `Bearer ${token.token ?? ""}`);
@@ -1657,6 +1670,16 @@ var VertexOpenAIAdapter = class {
1657
1670
  async listAvailableModels() {
1658
1671
  return [...vertexOpenAIManifest.knownModels];
1659
1672
  }
1673
+ async testCredential() {
1674
+ if (!this.googleAuth) {
1675
+ throw new Error("VertexOpenAIAdapter: init() must be called before testCredential()");
1676
+ }
1677
+ const googleClient = await this.googleAuth.getClient();
1678
+ const token = await googleClient.getAccessToken();
1679
+ if (!token.token) {
1680
+ throw new Error("VertexOpenAIAdapter: service account did not mint an access token");
1681
+ }
1682
+ }
1660
1683
  async warmup() {
1661
1684
  }
1662
1685
  ensureClient() {
@@ -1678,6 +1701,7 @@ var vertexOpenAIFactory = {
1678
1701
 
1679
1702
  // src/adapters/bedrock/adapter.ts
1680
1703
  var import_client_bedrock_runtime = require("@aws-sdk/client-bedrock-runtime");
1704
+ var import_client_bedrock = require("@aws-sdk/client-bedrock");
1681
1705
 
1682
1706
  // src/adapters/bedrock/manifest.ts
1683
1707
  var BEDROCK_KNOWN_MODELS = [
@@ -1892,6 +1916,7 @@ var BedrockAdapter = class {
1892
1916
  vendor = bedrockManifest.vendor;
1893
1917
  acceptedAuth = ["bedrockApiKey", "bedrockIam"];
1894
1918
  client;
1919
+ controlClientConfig;
1895
1920
  init(auth, client) {
1896
1921
  if (!auth.region) {
1897
1922
  throw new Error("BedrockAdapter: region is required");
@@ -1922,6 +1947,7 @@ var BedrockAdapter = class {
1922
1947
  );
1923
1948
  }
1924
1949
  this.client = new import_client_bedrock_runtime.BedrockRuntimeClient(config);
1950
+ this.controlClientConfig = config;
1925
1951
  }
1926
1952
  async *stream(req) {
1927
1953
  assertValidRequest(req);
@@ -2100,6 +2126,17 @@ var BedrockAdapter = class {
2100
2126
  async listAvailableModels() {
2101
2127
  return [...bedrockManifest.knownModels];
2102
2128
  }
2129
+ async testCredential() {
2130
+ if (!this.controlClientConfig) {
2131
+ throw new Error("BedrockAdapter: init() must be called before testCredential()");
2132
+ }
2133
+ const control = new import_client_bedrock.BedrockClient(this.controlClientConfig);
2134
+ try {
2135
+ await control.send(new import_client_bedrock.ListFoundationModelsCommand({}));
2136
+ } finally {
2137
+ control.destroy();
2138
+ }
2139
+ }
2103
2140
  async warmup() {
2104
2141
  }
2105
2142
  ensureClient() {
@@ -2432,6 +2469,11 @@ function runContractTests(harness) {
2432
2469
  (0, import_vitest.expect)(typeof m.capabilities.tools).toBe("boolean");
2433
2470
  }
2434
2471
  });
2472
+ (0, import_vitest.it)("[15a] testCredential resolves on a valid auth probe", async () => {
2473
+ await harness.mockScenario("list-models");
2474
+ const adapter = await init(harness);
2475
+ await (0, import_vitest.expect)(adapter.testCredential()).resolves.not.toThrow();
2476
+ });
2435
2477
  if (harness.nonToolCapableModel) {
2436
2478
  (0, import_vitest.it)("[16] non-tool-capable model with tools declared either fails fast or runs without tool calls", async () => {
2437
2479
  await harness.mockScenario("simple-stream");
@@ -2626,6 +2668,9 @@ var FakeAdapter = class {
2626
2668
  this.ensureInitialized();
2627
2669
  return fakeManifest.knownModels;
2628
2670
  }
2671
+ async testCredential() {
2672
+ this.ensureInitialized();
2673
+ }
2629
2674
  ensureInitialized() {
2630
2675
  if (!this.initialized) {
2631
2676
  throw new Error("FakeAdapter: init() must be called before stream()/listAvailableModels()");