@cadraos/sdk 0.1.7 → 0.1.8
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 +38 -5
- package/dist/chat/index.cjs +134 -2
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +56 -8
- package/dist/chat/index.d.ts +56 -8
- package/dist/chat/index.js +134 -2
- package/dist/chat/index.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
# @cadraos/sdk
|
|
2
2
|
|
|
3
|
-
Official SDK for the
|
|
3
|
+
Official SDK for the CadraOS platform - programmatic access to agents, skills, tools, and artifacts.
|
|
4
|
+
|
|
5
|
+
> **Note**: For React chat components, use the new [@cadraos/react](https://www.npmjs.com/package/@cadraos/react) package.
|
|
6
|
+
> The `@cadraos/sdk/chat` subpath is deprecated.
|
|
7
|
+
|
|
8
|
+
## Deprecation Notice
|
|
9
|
+
|
|
10
|
+
The `@cadraos/sdk/chat` subpath is **deprecated** and will be removed in a future version.
|
|
11
|
+
|
|
12
|
+
**If you're using React chat components**, please migrate to `@cadraos/react`:
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
// Before (deprecated)
|
|
16
|
+
import { AgentChat, ChatConfigProvider } from '@cadraos/sdk/chat';
|
|
17
|
+
import '@cadraos/sdk/chat/styles.css';
|
|
18
|
+
|
|
19
|
+
// After (recommended)
|
|
20
|
+
import '@cadraos/react/styles.css';
|
|
21
|
+
import { CadraCopilot } from '@cadraos/react';
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return (
|
|
25
|
+
<CadraCopilot
|
|
26
|
+
apiKey="cdr_live_xxx"
|
|
27
|
+
orgId={123}
|
|
28
|
+
agentId="agent-uuid"
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For full migration instructions, see the [migration guide](https://github.com/cadraos/cadra-sdk/blob/main/packages/react/MIGRATION.md).
|
|
4
35
|
|
|
5
36
|
## Installation
|
|
6
37
|
|
|
@@ -15,12 +46,12 @@ yarn add @cadraos/sdk
|
|
|
15
46
|
## Quick Start
|
|
16
47
|
|
|
17
48
|
```typescript
|
|
18
|
-
import {
|
|
49
|
+
import { CadraClient } from '@cadraos/sdk';
|
|
19
50
|
|
|
20
51
|
// Initialize the client
|
|
21
|
-
const client = new
|
|
22
|
-
apiKey: process.env.
|
|
23
|
-
orgId: Number(process.env.
|
|
52
|
+
const client = new CadraClient({
|
|
53
|
+
apiKey: process.env.CADRA_API_KEY!, // e.g., cdr_live_xxx
|
|
54
|
+
orgId: Number(process.env.CADRA_ORG_ID),
|
|
24
55
|
});
|
|
25
56
|
|
|
26
57
|
// List available agents
|
|
@@ -34,6 +65,8 @@ const execution = await client.agents.executeSync(agents[0].uuid, {
|
|
|
34
65
|
console.log('Result:', execution.output);
|
|
35
66
|
```
|
|
36
67
|
|
|
68
|
+
> **Note**: `AISaaSClient` is deprecated but still works as an alias for `CadraClient`.
|
|
69
|
+
|
|
37
70
|
## Authentication
|
|
38
71
|
|
|
39
72
|
The SDK supports three authentication methods:
|
package/dist/chat/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
+
var fetchEventSource = require('@microsoft/fetch-event-source');
|
|
4
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
var ReactMarkdown = require('react-markdown');
|
|
6
7
|
var remarkGfm = require('remark-gfm');
|
|
@@ -2210,7 +2211,7 @@ function resolveClient(config) {
|
|
|
2210
2211
|
}
|
|
2211
2212
|
function resolveBaseUrl(config) {
|
|
2212
2213
|
if (config.baseUrl) return config.baseUrl;
|
|
2213
|
-
return "https://api.
|
|
2214
|
+
return "https://api.cadra.io/v1";
|
|
2214
2215
|
}
|
|
2215
2216
|
async function getAuthHeaders(config) {
|
|
2216
2217
|
const headers = {
|
|
@@ -2316,7 +2317,7 @@ function createDefaultAdapter(config) {
|
|
|
2316
2317
|
};
|
|
2317
2318
|
},
|
|
2318
2319
|
// -------------------------------------------------------------------------
|
|
2319
|
-
// Attachment Methods (raw fetch —
|
|
2320
|
+
// Attachment Methods (raw fetch — CadraClient has no AttachmentsAPI yet)
|
|
2320
2321
|
// -------------------------------------------------------------------------
|
|
2321
2322
|
async getUploadUrl(input) {
|
|
2322
2323
|
return rawRequest(config, "POST", "/attachments/upload-url", {
|
|
@@ -2396,8 +2397,106 @@ function createDefaultAdapter(config) {
|
|
|
2396
2397
|
// -------------------------------------------------------------------------
|
|
2397
2398
|
// SSE Stream URL (legacy backward compat)
|
|
2398
2399
|
// -------------------------------------------------------------------------
|
|
2400
|
+
/**
|
|
2401
|
+
* @deprecated Use subscribeToStream() instead. getStreamUrl() exposes
|
|
2402
|
+
* API keys in URLs which are logged by browsers, proxies, and servers.
|
|
2403
|
+
*/
|
|
2399
2404
|
getStreamUrl(executionId) {
|
|
2405
|
+
if (typeof window !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
2406
|
+
const warnKey = "__cadra_getStreamUrl_deprecated__";
|
|
2407
|
+
const win = window;
|
|
2408
|
+
if (!win[warnKey]) {
|
|
2409
|
+
win[warnKey] = true;
|
|
2410
|
+
console.warn(
|
|
2411
|
+
"[CadraOS SDK] getStreamUrl() is deprecated. Use subscribeToStream() instead which provides secure header-based auth. API keys in URLs are a security risk."
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2400
2415
|
return `${baseUrl}/agents/runs/${executionId}/stream`;
|
|
2416
|
+
},
|
|
2417
|
+
// -------------------------------------------------------------------------
|
|
2418
|
+
// Secure SSE Streaming (Recommended)
|
|
2419
|
+
// -------------------------------------------------------------------------
|
|
2420
|
+
subscribeToStream(executionId, callbacks) {
|
|
2421
|
+
const abortController = new AbortController();
|
|
2422
|
+
const url = `${baseUrl}/api/v1/agents/runs/${executionId}/stream`;
|
|
2423
|
+
const getHeaders = async () => {
|
|
2424
|
+
const headers = {
|
|
2425
|
+
Accept: "text/event-stream",
|
|
2426
|
+
"Cache-Control": "no-cache"
|
|
2427
|
+
};
|
|
2428
|
+
if (config.apiKey) {
|
|
2429
|
+
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
2430
|
+
} else if (config.token) {
|
|
2431
|
+
headers["Authorization"] = `Bearer ${config.token}`;
|
|
2432
|
+
} else if (config.tokenProvider) {
|
|
2433
|
+
const token = await config.tokenProvider();
|
|
2434
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
2435
|
+
}
|
|
2436
|
+
if (config.orgId !== void 0) {
|
|
2437
|
+
headers["X-Org-Id"] = String(config.orgId);
|
|
2438
|
+
}
|
|
2439
|
+
return headers;
|
|
2440
|
+
};
|
|
2441
|
+
const terminalEvents = /* @__PURE__ */ new Set(["complete", "failed", "error"]);
|
|
2442
|
+
(async () => {
|
|
2443
|
+
try {
|
|
2444
|
+
const headers = await getHeaders();
|
|
2445
|
+
callbacks.onConnectionChange?.(true);
|
|
2446
|
+
await fetchEventSource.fetchEventSource(url, {
|
|
2447
|
+
method: "GET",
|
|
2448
|
+
headers,
|
|
2449
|
+
signal: abortController.signal,
|
|
2450
|
+
openWhenHidden: true,
|
|
2451
|
+
// Keep connection open even when tab is hidden
|
|
2452
|
+
onopen: async (response) => {
|
|
2453
|
+
if (!response.ok) {
|
|
2454
|
+
const errorText = await response.text();
|
|
2455
|
+
throw new Error(`SSE connection failed: ${response.status} - ${errorText}`);
|
|
2456
|
+
}
|
|
2457
|
+
},
|
|
2458
|
+
onmessage: (ev) => {
|
|
2459
|
+
if (!ev.event || ev.event === "") {
|
|
2460
|
+
return;
|
|
2461
|
+
}
|
|
2462
|
+
let data;
|
|
2463
|
+
try {
|
|
2464
|
+
data = ev.data ? JSON.parse(ev.data) : {};
|
|
2465
|
+
} catch {
|
|
2466
|
+
data = ev.data;
|
|
2467
|
+
}
|
|
2468
|
+
const event = {
|
|
2469
|
+
type: ev.event,
|
|
2470
|
+
id: ev.id,
|
|
2471
|
+
data
|
|
2472
|
+
};
|
|
2473
|
+
callbacks.onEvent(event);
|
|
2474
|
+
if (terminalEvents.has(ev.event)) {
|
|
2475
|
+
callbacks.onComplete?.();
|
|
2476
|
+
abortController.abort();
|
|
2477
|
+
}
|
|
2478
|
+
},
|
|
2479
|
+
onerror: (err) => {
|
|
2480
|
+
callbacks.onConnectionChange?.(false);
|
|
2481
|
+
callbacks.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
2482
|
+
throw err;
|
|
2483
|
+
},
|
|
2484
|
+
onclose: () => {
|
|
2485
|
+
callbacks.onConnectionChange?.(false);
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
} catch (err) {
|
|
2489
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
callbacks.onConnectionChange?.(false);
|
|
2493
|
+
callbacks.onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
2494
|
+
}
|
|
2495
|
+
})();
|
|
2496
|
+
return () => {
|
|
2497
|
+
abortController.abort();
|
|
2498
|
+
callbacks.onConnectionChange?.(false);
|
|
2499
|
+
};
|
|
2401
2500
|
}
|
|
2402
2501
|
};
|
|
2403
2502
|
}
|
|
@@ -6083,6 +6182,39 @@ function TodoList({
|
|
|
6083
6182
|
);
|
|
6084
6183
|
}
|
|
6085
6184
|
|
|
6185
|
+
// src/chat/index.ts
|
|
6186
|
+
var DEPRECATION_WARNING = `
|
|
6187
|
+
[@cadraos/sdk/chat] DEPRECATION WARNING
|
|
6188
|
+
|
|
6189
|
+
This module is deprecated and will be removed in a future version.
|
|
6190
|
+
Please migrate to @cadraos/react for:
|
|
6191
|
+
- Simpler setup with CadraCopilot
|
|
6192
|
+
- Better security (header-based SSE auth)
|
|
6193
|
+
- Scoped CSS that won't conflict with your app
|
|
6194
|
+
|
|
6195
|
+
Migration steps:
|
|
6196
|
+
1. npm install @cadraos/react
|
|
6197
|
+
2. import '@cadraos/react/styles.css'
|
|
6198
|
+
3. Replace <AgentChat> with <CadraCopilot> or <CadraChat>
|
|
6199
|
+
|
|
6200
|
+
See: https://github.com/cadraos/cadra-sdk/blob/main/packages/react/MIGRATION.md
|
|
6201
|
+
`;
|
|
6202
|
+
var hasWarned = false;
|
|
6203
|
+
function showDeprecationWarning() {
|
|
6204
|
+
if (hasWarned) return;
|
|
6205
|
+
hasWarned = true;
|
|
6206
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
|
|
6207
|
+
return;
|
|
6208
|
+
}
|
|
6209
|
+
if (typeof window === "undefined") {
|
|
6210
|
+
return;
|
|
6211
|
+
}
|
|
6212
|
+
console.warn(DEPRECATION_WARNING);
|
|
6213
|
+
}
|
|
6214
|
+
if (typeof window !== "undefined") {
|
|
6215
|
+
setTimeout(showDeprecationWarning, 0);
|
|
6216
|
+
}
|
|
6217
|
+
|
|
6086
6218
|
exports.AgentChat = AgentChat;
|
|
6087
6219
|
exports.AlertCircleIcon = AlertCircleIcon;
|
|
6088
6220
|
exports.AskUserPrompt = AskUserPrompt;
|