@tessera-llm/mastra 0.1.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.
- package/LICENSE +201 -0
- package/README.md +174 -0
- package/dist/index.cjs +200 -0
- package/dist/index.d.cts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +153 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# `@tessera-llm/mastra`
|
|
2
|
+
|
|
3
|
+
**Drop-in cost optimization for the [Mastra](https://mastra.ai) agent framework.** One line of config routes every Mastra Agent's LLM calls through the [Tessera](https://tesseraai.io) optimization proxy — auto-route to cheaper-equivalent models, exact + provider-prompt-cache hits, prompt compression with per-stack quality canary, batch arbitrage on async-tolerant calls. Free Dev tier: **60M tokens/month, no card**. Production: **20% of measured savings, $0 if we save you nothing**.
|
|
4
|
+
|
|
5
|
+
<!-- COMPANION-PACKAGES-START -->
|
|
6
|
+
Companion to [`tessera-sdk`](https://github.com/tessera-llm/tessera-sdk) (vanilla provider SDKs), [`tessera-langchain`](https://github.com/tessera-llm/tessera-langchain) (LangChain integration), [`tessera-vercel-ai`](https://github.com/tessera-llm/tessera-vercel-ai) (Vercel AI SDK integration), [`tessera-llamaindex`](https://github.com/tessera-llm/tessera-llamaindex) (LlamaIndex integration), [`tessera-pydantic-ai`](https://github.com/tessera-llm/tessera-pydantic-ai) (Pydantic AI integration), [`tessera-crewai`](https://github.com/tessera-llm/tessera-crewai) (CrewAI multi-agent integration), and [`tessera-autogen`](https://github.com/tessera-llm/tessera-autogen) (AutoGen 0.4+ multi-agent integration). Same proxy, same mechanic stack, Mastra-shaped API.
|
|
7
|
+
<!-- COMPANION-PACKAGES-END -->
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/@tessera-llm/mastra) [](LICENSE)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What it looks like
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Agent } from "@mastra/core/agent";
|
|
17
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
18
|
+
import { tesseraOpenAIConfig } from "@tessera-llm/mastra";
|
|
19
|
+
|
|
20
|
+
const openai = createOpenAI({
|
|
21
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
22
|
+
...tesseraOpenAIConfig({ apiKey: process.env.TESSERA_API_KEY! }),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const supportAgent = new Agent({
|
|
26
|
+
name: "Support",
|
|
27
|
+
instructions: "Triage incoming support tickets in two sentences.",
|
|
28
|
+
model: openai("gpt-4o"),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Three changes in your code: one import, three lines in the constructor call. Every `agent.generate()` and `agent.stream()` call lands on the Tessera proxy with auto-route + auto-cache + auto-compress + auto-batch applied.
|
|
33
|
+
|
|
34
|
+
Or use the convenience factory (skips the explicit `createOpenAI` import):
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { Agent } from "@mastra/core/agent";
|
|
38
|
+
import { tesseraOpenAI } from "@tessera-llm/mastra";
|
|
39
|
+
|
|
40
|
+
const openai = await tesseraOpenAI({
|
|
41
|
+
openaiApiKey: process.env.OPENAI_API_KEY!,
|
|
42
|
+
tesseraApiKey: process.env.TESSERA_API_KEY!,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const supportAgent = new Agent({
|
|
46
|
+
name: "Support",
|
|
47
|
+
instructions: "Triage incoming support tickets in two sentences.",
|
|
48
|
+
model: openai("gpt-4o"),
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Mastra's [model router](https://mastra.ai/models) accepts AI SDK provider modules natively, so any provider returned by Tessera's factory works as a drop-in for the `model:` field on `new Agent({...})`.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install @tessera-llm/mastra @mastra/core
|
|
60
|
+
# Plus whichever provider package you use:
|
|
61
|
+
npm install @ai-sdk/openai # or @ai-sdk/anthropic / @ai-sdk/mistral / @ai-sdk/groq / @ai-sdk/cohere
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The `@ai-sdk/*` and `@mastra/core` packages are peer dependencies — install only the providers you actually use. The Mastra core SDK is whatever version you already have on the project.
|
|
65
|
+
|
|
66
|
+
Get a free Tessera API key (60M tokens/mo, no card) at **[tesseraai.io/dev](https://tesseraai.io/dev)** — sign-up takes ~30 seconds and returns an instant `tsr_…` key plus magic-link dashboard access.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Provider support
|
|
71
|
+
|
|
72
|
+
| Provider | @ai-sdk package | Tessera config function | Convenience factory |
|
|
73
|
+
|---|---|---|---|
|
|
74
|
+
| OpenAI | `@ai-sdk/openai` | `tesseraOpenAIConfig` | `tesseraOpenAI` |
|
|
75
|
+
| Anthropic | `@ai-sdk/anthropic` | `tesseraAnthropicConfig` | `tesseraAnthropic` |
|
|
76
|
+
| Mistral | `@ai-sdk/mistral` | `tesseraMistralConfig` | `tesseraMistral` |
|
|
77
|
+
| Groq | `@ai-sdk/groq` | `tesseraGroqConfig` | `tesseraGroq` |
|
|
78
|
+
| Cohere | `@ai-sdk/cohere` | `tesseraCohereConfig` | `tesseraCohere` |
|
|
79
|
+
|
|
80
|
+
Generic dispatcher available too: `tesseraConfig("openai", { apiKey: "tsr_..." })` — returns the right `{ baseURL, headers }` object regardless of provider. Useful when the provider is parameterized at runtime.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Worked example
|
|
85
|
+
|
|
86
|
+
Real customer-support agent on `gpt-4o`, 5B tokens/month, OpenAI list prices:
|
|
87
|
+
|
|
88
|
+
| Stage | Cost / mo | Saved |
|
|
89
|
+
|---|---:|---:|
|
|
90
|
+
| Baseline — OpenAI direct via Mastra | $24,000 | — |
|
|
91
|
+
| + Tessera (route, cache, prompt-cache headers, compress, M9 ceiling, batch) | $9,400 | $14,600 |
|
|
92
|
+
| Tessera fee (20% × savings) | $2,920 | — |
|
|
93
|
+
| **You net pay** | **$12,320** | **$11,680 / mo saved** |
|
|
94
|
+
|
|
95
|
+
Quality canary across the full mechanic stack: mean-score 0.96 (floor 0.95) — 0.95 SLA held all 30 days. Full breakdown: [`/blog/cut-openai-bill-38-percent-without-quality-regression`](https://tesseraai.io/blog/cut-openai-bill-38-percent-without-quality-regression).
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## What Tessera does on every Agent call
|
|
100
|
+
|
|
101
|
+
Same mechanic stack as the main [`tessera-sdk`](https://github.com/tessera-llm/tessera-sdk). Each mechanic is opt-in per workload, observable per request, and bypasses when its quality canary drops below the per-stack 0.95 floor.
|
|
102
|
+
|
|
103
|
+
| Mechanic | What it does | Typical savings |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| **Auto-route** <sub>(m1)</sub> | Route to a cheaper-equivalent model gated by a daily promptfoo canary on your eval set | 15–35% on routed calls |
|
|
106
|
+
| **Auto-cache** <sub>(m2)</sub> | sha256 cache on the canonical request body, 7-day TTL, Cloudflare edge KV | 5–40% depending on prompt repetition |
|
|
107
|
+
| **Auto-compress** <sub>(m3)</sub> | Per-role heuristic compression (system + user toggles independent). Preserves code fences and JSON shapes. | 5–15% on prompt tokens |
|
|
108
|
+
| **Prompt cache** <sub>(m6)</sub> | Inject provider-native cache headers — OpenAI cached-input (50% off), Anthropic `cache_control: ephemeral` (90% off cache reads) | 50–90% on cached prefixes |
|
|
109
|
+
| **Context prune** <sub>(m7)</sub> | Conservative trim on long conversations (system + last 8 turns; TF-IDF rerank on RAG attachments) | 5–25% on multi-turn workloads |
|
|
110
|
+
| **Output-length ceiling** <sub>(m9)</sub> | Daily compute fits p90 of completion length per workload, injects `maxTokens = p90 × 1.3` | 5–15% on completion cost |
|
|
111
|
+
| **Batch arbitrage** <sub>(m10)</sub> | Route async-tolerant Agent calls to provider Batch APIs (OpenAI Batch + Anthropic Message Batches both 50% off) | 50% on batch-eligible traffic |
|
|
112
|
+
| **Cross-provider failover** <sub>(m11)</sub> | When primary upstream returns 5xx / connection error / timeout, retry on OpenRouter (opt-in, default OFF) | Reliability primitive, n/a cost |
|
|
113
|
+
| **Per-provider circuit breaker** | Rolling 5xx-rate state machine per upstream — when a provider degrades, auto-route skips its intra-provider alternative mappings until the half-open probe succeeds. | n/a — keeps the savings stack honest |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Pricing
|
|
118
|
+
|
|
119
|
+
- **Free Dev** — 60M tokens/month, 30 requests/minute, all mechanics on, no card. Forever.
|
|
120
|
+
- **Production** — over 60M tokens/month or higher rate limit. **20% of measured savings only.** Zero savings, zero fee. Prepaid Stripe balance, $100 minimum top-up. No subscription, no commit, no minimum monthly.
|
|
121
|
+
|
|
122
|
+
Existing customers of `tessera-sdk`, `tessera-langchain`, `tessera-llamaindex`, or `tessera-vercel-ai` keep their `rate_locked_pct` (if any) on this package too — same `tsr_…` key, same billing record.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## FAQ
|
|
127
|
+
|
|
128
|
+
### Q: How is this different from the other tessera-* packages?
|
|
129
|
+
|
|
130
|
+
Same proxy. Same mechanics. Same billing. The five packages target different code surfaces:
|
|
131
|
+
|
|
132
|
+
- **`tessera-sdk`** — patches the underlying provider client constructors (OpenAI, Anthropic, etc.) directly via `tessera.activate(key)`. Use when calling provider SDKs without a framework.
|
|
133
|
+
- **`tessera-langchain`** — wires into LangChain ChatModel constructors. Use when you're on LangChain.
|
|
134
|
+
- **`tessera-llamaindex`** — wires into LlamaIndex `LLM` adapter constructors. Use when you're on LlamaIndex.
|
|
135
|
+
- **`tessera-vercel-ai`** — wires into the Vercel AI SDK provider factories. Use when you're on `ai` core + `@ai-sdk/*` without Mastra.
|
|
136
|
+
- **`tessera-mastra`** *(this package)* — same Vercel AI SDK provider factory shape, Mastra-shaped README and E2E gate. Use when you're on Mastra Agents.
|
|
137
|
+
|
|
138
|
+
Pick whichever fits your codebase. Side-by-side install is supported — all five resolve to the same proxy and same billing record.
|
|
139
|
+
|
|
140
|
+
### Q: Does this break my Agent tools / structured outputs / streaming / RAG?
|
|
141
|
+
|
|
142
|
+
No. The Vercel AI SDK provider object that Mastra accepts is unchanged in shape — `agent.generate()`, `agent.stream()`, `generateObject`, schema-constrained tool calls, and RAG retrieval workflows all work unchanged. Auto-route gates on tool-calling capability so an agent using tools never gets routed to a non-tool-capable model.
|
|
143
|
+
|
|
144
|
+
### Q: Does this work with Mastra's string-shorthand model ID (`"openai/gpt-4o"`)?
|
|
145
|
+
|
|
146
|
+
Not directly. Mastra's string shorthand uses environment variables like `OPENAI_API_KEY` against the provider's canonical endpoint. Tessera needs a custom `baseURL` + custom `x-tessera-api-key` header, which the string shorthand doesn't surface. Use the AI SDK provider factory form (shown in the examples above) — Mastra accepts it as a first-class alternative to the string shorthand.
|
|
147
|
+
|
|
148
|
+
### Q: What happens if Tessera's proxy is down?
|
|
149
|
+
|
|
150
|
+
Your Agent gets HTTP errors instead of LLM responses. On the proxy side, a per-provider circuit breaker tracks rolling 5xx rates and skips degraded providers in auto-route decisions. Cross-provider failover (m11) is opt-in and re-routes to OpenRouter when the primary upstream is down — see the workload toggle in the dashboard.
|
|
151
|
+
|
|
152
|
+
### Q: What happens to my OpenAI / Anthropic rate limits?
|
|
153
|
+
|
|
154
|
+
They pass through. Tessera does not aggregate quotas across customers. Your provider rate limits apply normally; the proxy enforces only the Tessera tier limits (30 rpm Free Dev, 60 rpm Production by default — higher on request).
|
|
155
|
+
|
|
156
|
+
### Q: Are you storing my prompts and completions?
|
|
157
|
+
|
|
158
|
+
No. We log only token counts, cost deltas, mechanics_stack, and provider response status. Prompts and completions are never persisted. Full data handling on [`tesseraai.io/security`](https://tesseraai.io/security).
|
|
159
|
+
|
|
160
|
+
### Q: Why are there two API surfaces (`tesseraOpenAIConfig` vs `tesseraOpenAI`)?
|
|
161
|
+
|
|
162
|
+
The config function returns the kwargs object you spread into `createOpenAI(...)` — explicit, easy to combine with other settings (organization, custom fetch, etc.). The convenience factory imports `createOpenAI` for you and pre-merges. Use whichever you find more readable. Both ship in the same package.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Links
|
|
167
|
+
|
|
168
|
+
- **Dashboard + free signup:** [tesseraai.io/dev](https://tesseraai.io/dev)
|
|
169
|
+
- **How it works (per-mechanic deep dives):** [tesseraai.io/how-it-works](https://tesseraai.io/how-it-works)
|
|
170
|
+
- **Security + data handling:** [tesseraai.io/security](https://tesseraai.io/security)
|
|
171
|
+
- **Worked-numbers blog post:** [tesseraai.io/blog/cut-openai-bill-38-percent-without-quality-regression](https://tesseraai.io/blog/cut-openai-bill-38-percent-without-quality-regression)
|
|
172
|
+
- **Mastra docs:** [mastra.ai](https://mastra.ai)
|
|
173
|
+
|
|
174
|
+
Apache-2.0. Built by [Tessera (Fintechagency OÜ)](https://tesseraai.io). Issues: [github.com/tessera-llm/tessera-mastra/issues](https://github.com/tessera-llm/tessera-mastra/issues).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
TESSERA_BASE_URL: () => TESSERA_BASE_URL,
|
|
34
|
+
VERSION: () => VERSION,
|
|
35
|
+
tesseraAnthropic: () => tesseraAnthropic,
|
|
36
|
+
tesseraAnthropicConfig: () => tesseraAnthropicConfig,
|
|
37
|
+
tesseraCohere: () => tesseraCohere,
|
|
38
|
+
tesseraCohereConfig: () => tesseraCohereConfig,
|
|
39
|
+
tesseraConfig: () => tesseraConfig,
|
|
40
|
+
tesseraGroq: () => tesseraGroq,
|
|
41
|
+
tesseraGroqConfig: () => tesseraGroqConfig,
|
|
42
|
+
tesseraMistral: () => tesseraMistral,
|
|
43
|
+
tesseraMistralConfig: () => tesseraMistralConfig,
|
|
44
|
+
tesseraOpenAI: () => tesseraOpenAI,
|
|
45
|
+
tesseraOpenAIConfig: () => tesseraOpenAIConfig
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
48
|
+
var TESSERA_BASE_URL = "https://api.tesseraai.io";
|
|
49
|
+
var VERSION = "0.1.0";
|
|
50
|
+
function validateApiKey(apiKey) {
|
|
51
|
+
if (typeof apiKey !== "string" || apiKey.length === 0) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"tessera*Config({ apiKey }) requires a non-empty string. Get a free key from https://tesseraai.io/dev"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return apiKey;
|
|
57
|
+
}
|
|
58
|
+
function proxyEndpoint(provider) {
|
|
59
|
+
return `${TESSERA_BASE_URL}/v1/${provider}`;
|
|
60
|
+
}
|
|
61
|
+
function buildHeaders(apiKey, extra) {
|
|
62
|
+
return { ...extra ?? {}, "x-tessera-api-key": apiKey };
|
|
63
|
+
}
|
|
64
|
+
function tesseraOpenAIConfig(input) {
|
|
65
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
66
|
+
return {
|
|
67
|
+
baseURL: input.baseUrl ?? proxyEndpoint("openai"),
|
|
68
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function tesseraAnthropicConfig(input) {
|
|
72
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
73
|
+
return {
|
|
74
|
+
baseURL: input.baseUrl ?? proxyEndpoint("anthropic"),
|
|
75
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function tesseraMistralConfig(input) {
|
|
79
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
80
|
+
return {
|
|
81
|
+
baseURL: input.baseUrl ?? proxyEndpoint("mistral"),
|
|
82
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function tesseraGroqConfig(input) {
|
|
86
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
87
|
+
return {
|
|
88
|
+
baseURL: input.baseUrl ?? proxyEndpoint("groq"),
|
|
89
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function tesseraCohereConfig(input) {
|
|
93
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
94
|
+
return {
|
|
95
|
+
baseURL: input.baseUrl ?? proxyEndpoint("cohere"),
|
|
96
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function tesseraConfig(provider, input) {
|
|
100
|
+
switch (provider) {
|
|
101
|
+
case "openai":
|
|
102
|
+
return tesseraOpenAIConfig(input);
|
|
103
|
+
case "anthropic":
|
|
104
|
+
return tesseraAnthropicConfig(input);
|
|
105
|
+
case "mistral":
|
|
106
|
+
return tesseraMistralConfig(input);
|
|
107
|
+
case "groq":
|
|
108
|
+
return tesseraGroqConfig(input);
|
|
109
|
+
case "cohere":
|
|
110
|
+
return tesseraCohereConfig(input);
|
|
111
|
+
default: {
|
|
112
|
+
const _exhaustive = provider;
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Unknown provider ${_exhaustive}. Supported: openai, anthropic, mistral, groq, cohere`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function tesseraOpenAI(input) {
|
|
120
|
+
const { createOpenAI } = await import("@ai-sdk/openai");
|
|
121
|
+
const cfg = tesseraOpenAIConfig({
|
|
122
|
+
apiKey: input.tesseraApiKey,
|
|
123
|
+
extraHeaders: input.extraHeaders,
|
|
124
|
+
baseUrl: input.baseUrl
|
|
125
|
+
});
|
|
126
|
+
return createOpenAI({
|
|
127
|
+
apiKey: input.openaiApiKey,
|
|
128
|
+
baseURL: cfg.baseURL,
|
|
129
|
+
headers: cfg.headers,
|
|
130
|
+
...input.organization ? { organization: input.organization } : {}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async function tesseraAnthropic(input) {
|
|
134
|
+
const { createAnthropic } = await import("@ai-sdk/anthropic");
|
|
135
|
+
const cfg = tesseraAnthropicConfig({
|
|
136
|
+
apiKey: input.tesseraApiKey,
|
|
137
|
+
extraHeaders: input.extraHeaders,
|
|
138
|
+
baseUrl: input.baseUrl
|
|
139
|
+
});
|
|
140
|
+
return createAnthropic({
|
|
141
|
+
apiKey: input.anthropicApiKey,
|
|
142
|
+
baseURL: cfg.baseURL,
|
|
143
|
+
headers: cfg.headers
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async function tesseraMistral(input) {
|
|
147
|
+
const { createMistral } = await import("@ai-sdk/mistral");
|
|
148
|
+
const cfg = tesseraMistralConfig({
|
|
149
|
+
apiKey: input.tesseraApiKey,
|
|
150
|
+
extraHeaders: input.extraHeaders,
|
|
151
|
+
baseUrl: input.baseUrl
|
|
152
|
+
});
|
|
153
|
+
return createMistral({
|
|
154
|
+
apiKey: input.mistralApiKey,
|
|
155
|
+
baseURL: cfg.baseURL,
|
|
156
|
+
headers: cfg.headers
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
async function tesseraGroq(input) {
|
|
160
|
+
const { createGroq } = await import("@ai-sdk/groq");
|
|
161
|
+
const cfg = tesseraGroqConfig({
|
|
162
|
+
apiKey: input.tesseraApiKey,
|
|
163
|
+
extraHeaders: input.extraHeaders,
|
|
164
|
+
baseUrl: input.baseUrl
|
|
165
|
+
});
|
|
166
|
+
return createGroq({
|
|
167
|
+
apiKey: input.groqApiKey,
|
|
168
|
+
baseURL: cfg.baseURL,
|
|
169
|
+
headers: cfg.headers
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async function tesseraCohere(input) {
|
|
173
|
+
const { createCohere } = await import("@ai-sdk/cohere");
|
|
174
|
+
const cfg = tesseraCohereConfig({
|
|
175
|
+
apiKey: input.tesseraApiKey,
|
|
176
|
+
extraHeaders: input.extraHeaders,
|
|
177
|
+
baseUrl: input.baseUrl
|
|
178
|
+
});
|
|
179
|
+
return createCohere({
|
|
180
|
+
apiKey: input.cohereApiKey,
|
|
181
|
+
baseURL: cfg.baseURL,
|
|
182
|
+
headers: cfg.headers
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
186
|
+
0 && (module.exports = {
|
|
187
|
+
TESSERA_BASE_URL,
|
|
188
|
+
VERSION,
|
|
189
|
+
tesseraAnthropic,
|
|
190
|
+
tesseraAnthropicConfig,
|
|
191
|
+
tesseraCohere,
|
|
192
|
+
tesseraCohereConfig,
|
|
193
|
+
tesseraConfig,
|
|
194
|
+
tesseraGroq,
|
|
195
|
+
tesseraGroqConfig,
|
|
196
|
+
tesseraMistral,
|
|
197
|
+
tesseraMistralConfig,
|
|
198
|
+
tesseraOpenAI,
|
|
199
|
+
tesseraOpenAIConfig
|
|
200
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tessera-llm/mastra — drop-in cost optimization for the Mastra agent
|
|
3
|
+
* framework (https://mastra.ai).
|
|
4
|
+
*
|
|
5
|
+
* Mastra accepts AI SDK provider modules directly via `new Agent({ model:
|
|
6
|
+
* openai("gpt-4o") })`. This package returns the same shape `@ai-sdk/*`
|
|
7
|
+
* `createX` factories return — Tessera's proxy URL pre-merged + the
|
|
8
|
+
* `x-tessera-api-key` header injected — so any Mastra Agent calling
|
|
9
|
+
* generateText / streamText / generateObject lands on Tessera's auto-route
|
|
10
|
+
* + auto-cache + auto-compress + auto-batch substrate proxy.
|
|
11
|
+
*
|
|
12
|
+
* Two API surfaces:
|
|
13
|
+
*
|
|
14
|
+
* 1. tesseraOpenAIConfig / tesseraAnthropicConfig / tesseraMistralConfig /
|
|
15
|
+
* tesseraGroqConfig / tesseraCohereConfig — returns the constructor
|
|
16
|
+
* options object for the corresponding @ai-sdk/* provider factory.
|
|
17
|
+
* Pass-through pattern. Recommended for codepaths already calling
|
|
18
|
+
* createOpenAI / createAnthropic / etc. directly.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* import { Agent } from "@mastra/core/agent";
|
|
22
|
+
* import { createOpenAI } from "@ai-sdk/openai";
|
|
23
|
+
* import { tesseraOpenAIConfig } from "@tessera-llm/mastra";
|
|
24
|
+
*
|
|
25
|
+
* const openai = createOpenAI({
|
|
26
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
27
|
+
* ...tesseraOpenAIConfig({ apiKey: process.env.TESSERA_API_KEY! }),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* export const agent = new Agent({
|
|
31
|
+
* name: "Helper",
|
|
32
|
+
* instructions: "You are a helpful assistant.",
|
|
33
|
+
* model: openai("gpt-4o"),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* 2. tesseraOpenAI / tesseraAnthropic / tesseraMistral / tesseraGroq /
|
|
37
|
+
* tesseraCohere — convenience factories that internally call the
|
|
38
|
+
* corresponding @ai-sdk/* createX factory with Tessera config merged
|
|
39
|
+
* in. Returns the provider function (modelId) => model — pass directly
|
|
40
|
+
* to a Mastra Agent.
|
|
41
|
+
*
|
|
42
|
+
* Example:
|
|
43
|
+
* import { Agent } from "@mastra/core/agent";
|
|
44
|
+
* import { tesseraOpenAI } from "@tessera-llm/mastra";
|
|
45
|
+
*
|
|
46
|
+
* const openai = await tesseraOpenAI({
|
|
47
|
+
* openaiApiKey: process.env.OPENAI_API_KEY!,
|
|
48
|
+
* tesseraApiKey: process.env.TESSERA_API_KEY!,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* export const agent = new Agent({
|
|
52
|
+
* name: "Helper",
|
|
53
|
+
* instructions: "You are a helpful assistant.",
|
|
54
|
+
* model: openai("gpt-4o"),
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* The convenience factories dynamically import @ai-sdk/* so peer-dependent
|
|
58
|
+
* imports never blow up when the corresponding provider package is not
|
|
59
|
+
* installed. Install only the @ai-sdk/* packages you actually use.
|
|
60
|
+
*
|
|
61
|
+
* See https://tesseraai.io/dev for the dashboard, free tier, and full
|
|
62
|
+
* mechanic documentation.
|
|
63
|
+
*/
|
|
64
|
+
declare const TESSERA_BASE_URL = "https://api.tesseraai.io";
|
|
65
|
+
declare const VERSION = "0.1.0";
|
|
66
|
+
type ProviderName = "openai" | "anthropic" | "mistral" | "groq" | "cohere";
|
|
67
|
+
interface TesseraConfigInput {
|
|
68
|
+
apiKey: string;
|
|
69
|
+
extraHeaders?: Record<string, string>;
|
|
70
|
+
baseUrl?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The shape every @ai-sdk/* `createX` factory accepts (minus apiKey, which
|
|
74
|
+
* the caller already supplies). Tessera config returns exactly this shape.
|
|
75
|
+
* Mastra accepts AI SDK provider modules constructed from these options
|
|
76
|
+
* via `new Agent({ model: provider("model-id") })`.
|
|
77
|
+
*/
|
|
78
|
+
interface AiSdkProviderInit {
|
|
79
|
+
baseURL: string;
|
|
80
|
+
headers: Record<string, string>;
|
|
81
|
+
}
|
|
82
|
+
declare function tesseraOpenAIConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
83
|
+
declare function tesseraAnthropicConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
84
|
+
declare function tesseraMistralConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
85
|
+
declare function tesseraGroqConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
86
|
+
declare function tesseraCohereConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
87
|
+
/**
|
|
88
|
+
* Generic dispatcher — returns the right init for the given provider.
|
|
89
|
+
*/
|
|
90
|
+
declare function tesseraConfig(provider: ProviderName, input: TesseraConfigInput): AiSdkProviderInit;
|
|
91
|
+
interface TesseraOpenAIFactoryInput {
|
|
92
|
+
/** Your OpenAI API key (sk-...). Stays in your env, forwarded upstream. */
|
|
93
|
+
openaiApiKey: string;
|
|
94
|
+
/** Your Tessera API key (tsr_...). Get one at tesseraai.io/dev. */
|
|
95
|
+
tesseraApiKey: string;
|
|
96
|
+
/** Additional headers to merge with the Tessera auth header. */
|
|
97
|
+
extraHeaders?: Record<string, string>;
|
|
98
|
+
/** Override the upstream proxy URL (defaults to api.tesseraai.io/v1/openai). */
|
|
99
|
+
baseUrl?: string;
|
|
100
|
+
/** OpenAI organization id, passed through to @ai-sdk/openai. */
|
|
101
|
+
organization?: string;
|
|
102
|
+
}
|
|
103
|
+
declare function tesseraOpenAI(input: TesseraOpenAIFactoryInput): Promise<unknown>;
|
|
104
|
+
interface TesseraAnthropicFactoryInput {
|
|
105
|
+
anthropicApiKey: string;
|
|
106
|
+
tesseraApiKey: string;
|
|
107
|
+
extraHeaders?: Record<string, string>;
|
|
108
|
+
baseUrl?: string;
|
|
109
|
+
}
|
|
110
|
+
declare function tesseraAnthropic(input: TesseraAnthropicFactoryInput): Promise<unknown>;
|
|
111
|
+
interface TesseraMistralFactoryInput {
|
|
112
|
+
mistralApiKey: string;
|
|
113
|
+
tesseraApiKey: string;
|
|
114
|
+
extraHeaders?: Record<string, string>;
|
|
115
|
+
baseUrl?: string;
|
|
116
|
+
}
|
|
117
|
+
declare function tesseraMistral(input: TesseraMistralFactoryInput): Promise<unknown>;
|
|
118
|
+
interface TesseraGroqFactoryInput {
|
|
119
|
+
groqApiKey: string;
|
|
120
|
+
tesseraApiKey: string;
|
|
121
|
+
extraHeaders?: Record<string, string>;
|
|
122
|
+
baseUrl?: string;
|
|
123
|
+
}
|
|
124
|
+
declare function tesseraGroq(input: TesseraGroqFactoryInput): Promise<unknown>;
|
|
125
|
+
interface TesseraCohereFactoryInput {
|
|
126
|
+
cohereApiKey: string;
|
|
127
|
+
tesseraApiKey: string;
|
|
128
|
+
extraHeaders?: Record<string, string>;
|
|
129
|
+
baseUrl?: string;
|
|
130
|
+
}
|
|
131
|
+
declare function tesseraCohere(input: TesseraCohereFactoryInput): Promise<unknown>;
|
|
132
|
+
|
|
133
|
+
export { type AiSdkProviderInit, type ProviderName, TESSERA_BASE_URL, type TesseraAnthropicFactoryInput, type TesseraCohereFactoryInput, type TesseraConfigInput, type TesseraGroqFactoryInput, type TesseraMistralFactoryInput, type TesseraOpenAIFactoryInput, VERSION, tesseraAnthropic, tesseraAnthropicConfig, tesseraCohere, tesseraCohereConfig, tesseraConfig, tesseraGroq, tesseraGroqConfig, tesseraMistral, tesseraMistralConfig, tesseraOpenAI, tesseraOpenAIConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tessera-llm/mastra — drop-in cost optimization for the Mastra agent
|
|
3
|
+
* framework (https://mastra.ai).
|
|
4
|
+
*
|
|
5
|
+
* Mastra accepts AI SDK provider modules directly via `new Agent({ model:
|
|
6
|
+
* openai("gpt-4o") })`. This package returns the same shape `@ai-sdk/*`
|
|
7
|
+
* `createX` factories return — Tessera's proxy URL pre-merged + the
|
|
8
|
+
* `x-tessera-api-key` header injected — so any Mastra Agent calling
|
|
9
|
+
* generateText / streamText / generateObject lands on Tessera's auto-route
|
|
10
|
+
* + auto-cache + auto-compress + auto-batch substrate proxy.
|
|
11
|
+
*
|
|
12
|
+
* Two API surfaces:
|
|
13
|
+
*
|
|
14
|
+
* 1. tesseraOpenAIConfig / tesseraAnthropicConfig / tesseraMistralConfig /
|
|
15
|
+
* tesseraGroqConfig / tesseraCohereConfig — returns the constructor
|
|
16
|
+
* options object for the corresponding @ai-sdk/* provider factory.
|
|
17
|
+
* Pass-through pattern. Recommended for codepaths already calling
|
|
18
|
+
* createOpenAI / createAnthropic / etc. directly.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* import { Agent } from "@mastra/core/agent";
|
|
22
|
+
* import { createOpenAI } from "@ai-sdk/openai";
|
|
23
|
+
* import { tesseraOpenAIConfig } from "@tessera-llm/mastra";
|
|
24
|
+
*
|
|
25
|
+
* const openai = createOpenAI({
|
|
26
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
27
|
+
* ...tesseraOpenAIConfig({ apiKey: process.env.TESSERA_API_KEY! }),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* export const agent = new Agent({
|
|
31
|
+
* name: "Helper",
|
|
32
|
+
* instructions: "You are a helpful assistant.",
|
|
33
|
+
* model: openai("gpt-4o"),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* 2. tesseraOpenAI / tesseraAnthropic / tesseraMistral / tesseraGroq /
|
|
37
|
+
* tesseraCohere — convenience factories that internally call the
|
|
38
|
+
* corresponding @ai-sdk/* createX factory with Tessera config merged
|
|
39
|
+
* in. Returns the provider function (modelId) => model — pass directly
|
|
40
|
+
* to a Mastra Agent.
|
|
41
|
+
*
|
|
42
|
+
* Example:
|
|
43
|
+
* import { Agent } from "@mastra/core/agent";
|
|
44
|
+
* import { tesseraOpenAI } from "@tessera-llm/mastra";
|
|
45
|
+
*
|
|
46
|
+
* const openai = await tesseraOpenAI({
|
|
47
|
+
* openaiApiKey: process.env.OPENAI_API_KEY!,
|
|
48
|
+
* tesseraApiKey: process.env.TESSERA_API_KEY!,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* export const agent = new Agent({
|
|
52
|
+
* name: "Helper",
|
|
53
|
+
* instructions: "You are a helpful assistant.",
|
|
54
|
+
* model: openai("gpt-4o"),
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* The convenience factories dynamically import @ai-sdk/* so peer-dependent
|
|
58
|
+
* imports never blow up when the corresponding provider package is not
|
|
59
|
+
* installed. Install only the @ai-sdk/* packages you actually use.
|
|
60
|
+
*
|
|
61
|
+
* See https://tesseraai.io/dev for the dashboard, free tier, and full
|
|
62
|
+
* mechanic documentation.
|
|
63
|
+
*/
|
|
64
|
+
declare const TESSERA_BASE_URL = "https://api.tesseraai.io";
|
|
65
|
+
declare const VERSION = "0.1.0";
|
|
66
|
+
type ProviderName = "openai" | "anthropic" | "mistral" | "groq" | "cohere";
|
|
67
|
+
interface TesseraConfigInput {
|
|
68
|
+
apiKey: string;
|
|
69
|
+
extraHeaders?: Record<string, string>;
|
|
70
|
+
baseUrl?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The shape every @ai-sdk/* `createX` factory accepts (minus apiKey, which
|
|
74
|
+
* the caller already supplies). Tessera config returns exactly this shape.
|
|
75
|
+
* Mastra accepts AI SDK provider modules constructed from these options
|
|
76
|
+
* via `new Agent({ model: provider("model-id") })`.
|
|
77
|
+
*/
|
|
78
|
+
interface AiSdkProviderInit {
|
|
79
|
+
baseURL: string;
|
|
80
|
+
headers: Record<string, string>;
|
|
81
|
+
}
|
|
82
|
+
declare function tesseraOpenAIConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
83
|
+
declare function tesseraAnthropicConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
84
|
+
declare function tesseraMistralConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
85
|
+
declare function tesseraGroqConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
86
|
+
declare function tesseraCohereConfig(input: TesseraConfigInput): AiSdkProviderInit;
|
|
87
|
+
/**
|
|
88
|
+
* Generic dispatcher — returns the right init for the given provider.
|
|
89
|
+
*/
|
|
90
|
+
declare function tesseraConfig(provider: ProviderName, input: TesseraConfigInput): AiSdkProviderInit;
|
|
91
|
+
interface TesseraOpenAIFactoryInput {
|
|
92
|
+
/** Your OpenAI API key (sk-...). Stays in your env, forwarded upstream. */
|
|
93
|
+
openaiApiKey: string;
|
|
94
|
+
/** Your Tessera API key (tsr_...). Get one at tesseraai.io/dev. */
|
|
95
|
+
tesseraApiKey: string;
|
|
96
|
+
/** Additional headers to merge with the Tessera auth header. */
|
|
97
|
+
extraHeaders?: Record<string, string>;
|
|
98
|
+
/** Override the upstream proxy URL (defaults to api.tesseraai.io/v1/openai). */
|
|
99
|
+
baseUrl?: string;
|
|
100
|
+
/** OpenAI organization id, passed through to @ai-sdk/openai. */
|
|
101
|
+
organization?: string;
|
|
102
|
+
}
|
|
103
|
+
declare function tesseraOpenAI(input: TesseraOpenAIFactoryInput): Promise<unknown>;
|
|
104
|
+
interface TesseraAnthropicFactoryInput {
|
|
105
|
+
anthropicApiKey: string;
|
|
106
|
+
tesseraApiKey: string;
|
|
107
|
+
extraHeaders?: Record<string, string>;
|
|
108
|
+
baseUrl?: string;
|
|
109
|
+
}
|
|
110
|
+
declare function tesseraAnthropic(input: TesseraAnthropicFactoryInput): Promise<unknown>;
|
|
111
|
+
interface TesseraMistralFactoryInput {
|
|
112
|
+
mistralApiKey: string;
|
|
113
|
+
tesseraApiKey: string;
|
|
114
|
+
extraHeaders?: Record<string, string>;
|
|
115
|
+
baseUrl?: string;
|
|
116
|
+
}
|
|
117
|
+
declare function tesseraMistral(input: TesseraMistralFactoryInput): Promise<unknown>;
|
|
118
|
+
interface TesseraGroqFactoryInput {
|
|
119
|
+
groqApiKey: string;
|
|
120
|
+
tesseraApiKey: string;
|
|
121
|
+
extraHeaders?: Record<string, string>;
|
|
122
|
+
baseUrl?: string;
|
|
123
|
+
}
|
|
124
|
+
declare function tesseraGroq(input: TesseraGroqFactoryInput): Promise<unknown>;
|
|
125
|
+
interface TesseraCohereFactoryInput {
|
|
126
|
+
cohereApiKey: string;
|
|
127
|
+
tesseraApiKey: string;
|
|
128
|
+
extraHeaders?: Record<string, string>;
|
|
129
|
+
baseUrl?: string;
|
|
130
|
+
}
|
|
131
|
+
declare function tesseraCohere(input: TesseraCohereFactoryInput): Promise<unknown>;
|
|
132
|
+
|
|
133
|
+
export { type AiSdkProviderInit, type ProviderName, TESSERA_BASE_URL, type TesseraAnthropicFactoryInput, type TesseraCohereFactoryInput, type TesseraConfigInput, type TesseraGroqFactoryInput, type TesseraMistralFactoryInput, type TesseraOpenAIFactoryInput, VERSION, tesseraAnthropic, tesseraAnthropicConfig, tesseraCohere, tesseraCohereConfig, tesseraConfig, tesseraGroq, tesseraGroqConfig, tesseraMistral, tesseraMistralConfig, tesseraOpenAI, tesseraOpenAIConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var TESSERA_BASE_URL = "https://api.tesseraai.io";
|
|
3
|
+
var VERSION = "0.1.0";
|
|
4
|
+
function validateApiKey(apiKey) {
|
|
5
|
+
if (typeof apiKey !== "string" || apiKey.length === 0) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"tessera*Config({ apiKey }) requires a non-empty string. Get a free key from https://tesseraai.io/dev"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return apiKey;
|
|
11
|
+
}
|
|
12
|
+
function proxyEndpoint(provider) {
|
|
13
|
+
return `${TESSERA_BASE_URL}/v1/${provider}`;
|
|
14
|
+
}
|
|
15
|
+
function buildHeaders(apiKey, extra) {
|
|
16
|
+
return { ...extra ?? {}, "x-tessera-api-key": apiKey };
|
|
17
|
+
}
|
|
18
|
+
function tesseraOpenAIConfig(input) {
|
|
19
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
20
|
+
return {
|
|
21
|
+
baseURL: input.baseUrl ?? proxyEndpoint("openai"),
|
|
22
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function tesseraAnthropicConfig(input) {
|
|
26
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
27
|
+
return {
|
|
28
|
+
baseURL: input.baseUrl ?? proxyEndpoint("anthropic"),
|
|
29
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function tesseraMistralConfig(input) {
|
|
33
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
34
|
+
return {
|
|
35
|
+
baseURL: input.baseUrl ?? proxyEndpoint("mistral"),
|
|
36
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function tesseraGroqConfig(input) {
|
|
40
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
41
|
+
return {
|
|
42
|
+
baseURL: input.baseUrl ?? proxyEndpoint("groq"),
|
|
43
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function tesseraCohereConfig(input) {
|
|
47
|
+
const apiKey = validateApiKey(input.apiKey);
|
|
48
|
+
return {
|
|
49
|
+
baseURL: input.baseUrl ?? proxyEndpoint("cohere"),
|
|
50
|
+
headers: buildHeaders(apiKey, input.extraHeaders)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function tesseraConfig(provider, input) {
|
|
54
|
+
switch (provider) {
|
|
55
|
+
case "openai":
|
|
56
|
+
return tesseraOpenAIConfig(input);
|
|
57
|
+
case "anthropic":
|
|
58
|
+
return tesseraAnthropicConfig(input);
|
|
59
|
+
case "mistral":
|
|
60
|
+
return tesseraMistralConfig(input);
|
|
61
|
+
case "groq":
|
|
62
|
+
return tesseraGroqConfig(input);
|
|
63
|
+
case "cohere":
|
|
64
|
+
return tesseraCohereConfig(input);
|
|
65
|
+
default: {
|
|
66
|
+
const _exhaustive = provider;
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Unknown provider ${_exhaustive}. Supported: openai, anthropic, mistral, groq, cohere`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function tesseraOpenAI(input) {
|
|
74
|
+
const { createOpenAI } = await import("@ai-sdk/openai");
|
|
75
|
+
const cfg = tesseraOpenAIConfig({
|
|
76
|
+
apiKey: input.tesseraApiKey,
|
|
77
|
+
extraHeaders: input.extraHeaders,
|
|
78
|
+
baseUrl: input.baseUrl
|
|
79
|
+
});
|
|
80
|
+
return createOpenAI({
|
|
81
|
+
apiKey: input.openaiApiKey,
|
|
82
|
+
baseURL: cfg.baseURL,
|
|
83
|
+
headers: cfg.headers,
|
|
84
|
+
...input.organization ? { organization: input.organization } : {}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function tesseraAnthropic(input) {
|
|
88
|
+
const { createAnthropic } = await import("@ai-sdk/anthropic");
|
|
89
|
+
const cfg = tesseraAnthropicConfig({
|
|
90
|
+
apiKey: input.tesseraApiKey,
|
|
91
|
+
extraHeaders: input.extraHeaders,
|
|
92
|
+
baseUrl: input.baseUrl
|
|
93
|
+
});
|
|
94
|
+
return createAnthropic({
|
|
95
|
+
apiKey: input.anthropicApiKey,
|
|
96
|
+
baseURL: cfg.baseURL,
|
|
97
|
+
headers: cfg.headers
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async function tesseraMistral(input) {
|
|
101
|
+
const { createMistral } = await import("@ai-sdk/mistral");
|
|
102
|
+
const cfg = tesseraMistralConfig({
|
|
103
|
+
apiKey: input.tesseraApiKey,
|
|
104
|
+
extraHeaders: input.extraHeaders,
|
|
105
|
+
baseUrl: input.baseUrl
|
|
106
|
+
});
|
|
107
|
+
return createMistral({
|
|
108
|
+
apiKey: input.mistralApiKey,
|
|
109
|
+
baseURL: cfg.baseURL,
|
|
110
|
+
headers: cfg.headers
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function tesseraGroq(input) {
|
|
114
|
+
const { createGroq } = await import("@ai-sdk/groq");
|
|
115
|
+
const cfg = tesseraGroqConfig({
|
|
116
|
+
apiKey: input.tesseraApiKey,
|
|
117
|
+
extraHeaders: input.extraHeaders,
|
|
118
|
+
baseUrl: input.baseUrl
|
|
119
|
+
});
|
|
120
|
+
return createGroq({
|
|
121
|
+
apiKey: input.groqApiKey,
|
|
122
|
+
baseURL: cfg.baseURL,
|
|
123
|
+
headers: cfg.headers
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async function tesseraCohere(input) {
|
|
127
|
+
const { createCohere } = await import("@ai-sdk/cohere");
|
|
128
|
+
const cfg = tesseraCohereConfig({
|
|
129
|
+
apiKey: input.tesseraApiKey,
|
|
130
|
+
extraHeaders: input.extraHeaders,
|
|
131
|
+
baseUrl: input.baseUrl
|
|
132
|
+
});
|
|
133
|
+
return createCohere({
|
|
134
|
+
apiKey: input.cohereApiKey,
|
|
135
|
+
baseURL: cfg.baseURL,
|
|
136
|
+
headers: cfg.headers
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
TESSERA_BASE_URL,
|
|
141
|
+
VERSION,
|
|
142
|
+
tesseraAnthropic,
|
|
143
|
+
tesseraAnthropicConfig,
|
|
144
|
+
tesseraCohere,
|
|
145
|
+
tesseraCohereConfig,
|
|
146
|
+
tesseraConfig,
|
|
147
|
+
tesseraGroq,
|
|
148
|
+
tesseraGroqConfig,
|
|
149
|
+
tesseraMistral,
|
|
150
|
+
tesseraMistralConfig,
|
|
151
|
+
tesseraOpenAI,
|
|
152
|
+
tesseraOpenAIConfig
|
|
153
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tessera-llm/mastra",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drop-in Tessera integration for the Mastra agent framework. One line of config routes every Mastra Agent's LLM calls through Tessera's auto-route + auto-cache + auto-compress + auto-batch proxy. Compatible with @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/mistral, @ai-sdk/groq, @ai-sdk/cohere — Mastra's first-class AI SDK provider interop. Free 60M tokens/mo. Production: 20% of measured savings.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tessera",
|
|
7
|
+
"mastra",
|
|
8
|
+
"mastra-ai",
|
|
9
|
+
"ai-agent",
|
|
10
|
+
"agent-framework",
|
|
11
|
+
"llm",
|
|
12
|
+
"openai",
|
|
13
|
+
"anthropic",
|
|
14
|
+
"mistral",
|
|
15
|
+
"groq",
|
|
16
|
+
"cohere",
|
|
17
|
+
"cost-optimization",
|
|
18
|
+
"ai-cost",
|
|
19
|
+
"llm-cost",
|
|
20
|
+
"llm-proxy",
|
|
21
|
+
"gpt-4o",
|
|
22
|
+
"claude",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://tesseraai.io/dev",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/tessera-llm/tessera-mastra.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/tessera-llm/tessera-mastra/issues"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"author": "Tessera (Fintechagency OÜ) <contact@tesseraai.io>",
|
|
35
|
+
"type": "module",
|
|
36
|
+
"main": "./dist/index.cjs",
|
|
37
|
+
"module": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"import": "./dist/index.js",
|
|
43
|
+
"require": "./dist/index.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --target node18",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"prepublishOnly": "npm run build && npm test"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"@ai-sdk/anthropic": "*",
|
|
62
|
+
"@ai-sdk/cohere": "*",
|
|
63
|
+
"@ai-sdk/groq": "*",
|
|
64
|
+
"@ai-sdk/mistral": "*",
|
|
65
|
+
"@ai-sdk/openai": "*",
|
|
66
|
+
"@mastra/core": "*"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"@ai-sdk/anthropic": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"@ai-sdk/cohere": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"@ai-sdk/groq": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@ai-sdk/mistral": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@ai-sdk/openai": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"@mastra/core": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"@ai-sdk/anthropic": "^3.0.78",
|
|
90
|
+
"@ai-sdk/cohere": "^3.0.36",
|
|
91
|
+
"@ai-sdk/groq": "^3.0.39",
|
|
92
|
+
"@ai-sdk/mistral": "^3.0.37",
|
|
93
|
+
"@ai-sdk/openai": "^3.0.64",
|
|
94
|
+
"@types/node": "^22.0.0",
|
|
95
|
+
"tsup": "^8.3.0",
|
|
96
|
+
"typescript": "^5.7.0",
|
|
97
|
+
"vitest": "^2.1.0"
|
|
98
|
+
},
|
|
99
|
+
"publishConfig": {
|
|
100
|
+
"access": "public"
|
|
101
|
+
}
|
|
102
|
+
}
|