@naturali/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/README.md +90 -0
- package/dist/index.cjs +1796 -0
- package/dist/index.d.cts +5706 -0
- package/dist/index.d.mts +5706 -0
- package/dist/index.mjs +1780 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @naturali/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [naturali.ai](https://naturali.ai) API, generated from
|
|
4
|
+
its [OpenAPI specs](../../api/openapi/).
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @naturali/sdk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { NaturaliClient } from '@naturali/sdk';
|
|
14
|
+
|
|
15
|
+
const naturali = new NaturaliClient({
|
|
16
|
+
baseUrl: 'https://api.naturali.ai',
|
|
17
|
+
token: process.env.NATURALI_TOKEN, // nat_sk_… or a session access JWT
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { data, error } = await naturali.agents.listAgents({
|
|
21
|
+
path: { project_id: 'proj_V1StGXR8Z5jdHi6B' },
|
|
22
|
+
query: { limit: 10 },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (error) {
|
|
26
|
+
// The platform's error envelope, typed: { error: { code, message, details } }
|
|
27
|
+
console.error(error);
|
|
28
|
+
} else {
|
|
29
|
+
console.log(data.data);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A method never throws on a non-2xx response — it resolves to `{ data, error }`,
|
|
34
|
+
so the machine-readable `code` (`approval_required`, `budget_exceeded`,
|
|
35
|
+
`access_denied`, …) is available as typed data.
|
|
36
|
+
|
|
37
|
+
## Options
|
|
38
|
+
|
|
39
|
+
| Option | Purpose |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `baseUrl` | API **origin** — operation paths already carry `/v1`, so pass `https://api.naturali.ai`, not `…/v1`. Defaults to `''` (same origin), which is what a browser app wants. |
|
|
42
|
+
| `token` | Sent as `Authorization: Bearer …`. Accepts a `nat_sk_…` API key or a session access JWT. |
|
|
43
|
+
| `headers` | Merged last, so it can override the header above or add your own. |
|
|
44
|
+
|
|
45
|
+
There is no `project` option: a project-scoped operation takes `project_id` in
|
|
46
|
+
its path, and that is the only thing the API authorizes against.
|
|
47
|
+
|
|
48
|
+
## Call shape
|
|
49
|
+
|
|
50
|
+
Each resource property mirrors a generated service class, with the configured
|
|
51
|
+
HTTP client already bound. Arguments follow the spec's own structure and
|
|
52
|
+
**snake_case** field names:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
await naturali.sessions.addSessionMessage({
|
|
56
|
+
path: { project_id, agent_id, session_id },
|
|
57
|
+
body: { message: 'What is the capital of France?' },
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await naturali.knowledge.queryKnowledgeCollection({
|
|
61
|
+
path: { project_id, collection_id },
|
|
62
|
+
body: { query: 'refund policy', limit: 5 },
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Resources: `agents`, `apiKeys`, `auth`, `channels`, `contacts`, `generations`,
|
|
67
|
+
`knowledge`, `models`, `projects`, `providers`, `sessions`, `tools`, `traces`.
|
|
68
|
+
|
|
69
|
+
`naturali.http` exposes the underlying client for interceptors or a one-off
|
|
70
|
+
request (`naturali.http.get({ url: '/health' })`).
|
|
71
|
+
|
|
72
|
+
## Types
|
|
73
|
+
|
|
74
|
+
Every schema in the specs is exported as a type:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import type { Agent, AgentCreate, ErrorResponse } from '@naturali/sdk';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`created_at` / `updated_at` are handed to callers as `Date` objects; everything
|
|
81
|
+
else matches the wire shape exactly.
|
|
82
|
+
|
|
83
|
+
## Generation
|
|
84
|
+
|
|
85
|
+
`src/generated/` is build output — never edit it, and never commit it. It is
|
|
86
|
+
rebuilt from `api/openapi/v1/*.yaml` by `pnpm generate`, which `typecheck`,
|
|
87
|
+
`test` and `build` all run first. See [`../README.md`](../README.md) for the
|
|
88
|
+
pipeline.
|
|
89
|
+
|
|
90
|
+
The only hand-written source is `src/naturaliClient.ts`.
|