@agentrouter/agentrouter 0.1.7
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 +241 -0
- package/dist/cli-core.d.ts +13 -0
- package/dist/cli-core.d.ts.map +1 -0
- package/dist/cli-core.js +563 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +6 -0
- package/dist/index.d.ts +357 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +549 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# AgentRouter SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the AgentRouter.
|
|
4
|
+
|
|
5
|
+
AgentRouter is capability-first. You discover domains and capabilities, inspect
|
|
6
|
+
routes and contracts, ask for a recommendation, and then execute explicitly
|
|
7
|
+
through one client.
|
|
8
|
+
|
|
9
|
+
- Package: `@agentrouter/agentrouter`
|
|
10
|
+
- Docs: `https://docs.agentrouter.to/integrations/sdk`
|
|
11
|
+
- Base URL: `https://api.agentrouter.to/api/agentic-api`
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @agentrouter/agentrouter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Get an API Key
|
|
20
|
+
|
|
21
|
+
Hosted AgentRouter requests require an API key.
|
|
22
|
+
|
|
23
|
+
1. Open `https://www.agentrouter.to/agentic-api/install`
|
|
24
|
+
2. Sign in and copy your API key
|
|
25
|
+
3. Export it in your shell
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
export AGENTIC_API_KEY=your_key_here
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For local development against a local AgentRouter server, you can also use
|
|
32
|
+
`userId` instead of an API key.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { AgentRouterClient } from "@agentrouter/agentrouter";
|
|
38
|
+
|
|
39
|
+
const client = new AgentRouterClient({
|
|
40
|
+
apiKey: process.env.AGENTIC_API_KEY,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const domains = await client.catalog.domains.list();
|
|
44
|
+
const capabilities = await client.catalog.capabilities.list("email");
|
|
45
|
+
|
|
46
|
+
const recommendation = await client.capabilities.recommend({
|
|
47
|
+
domain: "email",
|
|
48
|
+
capability: "send",
|
|
49
|
+
input: {
|
|
50
|
+
optimizationPreferences: ["cost", "quality"],
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const result = await client.capabilities.execute({
|
|
55
|
+
domain: "email",
|
|
56
|
+
capability: "send",
|
|
57
|
+
input: {
|
|
58
|
+
to: "maya@example.com",
|
|
59
|
+
subject: "Hello from AgentRouter",
|
|
60
|
+
html: "<p>Hello</p>",
|
|
61
|
+
},
|
|
62
|
+
provider: recommendation.recommendedProvider,
|
|
63
|
+
allowFallback: true,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## CLI
|
|
68
|
+
|
|
69
|
+
The package also ships a thin CLI wrapper over the same SDK semantics.
|
|
70
|
+
|
|
71
|
+
Create an API key at `https://www.agentrouter.to/agentic-api/install` and
|
|
72
|
+
export it before hosted CLI requests:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
export AGENTIC_API_KEY=your_key_here
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Install locally:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install @agentrouter/agentrouter
|
|
82
|
+
npx agentrouter domains list
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Or run it without adding the package to your app:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx -p @agentrouter/agentrouter agentrouter domains list
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Examples:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
agentrouter wallet
|
|
95
|
+
agentrouter capabilities list email
|
|
96
|
+
agentrouter routes context email.send.resend
|
|
97
|
+
agentrouter recommend email send --input '{"optimizationPreferences":["cost"]}'
|
|
98
|
+
agentrouter execute email send --input @send-email.json --route-key email.send.resend --allow-fallback
|
|
99
|
+
agentrouter route enrichment --input '{"intent":"Find the work email for the VP Engineering at Example Corp"}'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Environment variables:
|
|
103
|
+
|
|
104
|
+
- `AGENTIC_API_BASE_URL`
|
|
105
|
+
- `AGENTIC_API_KEY`
|
|
106
|
+
- `AGENTIC_API_SESSION_TOKEN`
|
|
107
|
+
- `AGENTIC_API_USER_ID`
|
|
108
|
+
- `AGENTIC_API_TIMEOUT_MS`
|
|
109
|
+
|
|
110
|
+
## Recommended Flow
|
|
111
|
+
|
|
112
|
+
1. List domains with `client.catalog.domains.list()`
|
|
113
|
+
2. List capabilities with `client.catalog.capabilities.list(domainKey)`
|
|
114
|
+
3. Inspect routes or contracts for a capability
|
|
115
|
+
4. Ask for a recommendation
|
|
116
|
+
5. Execute explicitly
|
|
117
|
+
|
|
118
|
+
This keeps your integration stable even when providers or routes change.
|
|
119
|
+
|
|
120
|
+
## Catalog Discovery
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const domain = await client.catalog.domains.get("enrichment");
|
|
124
|
+
|
|
125
|
+
const capability = await client.catalog.capabilities.get("email", "send");
|
|
126
|
+
|
|
127
|
+
const routes = await client.catalog.capabilities.routes("email", "send");
|
|
128
|
+
|
|
129
|
+
const contract = await client.catalog.capabilities.contract("email", "send");
|
|
130
|
+
|
|
131
|
+
const routeContext = await client.catalog.routes.context("email.send.resend");
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Capability contracts describe the common input shape for a workflow. Route
|
|
135
|
+
contexts describe the executable surface for one selected route, including
|
|
136
|
+
route-specific fields and possible provider/wrapper values. Read each possible
|
|
137
|
+
value's label and description to map natural language to the exact value.
|
|
138
|
+
|
|
139
|
+
When you want one concrete route, execute through the capability endpoint and
|
|
140
|
+
pass `routeKey`; the SDK sends it in the request body.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const result = await client.capabilities.execute({
|
|
144
|
+
domain: "travel",
|
|
145
|
+
capability: "flight-search",
|
|
146
|
+
routeKey: "travel.flight.search.stabletravel.googleflights.agentcash",
|
|
147
|
+
input: {
|
|
148
|
+
departure_id: "JFK",
|
|
149
|
+
arrival_id: "LAX",
|
|
150
|
+
outbound_date: "2026-05-01",
|
|
151
|
+
type: "2",
|
|
152
|
+
travel_class: "1",
|
|
153
|
+
adults: 1,
|
|
154
|
+
},
|
|
155
|
+
allowFallback: false,
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Domain Helpers
|
|
160
|
+
|
|
161
|
+
The generic capability methods are the main contract. The SDK also includes
|
|
162
|
+
helper namespaces where they improve ergonomics:
|
|
163
|
+
|
|
164
|
+
- `client.email`
|
|
165
|
+
- `client.enrichment`
|
|
166
|
+
- `client.social`
|
|
167
|
+
|
|
168
|
+
Example:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const routed = await client.enrichment.route({
|
|
172
|
+
intent: "Find the work email for the VP Engineering at Example Corp",
|
|
173
|
+
companyName: "Example Corp",
|
|
174
|
+
title: "VP Engineering",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const contact = await client.enrichment.contactEnrich.execute(
|
|
178
|
+
{
|
|
179
|
+
linkedinUrl: "https://www.linkedin.com/in/example",
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
allowFallback: true,
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Auth
|
|
188
|
+
|
|
189
|
+
Hosted usage:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const client = new AgentRouterClient({
|
|
193
|
+
apiKey: process.env.AGENTIC_API_KEY,
|
|
194
|
+
baseUrl: "https://api.agentrouter.to/api/agentic-api",
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Local development also supports user-scoped fallback against local AgentRouter
|
|
199
|
+
servers:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
const wallet = await client.wallet.get({
|
|
203
|
+
userId: "agentrouter-sdk-smoke-user",
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Security Note
|
|
208
|
+
|
|
209
|
+
Do not expose `AGENTIC_API_KEY` in browser client code. Use this SDK from
|
|
210
|
+
server-side environments such as:
|
|
211
|
+
|
|
212
|
+
- Node.js services
|
|
213
|
+
- Next.js server routes and server actions
|
|
214
|
+
- CLI tools
|
|
215
|
+
- agent runtimes
|
|
216
|
+
|
|
217
|
+
## API Surface
|
|
218
|
+
|
|
219
|
+
Top-level modules:
|
|
220
|
+
|
|
221
|
+
- `client.catalog`
|
|
222
|
+
- `client.capabilities`
|
|
223
|
+
- `client.wallet`
|
|
224
|
+
- `client.usage`
|
|
225
|
+
- `client.auth`
|
|
226
|
+
- `client.raw`
|
|
227
|
+
|
|
228
|
+
## Notes
|
|
229
|
+
|
|
230
|
+
- Canonical capability IDs come from the catalog.
|
|
231
|
+
- For email inbox acquisition, the canonical capability ID is `inbox-acquire`.
|
|
232
|
+
- The backend may still accept legacy aliases such as `inbox-buy`, but the SDK
|
|
233
|
+
normalizes to canonical capability IDs.
|
|
234
|
+
- Recommend, route, and execute responses preserve the raw backend payload on
|
|
235
|
+
`raw`.
|
|
236
|
+
|
|
237
|
+
## Resources
|
|
238
|
+
|
|
239
|
+
- SDK docs: `https://docs.agentrouter.to/integrations/sdk`
|
|
240
|
+
- Install flow: `https://www.agentrouter.to/agentic-api/install`
|
|
241
|
+
- skill.md: `https://www.agentrouter.to/SKILL.md`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type AgenticApiFetchLike } from "./index.js";
|
|
2
|
+
type CliEnv = Record<string, string | undefined>;
|
|
3
|
+
type CliIo = {
|
|
4
|
+
env?: CliEnv;
|
|
5
|
+
stdout?: (value: string) => void;
|
|
6
|
+
stderr?: (value: string) => void;
|
|
7
|
+
readFile?: (path: string) => Promise<string>;
|
|
8
|
+
fetch?: AgenticApiFetchLike;
|
|
9
|
+
};
|
|
10
|
+
export declare function runAgentRouterCli(argv: string[], io?: CliIo): Promise<number>;
|
|
11
|
+
export declare const runAgenticCli: typeof runAgentRouterCli;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=cli-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-core.d.ts","sourceRoot":"","sources":["../src/cli-core.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,mBAAmB,EAGzB,MAAM,YAAY,CAAC;AAEpB,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEjD,KAAK,KAAK,GAAG;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,KAAK,CAAC,EAAE,mBAAmB,CAAC;CAC7B,CAAC;AA+sBF,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,GAAE,KAAU,GACb,OAAO,CAAC,MAAM,CAAC,CAqGjB;AAED,eAAO,MAAM,aAAa,0BAAoB,CAAC"}
|