@jambonz/llm 0.2.6 → 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.
@@ -1,4 +1,4 @@
1
- import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-bq1XMi_T.cjs';
1
+ import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-4d2QrlAe.cjs';
2
2
 
3
3
  /**
4
4
  * Named scenarios the harness must be able to stage. Each scenario configures
@@ -132,6 +132,7 @@ declare class FakeAdapter implements LlmAdapter<ApiKeyAuth> {
132
132
  appendAssistantToolCall(history: Message[], toolCalls: ReadonlyArray<ToolCallEvent>): Message[];
133
133
  appendToolResult(history: Message[], toolCallId: string, result: unknown): Message[];
134
134
  listAvailableModels(): Promise<ModelInfo[]>;
135
+ testCredential(): Promise<void>;
135
136
  private ensureInitialized;
136
137
  private capture;
137
138
  }
@@ -1,4 +1,4 @@
1
- import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-bq1XMi_T.js';
1
+ import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-4d2QrlAe.js';
2
2
 
3
3
  /**
4
4
  * Named scenarios the harness must be able to stage. Each scenario configures
@@ -132,6 +132,7 @@ declare class FakeAdapter implements LlmAdapter<ApiKeyAuth> {
132
132
  appendAssistantToolCall(history: Message[], toolCalls: ReadonlyArray<ToolCallEvent>): Message[];
133
133
  appendToolResult(history: Message[], toolCallId: string, result: unknown): Message[];
134
134
  listAvailableModels(): Promise<ModelInfo[]>;
135
+ testCredential(): Promise<void>;
135
136
  private ensureInitialized;
136
137
  private capture;
137
138
  }
@@ -426,6 +426,9 @@ var OpenAIAdapter = class {
426
426
  async listAvailableModels() {
427
427
  return listOpenAICompatibleModels(this.ensureClient(), openAIManifest.knownModels);
428
428
  }
429
+ async testCredential() {
430
+ await this.ensureClient().models.list();
431
+ }
429
432
  async warmup() {
430
433
  const client = this.ensureClient();
431
434
  await client.models.list().catch(() => void 0);
@@ -852,6 +855,9 @@ var AnthropicAdapter = class {
852
855
  }
853
856
  return models;
854
857
  }
858
+ async testCredential() {
859
+ await this.ensureClient().models.list();
860
+ }
855
861
  async warmup() {
856
862
  const client = this.ensureClient();
857
863
  await client.models.list().catch(() => void 0);
@@ -1278,6 +1284,9 @@ var GoogleAdapter = class {
1278
1284
  async listAvailableModels() {
1279
1285
  return listGeminiModels(this.ensureClient(), googleManifest.knownModels);
1280
1286
  }
1287
+ async testCredential() {
1288
+ await listGeminiModels(this.ensureClient(), googleManifest.knownModels);
1289
+ }
1281
1290
  async warmup() {
1282
1291
  }
1283
1292
  ensureClient() {
@@ -1448,6 +1457,9 @@ var VertexGeminiAdapter = class {
1448
1457
  async listAvailableModels() {
1449
1458
  return listGeminiModels(this.ensureClient(), vertexGeminiManifest.knownModels);
1450
1459
  }
1460
+ async testCredential() {
1461
+ await listGeminiModels(this.ensureClient(), vertexGeminiManifest.knownModels);
1462
+ }
1451
1463
  async warmup() {
1452
1464
  }
1453
1465
  ensureClient() {
@@ -1568,6 +1580,7 @@ var VertexOpenAIAdapter = class {
1568
1580
  vendor = vertexOpenAIManifest.vendor;
1569
1581
  acceptedAuth = ["vertexServiceAccount"];
1570
1582
  client;
1583
+ googleAuth;
1571
1584
  init(auth, client) {
1572
1585
  if (auth.kind !== "vertexServiceAccount") {
1573
1586
  throw new Error(
@@ -1584,12 +1597,12 @@ var VertexOpenAIAdapter = class {
1584
1597
  throw new Error("VertexOpenAIAdapter: location is required");
1585
1598
  }
1586
1599
  const baseURL = `https://${auth.location}-aiplatform.googleapis.com/v1beta1/projects/${auth.projectId}/locations/${auth.location}/endpoints/openapi`;
1587
- const googleAuth = new GoogleAuth({
1600
+ this.googleAuth = new GoogleAuth({
1588
1601
  credentials: auth.credentials,
1589
1602
  scopes: ["https://www.googleapis.com/auth/cloud-platform"]
1590
1603
  });
1591
1604
  const authedFetch = async (input, init2) => {
1592
- const googleClient = await googleAuth.getClient();
1605
+ const googleClient = await this.googleAuth.getClient();
1593
1606
  const token = await googleClient.getAccessToken();
1594
1607
  const headers = new Headers(init2?.headers);
1595
1608
  headers.set("Authorization", `Bearer ${token.token ?? ""}`);
@@ -1618,6 +1631,16 @@ var VertexOpenAIAdapter = class {
1618
1631
  async listAvailableModels() {
1619
1632
  return [...vertexOpenAIManifest.knownModels];
1620
1633
  }
1634
+ async testCredential() {
1635
+ if (!this.googleAuth) {
1636
+ throw new Error("VertexOpenAIAdapter: init() must be called before testCredential()");
1637
+ }
1638
+ const googleClient = await this.googleAuth.getClient();
1639
+ const token = await googleClient.getAccessToken();
1640
+ if (!token.token) {
1641
+ throw new Error("VertexOpenAIAdapter: service account did not mint an access token");
1642
+ }
1643
+ }
1621
1644
  async warmup() {
1622
1645
  }
1623
1646
  ensureClient() {
@@ -1642,6 +1665,10 @@ import {
1642
1665
  BedrockRuntimeClient,
1643
1666
  ConverseStreamCommand
1644
1667
  } from "@aws-sdk/client-bedrock-runtime";
1668
+ import {
1669
+ BedrockClient,
1670
+ ListFoundationModelsCommand
1671
+ } from "@aws-sdk/client-bedrock";
1645
1672
 
1646
1673
  // src/adapters/bedrock/manifest.ts
1647
1674
  var BEDROCK_KNOWN_MODELS = [
@@ -1856,6 +1883,7 @@ var BedrockAdapter = class {
1856
1883
  vendor = bedrockManifest.vendor;
1857
1884
  acceptedAuth = ["bedrockApiKey", "bedrockIam"];
1858
1885
  client;
1886
+ controlClientConfig;
1859
1887
  init(auth, client) {
1860
1888
  if (!auth.region) {
1861
1889
  throw new Error("BedrockAdapter: region is required");
@@ -1886,6 +1914,7 @@ var BedrockAdapter = class {
1886
1914
  );
1887
1915
  }
1888
1916
  this.client = new BedrockRuntimeClient(config);
1917
+ this.controlClientConfig = config;
1889
1918
  }
1890
1919
  async *stream(req) {
1891
1920
  assertValidRequest(req);
@@ -2064,6 +2093,17 @@ var BedrockAdapter = class {
2064
2093
  async listAvailableModels() {
2065
2094
  return [...bedrockManifest.knownModels];
2066
2095
  }
2096
+ async testCredential() {
2097
+ if (!this.controlClientConfig) {
2098
+ throw new Error("BedrockAdapter: init() must be called before testCredential()");
2099
+ }
2100
+ const control = new BedrockClient(this.controlClientConfig);
2101
+ try {
2102
+ await control.send(new ListFoundationModelsCommand({}));
2103
+ } finally {
2104
+ control.destroy();
2105
+ }
2106
+ }
2067
2107
  async warmup() {
2068
2108
  }
2069
2109
  ensureClient() {
@@ -2396,6 +2436,11 @@ function runContractTests(harness) {
2396
2436
  expect(typeof m.capabilities.tools).toBe("boolean");
2397
2437
  }
2398
2438
  });
2439
+ it("[15a] testCredential resolves on a valid auth probe", async () => {
2440
+ await harness.mockScenario("list-models");
2441
+ const adapter = await init(harness);
2442
+ await expect(adapter.testCredential()).resolves.not.toThrow();
2443
+ });
2399
2444
  if (harness.nonToolCapableModel) {
2400
2445
  it("[16] non-tool-capable model with tools declared either fails fast or runs without tool calls", async () => {
2401
2446
  await harness.mockScenario("simple-stream");
@@ -2590,6 +2635,9 @@ var FakeAdapter = class {
2590
2635
  this.ensureInitialized();
2591
2636
  return fakeManifest.knownModels;
2592
2637
  }
2638
+ async testCredential() {
2639
+ this.ensureInitialized();
2640
+ }
2593
2641
  ensureInitialized() {
2594
2642
  if (!this.initialized) {
2595
2643
  throw new Error("FakeAdapter: init() must be called before stream()/listAvailableModels()");