tolvyn 1.0.2 → 1.0.4
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 +23 -143
- package/dist/cjs/anthropic.d.ts +2 -0
- package/dist/cjs/anthropic.d.ts.map +1 -1
- package/dist/cjs/anthropic.js +5 -1
- package/dist/cjs/anthropic.js.map +1 -1
- package/dist/cjs/client.d.ts +2 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +5 -1
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/google.d.ts +25 -0
- package/dist/cjs/google.d.ts.map +1 -0
- package/dist/cjs/google.js +51 -0
- package/dist/cjs/google.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/anthropic.d.ts +2 -0
- package/dist/esm/anthropic.d.ts.map +1 -1
- package/dist/esm/anthropic.js +5 -1
- package/dist/esm/anthropic.js.map +1 -1
- package/dist/esm/client.d.ts +2 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +5 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/google.d.ts +25 -0
- package/dist/esm/google.d.ts.map +1 -0
- package/dist/esm/google.js +47 -0
- package/dist/esm/google.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +5 -2
- package/src/anthropic.ts +10 -5
- package/src/client.ts +10 -5
- package/src/google.ts +74 -0
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
# tolvyn
|
|
1
|
+
# tolvyn · npm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/tolvyn)
|
|
4
|
+
|
|
5
|
+
Drop-in replacement for `openai` and `@anthropic-ai/sdk`.
|
|
6
|
+
One line change. Every AI call metered, attributed, and governed.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
4
9
|
|
|
5
10
|
```bash
|
|
6
11
|
npm install tolvyn
|
|
7
12
|
```
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
### OpenAI (ESM / TypeScript)
|
|
14
|
+
## Quick start
|
|
14
15
|
|
|
15
16
|
```typescript
|
|
16
17
|
// Before
|
|
@@ -20,7 +21,7 @@ const client = new OpenAI();
|
|
|
20
21
|
// After — one line change
|
|
21
22
|
import { OpenAI } from "tolvyn";
|
|
22
23
|
const client = new OpenAI({
|
|
23
|
-
tolvynApiKey: "tlv_live_...",
|
|
24
|
+
tolvynApiKey: "tlv_live_...",
|
|
24
25
|
team: "backend",
|
|
25
26
|
service: "summariser",
|
|
26
27
|
});
|
|
@@ -32,152 +33,31 @@ const response = await client.chat.completions.create({
|
|
|
32
33
|
});
|
|
33
34
|
```
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
const { OpenAI } = require("tolvyn");
|
|
39
|
-
|
|
40
|
-
const client = new OpenAI({
|
|
41
|
-
tolvynApiKey: process.env.TOLVYN_API_KEY,
|
|
42
|
-
team: "backend",
|
|
43
|
-
service: "summariser",
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Anthropic (ESM / TypeScript)
|
|
36
|
+
Works the same way for Anthropic:
|
|
48
37
|
|
|
49
38
|
```typescript
|
|
50
|
-
// Before
|
|
51
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
52
|
-
const client = new Anthropic();
|
|
53
|
-
|
|
54
|
-
// After
|
|
55
39
|
import { Anthropic } from "tolvyn";
|
|
56
|
-
const client = new Anthropic({
|
|
57
|
-
tolvynApiKey: "tlv_live_...",
|
|
58
|
-
team: "ml-team",
|
|
59
|
-
service: "classifier",
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const message = await client.messages.create({
|
|
63
|
-
model: "claude-sonnet-4-6",
|
|
64
|
-
max_tokens: 1024,
|
|
65
|
-
messages: [{ role: "user", content: "Hello" }],
|
|
66
|
-
});
|
|
40
|
+
const client = new Anthropic({ tolvynApiKey: "tlv_live_...", team: "ml", service: "classifier" });
|
|
67
41
|
```
|
|
68
42
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## Classes
|
|
72
|
-
|
|
73
|
-
| Class | Extends | Provider |
|
|
74
|
-
|--------------------|-------------------------------|-----------|
|
|
75
|
-
| `tolvyn.OpenAI` | `openai` OpenAI | OpenAI |
|
|
76
|
-
| `tolvyn.Anthropic` | `@anthropic-ai/sdk` Anthropic | Anthropic |
|
|
77
|
-
|
|
78
|
-
Both classes are strict drop-ins. Every method, event, and behaviour of the underlying SDK is preserved.
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## Parameters
|
|
83
|
-
|
|
84
|
-
### `OpenAI` (`TolvynOpenAIOptions`)
|
|
85
|
-
|
|
86
|
-
Extends `openai.ClientOptions` (omitting `apiKey` and `baseURL`).
|
|
87
|
-
|
|
88
|
-
| Parameter | Type | Default | Description |
|
|
89
|
-
|----------------|-----------------------|-------------|-----------------------------------------------------------------------------------------------------------|
|
|
90
|
-
| `tolvynApiKey` | `string or undefined` | `undefined` | Your TOLVYN API key. Falls back to `TOLVYN_API_KEY` env var. Required. |
|
|
91
|
-
| `proxyUrl` | `string or undefined` | `undefined` | TOLVYN proxy URL. Falls back to `TOLVYN_PROXY_URL` env var, then `http://localhost:8081/v1/proxy/openai`. |
|
|
92
|
-
| `team` | `string or undefined` | `undefined` | Team name for cost attribution. Sent as `X-Tolvyn-Team` header. |
|
|
93
|
-
| `service` | `string or undefined` | `undefined` | Service name. Sent as `X-Tolvyn-Service` header. |
|
|
94
|
-
| `feature` | `string or undefined` | `undefined` | Feature name. Sent as `X-Tolvyn-Feature` header. |
|
|
95
|
-
| `agent` | `string or undefined` | `undefined` | Agent name. Sent as `X-Tolvyn-Agent` header. |
|
|
96
|
-
| `failOpen` | `boolean` | `true` | If `true` and the proxy is unreachable, retry directly against OpenAI using `openAIApiKey`. |
|
|
97
|
-
| `openAIApiKey` | `string or undefined` | `undefined` | OpenAI key used only for fail-open fallback. Falls back to `OPENAI_API_KEY` env var. |
|
|
98
|
-
| `...rest` | any | — | All other `openai.ClientOptions` fields are forwarded to the underlying client. |
|
|
99
|
-
|
|
100
|
-
### `Anthropic` (`TolvynAnthropicOptions`)
|
|
101
|
-
|
|
102
|
-
Extends `@anthropic-ai/sdk` ClientOptions (omitting `apiKey` and `baseURL`).
|
|
103
|
-
|
|
104
|
-
| Parameter | Type | Default | Description |
|
|
105
|
-
|------------------|-----------------------|-------------|--------------------------------------------------------------------------------------------------------------|
|
|
106
|
-
| `tolvynApiKey` | `string or undefined` | `undefined` | Your TOLVYN API key. Falls back to `TOLVYN_API_KEY` env var. Required. |
|
|
107
|
-
| `proxyUrl` | `string or undefined` | `undefined` | TOLVYN proxy URL. Falls back to `TOLVYN_PROXY_URL` env var, then `http://localhost:8081/v1/proxy/anthropic`. |
|
|
108
|
-
| `team` | `string or undefined` | `undefined` | Team name for cost attribution. |
|
|
109
|
-
| `service` | `string or undefined` | `undefined` | Service name. |
|
|
110
|
-
| `feature` | `string or undefined` | `undefined` | Feature name. |
|
|
111
|
-
| `agent` | `string or undefined` | `undefined` | Agent name. |
|
|
112
|
-
| `failOpen` | `boolean` | `true` | If `true` and the proxy is unreachable, retry directly against Anthropic. |
|
|
113
|
-
| `anthropicApiKey`| `string or undefined` | `undefined` | Anthropic key used only for fail-open fallback. Falls back to `ANTHROPIC_API_KEY` env var. |
|
|
114
|
-
| `...rest` | any | — | All other Anthropic ClientOptions fields are forwarded. |
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## Tagging
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
const client = new OpenAI({
|
|
122
|
-
tolvynApiKey: "tlv_live_...",
|
|
123
|
-
team: "search-team", // Maps to a team in TOLVYN → budget applies
|
|
124
|
-
service: "semantic-search", // Sub-component (e.g. microservice name)
|
|
125
|
-
feature: "query-expansion", // Feature within the service
|
|
126
|
-
agent: "reranker-v2", // Agent name for multi-agent pipelines
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
All four tags are optional and independent. They appear in `tolvyn tail` output, the dashboard, and usage breakdown endpoints.
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## Fail-open behaviour
|
|
135
|
-
|
|
136
|
-
By default, `failOpen: true`. When the TOLVYN proxy is unreachable (connection refused, HTTP 503), the SDK retries the request directly against the AI provider using the fallback API key.
|
|
137
|
-
|
|
138
|
-
A proxy outage **never breaks your application**. Requests that bypass the proxy are not metered; they appear in the provider's billing but not in TOLVYN.
|
|
139
|
-
|
|
140
|
-
To hard-fail on proxy errors:
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
const client = new OpenAI({ tolvynApiKey: "tlv_live_...", failOpen: false });
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## Imports
|
|
149
|
-
|
|
150
|
-
### ESM
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
import { OpenAI, Anthropic } from "tolvyn";
|
|
154
|
-
import type { TolvynOpenAIOptions, TolvynAnthropicOptions } from "tolvyn";
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### CommonJS
|
|
43
|
+
CommonJS:
|
|
158
44
|
|
|
159
45
|
```javascript
|
|
160
|
-
const { OpenAI
|
|
46
|
+
const { OpenAI } = require("tolvyn");
|
|
47
|
+
const client = new OpenAI({ tolvynApiKey: process.env.TOLVYN_API_KEY, team: "backend" });
|
|
161
48
|
```
|
|
162
49
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
---
|
|
50
|
+
## What you get
|
|
166
51
|
|
|
167
|
-
|
|
52
|
+
- **Cost metering** — every request logged with exact token counts and cost in microdollars
|
|
53
|
+
- **Team attribution** — see spend by team and service, not just a total invoice number
|
|
54
|
+
- **Budget enforcement** — set hard limits that block requests before they hit your provider
|
|
55
|
+
- **Immutable ledger** — hash-chained audit trail, verifiable at any time
|
|
56
|
+
- **Drop-in** — no changes to your existing API calls, models, or response handling
|
|
168
57
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
| `TOLVYN_API_KEY` | All classes | TOLVYN API key |
|
|
172
|
-
| `TOLVYN_PROXY_URL` | All classes | Proxy URL override |
|
|
173
|
-
| `OPENAI_API_KEY` | OpenAI classes | OpenAI key for fail-open fallback |
|
|
174
|
-
| `ANTHROPIC_API_KEY` | Anthropic classes | Anthropic key for fail-open fallback |
|
|
58
|
+
Full docs: [docs.tolvyn.io/nodejs-sdk](https://docs.tolvyn.io/nodejs-sdk)
|
|
59
|
+
Free trial: [tolvyn.io](https://tolvyn.io)
|
|
175
60
|
|
|
176
61
|
---
|
|
177
62
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
- Node.js 18+
|
|
181
|
-
- `openai >= 4.0.0` (peer dependency)
|
|
182
|
-
- `@anthropic-ai/sdk >= 0.20.0` (peer dependency)
|
|
183
|
-
- TypeScript 5.0+ (if using TypeScript)
|
|
63
|
+
© 2026 TOLVYN. All rights reserved.
|
package/dist/cjs/anthropic.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAa,EAAE,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMjE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,SAAU,SAAQ,aAAa;IAC1C,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE3C,OAAO,GAAE,sBAA2B;
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAa,EAAE,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMjE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,SAAU,SAAQ,aAAa;IAC1C,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE3C,OAAO,GAAE,sBAA2B;CA+CjD"}
|
package/dist/cjs/anthropic.js
CHANGED
|
@@ -29,9 +29,13 @@ class Anthropic extends sdk_1.default {
|
|
|
29
29
|
defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
30
30
|
if (options.agent)
|
|
31
31
|
defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
32
|
+
if (options.user)
|
|
33
|
+
defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
34
|
+
if (options.endCustomer)
|
|
35
|
+
defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
32
36
|
const fallbackKey = options.anthropicApiKey ?? process.env['ANTHROPIC_API_KEY'];
|
|
33
37
|
const failOpen = options.failOpen ?? true;
|
|
34
|
-
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, failOpen: _fo, anthropicApiKey: _aak, ...rest } = options;
|
|
38
|
+
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, user: _u, endCustomer: _ec, failOpen: _fo, anthropicApiKey: _aak, ...rest } = options;
|
|
35
39
|
const superOptions = {
|
|
36
40
|
...rest,
|
|
37
41
|
apiKey: tolvynApiKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,4DAAiE;AACjE,yCAA+C;AAE/C,MAAM,2BAA2B,GAAG,6CAA6C,CAAC;AAClF,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,4DAAiE;AACjE,yCAA+C;AAE/C,MAAM,2BAA2B,GAAG,6CAA6C,CAAC;AAClF,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAgBzD,MAAa,SAAU,SAAQ,aAAa;IAI1C,YAAY,UAAkC,EAAE;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC3E,IAAI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OAAO,CAAC;QAEZ,MAAM,YAAY,GAAkB;YAClC,GAAG,IAAI;YACP,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,QAAQ;YACjB,cAAc;SACf,CAAC;QAEF,IAAI,QAAQ,IAAI,WAAW,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YACnD,YAAY,CAAC,KAAK,GAAG,IAAA,4BAAiB,EAAC,WAAW,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;QACzF,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,CAAC;QAEpB,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;IACxC,CAAC;CACF;AAnDD,8BAmDC"}
|
package/dist/cjs/client.d.ts
CHANGED
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,UAAU,EAAE,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAMnD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6CD,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAE5B,OAAO,GAAE,mBAAwB;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,UAAU,EAAE,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAMnD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6CD,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAE5B,OAAO,GAAE,mBAAwB;CAgD9C"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -61,9 +61,13 @@ class OpenAI extends openai_1.default {
|
|
|
61
61
|
defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
62
62
|
if (options.agent)
|
|
63
63
|
defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
64
|
+
if (options.user)
|
|
65
|
+
defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
66
|
+
if (options.endCustomer)
|
|
67
|
+
defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
64
68
|
const fallbackKey = options.openAIApiKey ?? process.env['OPENAI_API_KEY'];
|
|
65
69
|
const failOpen = options.failOpen ?? true;
|
|
66
|
-
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, failOpen: _fo, openAIApiKey: _oak, ...rest } = options;
|
|
70
|
+
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, user: _u, endCustomer: _ec, failOpen: _fo, openAIApiKey: _oak, ...rest } = options;
|
|
67
71
|
const superOptions = {
|
|
68
72
|
...rest,
|
|
69
73
|
apiKey: tolvynApiKey,
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,oDAAmD;AACnD,yCAA6D;AAE7D,MAAM,wBAAwB,GAAG,0CAA0C,CAAC;AAC5E,MAAM,iBAAiB,GAAG,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,oDAAmD;AACnD,yCAA6D;AAE7D,MAAM,wBAAwB,GAAG,0CAA0C,CAAC;AAC5E,MAAM,iBAAiB,GAAG,2BAA2B,CAAC;AAgBtD,SAAS,iBAAiB,CACxB,WAAmB,EACnB,SAAiB,EACjB,QAAgB;IAEhB,OAAO,KAAK,UAAU,aAAa,CACjC,KAAwB,EACxB,IAAkB;QAElB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACvB,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,IAAI,IAAA,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AE,IAAI,EACjC,GAAG,IAAI,EACR,GAAG,OAAO,CAAC;QAEZ,MAAM,YAAY,GAAkB;YAClC,GAAG,IAAI;YACP,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,QAAQ;YACjB,cAAc;SACf,CAAC;QAEF,IAAI,QAAQ,IAAI,WAAW,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YACnD,YAAY,CAAC,KAAK,GAAG,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACnF,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,CAAC;QAEpB,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;IAClC,CAAC;CACF;AArDD,wBAqDC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOLVYN Google wrapper — thin drop-in over @google/generative-ai.
|
|
3
|
+
*/
|
|
4
|
+
import { GoogleGenerativeAI, ModelParams, RequestOptions } from '@google/generative-ai';
|
|
5
|
+
export interface TolvynGoogleOptions {
|
|
6
|
+
tolvynApiKey?: string;
|
|
7
|
+
proxyUrl?: string;
|
|
8
|
+
team?: string;
|
|
9
|
+
service?: string;
|
|
10
|
+
feature?: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
user?: string;
|
|
13
|
+
endCustomer?: string;
|
|
14
|
+
failOpen?: boolean;
|
|
15
|
+
googleApiKey?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class TolvynGoogle extends GoogleGenerativeAI {
|
|
18
|
+
readonly _tolvynFailOpen: boolean;
|
|
19
|
+
readonly _tolvynFallbackKey: string | undefined;
|
|
20
|
+
private readonly _tolvynProxyUrl;
|
|
21
|
+
private readonly _tolvynHeaders;
|
|
22
|
+
constructor(options?: TolvynGoogleOptions);
|
|
23
|
+
getGenerativeModel(modelParams: ModelParams, requestOptions?: RequestOptions): import("@google/generative-ai").GenerativeModel;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/google.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,cAAc,EACf,MAAM,uBAAuB,CAAC;AAM/B,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,YAAa,SAAQ,kBAAkB;IAClD,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAE5C,OAAO,GAAE,mBAAwB;IA8BpC,kBAAkB,CACzB,WAAW,EAAE,WAAW,EACxB,cAAc,CAAC,EAAE,cAAc;CASlC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TolvynGoogle = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TOLVYN Google wrapper — thin drop-in over @google/generative-ai.
|
|
6
|
+
*/
|
|
7
|
+
const generative_ai_1 = require("@google/generative-ai");
|
|
8
|
+
// The proxy base URL is prepended to Google API paths (/v1beta/models/...).
|
|
9
|
+
// The TOLVYN proxy strips /v1/proxy/google and forwards the remainder to Google.
|
|
10
|
+
const GOOGLE_DEFAULT_PROXY_URL = 'https://proxy.tolvyn.io/v1/proxy/google';
|
|
11
|
+
class TolvynGoogle extends generative_ai_1.GoogleGenerativeAI {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
const tolvynApiKey = options.tolvynApiKey ?? process.env['TOLVYN_API_KEY'];
|
|
14
|
+
if (!tolvynApiKey) {
|
|
15
|
+
throw new Error('tolvynApiKey required. Set TOLVYN_API_KEY env var or pass tolvynApiKey.');
|
|
16
|
+
}
|
|
17
|
+
// GoogleGenerativeAI sends this value as x-goog-api-key.
|
|
18
|
+
// The TOLVYN proxy's extractBearer reads x-goog-api-key as a fallback.
|
|
19
|
+
super(tolvynApiKey);
|
|
20
|
+
this._tolvynProxyUrl =
|
|
21
|
+
options.proxyUrl ??
|
|
22
|
+
process.env['TOLVYN_PROXY_URL'] ??
|
|
23
|
+
GOOGLE_DEFAULT_PROXY_URL;
|
|
24
|
+
this._tolvynHeaders = {};
|
|
25
|
+
if (options.team)
|
|
26
|
+
this._tolvynHeaders['X-Tolvyn-Team'] = options.team;
|
|
27
|
+
if (options.service)
|
|
28
|
+
this._tolvynHeaders['X-Tolvyn-Service'] = options.service;
|
|
29
|
+
if (options.feature)
|
|
30
|
+
this._tolvynHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
31
|
+
if (options.agent)
|
|
32
|
+
this._tolvynHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
33
|
+
if (options.user)
|
|
34
|
+
this._tolvynHeaders['X-Tolvyn-User'] = options.user;
|
|
35
|
+
if (options.endCustomer)
|
|
36
|
+
this._tolvynHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
37
|
+
this._tolvynFailOpen = options.failOpen ?? true;
|
|
38
|
+
this._tolvynFallbackKey =
|
|
39
|
+
options.googleApiKey ?? process.env['GOOGLE_API_KEY'];
|
|
40
|
+
}
|
|
41
|
+
getGenerativeModel(modelParams, requestOptions) {
|
|
42
|
+
const mergedOptions = {
|
|
43
|
+
baseUrl: this._tolvynProxyUrl,
|
|
44
|
+
customHeaders: this._tolvynHeaders,
|
|
45
|
+
...requestOptions,
|
|
46
|
+
};
|
|
47
|
+
return super.getGenerativeModel(modelParams, mergedOptions);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.TolvynGoogle = TolvynGoogle;
|
|
51
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/google.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAI+B;AAE/B,4EAA4E;AAC5E,iFAAiF;AACjF,MAAM,wBAAwB,GAAG,yCAAyC,CAAC;AAe3E,MAAa,YAAa,SAAQ,kCAAkB;IAMlD,YAAY,UAA+B,EAAE;QAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC3E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;QACJ,CAAC;QAED,yDAAyD;QACzD,uEAAuE;QACvE,KAAK,CAAC,YAAY,CAAC,CAAC;QAEpB,IAAI,CAAC,eAAe;YAClB,OAAO,CAAC,QAAQ;gBAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;gBAC/B,wBAAwB,CAAC;QAE3B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,IAAI;YAAS,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,GAAW,OAAO,CAAC,IAAI,CAAC;QACrF,IAAI,OAAO,CAAC,OAAO;YAAM,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,GAAQ,OAAO,CAAC,OAAO,CAAC;QACxF,IAAI,OAAO,CAAC,OAAO;YAAM,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,GAAQ,OAAO,CAAC,OAAO,CAAC;QACxF,IAAI,OAAO,CAAC,KAAK;YAAQ,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,GAAU,OAAO,CAAC,KAAK,CAAC;QACtF,IAAI,OAAO,CAAC,IAAI;YAAS,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,GAAW,OAAO,CAAC,IAAI,CAAC;QACrF,IAAI,OAAO,CAAC,WAAW;YAAE,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;QAE5F,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;QAChD,IAAI,CAAC,kBAAkB;YACrB,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAEQ,kBAAkB,CACzB,WAAwB,EACxB,cAA+B;QAE/B,MAAM,aAAa,GAAmB;YACpC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,aAAa,EAAE,IAAI,CAAC,cAAc;YAClC,GAAG,cAAc;SAClB,CAAC;QACF,OAAO,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC;CACF;AA/CD,oCA+CC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { OpenAI } from './client';
|
|
|
2
2
|
export type { TolvynOpenAIOptions } from './client';
|
|
3
3
|
export { Anthropic } from './anthropic';
|
|
4
4
|
export type { TolvynAnthropicOptions } from './anthropic';
|
|
5
|
+
export { TolvynGoogle as Google } from './google';
|
|
6
|
+
export type { TolvynGoogleOptions } from './google';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Anthropic = exports.OpenAI = void 0;
|
|
3
|
+
exports.Google = exports.Anthropic = exports.OpenAI = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "OpenAI", { enumerable: true, get: function () { return client_1.OpenAI; } });
|
|
6
6
|
var anthropic_1 = require("./anthropic");
|
|
7
7
|
Object.defineProperty(exports, "Anthropic", { enumerable: true, get: function () { return anthropic_1.Anthropic; } });
|
|
8
|
+
var google_1 = require("./google");
|
|
9
|
+
Object.defineProperty(exports, "Google", { enumerable: true, get: function () { return google_1.TolvynGoogle; } });
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAElB,mCAAkD;AAAzC,gGAAA,YAAY,OAAU"}
|
package/dist/esm/anthropic.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAa,EAAE,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMjE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,SAAU,SAAQ,aAAa;IAC1C,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE3C,OAAO,GAAE,sBAA2B;
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAa,EAAE,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMjE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,SAAU,SAAQ,aAAa;IAC1C,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE3C,OAAO,GAAE,sBAA2B;CA+CjD"}
|
package/dist/esm/anthropic.js
CHANGED
|
@@ -23,9 +23,13 @@ export class Anthropic extends AnthropicBase {
|
|
|
23
23
|
defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
24
24
|
if (options.agent)
|
|
25
25
|
defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
26
|
+
if (options.user)
|
|
27
|
+
defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
28
|
+
if (options.endCustomer)
|
|
29
|
+
defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
26
30
|
const fallbackKey = options.anthropicApiKey ?? process.env['ANTHROPIC_API_KEY'];
|
|
27
31
|
const failOpen = options.failOpen ?? true;
|
|
28
|
-
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, failOpen: _fo, anthropicApiKey: _aak, ...rest } = options;
|
|
32
|
+
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, user: _u, endCustomer: _ec, failOpen: _fo, anthropicApiKey: _aak, ...rest } = options;
|
|
29
33
|
const superOptions = {
|
|
30
34
|
...rest,
|
|
31
35
|
apiKey: tolvynApiKey,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAgC,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,2BAA2B,GAAG,6CAA6C,CAAC;AAClF,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAgC,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,2BAA2B,GAAG,6CAA6C,CAAC;AAClF,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAgBzD,MAAM,OAAO,SAAU,SAAQ,aAAa;IAI1C,YAAY,UAAkC,EAAE;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC3E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GACZ,OAAO,CAAC,QAAQ;YAChB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;YAC/B,2BAA2B,CAAC;QAE9B,MAAM,cAAc,GAA2B,EAAE,CAAC;QAClD,IAAI,OAAO,CAAC,IAAI;YAAS,cAAc,CAAC,eAAe,CAAC,GAAW,OAAO,CAAC,IAAI,CAAC;QAChF,IAAI,OAAO,CAAC,OAAO;YAAM,cAAc,CAAC,kBAAkB,CAAC,GAAQ,OAAO,CAAC,OAAO,CAAC;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CAAC;IACxC,CAAC;CACF"}
|
package/dist/esm/client.d.ts
CHANGED
package/dist/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,UAAU,EAAE,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAMnD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6CD,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAE5B,OAAO,GAAE,mBAAwB;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,UAAU,EAAE,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAMnD,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6CD,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAE5B,OAAO,GAAE,mBAAwB;CAgD9C"}
|
package/dist/esm/client.js
CHANGED
|
@@ -55,9 +55,13 @@ export class OpenAI extends OpenAIBase {
|
|
|
55
55
|
defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
56
56
|
if (options.agent)
|
|
57
57
|
defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
58
|
+
if (options.user)
|
|
59
|
+
defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
60
|
+
if (options.endCustomer)
|
|
61
|
+
defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
58
62
|
const fallbackKey = options.openAIApiKey ?? process.env['OPENAI_API_KEY'];
|
|
59
63
|
const failOpen = options.failOpen ?? true;
|
|
60
|
-
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, failOpen: _fo, openAIApiKey: _oak, ...rest } = options;
|
|
64
|
+
const { tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv, feature: _f, agent: _a, user: _u, endCustomer: _ec, failOpen: _fo, openAIApiKey: _oak, ...rest } = options;
|
|
61
65
|
const superOptions = {
|
|
62
66
|
...rest,
|
|
63
67
|
apiKey: tolvynApiKey,
|
package/dist/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OA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AC,CAAC;QACnF,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,CAAC;QAEpB,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOLVYN Google wrapper — thin drop-in over @google/generative-ai.
|
|
3
|
+
*/
|
|
4
|
+
import { GoogleGenerativeAI, ModelParams, RequestOptions } from '@google/generative-ai';
|
|
5
|
+
export interface TolvynGoogleOptions {
|
|
6
|
+
tolvynApiKey?: string;
|
|
7
|
+
proxyUrl?: string;
|
|
8
|
+
team?: string;
|
|
9
|
+
service?: string;
|
|
10
|
+
feature?: string;
|
|
11
|
+
agent?: string;
|
|
12
|
+
user?: string;
|
|
13
|
+
endCustomer?: string;
|
|
14
|
+
failOpen?: boolean;
|
|
15
|
+
googleApiKey?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class TolvynGoogle extends GoogleGenerativeAI {
|
|
18
|
+
readonly _tolvynFailOpen: boolean;
|
|
19
|
+
readonly _tolvynFallbackKey: string | undefined;
|
|
20
|
+
private readonly _tolvynProxyUrl;
|
|
21
|
+
private readonly _tolvynHeaders;
|
|
22
|
+
constructor(options?: TolvynGoogleOptions);
|
|
23
|
+
getGenerativeModel(modelParams: ModelParams, requestOptions?: RequestOptions): import("@google/generative-ai").GenerativeModel;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=google.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/google.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,cAAc,EACf,MAAM,uBAAuB,CAAC;AAM/B,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,YAAa,SAAQ,kBAAkB;IAClD,SAAgB,eAAe,EAAE,OAAO,CAAC;IACzC,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAE5C,OAAO,GAAE,mBAAwB;IA8BpC,kBAAkB,CACzB,WAAW,EAAE,WAAW,EACxB,cAAc,CAAC,EAAE,cAAc;CASlC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOLVYN Google wrapper — thin drop-in over @google/generative-ai.
|
|
3
|
+
*/
|
|
4
|
+
import { GoogleGenerativeAI, } from '@google/generative-ai';
|
|
5
|
+
// The proxy base URL is prepended to Google API paths (/v1beta/models/...).
|
|
6
|
+
// The TOLVYN proxy strips /v1/proxy/google and forwards the remainder to Google.
|
|
7
|
+
const GOOGLE_DEFAULT_PROXY_URL = 'https://proxy.tolvyn.io/v1/proxy/google';
|
|
8
|
+
export class TolvynGoogle extends GoogleGenerativeAI {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
const tolvynApiKey = options.tolvynApiKey ?? process.env['TOLVYN_API_KEY'];
|
|
11
|
+
if (!tolvynApiKey) {
|
|
12
|
+
throw new Error('tolvynApiKey required. Set TOLVYN_API_KEY env var or pass tolvynApiKey.');
|
|
13
|
+
}
|
|
14
|
+
// GoogleGenerativeAI sends this value as x-goog-api-key.
|
|
15
|
+
// The TOLVYN proxy's extractBearer reads x-goog-api-key as a fallback.
|
|
16
|
+
super(tolvynApiKey);
|
|
17
|
+
this._tolvynProxyUrl =
|
|
18
|
+
options.proxyUrl ??
|
|
19
|
+
process.env['TOLVYN_PROXY_URL'] ??
|
|
20
|
+
GOOGLE_DEFAULT_PROXY_URL;
|
|
21
|
+
this._tolvynHeaders = {};
|
|
22
|
+
if (options.team)
|
|
23
|
+
this._tolvynHeaders['X-Tolvyn-Team'] = options.team;
|
|
24
|
+
if (options.service)
|
|
25
|
+
this._tolvynHeaders['X-Tolvyn-Service'] = options.service;
|
|
26
|
+
if (options.feature)
|
|
27
|
+
this._tolvynHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
28
|
+
if (options.agent)
|
|
29
|
+
this._tolvynHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
30
|
+
if (options.user)
|
|
31
|
+
this._tolvynHeaders['X-Tolvyn-User'] = options.user;
|
|
32
|
+
if (options.endCustomer)
|
|
33
|
+
this._tolvynHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
34
|
+
this._tolvynFailOpen = options.failOpen ?? true;
|
|
35
|
+
this._tolvynFallbackKey =
|
|
36
|
+
options.googleApiKey ?? process.env['GOOGLE_API_KEY'];
|
|
37
|
+
}
|
|
38
|
+
getGenerativeModel(modelParams, requestOptions) {
|
|
39
|
+
const mergedOptions = {
|
|
40
|
+
baseUrl: this._tolvynProxyUrl,
|
|
41
|
+
customHeaders: this._tolvynHeaders,
|
|
42
|
+
...requestOptions,
|
|
43
|
+
};
|
|
44
|
+
return super.getGenerativeModel(modelParams, mergedOptions);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=google.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/google.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,k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I,CAAC,eAAe,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;QAChD,IAAI,CAAC,kBAAkB;YACrB,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC1D,CAAC;IAEQ,kBAAkB,CACzB,WAAwB,EACxB,cAA+B;QAE/B,MAAM,aAAa,GAAmB;YACpC,OAAO,EAAE,IAAI,CAAC,eAAe;YAC7B,aAAa,EAAE,IAAI,CAAC,cAAc;YAClC,GAAG,cAAc;SAClB,CAAC;QACF,OAAO,KAAK,CAAC,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { OpenAI } from './client';
|
|
|
2
2
|
export type { TolvynOpenAIOptions } from './client';
|
|
3
3
|
export { Anthropic } from './anthropic';
|
|
4
4
|
export type { TolvynAnthropicOptions } from './anthropic';
|
|
5
|
+
export { TolvynGoogle as Google } from './google';
|
|
6
|
+
export type { TolvynGoogleOptions } from './google';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tolvyn",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Drop-in replacement for the OpenAI/Anthropic SDK — routes through TOLVYN for cost attribution, budget enforcement, and audit logging.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/sdk": "^0.20.0",
|
|
26
|
+
"@google/generative-ai": "^0.21.0",
|
|
26
27
|
"openai": "^4.0.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
@@ -35,7 +36,9 @@
|
|
|
35
36
|
"jest": {
|
|
36
37
|
"preset": "ts-jest",
|
|
37
38
|
"testEnvironment": "node",
|
|
38
|
-
"testMatch": [
|
|
39
|
+
"testMatch": [
|
|
40
|
+
"**/tests/**/*.test.ts"
|
|
41
|
+
],
|
|
39
42
|
"globals": {
|
|
40
43
|
"ts-jest": {
|
|
41
44
|
"tsconfig": "tsconfig.cjs.json"
|
package/src/anthropic.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface TolvynAnthropicOptions
|
|
|
15
15
|
service?: string;
|
|
16
16
|
feature?: string;
|
|
17
17
|
agent?: string;
|
|
18
|
+
user?: string;
|
|
19
|
+
endCustomer?: string;
|
|
18
20
|
failOpen?: boolean;
|
|
19
21
|
anthropicApiKey?: string;
|
|
20
22
|
}
|
|
@@ -37,17 +39,20 @@ export class Anthropic extends AnthropicBase {
|
|
|
37
39
|
ANTHROPIC_DEFAULT_PROXY_URL;
|
|
38
40
|
|
|
39
41
|
const defaultHeaders: Record<string, string> = {};
|
|
40
|
-
if (options.team)
|
|
41
|
-
if (options.service)
|
|
42
|
-
if (options.feature)
|
|
43
|
-
if (options.agent)
|
|
42
|
+
if (options.team) defaultHeaders['X-Tolvyn-Team'] = options.team;
|
|
43
|
+
if (options.service) defaultHeaders['X-Tolvyn-Service'] = options.service;
|
|
44
|
+
if (options.feature) defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
45
|
+
if (options.agent) defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
46
|
+
if (options.user) defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
47
|
+
if (options.endCustomer) defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
44
48
|
|
|
45
49
|
const fallbackKey = options.anthropicApiKey ?? process.env['ANTHROPIC_API_KEY'];
|
|
46
50
|
const failOpen = options.failOpen ?? true;
|
|
47
51
|
|
|
48
52
|
const {
|
|
49
53
|
tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv,
|
|
50
|
-
feature: _f, agent: _a,
|
|
54
|
+
feature: _f, agent: _a, user: _u, endCustomer: _ec,
|
|
55
|
+
failOpen: _fo, anthropicApiKey: _aak,
|
|
51
56
|
...rest
|
|
52
57
|
} = options;
|
|
53
58
|
|
package/src/client.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface TolvynOpenAIOptions
|
|
|
15
15
|
service?: string;
|
|
16
16
|
feature?: string;
|
|
17
17
|
agent?: string;
|
|
18
|
+
user?: string;
|
|
19
|
+
endCustomer?: string;
|
|
18
20
|
failOpen?: boolean;
|
|
19
21
|
openAIApiKey?: string;
|
|
20
22
|
}
|
|
@@ -81,17 +83,20 @@ export class OpenAI extends OpenAIBase {
|
|
|
81
83
|
OPENAI_DEFAULT_PROXY_URL;
|
|
82
84
|
|
|
83
85
|
const defaultHeaders: Record<string, string> = {};
|
|
84
|
-
if (options.team)
|
|
85
|
-
if (options.service)
|
|
86
|
-
if (options.feature)
|
|
87
|
-
if (options.agent)
|
|
86
|
+
if (options.team) defaultHeaders['X-Tolvyn-Team'] = options.team;
|
|
87
|
+
if (options.service) defaultHeaders['X-Tolvyn-Service'] = options.service;
|
|
88
|
+
if (options.feature) defaultHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
89
|
+
if (options.agent) defaultHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
90
|
+
if (options.user) defaultHeaders['X-Tolvyn-User'] = options.user;
|
|
91
|
+
if (options.endCustomer) defaultHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
88
92
|
|
|
89
93
|
const fallbackKey = options.openAIApiKey ?? process.env['OPENAI_API_KEY'];
|
|
90
94
|
const failOpen = options.failOpen ?? true;
|
|
91
95
|
|
|
92
96
|
const {
|
|
93
97
|
tolvynApiKey: _tk, proxyUrl: _pu, team: _t, service: _sv,
|
|
94
|
-
feature: _f, agent: _a,
|
|
98
|
+
feature: _f, agent: _a, user: _u, endCustomer: _ec,
|
|
99
|
+
failOpen: _fo, openAIApiKey: _oak,
|
|
95
100
|
...rest
|
|
96
101
|
} = options;
|
|
97
102
|
|
package/src/google.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOLVYN Google wrapper — thin drop-in over @google/generative-ai.
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
GoogleGenerativeAI,
|
|
6
|
+
ModelParams,
|
|
7
|
+
RequestOptions,
|
|
8
|
+
} from '@google/generative-ai';
|
|
9
|
+
|
|
10
|
+
// The proxy base URL is prepended to Google API paths (/v1beta/models/...).
|
|
11
|
+
// The TOLVYN proxy strips /v1/proxy/google and forwards the remainder to Google.
|
|
12
|
+
const GOOGLE_DEFAULT_PROXY_URL = 'https://proxy.tolvyn.io/v1/proxy/google';
|
|
13
|
+
|
|
14
|
+
export interface TolvynGoogleOptions {
|
|
15
|
+
tolvynApiKey?: string;
|
|
16
|
+
proxyUrl?: string;
|
|
17
|
+
team?: string;
|
|
18
|
+
service?: string;
|
|
19
|
+
feature?: string;
|
|
20
|
+
agent?: string;
|
|
21
|
+
user?: string;
|
|
22
|
+
endCustomer?: string;
|
|
23
|
+
failOpen?: boolean;
|
|
24
|
+
googleApiKey?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class TolvynGoogle extends GoogleGenerativeAI {
|
|
28
|
+
public readonly _tolvynFailOpen: boolean;
|
|
29
|
+
public readonly _tolvynFallbackKey: string | undefined;
|
|
30
|
+
private readonly _tolvynProxyUrl: string;
|
|
31
|
+
private readonly _tolvynHeaders: Record<string, string>;
|
|
32
|
+
|
|
33
|
+
constructor(options: TolvynGoogleOptions = {}) {
|
|
34
|
+
const tolvynApiKey = options.tolvynApiKey ?? process.env['TOLVYN_API_KEY'];
|
|
35
|
+
if (!tolvynApiKey) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'tolvynApiKey required. Set TOLVYN_API_KEY env var or pass tolvynApiKey.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// GoogleGenerativeAI sends this value as x-goog-api-key.
|
|
42
|
+
// The TOLVYN proxy's extractBearer reads x-goog-api-key as a fallback.
|
|
43
|
+
super(tolvynApiKey);
|
|
44
|
+
|
|
45
|
+
this._tolvynProxyUrl =
|
|
46
|
+
options.proxyUrl ??
|
|
47
|
+
process.env['TOLVYN_PROXY_URL'] ??
|
|
48
|
+
GOOGLE_DEFAULT_PROXY_URL;
|
|
49
|
+
|
|
50
|
+
this._tolvynHeaders = {};
|
|
51
|
+
if (options.team) this._tolvynHeaders['X-Tolvyn-Team'] = options.team;
|
|
52
|
+
if (options.service) this._tolvynHeaders['X-Tolvyn-Service'] = options.service;
|
|
53
|
+
if (options.feature) this._tolvynHeaders['X-Tolvyn-Feature'] = options.feature;
|
|
54
|
+
if (options.agent) this._tolvynHeaders['X-Tolvyn-Agent'] = options.agent;
|
|
55
|
+
if (options.user) this._tolvynHeaders['X-Tolvyn-User'] = options.user;
|
|
56
|
+
if (options.endCustomer) this._tolvynHeaders['X-Tolvyn-End-Customer'] = options.endCustomer;
|
|
57
|
+
|
|
58
|
+
this._tolvynFailOpen = options.failOpen ?? true;
|
|
59
|
+
this._tolvynFallbackKey =
|
|
60
|
+
options.googleApiKey ?? process.env['GOOGLE_API_KEY'];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override getGenerativeModel(
|
|
64
|
+
modelParams: ModelParams,
|
|
65
|
+
requestOptions?: RequestOptions
|
|
66
|
+
) {
|
|
67
|
+
const mergedOptions: RequestOptions = {
|
|
68
|
+
baseUrl: this._tolvynProxyUrl,
|
|
69
|
+
customHeaders: this._tolvynHeaders,
|
|
70
|
+
...requestOptions,
|
|
71
|
+
};
|
|
72
|
+
return super.getGenerativeModel(modelParams, mergedOptions);
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { OpenAI } from './client';
|
|
|
2
2
|
export type { TolvynOpenAIOptions } from './client';
|
|
3
3
|
export { Anthropic } from './anthropic';
|
|
4
4
|
export type { TolvynAnthropicOptions } from './anthropic';
|
|
5
|
+
export { TolvynGoogle as Google } from './google';
|
|
6
|
+
export type { TolvynGoogleOptions } from './google';
|