@flashbacktech/tsclient 0.4.33
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 +61 -0
- package/dist/index.cjs +1805 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1953 -0
- package/dist/index.d.ts +1953 -0
- package/dist/index.js +1778 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @flashbacktech/tsclient
|
|
2
|
+
|
|
3
|
+
TypeScript client for the cloud-agent platform API. Speaks the new domain vocabulary (`project` / `sandbox`) regardless of any residual legacy field names on the wire.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @flashbacktech/tsclient
|
|
9
|
+
# Optional, only needed if you use the chat SSE helper in a browser
|
|
10
|
+
npm install event-source-polyfill
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { CloudAgentClient } from '@flashbacktech/tsclient';
|
|
17
|
+
|
|
18
|
+
const client = new CloudAgentClient({
|
|
19
|
+
baseUrl: 'http://localhost:3010',
|
|
20
|
+
getToken: () => localStorage.getItem('access_token'),
|
|
21
|
+
onUnauthorized: async () => {
|
|
22
|
+
// refresh + re-authenticate; SDK does not auto-retry
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Auth
|
|
27
|
+
const session = await client.auth.login({ email, password });
|
|
28
|
+
|
|
29
|
+
// Projects + sandboxes
|
|
30
|
+
const projects = await client.projects.list();
|
|
31
|
+
const sandbox = await client.sandboxes.create({ projectId, name: 'demo', storageType: 'S3', mode: 'NORMAL' });
|
|
32
|
+
|
|
33
|
+
// Chat SSE
|
|
34
|
+
const stream = client.chat.openStream({
|
|
35
|
+
scope: { orgId, userId, sandboxId, projectId },
|
|
36
|
+
conversationId,
|
|
37
|
+
onEvent: (e) => console.log(e),
|
|
38
|
+
});
|
|
39
|
+
// later:
|
|
40
|
+
stream.close();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Errors
|
|
44
|
+
|
|
45
|
+
Every non-2xx response throws an `HttpError`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { HttpError } from '@flashbacktech/tsclient';
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await client.auth.login({ email, password });
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err instanceof HttpError) {
|
|
54
|
+
console.log(err.status, err.errorCode, err.message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Releasing
|
|
60
|
+
|
|
61
|
+
`./patch.sh` from the repo root bumps the patch version, builds, and publishes to npm. Pass `--minor`, `--major`, or `--dry-run` as needed.
|