@caitlyn-ai/sdk 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-browser/sdk/index.mjs +59 -33
- package/dist-browser/sdk/index.mjs.map +3 -3
- package/dist-cjs/sdk/index.cjs +59 -32
- package/dist-cjs/sdk/index.cjs.map +3 -3
- package/dist-es/sdk/index.mjs +59 -33
- package/dist-es/sdk/index.mjs.map +3 -3
- package/dist-types/sdk/index.d.ts +5376 -8
- package/package.json +2 -3
- package/dist-types/Caitlyn.d.ts +0 -76
- package/dist-types/CaitlynClient.d.ts +0 -160
- package/dist-types/auth/httpAuthExtensionConfiguration.d.ts +0 -29
- package/dist-types/auth/httpAuthSchemeProvider.d.ts +0 -81
- package/dist-types/commandBuilder.d.ts +0 -18
- package/dist-types/commands/CreateDocumentCommand.d.ts +0 -190
- package/dist-types/commands/CreateUploadCommand.d.ts +0 -165
- package/dist-types/commands/GetAgentVersionCommand.d.ts +0 -177
- package/dist-types/commands/ListDocumentsCommand.d.ts +0 -176
- package/dist-types/commands/ResumeConversationStreamCommand.d.ts +0 -146
- package/dist-types/commands/SendMessageCommand.d.ts +0 -183
- package/dist-types/commands/UpdateDraftVersionCommand.d.ts +0 -202
- package/dist-types/commands/index.d.ts +0 -7
- package/dist-types/endpoint/EndpointParameters.d.ts +0 -32
- package/dist-types/endpoint/bdd.d.ts +0 -2
- package/dist-types/endpoint/endpointResolver.d.ts +0 -8
- package/dist-types/extensionConfiguration.d.ts +0 -8
- package/dist-types/index.d.ts +0 -22
- package/dist-types/models/CaitlynServiceException.d.ts +0 -15
- package/dist-types/models/enums.d.ts +0 -148
- package/dist-types/models/errors.d.ts +0 -659
- package/dist-types/models/models_0.d.ts +0 -754
- package/dist-types/pagination/Interfaces.d.ts +0 -8
- package/dist-types/pagination/ListDocumentsPaginator.d.ts +0 -7
- package/dist-types/pagination/index.d.ts +0 -2
- package/dist-types/runtimeConfig.browser.d.ts +0 -50
- package/dist-types/runtimeConfig.d.ts +0 -50
- package/dist-types/runtimeConfig.native.d.ts +0 -49
- package/dist-types/runtimeConfig.shared.d.ts +0 -36
- package/dist-types/runtimeExtensions.d.ts +0 -17
- package/dist-types/schemas/schemas_0.d.ts +0 -51
- package/dist-types/sdk/client.d.ts +0 -47
- package/dist-types/sdk/events.d.ts +0 -163
- package/dist-types/sdk/operations.d.ts +0 -70
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
|
|
@@ -77,19 +77,19 @@ import { TypeRegistry } from "@smithy/core/schema";
|
|
|
77
77
|
import {
|
|
78
78
|
ServiceException as __ServiceException
|
|
79
79
|
} from "@smithy/core/client";
|
|
80
|
-
var CaitlynServiceException = class
|
|
80
|
+
var CaitlynServiceException = class extends __ServiceException {
|
|
81
81
|
static shapeId = "smithy.ts.sdk.synthetic.ai.caitlyn.v3#CaitlynServiceException";
|
|
82
82
|
/**
|
|
83
83
|
* @internal
|
|
84
84
|
*/
|
|
85
85
|
constructor(options) {
|
|
86
86
|
super(options);
|
|
87
|
-
Object.setPrototypeOf(this,
|
|
87
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
// packages/sdk/src/models/errors.ts
|
|
92
|
-
var InternalError = class
|
|
92
|
+
var InternalError = class extends CaitlynServiceException {
|
|
93
93
|
static shapeId = "ai.caitlyn.v3#InternalError";
|
|
94
94
|
name = "InternalError";
|
|
95
95
|
$fault = "server";
|
|
@@ -142,7 +142,7 @@ var InternalError = class _InternalError extends CaitlynServiceException {
|
|
|
142
142
|
$fault: "server",
|
|
143
143
|
...opts
|
|
144
144
|
});
|
|
145
|
-
Object.setPrototypeOf(this,
|
|
145
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
146
146
|
this.type = opts.type;
|
|
147
147
|
this.title = opts.title;
|
|
148
148
|
this.status = opts.status;
|
|
@@ -152,7 +152,7 @@ var InternalError = class _InternalError extends CaitlynServiceException {
|
|
|
152
152
|
this.errors = opts.errors;
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
|
-
var NotFoundError = class
|
|
155
|
+
var NotFoundError = class extends CaitlynServiceException {
|
|
156
156
|
static shapeId = "ai.caitlyn.v3#NotFoundError";
|
|
157
157
|
name = "NotFoundError";
|
|
158
158
|
$fault = "client";
|
|
@@ -205,7 +205,7 @@ var NotFoundError = class _NotFoundError extends CaitlynServiceException {
|
|
|
205
205
|
$fault: "client",
|
|
206
206
|
...opts
|
|
207
207
|
});
|
|
208
|
-
Object.setPrototypeOf(this,
|
|
208
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
209
209
|
this.type = opts.type;
|
|
210
210
|
this.title = opts.title;
|
|
211
211
|
this.status = opts.status;
|
|
@@ -215,7 +215,7 @@ var NotFoundError = class _NotFoundError extends CaitlynServiceException {
|
|
|
215
215
|
this.errors = opts.errors;
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
|
-
var PermissionDeniedError = class
|
|
218
|
+
var PermissionDeniedError = class extends CaitlynServiceException {
|
|
219
219
|
static shapeId = "ai.caitlyn.v3#PermissionDeniedError";
|
|
220
220
|
name = "PermissionDeniedError";
|
|
221
221
|
$fault = "client";
|
|
@@ -268,7 +268,7 @@ var PermissionDeniedError = class _PermissionDeniedError extends CaitlynServiceE
|
|
|
268
268
|
$fault: "client",
|
|
269
269
|
...opts
|
|
270
270
|
});
|
|
271
|
-
Object.setPrototypeOf(this,
|
|
271
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
272
272
|
this.type = opts.type;
|
|
273
273
|
this.title = opts.title;
|
|
274
274
|
this.status = opts.status;
|
|
@@ -278,7 +278,7 @@ var PermissionDeniedError = class _PermissionDeniedError extends CaitlynServiceE
|
|
|
278
278
|
this.errors = opts.errors;
|
|
279
279
|
}
|
|
280
280
|
};
|
|
281
|
-
var PreconditionFailedError = class
|
|
281
|
+
var PreconditionFailedError = class extends CaitlynServiceException {
|
|
282
282
|
static shapeId = "ai.caitlyn.v3#PreconditionFailedError";
|
|
283
283
|
name = "PreconditionFailedError";
|
|
284
284
|
$fault = "client";
|
|
@@ -331,7 +331,7 @@ var PreconditionFailedError = class _PreconditionFailedError extends CaitlynServ
|
|
|
331
331
|
$fault: "client",
|
|
332
332
|
...opts
|
|
333
333
|
});
|
|
334
|
-
Object.setPrototypeOf(this,
|
|
334
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
335
335
|
this.type = opts.type;
|
|
336
336
|
this.title = opts.title;
|
|
337
337
|
this.status = opts.status;
|
|
@@ -341,7 +341,7 @@ var PreconditionFailedError = class _PreconditionFailedError extends CaitlynServ
|
|
|
341
341
|
this.errors = opts.errors;
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
|
-
var PreconditionRequiredError = class
|
|
344
|
+
var PreconditionRequiredError = class extends CaitlynServiceException {
|
|
345
345
|
static shapeId = "ai.caitlyn.v3#PreconditionRequiredError";
|
|
346
346
|
name = "PreconditionRequiredError";
|
|
347
347
|
$fault = "client";
|
|
@@ -394,7 +394,7 @@ var PreconditionRequiredError = class _PreconditionRequiredError extends Caitlyn
|
|
|
394
394
|
$fault: "client",
|
|
395
395
|
...opts
|
|
396
396
|
});
|
|
397
|
-
Object.setPrototypeOf(this,
|
|
397
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
398
398
|
this.type = opts.type;
|
|
399
399
|
this.title = opts.title;
|
|
400
400
|
this.status = opts.status;
|
|
@@ -404,7 +404,7 @@ var PreconditionRequiredError = class _PreconditionRequiredError extends Caitlyn
|
|
|
404
404
|
this.errors = opts.errors;
|
|
405
405
|
}
|
|
406
406
|
};
|
|
407
|
-
var ServiceUnavailableError = class
|
|
407
|
+
var ServiceUnavailableError = class extends CaitlynServiceException {
|
|
408
408
|
static shapeId = "ai.caitlyn.v3#ServiceUnavailableError";
|
|
409
409
|
name = "ServiceUnavailableError";
|
|
410
410
|
$fault = "server";
|
|
@@ -463,7 +463,7 @@ var ServiceUnavailableError = class _ServiceUnavailableError extends CaitlynServ
|
|
|
463
463
|
$fault: "server",
|
|
464
464
|
...opts
|
|
465
465
|
});
|
|
466
|
-
Object.setPrototypeOf(this,
|
|
466
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
467
467
|
this.type = opts.type;
|
|
468
468
|
this.title = opts.title;
|
|
469
469
|
this.status = opts.status;
|
|
@@ -474,7 +474,7 @@ var ServiceUnavailableError = class _ServiceUnavailableError extends CaitlynServ
|
|
|
474
474
|
this.retryAfterSeconds = opts.retryAfterSeconds;
|
|
475
475
|
}
|
|
476
476
|
};
|
|
477
|
-
var TooManyRequestsError = class
|
|
477
|
+
var TooManyRequestsError = class extends CaitlynServiceException {
|
|
478
478
|
static shapeId = "ai.caitlyn.v3#TooManyRequestsError";
|
|
479
479
|
name = "TooManyRequestsError";
|
|
480
480
|
$fault = "client";
|
|
@@ -535,7 +535,7 @@ var TooManyRequestsError = class _TooManyRequestsError extends CaitlynServiceExc
|
|
|
535
535
|
$fault: "client",
|
|
536
536
|
...opts
|
|
537
537
|
});
|
|
538
|
-
Object.setPrototypeOf(this,
|
|
538
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
539
539
|
this.type = opts.type;
|
|
540
540
|
this.title = opts.title;
|
|
541
541
|
this.status = opts.status;
|
|
@@ -546,7 +546,7 @@ var TooManyRequestsError = class _TooManyRequestsError extends CaitlynServiceExc
|
|
|
546
546
|
this.retryAfterSeconds = opts.retryAfterSeconds;
|
|
547
547
|
}
|
|
548
548
|
};
|
|
549
|
-
var UnauthenticatedError = class
|
|
549
|
+
var UnauthenticatedError = class extends CaitlynServiceException {
|
|
550
550
|
static shapeId = "ai.caitlyn.v3#UnauthenticatedError";
|
|
551
551
|
name = "UnauthenticatedError";
|
|
552
552
|
$fault = "client";
|
|
@@ -599,7 +599,7 @@ var UnauthenticatedError = class _UnauthenticatedError extends CaitlynServiceExc
|
|
|
599
599
|
$fault: "client",
|
|
600
600
|
...opts
|
|
601
601
|
});
|
|
602
|
-
Object.setPrototypeOf(this,
|
|
602
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
603
603
|
this.type = opts.type;
|
|
604
604
|
this.title = opts.title;
|
|
605
605
|
this.status = opts.status;
|
|
@@ -609,7 +609,7 @@ var UnauthenticatedError = class _UnauthenticatedError extends CaitlynServiceExc
|
|
|
609
609
|
this.errors = opts.errors;
|
|
610
610
|
}
|
|
611
611
|
};
|
|
612
|
-
var ValidationError = class
|
|
612
|
+
var ValidationError = class extends CaitlynServiceException {
|
|
613
613
|
static shapeId = "ai.caitlyn.v3#ValidationError";
|
|
614
614
|
name = "ValidationError";
|
|
615
615
|
$fault = "client";
|
|
@@ -662,7 +662,7 @@ var ValidationError = class _ValidationError extends CaitlynServiceException {
|
|
|
662
662
|
$fault: "client",
|
|
663
663
|
...opts
|
|
664
664
|
});
|
|
665
|
-
Object.setPrototypeOf(this,
|
|
665
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
666
666
|
this.type = opts.type;
|
|
667
667
|
this.title = opts.title;
|
|
668
668
|
this.status = opts.status;
|
|
@@ -672,7 +672,7 @@ var ValidationError = class _ValidationError extends CaitlynServiceException {
|
|
|
672
672
|
this.errors = opts.errors;
|
|
673
673
|
}
|
|
674
674
|
};
|
|
675
|
-
var ConflictError = class
|
|
675
|
+
var ConflictError = class extends CaitlynServiceException {
|
|
676
676
|
static shapeId = "ai.caitlyn.v3#ConflictError";
|
|
677
677
|
name = "ConflictError";
|
|
678
678
|
$fault = "client";
|
|
@@ -725,7 +725,7 @@ var ConflictError = class _ConflictError extends CaitlynServiceException {
|
|
|
725
725
|
$fault: "client",
|
|
726
726
|
...opts
|
|
727
727
|
});
|
|
728
|
-
Object.setPrototypeOf(this,
|
|
728
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
729
729
|
this.type = opts.type;
|
|
730
730
|
this.title = opts.title;
|
|
731
731
|
this.status = opts.status;
|
|
@@ -735,7 +735,7 @@ var ConflictError = class _ConflictError extends CaitlynServiceException {
|
|
|
735
735
|
this.errors = opts.errors;
|
|
736
736
|
}
|
|
737
737
|
};
|
|
738
|
-
var PayloadTooLargeError = class
|
|
738
|
+
var PayloadTooLargeError = class extends CaitlynServiceException {
|
|
739
739
|
static shapeId = "ai.caitlyn.v3#PayloadTooLargeError";
|
|
740
740
|
name = "PayloadTooLargeError";
|
|
741
741
|
$fault = "client";
|
|
@@ -788,7 +788,7 @@ var PayloadTooLargeError = class _PayloadTooLargeError extends CaitlynServiceExc
|
|
|
788
788
|
$fault: "client",
|
|
789
789
|
...opts
|
|
790
790
|
});
|
|
791
|
-
Object.setPrototypeOf(this,
|
|
791
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
792
792
|
this.type = opts.type;
|
|
793
793
|
this.title = opts.title;
|
|
794
794
|
this.status = opts.status;
|
|
@@ -798,7 +798,7 @@ var PayloadTooLargeError = class _PayloadTooLargeError extends CaitlynServiceExc
|
|
|
798
798
|
this.errors = opts.errors;
|
|
799
799
|
}
|
|
800
800
|
};
|
|
801
|
-
var UnprocessableContentError = class
|
|
801
|
+
var UnprocessableContentError = class extends CaitlynServiceException {
|
|
802
802
|
static shapeId = "ai.caitlyn.v3#UnprocessableContentError";
|
|
803
803
|
name = "UnprocessableContentError";
|
|
804
804
|
$fault = "client";
|
|
@@ -851,7 +851,7 @@ var UnprocessableContentError = class _UnprocessableContentError extends Caitlyn
|
|
|
851
851
|
$fault: "client",
|
|
852
852
|
...opts
|
|
853
853
|
});
|
|
854
|
-
Object.setPrototypeOf(this,
|
|
854
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
855
855
|
this.type = opts.type;
|
|
856
856
|
this.title = opts.title;
|
|
857
857
|
this.status = opts.status;
|
|
@@ -1439,7 +1439,7 @@ var getRuntimeConfig = (config) => {
|
|
|
1439
1439
|
apiVersion: "3.0.0",
|
|
1440
1440
|
base64Decoder: config?.base64Decoder ?? fromBase64,
|
|
1441
1441
|
base64Encoder: config?.base64Encoder ?? toBase64,
|
|
1442
|
-
caitlynSdkVersion: config?.caitlynSdkVersion ?? "0.
|
|
1442
|
+
caitlynSdkVersion: config?.caitlynSdkVersion ?? "0.1.1",
|
|
1443
1443
|
disableHostPrefix: config?.disableHostPrefix ?? false,
|
|
1444
1444
|
endpointProvider: config?.endpointProvider ?? caitlynEndpointProvider,
|
|
1445
1445
|
extensions: config?.extensions ?? [],
|
|
@@ -1583,7 +1583,24 @@ var CaitlynClient = class extends __Client {
|
|
|
1583
1583
|
};
|
|
1584
1584
|
|
|
1585
1585
|
// packages/sdk/src/sdk/client.ts
|
|
1586
|
-
import { clientConfig, createAuth, getCaitlynAuthPlugin, getCaitlynTelemetryPlugin } from "@caitlyn-ai/sdk-core";
|
|
1586
|
+
import { clientConfig, createAuth, getCaitlynAuthPlugin, getCaitlynConnectionErrorPlugin, getCaitlynTelemetryPlugin } from "@caitlyn-ai/sdk-core";
|
|
1587
|
+
|
|
1588
|
+
// packages/sdk/src/sdk/connection.ts
|
|
1589
|
+
var CaitlynConnectionError = class _CaitlynConnectionError extends CaitlynServiceException {
|
|
1590
|
+
status = 0;
|
|
1591
|
+
code = "CONNECTION_ERROR";
|
|
1592
|
+
title;
|
|
1593
|
+
requestId = void 0;
|
|
1594
|
+
rawBody = "";
|
|
1595
|
+
rawBodyTruncated = false;
|
|
1596
|
+
constructor(operation, cause) {
|
|
1597
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
1598
|
+
super({ name: "CaitlynConnectionError", $fault: "client", $metadata: {}, message: `${operation}: no response: ${reason}` });
|
|
1599
|
+
Object.setPrototypeOf(this, _CaitlynConnectionError.prototype);
|
|
1600
|
+
this.title = `${operation}: no response`;
|
|
1601
|
+
this.cause = cause;
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1587
1604
|
|
|
1588
1605
|
// packages/sdk/src/sdk/operations.ts
|
|
1589
1606
|
import { SseStream, uploadFile } from "@caitlyn-ai/sdk-core";
|
|
@@ -1687,7 +1704,7 @@ var toError = (problem) => {
|
|
|
1687
1704
|
const fault = status >= 500 ? "server" : "client";
|
|
1688
1705
|
const message = String(problem.detail ?? problem.title ?? problem.code);
|
|
1689
1706
|
const Typed = ERROR_CLASSES[status];
|
|
1690
|
-
const error = Typed ? new Typed({ $fault: fault, $metadata: {}, message }) : new CaitlynServiceException({ name:
|
|
1707
|
+
const error = Typed ? new Typed({ $fault: fault, $metadata: {}, message }) : new CaitlynServiceException({ name: "CaitlynError", $fault: fault, $metadata: {}, message });
|
|
1691
1708
|
return Object.assign(error, problem, { message });
|
|
1692
1709
|
};
|
|
1693
1710
|
function createDocument(client, input, options = {}) {
|
|
@@ -1715,7 +1732,7 @@ function resumeConversationStream(client, conversationId, input, options = {}) {
|
|
|
1715
1732
|
const { signal, ...rest } = options;
|
|
1716
1733
|
return new SseStream(
|
|
1717
1734
|
{ known: ConversationEventNames, final: { event: "message.completed", member: "message" }, errorEvent: "message.failed", toError },
|
|
1718
|
-
|
|
1735
|
+
() => client.send(new ResumeConversationStreamCommand({ ...input, conversationId, ...rest }), { abortSignal: signal }),
|
|
1719
1736
|
void 0,
|
|
1720
1737
|
signal
|
|
1721
1738
|
);
|
|
@@ -1724,8 +1741,8 @@ function sendMessage(client, conversationId, input, options = {}) {
|
|
|
1724
1741
|
const { signal, ...rest } = options;
|
|
1725
1742
|
return new SseStream(
|
|
1726
1743
|
{ known: ConversationEventNames, final: { event: "message.completed", member: "message" }, errorEvent: "message.failed", toError },
|
|
1727
|
-
|
|
1728
|
-
|
|
1744
|
+
() => client.send(new SendMessageCommand({ ...input, conversationId, ...rest }), { abortSignal: signal }),
|
|
1745
|
+
(lastEventId) => client.send(new ResumeConversationStreamCommand({ conversationId, lastEventId }), { abortSignal: signal }),
|
|
1729
1746
|
signal
|
|
1730
1747
|
);
|
|
1731
1748
|
}
|
|
@@ -1735,7 +1752,14 @@ function updateDraftVersion(client, agentId, input, options) {
|
|
|
1735
1752
|
}
|
|
1736
1753
|
function createUploadFromFile(client, input, options = {}) {
|
|
1737
1754
|
const { file, fileName, ...rest } = input;
|
|
1738
|
-
return uploadFile(
|
|
1755
|
+
return uploadFile(
|
|
1756
|
+
file,
|
|
1757
|
+
fileName,
|
|
1758
|
+
(meta) => createUpload(client, { ...rest, ...meta }, options),
|
|
1759
|
+
toError,
|
|
1760
|
+
options.signal,
|
|
1761
|
+
client.config.caitlynTracer
|
|
1762
|
+
);
|
|
1739
1763
|
}
|
|
1740
1764
|
async function uploadDocument(client, input, options = {}) {
|
|
1741
1765
|
const { file, fileName, ...rest } = input;
|
|
@@ -1748,6 +1772,7 @@ function createCaitlynClient(options, auth = createAuth(options)) {
|
|
|
1748
1772
|
const client = new CaitlynClient(clientConfig(options, auth));
|
|
1749
1773
|
client.middlewareStack.use(getCaitlynAuthPlugin(auth));
|
|
1750
1774
|
if (options.telemetry?.enabled !== false) client.middlewareStack.use(getCaitlynTelemetryPlugin(options.telemetry?.tracerProvider));
|
|
1775
|
+
client.middlewareStack.use(getCaitlynConnectionErrorPlugin((operation, cause) => new CaitlynConnectionError(operation, cause)));
|
|
1751
1776
|
return client;
|
|
1752
1777
|
}
|
|
1753
1778
|
var Caitlyn = class {
|
|
@@ -1884,6 +1909,7 @@ import { NotSupportedByServer, SseStream as SseStream2, CaitlynAuthError, Waiter
|
|
|
1884
1909
|
export {
|
|
1885
1910
|
Caitlyn,
|
|
1886
1911
|
CaitlynAuthError,
|
|
1912
|
+
CaitlynConnectionError,
|
|
1887
1913
|
CaitlynServiceException as CaitlynError,
|
|
1888
1914
|
ClearableDraftField,
|
|
1889
1915
|
ConflictError,
|