@caitlyn-ai/sdk-core 0.0.2 → 0.1.1
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 +39 -7
- package/dist-cjs/index.cjs +309 -173
- package/dist-cjs/index.cjs.map +3 -3
- package/dist-es/index.mjs +302 -168
- package/dist-es/index.mjs.map +3 -3
- package/dist-types/index.d.ts +3169 -12
- package/package.json +1 -2
- package/dist-types/auth.d.ts +0 -140
- package/dist-types/aws.d.ts +0 -43
- package/dist-types/client.d.ts +0 -62
- package/dist-types/endpoint.d.ts +0 -4
- package/dist-types/plugin.d.ts +0 -21
- package/dist-types/protocol.d.ts +0 -24
- package/dist-types/retry.d.ts +0 -11
- package/dist-types/sse.d.ts +0 -6
- package/dist-types/stream.d.ts +0 -34
- package/dist-types/telemetry.d.ts +0 -3
- package/dist-types/upload.d.ts +0 -12
- package/dist-types/waiter.d.ts +0 -30
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ before it expires, one request at a time however many calls are waiting.
|
|
|
22
22
|
```ts
|
|
23
23
|
import { Caitlyn } from '@caitlyn-ai/sdk';
|
|
24
24
|
|
|
25
|
-
// A script using a personal access token
|
|
25
|
+
// A script using a personal access token (it starts cait-pat-)
|
|
26
26
|
const caitlyn = new Caitlyn({ workspace: 'your-company.getcaitlyn.ai', auth: { mode: 'token', token: process.env.CAITLYN_TOKEN! } });
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ const caitlyn = new Caitlyn({ workspace: 'your-company.getcaitlyn.ai', auth: { m
|
|
|
36
36
|
| `session` | The Caitlyn app itself, or a tool driving a local app with a session cookie | `cookie` (server side only), `origin` |
|
|
37
37
|
|
|
38
38
|
The workspace works as a region does in the AWS SDKs: it decides where requests go (`https://<workspace>/api`)
|
|
39
|
-
and the audience every token is bound to (`https://<workspace>/api
|
|
39
|
+
and the audience every token is bound to (`https://<workspace>/api`). `endpoint` overrides only where
|
|
40
40
|
requests go, for a proxy or a local app; the audience still comes from the workspace. `caitlyn.auth.workspace`
|
|
41
41
|
and `caitlyn.auth.resource` show what the client uses.
|
|
42
42
|
|
|
@@ -90,13 +90,22 @@ that trusts the account's issuer and the role.
|
|
|
90
90
|
publish:
|
|
91
91
|
id_tokens:
|
|
92
92
|
CAITLYN_ID_TOKEN:
|
|
93
|
-
aud: https://your-company.getcaitlyn.ai/api
|
|
93
|
+
aud: https://your-company.getcaitlyn.ai/api
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
97
|
new Caitlyn({ workspace, auth: { mode: 'workloadIdentity', token: () => process.env.CAITLYN_ID_TOKEN! } });
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
### In a browser
|
|
101
|
+
|
|
102
|
+
In a browser page, use `oauth` without a `clientSecret` (authorisation code with PKCE), or `session` for the
|
|
103
|
+
Caitlyn app itself. Creating a client with `clientCredentials`, `oauth` with a `clientSecret`, `awsIam` or
|
|
104
|
+
`workloadIdentity` throws `CaitlynAuthError` with code `not_allowed_in_browser`: a client secret in a page is
|
|
105
|
+
visible to everyone who loads it, and the other two sign in server workloads. `token` mode works but warns once
|
|
106
|
+
per client, because a long-lived token in a page is exposed; it is for local testing, and
|
|
107
|
+
`allowBrowserToken: true` on the mode silences the warning.
|
|
108
|
+
|
|
100
109
|
## Calls
|
|
101
110
|
|
|
102
111
|
Every operation is a method on a namespace (`caitlyn.documents.list`) and also a standalone function that
|
|
@@ -127,8 +136,12 @@ Every API error is a `CaitlynError` subclass, one per status (`ValidationError`,
|
|
|
127
136
|
`ConflictError`, `PreconditionFailedError`, `TooManyRequestsError`…), carrying the problem details: `status`,
|
|
128
137
|
`code`, `title`, `detail`, `requestId` (quote it to Caitlyn support) and, on a 400, `errors`, one entry per
|
|
129
138
|
field. An error page from something in front of the API (an HTML 404, a proxy's 502) is the same class for its
|
|
130
|
-
status, with `code` `HTTP_<status>` and the page in `rawBody`.
|
|
131
|
-
|
|
139
|
+
status, with `code` `HTTP_<status>` and the page in `rawBody`. A call that got no response (a refused or reset
|
|
140
|
+
connection, a DNS or TLS failure) is `CaitlynConnectionError`, a `CaitlynError` with `status` 0, `code`
|
|
141
|
+
`CONNECTION_ERROR` and the network error as its `cause`. Sign-in failures are `CaitlynAuthError`, with the OAuth
|
|
142
|
+
error code.
|
|
143
|
+
|
|
144
|
+
A result's `$metadata` has the response's `httpStatusCode` and `requestId`.
|
|
132
145
|
|
|
133
146
|
```ts
|
|
134
147
|
try {
|
|
@@ -146,10 +159,29 @@ try {
|
|
|
146
159
|
failure state throws `WaiterError`. They are generated from the model's `@waitable` traits, so they appear as
|
|
147
160
|
operations gain them.
|
|
148
161
|
|
|
162
|
+
## Your own HTTP handler
|
|
163
|
+
|
|
164
|
+
`requestHandler` gives this client its own HTTP handler, for a private certificate authority, a proxy or
|
|
165
|
+
keep-alive settings, without changing the process-wide default:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import https from 'node:https';
|
|
169
|
+
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
|
170
|
+
|
|
171
|
+
const caitlyn = new Caitlyn({
|
|
172
|
+
workspace: 'your-company.getcaitlyn.ai',
|
|
173
|
+
auth: { mode: 'token', token: process.env.CAITLYN_TOKEN! },
|
|
174
|
+
requestHandler: new NodeHttpHandler({ httpsAgent: new https.Agent({ ca: fs.readFileSync('ca.pem') }) }),
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Sign-in requests go through the `fetch` option, which takes your own `fetch` the same way.
|
|
179
|
+
|
|
149
180
|
## Telemetry
|
|
150
181
|
|
|
151
|
-
The client creates OpenTelemetry spans for each call
|
|
152
|
-
|
|
182
|
+
The client creates OpenTelemetry spans for each call (`caitlyn.call`), each HTTP attempt (`caitlyn.attempt`) and
|
|
183
|
+
an upload's bytes (`caitlyn.upload`), with the names and attributes every Caitlyn SDK uses (`model/PROTOCOL.md`
|
|
184
|
+
section 13), and passes `traceparent` on, with whatever tracer provider your application has registered. With none registered it costs nothing. Pass
|
|
153
185
|
`telemetry: {tracerProvider}` to use another provider, or `telemetry: {enabled: false}` to switch it off.
|
|
154
186
|
|
|
155
187
|
## Runtimes
|