@jambonz/llm 0.6.6 → 0.6.8

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.
@@ -42,8 +42,9 @@ var import_vitest = require("vitest");
42
42
 
43
43
  // src/registry.ts
44
44
  var registry = /* @__PURE__ */ new Map();
45
+ var credentialVendors = /* @__PURE__ */ new Map();
45
46
  function registerAdapter(factory) {
46
- if (registry.has(factory.vendor)) {
47
+ if (registry.has(factory.vendor) || credentialVendors.has(factory.vendor)) {
47
48
  throw new Error(
48
49
  `Adapter already registered for vendor '${factory.vendor}'. Use replaceAdapter() if you intended to override.`
49
50
  );
@@ -55,9 +56,23 @@ function registerAdapter(factory) {
55
56
  }
56
57
  registry.set(factory.vendor, factory);
57
58
  }
59
+ function registerCredentialVendor(manifest) {
60
+ if (!manifest.credentialOnly) {
61
+ throw new Error(`Vendor '${manifest.vendor}' manifest is not marked credentialOnly.`);
62
+ }
63
+ if (registry.has(manifest.vendor) || credentialVendors.has(manifest.vendor)) {
64
+ throw new Error(`Vendor '${manifest.vendor}' is already registered.`);
65
+ }
66
+ credentialVendors.set(manifest.vendor, manifest);
67
+ }
58
68
  function getAdapterFactory(vendor) {
59
69
  const factory = registry.get(vendor);
60
70
  if (!factory) {
71
+ if (credentialVendors.has(vendor)) {
72
+ throw new Error(
73
+ `Vendor '${vendor}' is credential-only: @jambonz/llm has no adapter for it.`
74
+ );
75
+ }
61
76
  const known = Array.from(registry.keys()).sort().join(", ") || "(none)";
62
77
  throw new Error(
63
78
  `Unknown vendor '${vendor}'. Registered vendors: ${known}`
@@ -67,6 +82,7 @@ function getAdapterFactory(vendor) {
67
82
  }
68
83
  function _resetRegistryForTests() {
69
84
  registry.clear();
85
+ credentialVendors.clear();
70
86
  }
71
87
 
72
88
  // src/adapters/openai/adapter.ts
@@ -3578,6 +3594,212 @@ var huggingfaceFactory = {
3578
3594
  create: () => new HuggingfaceAdapter()
3579
3595
  };
3580
3596
 
3597
+ // src/adapters/openrouter/manifest.ts
3598
+ var OPENROUTER_KNOWN_MODELS = [
3599
+ {
3600
+ id: "anthropic/claude-haiku-5.5",
3601
+ displayName: "Claude Haiku 5.5 (OpenRouter)",
3602
+ capabilities: {
3603
+ streaming: true,
3604
+ tools: true,
3605
+ vision: true,
3606
+ systemPrompt: true,
3607
+ maxContextTokens: 1e6
3608
+ }
3609
+ },
3610
+ {
3611
+ id: "anthropic/claude-sonnet-5.5",
3612
+ displayName: "Claude Sonnet 5.5 (OpenRouter)",
3613
+ capabilities: {
3614
+ streaming: true,
3615
+ tools: true,
3616
+ vision: true,
3617
+ systemPrompt: true,
3618
+ maxContextTokens: 1e6
3619
+ }
3620
+ },
3621
+ {
3622
+ id: "openai/gpt-5.4-mini",
3623
+ displayName: "GPT-5.4 Mini (OpenRouter)",
3624
+ capabilities: {
3625
+ streaming: true,
3626
+ tools: true,
3627
+ vision: true,
3628
+ systemPrompt: true,
3629
+ maxContextTokens: 4e5
3630
+ }
3631
+ },
3632
+ {
3633
+ id: "openai/gpt-4.1-mini",
3634
+ displayName: "GPT-4.1 Mini (OpenRouter)",
3635
+ capabilities: {
3636
+ streaming: true,
3637
+ tools: true,
3638
+ vision: true,
3639
+ systemPrompt: true,
3640
+ maxContextTokens: 1047576
3641
+ }
3642
+ },
3643
+ {
3644
+ id: "google/gemini-3.5-flash",
3645
+ displayName: "Gemini 3.5 Flash (OpenRouter)",
3646
+ capabilities: {
3647
+ streaming: true,
3648
+ tools: true,
3649
+ vision: true,
3650
+ systemPrompt: true,
3651
+ maxContextTokens: 1048576
3652
+ }
3653
+ },
3654
+ {
3655
+ id: "meta-llama/llama-3.3-70b-instruct",
3656
+ displayName: "Llama 3.3 70B Instruct (OpenRouter)",
3657
+ capabilities: {
3658
+ streaming: true,
3659
+ tools: true,
3660
+ vision: false,
3661
+ systemPrompt: true,
3662
+ maxContextTokens: 131072
3663
+ }
3664
+ }
3665
+ ];
3666
+ var openRouterManifest = {
3667
+ vendor: "openrouter",
3668
+ displayName: "OpenRouter",
3669
+ authKinds: [
3670
+ {
3671
+ kind: "apiKey",
3672
+ displayName: "API Key",
3673
+ fields: [
3674
+ {
3675
+ name: "apiKey",
3676
+ label: "API Key",
3677
+ type: "password",
3678
+ required: true,
3679
+ help: "Get an API key from https://openrouter.ai/settings/keys"
3680
+ },
3681
+ {
3682
+ name: "baseURL",
3683
+ label: "Base URL",
3684
+ type: "url",
3685
+ required: false,
3686
+ default: "https://openrouter.ai/api/v1",
3687
+ help: "Override only for proxies. Default points at OpenRouter's production endpoint."
3688
+ }
3689
+ ]
3690
+ }
3691
+ ],
3692
+ knownModels: OPENROUTER_KNOWN_MODELS,
3693
+ // /models is public; the adapter enriches it with OpenRouter's own capability metadata.
3694
+ supportsModelListing: true,
3695
+ docsUrl: "https://openrouter.ai/docs/api_reference/overview"
3696
+ };
3697
+
3698
+ // src/adapters/openrouter/adapter.ts
3699
+ var OPENROUTER_METADATA_EXTRACTOR = makeMetadataExtractor([
3700
+ { header: "x-generation-id", key: "request_id" }
3701
+ ]);
3702
+ var OPENROUTER_ATTRIBUTION_HEADERS = {
3703
+ "HTTP-Referer": "https://jambonz.org",
3704
+ "X-OpenRouter-Title": "jambonz"
3705
+ };
3706
+ var OpenRouterAdapter = class extends OpenAIAdapter {
3707
+ vendor = openRouterManifest.vendor;
3708
+ init(auth, client) {
3709
+ super.init(
3710
+ {
3711
+ ...auth,
3712
+ baseURL: auth.baseURL ?? "https://openrouter.ai/api/v1"
3713
+ },
3714
+ client
3715
+ );
3716
+ this.client = this.ensureClient().withOptions({
3717
+ defaultHeaders: OPENROUTER_ATTRIBUTION_HEADERS
3718
+ });
3719
+ }
3720
+ stream(req) {
3721
+ return streamFromOpenAI(this.ensureClient(), req, {
3722
+ knownModels: this.knownModels(),
3723
+ vendorMetadataExtractor: OPENROUTER_METADATA_EXTRACTOR,
3724
+ // Verified accepted by OpenRouter (forwarded to OpenAI-family upstreams).
3725
+ includeCacheKey: true,
3726
+ openRouterAutoCache: this.isOpenRouter
3727
+ });
3728
+ }
3729
+ async listAvailableModels() {
3730
+ const result = await this.ensureClient().models.list();
3731
+ const out = [];
3732
+ for (const m of result.data) {
3733
+ if (m.id.endsWith(":batch")) continue;
3734
+ const outputs = m.architecture?.output_modalities;
3735
+ if (outputs && !outputs.includes("text")) continue;
3736
+ const known = this.knownModels().find((k) => k.id === m.id);
3737
+ if (known) {
3738
+ out.push(known);
3739
+ continue;
3740
+ }
3741
+ out.push({
3742
+ id: m.id,
3743
+ ...m.name ? { displayName: m.name } : {},
3744
+ capabilities: {
3745
+ streaming: true,
3746
+ tools: m.supported_parameters?.includes("tools") ?? true,
3747
+ vision: m.architecture?.input_modalities?.includes("image") ?? false,
3748
+ systemPrompt: true,
3749
+ ...m.context_length ? { maxContextTokens: m.context_length } : {}
3750
+ }
3751
+ });
3752
+ }
3753
+ return out;
3754
+ }
3755
+ async testCredential() {
3756
+ await this.ensureClient().get("/key");
3757
+ }
3758
+ knownModels() {
3759
+ return openRouterManifest.knownModels;
3760
+ }
3761
+ };
3762
+
3763
+ // src/adapters/openrouter/factory.ts
3764
+ var openRouterFactory = {
3765
+ vendor: openRouterManifest.vendor,
3766
+ manifest: openRouterManifest,
3767
+ create: () => new OpenRouterAdapter()
3768
+ };
3769
+
3770
+ // src/vendors/harness.ts
3771
+ var harnessManifest = {
3772
+ vendor: "harness",
3773
+ displayName: "Harness",
3774
+ authKinds: [
3775
+ {
3776
+ // Only the form schema matters for a credential-only vendor; no
3777
+ // AuthSpec is ever built from it.
3778
+ kind: "apiKey",
3779
+ displayName: "API Key",
3780
+ fields: [
3781
+ {
3782
+ name: "url",
3783
+ label: "WebSocket URL",
3784
+ type: "url",
3785
+ required: true,
3786
+ help: "wss:// URL of your harness. ws:// is accepted only for a private or localhost address."
3787
+ },
3788
+ {
3789
+ name: "apiKey",
3790
+ label: "API Key",
3791
+ type: "password",
3792
+ required: true,
3793
+ help: 'Sent to the harness as "Authorization: Bearer <key>" when each call connects.'
3794
+ }
3795
+ ]
3796
+ }
3797
+ ],
3798
+ knownModels: [],
3799
+ supportsModelListing: false,
3800
+ credentialOnly: true
3801
+ };
3802
+
3581
3803
  // src/adapters/index.ts
3582
3804
  registerAdapter(openAIFactory);
3583
3805
  registerAdapter(deepseekFactory);
@@ -3594,6 +3816,8 @@ registerAdapter(bedrockFactory);
3594
3816
  registerAdapter(azureOpenAIFactory);
3595
3817
  registerAdapter(groqFactory);
3596
3818
  registerAdapter(huggingfaceFactory);
3819
+ registerAdapter(openRouterFactory);
3820
+ registerCredentialVendor(harnessManifest);
3597
3821
 
3598
3822
  // src/index.ts
3599
3823
  async function createLlm(args) {