@amux.ai/llm-bridge 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +180 -0
  2. package/package.json +7 -2
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # @amux.ai/llm-bridge
2
+
3
+ > Core IR (Intermediate Representation) and adapter interfaces for Amux
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@amux.ai/llm-bridge.svg)](https://www.npmjs.com/package/@amux.ai/llm-bridge)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Overview
9
+
10
+ `@amux.ai/llm-bridge` is the core package of Amux that provides:
11
+
12
+ - **Intermediate Representation (IR)**: Unified data structures for LLM requests/responses
13
+ - **Adapter Interface**: Standard interface for building provider adapters
14
+ - **Bridge Pattern**: Orchestration layer for bidirectional conversion
15
+ - **HTTP Client**: Built-in HTTP client with SSE streaming support
16
+ - **Zero Dependencies**: No runtime dependencies
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pnpm add @amux.ai/llm-bridge
22
+ # or
23
+ npm install @amux.ai/llm-bridge
24
+ # or
25
+ yarn add @amux.ai/llm-bridge
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ### Create a Bridge
31
+
32
+ ```typescript
33
+ import { createBridge } from '@amux.ai/llm-bridge'
34
+ import { openaiAdapter } from '@amux.ai/adapter-openai'
35
+ import { anthropicAdapter } from '@amux.ai/adapter-anthropic'
36
+
37
+ const bridge = createBridge({
38
+ inbound: openaiAdapter,
39
+ outbound: anthropicAdapter,
40
+ config: {
41
+ apiKey: process.env.ANTHROPIC_API_KEY,
42
+ baseURL: 'https://api.anthropic.com'
43
+ }
44
+ })
45
+
46
+ // Send request in OpenAI format, get response in OpenAI format
47
+ // But actually calls Anthropic API under the hood
48
+ const response = await bridge.chat({
49
+ model: 'gpt-4',
50
+ messages: [{ role: 'user', content: 'Hello!' }]
51
+ })
52
+ ```
53
+
54
+ ### Streaming
55
+
56
+ ```typescript
57
+ for await (const chunk of bridge.chatStream({
58
+ model: 'gpt-4',
59
+ messages: [{ role: 'user', content: 'Tell me a story' }],
60
+ stream: true
61
+ })) {
62
+ console.log(chunk)
63
+ }
64
+ ```
65
+
66
+ ## Core Concepts
67
+
68
+ ### Intermediate Representation (IR)
69
+
70
+ The IR is the central data structure that all adapters convert to/from:
71
+
72
+ - **LLMRequestIR**: Unified request format
73
+ - **LLMResponseIR**: Unified response format
74
+ - **LLMStreamEvent**: Unified streaming events
75
+ - **LLMErrorIR**: Unified error format
76
+
77
+ ### Adapter Interface
78
+
79
+ Every adapter implements the `LLMAdapter` interface:
80
+
81
+ ```typescript
82
+ interface LLMAdapter {
83
+ inbound: {
84
+ parseRequest(request: unknown): Promise<LLMRequestIR>
85
+ parseResponse(response: unknown): Promise<LLMResponseIR>
86
+ parseStream(chunk: string): Promise<LLMStreamEvent | null>
87
+ parseError(error: unknown): LLMErrorIR
88
+ }
89
+ outbound: {
90
+ buildRequest(ir: LLMRequestIR): unknown
91
+ buildResponse(ir: LLMResponseIR): unknown
92
+ }
93
+ capabilities: AdapterCapabilities
94
+ getInfo(): AdapterInfo
95
+ }
96
+ ```
97
+
98
+ ### Bridge Pattern
99
+
100
+ The Bridge orchestrates the conversion flow:
101
+
102
+ 1. Inbound adapter parses incoming request → IR
103
+ 2. Validate IR (optional)
104
+ 3. Outbound adapter builds provider request from IR
105
+ 4. Send HTTP request to target provider
106
+ 5. Outbound adapter parses response → IR
107
+ 6. Inbound adapter builds final response from IR
108
+
109
+ ## API Reference
110
+
111
+ ### `createBridge(options)`
112
+
113
+ Create a new bridge instance.
114
+
115
+ **Options:**
116
+ - `inbound` - Inbound adapter instance
117
+ - `outbound` - Outbound adapter instance
118
+ - `config` - Configuration object
119
+ - `apiKey` - API key for the outbound provider
120
+ - `baseURL` - Base URL for the outbound provider (optional)
121
+ - `timeout` - Request timeout in milliseconds (optional)
122
+ - `headers` - Additional HTTP headers (optional)
123
+
124
+ **Returns:** `Bridge` instance
125
+
126
+ ### `bridge.chat(request)`
127
+
128
+ Send a chat completion request.
129
+
130
+ **Parameters:**
131
+ - `request` - Request object in inbound adapter format
132
+
133
+ **Returns:** `Promise<Response>` - Response in inbound adapter format
134
+
135
+ ### `bridge.chatStream(request)`
136
+
137
+ Send a streaming chat completion request.
138
+
139
+ **Parameters:**
140
+ - `request` - Request object in inbound adapter format with `stream: true`
141
+
142
+ **Returns:** `AsyncIterable<string>` - Server-Sent Events stream
143
+
144
+ ## Available Adapters
145
+
146
+ - [@amux.ai/adapter-openai](https://www.npmjs.com/package/@amux.ai/adapter-openai) - OpenAI
147
+ - [@amux.ai/adapter-anthropic](https://www.npmjs.com/package/@amux.ai/adapter-anthropic) - Anthropic (Claude)
148
+ - [@amux.ai/adapter-deepseek](https://www.npmjs.com/package/@amux.ai/adapter-deepseek) - DeepSeek
149
+ - [@amux.ai/adapter-moonshot](https://www.npmjs.com/package/@amux.ai/adapter-moonshot) - Moonshot (Kimi)
150
+ - [@amux.ai/adapter-zhipu](https://www.npmjs.com/package/@amux.ai/adapter-zhipu) - Zhipu AI (GLM)
151
+ - [@amux.ai/adapter-qwen](https://www.npmjs.com/package/@amux.ai/adapter-qwen) - Qwen
152
+ - [@amux.ai/adapter-google](https://www.npmjs.com/package/@amux.ai/adapter-google) - Google Gemini
153
+
154
+ ## TypeScript Support
155
+
156
+ This package is written in TypeScript and provides full type definitions.
157
+
158
+ ```typescript
159
+ import type {
160
+ LLMRequestIR,
161
+ LLMResponseIR,
162
+ LLMAdapter,
163
+ Bridge
164
+ } from '@amux.ai/llm-bridge'
165
+ ```
166
+
167
+ ## Contributing
168
+
169
+ Contributions are welcome! Please see our [Contributing Guide](https://github.com/isboyjc/amux/blob/main/CONTRIBUTING.md).
170
+
171
+ ## License
172
+
173
+ MIT © [isboyjc](https://github.com/isboyjc)
174
+
175
+ ## Links
176
+
177
+ - [Documentation](https://github.com/isboyjc/amux#readme)
178
+ - [GitHub Repository](https://github.com/isboyjc/amux)
179
+ - [Issue Tracker](https://github.com/isboyjc/amux/issues)
180
+ - [Changelog](./CHANGELOG.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amux.ai/llm-bridge",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Core IR and adapter interfaces for Amux",
5
5
  "keywords": [
6
6
  "amux",
@@ -15,6 +15,10 @@
15
15
  "url": "https://github.com/isboyjc/amux.git",
16
16
  "directory": "packages/llm-bridge"
17
17
  },
18
+ "homepage": "https://github.com/isboyjc/amux#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/isboyjc/amux/issues"
21
+ },
18
22
  "license": "MIT",
19
23
  "author": "isboyjc",
20
24
  "type": "module",
@@ -29,7 +33,8 @@
29
33
  "module": "./dist/index.js",
30
34
  "types": "./dist/index.d.ts",
31
35
  "files": [
32
- "dist"
36
+ "dist",
37
+ "README.md"
33
38
  ],
34
39
  "devDependencies": {
35
40
  "@types/node": "^20.11.5",