@ralioco/sdk 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 +21 -0
- package/README.md +160 -0
- package/dist/index.cjs +635 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +604 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ralio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Ralio TypeScript SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ralioco/sdk)
|
|
4
|
+
[](https://github.com/Ralioco/ralio-node/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
The official TypeScript client for the [Ralio](https://ralio.co) agentic payment API.
|
|
8
|
+
|
|
9
|
+
It handles the machine-authentication path end to end — OAuth 2.1
|
|
10
|
+
`client_credentials` with `private_key_jwt` and DPoP-bound access tokens — so
|
|
11
|
+
your integration can talk to an agent without hand-rolling JWT signing, proof
|
|
12
|
+
generation, or token refresh.
|
|
13
|
+
|
|
14
|
+
> **Scope.** This SDK targets autonomous integrations (CI jobs, agent hosts,
|
|
15
|
+
> server-side callers). It authenticates as a **credential binding**, which can
|
|
16
|
+
> hold the `agents:execute` and `transactions:read` scopes. Agent and binding
|
|
17
|
+
> management (`agents:config`) is a human-only operation in the console and is
|
|
18
|
+
> intentionally not part of this SDK.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @ralioco/sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Node.js 20.19+, 22.13+, or 24+ (matches our toolchain's
|
|
27
|
+
`engines.node` floor). The SDK is ESM-first and ships CommonJS too; types are
|
|
28
|
+
bundled.
|
|
29
|
+
|
|
30
|
+
## Authentication model
|
|
31
|
+
|
|
32
|
+
Ralio's machine path has no shared secrets. Each credential is a P-256 private
|
|
33
|
+
key that lives on exactly one host:
|
|
34
|
+
|
|
35
|
+
1. The **owner** mints a one-time registration ticket in the console
|
|
36
|
+
(**Settings → Credentials → New credential**), choosing the target agent and
|
|
37
|
+
a scope ceiling. They send you the `ralio-reg-…` ticket.
|
|
38
|
+
2. You call `register(...)` on the agent host. It generates a keypair locally,
|
|
39
|
+
submits the public key, and waits until the owner approves the binding in the
|
|
40
|
+
console. You get back a `clientId` (`cb_…`).
|
|
41
|
+
3. From then on, `RalioClient` mints and refreshes DPoP-bound access tokens
|
|
42
|
+
transparently and signs a fresh proof for every request.
|
|
43
|
+
|
|
44
|
+
See the [API authentication guide](https://docs.ralio.co/api-reference/authentication)
|
|
45
|
+
for the protocol details.
|
|
46
|
+
|
|
47
|
+
## Register once
|
|
48
|
+
|
|
49
|
+
Run this on the host where the integration will live, after the owner sends you
|
|
50
|
+
a ticket:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { register } from "@ralioco/sdk";
|
|
54
|
+
|
|
55
|
+
const binding = await register({
|
|
56
|
+
ticket: "ralio-reg-...",
|
|
57
|
+
privateKeyPath: "ralio-key.pem", // generated and written here
|
|
58
|
+
requestedScopes: ["agents:execute", "transactions:read"],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
console.log(binding.clientId); // cb_... — store this alongside the key
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`register()` resolves once the owner approves (or rejects with a
|
|
65
|
+
`RalioRegistrationError` if the binding is rejected / expires / times out). The
|
|
66
|
+
private key never leaves the host.
|
|
67
|
+
|
|
68
|
+
## Use the client
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { RalioClient } from "@ralioco/sdk";
|
|
72
|
+
|
|
73
|
+
const client = await RalioClient.create({
|
|
74
|
+
clientId: "cb_...",
|
|
75
|
+
privateKeyPath: "ralio-key.pem",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// One-shot chat
|
|
79
|
+
const reply = await client.chat.send({
|
|
80
|
+
agentId: "d4e5...",
|
|
81
|
+
message: "What is my current balance?",
|
|
82
|
+
});
|
|
83
|
+
console.log(reply.reply);
|
|
84
|
+
|
|
85
|
+
// Streaming chat (server-sent events)
|
|
86
|
+
for await (const event of client.chat.stream({
|
|
87
|
+
agentId: "d4e5...",
|
|
88
|
+
message: "List my recent payments",
|
|
89
|
+
})) {
|
|
90
|
+
if (event.event === "text_delta") {
|
|
91
|
+
process.stdout.write(event.text);
|
|
92
|
+
} else if (event.event === "tool_started") {
|
|
93
|
+
console.log(`\n[tool] ${event.data.tool_name}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Transactions
|
|
98
|
+
const txns = await client.transactions.list({ limit: 20 });
|
|
99
|
+
for (const txn of txns) {
|
|
100
|
+
console.log(txn.date, txn.amount, txn.currency, txn.creditor, txn.status);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`RalioClient` also implements `Symbol.dispose`, so under `using` it is released
|
|
105
|
+
automatically:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
using client = await RalioClient.create({ clientId: "cb_...", privateKeyPath: "ralio-key.pem" });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Payments
|
|
112
|
+
|
|
113
|
+
There is no `payments.create()` method by design. Payments are executed by the
|
|
114
|
+
**agent**, not by direct REST calls: drive the agent with `chat.send` /
|
|
115
|
+
`chat.stream` ("Pay £500 to Bob for the April invoice") and it will create the
|
|
116
|
+
payment, subject to its spend limits and approval rules. Use
|
|
117
|
+
`transactions.list` to read what the agent did.
|
|
118
|
+
|
|
119
|
+
## Errors
|
|
120
|
+
|
|
121
|
+
All errors subclass `RalioError`:
|
|
122
|
+
|
|
123
|
+
| Class | When |
|
|
124
|
+
| ---------------------------- | --------------------------------------------------------------- |
|
|
125
|
+
| `RalioAuthError` (401) | Missing/invalid token, failed assertion, or rejected DPoP proof |
|
|
126
|
+
| `RalioPermissionError` (403) | Token lacks the required scope, or resource not owned |
|
|
127
|
+
| `RalioNotFoundError` (404) | Resource doesn't exist |
|
|
128
|
+
| `RalioValidationError` (422) | Invalid field values or business-rule violation |
|
|
129
|
+
| `RalioRateLimitError` (429) | Rate limited — back off and retry |
|
|
130
|
+
| `RalioAPIError` | Any other HTTP error (carries `statusCode`, `detail`) |
|
|
131
|
+
| `RalioRegistrationError` | Registration rejected, expired, or timed out |
|
|
132
|
+
| `RalioConfigError` | Local configuration problem |
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { RalioPermissionError } from "@ralioco/sdk";
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await client.chat.send({ agentId: "...", message: "..." });
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err instanceof RalioPermissionError) {
|
|
141
|
+
console.error("scope problem:", err.detail);
|
|
142
|
+
} else {
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npm install
|
|
152
|
+
npm run lint
|
|
153
|
+
npm run typecheck
|
|
154
|
+
npm test
|
|
155
|
+
npm run build
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT — see [LICENSE](LICENSE).
|