@wonnetix/tsclient
v0.4.1
Published
TypeScript client for the cloud-agent platform API.
Downloads
1,013
Readme
@wonnetix/tsclient
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.
Install
npm install @wonnetix/tsclient
# Optional, only needed if you use the chat SSE helper in a browser
npm install event-source-polyfillUsage
import { CloudAgentClient } from '@wonnetix/tsclient';
const client = new CloudAgentClient({
baseUrl: 'http://localhost:3010',
getToken: () => localStorage.getItem('access_token'),
onUnauthorized: async () => {
// refresh + re-authenticate; SDK does not auto-retry
},
});
// Auth
const session = await client.auth.login({ email, password });
// Projects + sandboxes
const projects = await client.projects.list();
const sandbox = await client.sandboxes.create({ projectId, name: 'demo', storageType: 'S3', mode: 'NORMAL' });
// Chat SSE
const stream = client.chat.openStream({
scope: { orgId, userId, sandboxId, projectId },
conversationId,
onEvent: (e) => console.log(e),
});
// later:
stream.close();Errors
Every non-2xx response throws an HttpError:
import { HttpError } from '@wonnetix/tsclient';
try {
await client.auth.login({ email, password });
} catch (err) {
if (err instanceof HttpError) {
console.log(err.status, err.errorCode, err.message);
}
}Releasing
./patch.sh from the repo root bumps the patch version, builds, and publishes to npm. Pass --minor, --major, or --dry-run as needed.
