supercompat 4.1.1 → 4.2.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/README.md ADDED
@@ -0,0 +1,93 @@
1
+ ![Supercompat — Switch AI models without compromises.](https://raw.githubusercontent.com/supercorp-ai/supercompat/main/packages/supercompat/supercompat.png)
2
+
3
+ Supercompat is AI compatibility layer without compromises. Supercompat library that lets you call **any LLM provider** through the **OpenAI SDK** (or the **Anthropic SDK**). Swap one adapter and the same `client.responses.create()` call reaches Anthropic, Google, Groq, Mistral, Together, OpenRouter, Perplexity, Ollama, or Azure — with the original SDK types intact.
4
+
5
+ It runs in-process. No proxy server, no request forwarding, no extra latency. Supercompat installs a custom `fetch` on the SDK instance and routes calls locally.
6
+
7
+ Full docs: **[supercompat.com/docs](https://supercompat.com/docs)**.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install supercompat openai
13
+ ```
14
+
15
+ ## Quick example
16
+
17
+ ```tsx
18
+ import {
19
+ supercompat,
20
+ anthropicClientAdapter,
21
+ completionsRunAdapter,
22
+ memoryStorageAdapter,
23
+ } from 'supercompat/openai'
24
+ import Anthropic from '@anthropic-ai/sdk'
25
+
26
+ const client = supercompat({
27
+ clientAdapter: anthropicClientAdapter({ anthropic: new Anthropic() }),
28
+ storageAdapter: memoryStorageAdapter(),
29
+ runAdapter: completionsRunAdapter(),
30
+ })
31
+
32
+ const response = await client.responses.create({
33
+ model: 'claude-sonnet-4-6',
34
+ input: 'Say hello.',
35
+ })
36
+
37
+ console.log(response.output_text)
38
+ ```
39
+
40
+ `client` is a real `OpenAI` instance with the real TypeScript types. Every call made on it — `responses`, `chat.completions`, `beta.threads` — is intercepted by Supercompat and translated into a request against the Anthropic SDK. Switching providers is a change to `clientAdapter`; everything else stays the same.
41
+
42
+ ## Persistent state
43
+
44
+ `memoryStorageAdapter` is fine for one-shot scripts but loses everything on restart. For persisted conversations, threads, and runs, swap it for [`prismaStorageAdapter`](https://supercompat.com/docs/adapters/storage-adapters/prisma):
45
+
46
+ ```tsx
47
+ import { PrismaClient } from '@prisma/client'
48
+ import {
49
+ supercompat,
50
+ anthropicClientAdapter,
51
+ completionsRunAdapter,
52
+ prismaStorageAdapter,
53
+ } from 'supercompat/openai'
54
+ import Anthropic from '@anthropic-ai/sdk'
55
+
56
+ const prisma = new PrismaClient()
57
+
58
+ const client = supercompat({
59
+ clientAdapter: anthropicClientAdapter({ anthropic: new Anthropic() }),
60
+ storageAdapter: prismaStorageAdapter({ prisma }),
61
+ runAdapter: completionsRunAdapter(),
62
+ })
63
+
64
+ // Continue a conversation across requests with previous_response_id:
65
+ const first = await client.responses.create({
66
+ model: 'claude-sonnet-4-6',
67
+ input: 'My name is Alice.',
68
+ })
69
+
70
+ const second = await client.responses.create({
71
+ model: 'claude-sonnet-4-6',
72
+ input: 'What did I just tell you?',
73
+ previous_response_id: first.id,
74
+ })
75
+ ```
76
+
77
+ Conversations, responses, assistants, threads, messages, and runs all land in Postgres. See [Storage adapters](https://supercompat.com/docs/adapters/storage-adapters) for every option — including OpenAI-managed and Azure-managed state.
78
+
79
+ ## Where to go next
80
+
81
+ - **[Installation](https://supercompat.com/docs/getting-started/installation)** — install the package, pick a provider SDK, and wire them together.
82
+ - **[Comparison](https://supercompat.com/docs/getting-started/comparison)** — how Supercompat compares to Vercel AI SDK, LiteLLM, LangChain, and others.
83
+ - **[Output SDKs](https://supercompat.com/docs/output-sdks)** — return an OpenAI-shaped or Anthropic-shaped client. Works with every provider.
84
+ - **[Adapters](https://supercompat.com/docs/adapters)** — the three adapter types (client, storage, run) and how they compose.
85
+ - **[Providers](https://supercompat.com/docs/providers)** — setup notes for OpenAI, Anthropic, Google, Azure, and every other backend.
86
+ - **[Tools](https://supercompat.com/docs/tools)** — function calling, web search, file search, code interpreter, and computer use.
87
+ - **[Streaming](https://supercompat.com/docs/streaming)** — stream deltas through the OpenAI SDK regardless of which provider is behind it.
88
+
89
+ ## Links
90
+
91
+ - Docs: [supercompat.com/docs](https://supercompat.com/docs)
92
+ - GitHub: [github.com/supercorp-ai/supercompat](https://github.com/supercorp-ai/supercompat)
93
+ - Supported by [Supercorp](https://supercorp.ai)
@@ -602,29 +602,29 @@ var import_openai = __toESM(require("openai"), 1);
602
602
  // src/supercompatFetch/requestHandlers.ts
603
603
  var import_radash = require("radash");
604
604
  var storageRequestHandlers = function(param) {
605
- var storage = param.storage, runAdapter = param.runAdapter, client = param.client;
606
- if (!storage) return {};
605
+ var storageAdapter = param.storageAdapter, runAdapter = param.runAdapter, clientAdapter = param.clientAdapter;
606
+ if (!storageAdapter) return {};
607
607
  if (!runAdapter) return {};
608
608
  var wrappedClient = supercompat({
609
- client: client
609
+ clientAdapter: clientAdapter
610
610
  });
611
- var result = storage({
611
+ var result = storageAdapter({
612
612
  runAdapter: _object_spread_props(_object_spread({}, runAdapter), {
613
613
  handleRun: (0, import_radash.partob)(runAdapter.handleRun, {
614
614
  client: wrappedClient
615
615
  })
616
616
  }),
617
617
  client: wrappedClient,
618
- originalClient: client
618
+ originalClientAdapter: clientAdapter
619
619
  });
620
620
  return result.requestHandlers;
621
621
  };
622
622
  var requestHandlers = function(param) {
623
- var client = param.client, storage = param.storage, runAdapter = param.runAdapter;
624
- return (0, import_radash.assign)(client.requestHandlers, storageRequestHandlers({
625
- storage: storage,
623
+ var clientAdapter = param.clientAdapter, storageAdapter = param.storageAdapter, runAdapter = param.runAdapter;
624
+ return (0, import_radash.assign)(clientAdapter.requestHandlers, storageRequestHandlers({
625
+ storageAdapter: storageAdapter,
626
626
  runAdapter: runAdapter,
627
- client: client
627
+ clientAdapter: clientAdapter
628
628
  }));
629
629
  };
630
630
  // src/supercompatFetch/findRequestHandler.ts
@@ -641,20 +641,20 @@ var findRequestHandler = function(param) {
641
641
  };
642
642
  // src/supercompatFetch/originalFetch.ts
643
643
  var originalFetch = function(param) {
644
- var args = param.args, client = param.client;
644
+ var args = param.args, clientAdapter = param.clientAdapter;
645
645
  return _async_to_generator(function() {
646
- var _client_client, _args, url, options, clientHeaders, newOptions;
646
+ var _clientAdapter_client, _args, url, options, clientHeaders, newOptions;
647
647
  return _ts_generator(this, function(_state) {
648
648
  switch(_state.label){
649
649
  case 0:
650
- if (!((_client_client = client.client) === null || _client_client === void 0 ? void 0 : _client_client.fetch)) return [
650
+ if (!((_clientAdapter_client = clientAdapter.client) === null || _clientAdapter_client === void 0 ? void 0 : _clientAdapter_client.fetch)) return [
651
651
  3,
652
652
  2
653
653
  ];
654
654
  _args = _sliced_to_array(args, 2), url = _args[0], options = _args[1];
655
655
  return [
656
656
  4,
657
- client.client.buildHeaders({
657
+ clientAdapter.client.buildHeaders({
658
658
  options: {},
659
659
  method: args[1].method.toLowerCase(),
660
660
  bodyHeaders: args[1].headers,
@@ -663,13 +663,13 @@ var originalFetch = function(param) {
663
663
  ];
664
664
  case 1:
665
665
  clientHeaders = _state.sent();
666
- clientHeaders.set("Authorization", "Bearer ".concat(client.client.apiKey));
666
+ clientHeaders.set("Authorization", "Bearer ".concat(clientAdapter.client.apiKey));
667
667
  newOptions = _object_spread_props(_object_spread({}, options), {
668
668
  headers: clientHeaders
669
669
  });
670
670
  return [
671
671
  2,
672
- client.client.fetch(url, newOptions)
672
+ clientAdapter.client.fetch(url, newOptions)
673
673
  ];
674
674
  case 2:
675
675
  return [
@@ -686,10 +686,10 @@ var originalFetch = function(param) {
686
686
  };
687
687
  // src/supercompatFetch/index.ts
688
688
  var supercompatFetch = function(param) {
689
- var client = param.client, storage = param.storage, runAdapter = param.runAdapter;
689
+ var clientAdapter = param.clientAdapter, storageAdapter = param.storageAdapter, runAdapter = param.runAdapter;
690
690
  var requestHandlers2 = requestHandlers({
691
- client: client,
692
- storage: storage,
691
+ clientAdapter: clientAdapter,
692
+ storageAdapter: storageAdapter,
693
693
  runAdapter: runAdapter
694
694
  });
695
695
  return function() {
@@ -708,7 +708,7 @@ var supercompatFetch = function(param) {
708
708
  return [
709
709
  2,
710
710
  originalFetch({
711
- client: client,
711
+ clientAdapter: clientAdapter,
712
712
  args: args
713
713
  })
714
714
  ];
@@ -719,7 +719,7 @@ var supercompatFetch = function(param) {
719
719
  return [
720
720
  2,
721
721
  originalFetch({
722
- client: client,
722
+ clientAdapter: clientAdapter,
723
723
  args: args
724
724
  })
725
725
  ];
@@ -739,17 +739,17 @@ var endpointFromBaseUrl = function(param) {
739
739
  };
740
740
  // src/supercompat.ts
741
741
  var supercompat = function(param) {
742
- var client = param.client, storage = param.storage, runAdapter = param.runAdapter;
743
- if (client.type === "AZURE_OPENAI") {
742
+ var clientAdapter = param.clientAdapter, storageAdapter = param.storageAdapter, runAdapter = param.runAdapter;
743
+ if (clientAdapter.type === "AZURE_OPENAI") {
744
744
  return new import_openai.AzureOpenAI({
745
- apiKey: client.client.apiKey,
746
- apiVersion: client.client.apiVersion,
745
+ apiKey: clientAdapter.client.apiKey,
746
+ apiVersion: clientAdapter.client.apiVersion,
747
747
  endpoint: endpointFromBaseUrl({
748
- baseURL: client.client.baseURL
748
+ baseURL: clientAdapter.client.baseURL
749
749
  }),
750
750
  fetch: supercompatFetch({
751
- client: client,
752
- storage: storage,
751
+ clientAdapter: clientAdapter,
752
+ storageAdapter: storageAdapter,
753
753
  runAdapter: runAdapter
754
754
  })
755
755
  });
@@ -757,8 +757,8 @@ var supercompat = function(param) {
757
757
  return new import_openai.default({
758
758
  apiKey: "SUPERCOMPAT_PLACEHOLDER_OPENAI_KEY",
759
759
  fetch: supercompatFetch({
760
- client: client,
761
- storage: storage,
760
+ clientAdapter: clientAdapter,
761
+ storageAdapter: storageAdapter,
762
762
  runAdapter: runAdapter
763
763
  })
764
764
  });
@@ -28114,10 +28114,10 @@ var azureResponsesStorageAdapter = function() {
28114
28114
  var createResponseItems = [];
28115
28115
  var cachedClient = null;
28116
28116
  return function(param) {
28117
- var runAdapter = param.runAdapter, client = param.client, originalClient = param.originalClient;
28117
+ var runAdapter = param.runAdapter, client = param.client, originalClientAdapter = param.originalClientAdapter;
28118
28118
  var getAIProjectClient = function() {
28119
- if (originalClient && (typeof originalClient === "undefined" ? "undefined" : _type_of(originalClient)) === "object" && "client" in originalClient) {
28120
- return originalClient.client;
28119
+ if (originalClientAdapter && (typeof originalClientAdapter === "undefined" ? "undefined" : _type_of(originalClientAdapter)) === "object" && "client" in originalClientAdapter) {
28120
+ return originalClientAdapter.client;
28121
28121
  }
28122
28122
  return client;
28123
28123
  };