@corti/embedded-web 0.1.0 → 0.2.0
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 +70 -47
- package/dist/CortiEmbedded.d.ts +5 -4
- package/dist/CortiEmbedded.js +186 -103
- package/dist/CortiEmbedded.js.map +1 -1
- package/dist/bundle.js +1615 -20
- package/dist/corti-embedded.d.ts +17 -1
- package/dist/corti-embedded.js +4 -3
- package/dist/corti-embedded.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/react/CortiEmbeddedReact.d.ts +30 -23
- package/dist/react/CortiEmbeddedReact.js +67 -21
- package/dist/react/CortiEmbeddedReact.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/styles/base.js +1 -1
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/container-styles.js +2 -2
- package/dist/styles/container-styles.js.map +1 -1
- package/dist/styles/theme.js +2 -2
- package/dist/styles/theme.js.map +1 -1
- package/dist/types/api.d.ts +3 -14
- package/dist/types/api.js.map +1 -1
- package/dist/types/payloads.d.ts +1 -4
- package/dist/types/payloads.js.map +1 -1
- package/dist/types/protocol.d.ts +0 -1
- package/dist/types/protocol.js.map +1 -1
- package/dist/utils/PostMessageHandler.d.ts +19 -70
- package/dist/utils/PostMessageHandler.js +98 -202
- package/dist/utils/PostMessageHandler.js.map +1 -1
- package/dist/utils/baseUrl.js +8 -8
- package/dist/utils/baseUrl.js.map +1 -1
- package/dist/utils/embedUrl.js +3 -3
- package/dist/utils/embedUrl.js.map +1 -1
- package/dist/utils/errorFormatter.js +44 -20
- package/dist/utils/errorFormatter.js.map +1 -1
- package/dist/web-bundle.js +1473 -13
- package/dist/web-index.d.ts +3 -3
- package/dist/web-index.js +3 -3
- package/dist/web-index.js.map +1 -1
- package/package.json +18 -10
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -15,12 +15,6 @@ A web component and React component library that provides an embedded interface
|
|
|
15
15
|
npm install @corti/embedded-web
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
The package provides a web component by default. For React usage, also install React as a peer dependency:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install react @types/react
|
|
22
|
-
```
|
|
23
|
-
|
|
24
18
|
## Usage
|
|
25
19
|
|
|
26
20
|
### Web Component
|
|
@@ -28,7 +22,7 @@ npm install react @types/react
|
|
|
28
22
|
```html
|
|
29
23
|
<corti-embedded
|
|
30
24
|
id="corti-component"
|
|
31
|
-
|
|
25
|
+
baseurl="https://assistant.eu.corti.app" <!-- REQUIRED -->
|
|
32
26
|
></corti-embedded>
|
|
33
27
|
```
|
|
34
28
|
|
|
@@ -55,58 +49,73 @@ await myComponent.navigate('/interactions/123');
|
|
|
55
49
|
await myComponent.show()
|
|
56
50
|
```
|
|
57
51
|
|
|
52
|
+
#### Generic Event Listener (Web Component)
|
|
53
|
+
|
|
54
|
+
Use `event` as the canonical event stream for web component integrations (formerly `embedded-event`).
|
|
55
|
+
|
|
56
|
+
- Event detail shape is `{ name: string; payload: unknown }`.
|
|
57
|
+
- Full event catalog and payload details are documented at:
|
|
58
|
+
- https://docs.corti.ai/assistant/events
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
myComponent.addEventListener("event", event => {
|
|
62
|
+
const { detail } = event;
|
|
63
|
+
console.log(detail.name, detail.payload);
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
58
67
|
### React Component
|
|
59
68
|
|
|
60
69
|
```tsx
|
|
61
|
-
import React, { useRef } from
|
|
70
|
+
import React, { useRef } from "react";
|
|
62
71
|
import {
|
|
63
72
|
CortiEmbeddedReact,
|
|
64
73
|
type CortiEmbeddedReactRef,
|
|
74
|
+
type CortiEmbeddedEvent,
|
|
75
|
+
type CortiEmbeddedReadyEvent,
|
|
65
76
|
useCortiEmbeddedApi,
|
|
66
77
|
useCortiEmbeddedStatus,
|
|
67
|
-
} from
|
|
78
|
+
} from "@corti/embedded-web/react";
|
|
68
79
|
|
|
69
80
|
function App() {
|
|
70
81
|
const cortiRef = useRef<CortiEmbeddedReactRef>(null);
|
|
71
82
|
const api = useCortiEmbeddedApi(cortiRef);
|
|
72
83
|
const { status } = useCortiEmbeddedStatus(cortiRef);
|
|
73
84
|
|
|
74
|
-
const handleReady = () => {
|
|
75
|
-
console.log(
|
|
85
|
+
const handleReady = (event: CortiEmbeddedReadyEvent) => {
|
|
86
|
+
console.log("Corti component is ready!", event.detail);
|
|
76
87
|
};
|
|
77
88
|
|
|
78
|
-
const handleEvent = (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.log('Event name:', event.detail.name);
|
|
82
|
-
console.log('Event payload:', event.detail.payload);
|
|
89
|
+
const handleEvent = (event: CortiEmbeddedEvent) => {
|
|
90
|
+
console.log("Event name:", event.detail.name);
|
|
91
|
+
console.log("Event payload:", event.detail.payload);
|
|
83
92
|
};
|
|
84
93
|
|
|
85
94
|
const handleAuth = async () => {
|
|
86
95
|
try {
|
|
87
96
|
const user = await api.auth({
|
|
88
|
-
access_token:
|
|
89
|
-
token_type:
|
|
97
|
+
access_token: "your-token",
|
|
98
|
+
token_type: "Bearer",
|
|
90
99
|
// ... rest of the token response
|
|
91
100
|
});
|
|
92
|
-
console.log(
|
|
101
|
+
console.log("Authenticated:", user);
|
|
93
102
|
|
|
94
|
-
await api.configureSession({ defaultTemplateKey:
|
|
103
|
+
await api.configureSession({ defaultTemplateKey: "soap_note" });
|
|
95
104
|
await api.createInteraction({
|
|
96
105
|
encounter: {
|
|
97
106
|
identifier: `encounter-${Date.now()}`,
|
|
98
|
-
status:
|
|
99
|
-
type:
|
|
107
|
+
status: "planned",
|
|
108
|
+
type: "first_consultation",
|
|
100
109
|
period: { startedAt: new Date().toISOString() },
|
|
101
110
|
},
|
|
102
111
|
});
|
|
103
112
|
} catch (error) {
|
|
104
|
-
console.error(
|
|
113
|
+
console.error("Auth failed:", error);
|
|
105
114
|
}
|
|
106
115
|
};
|
|
107
116
|
|
|
108
117
|
return (
|
|
109
|
-
<div style={{ height:
|
|
118
|
+
<div style={{ height: "100vh" }}>
|
|
110
119
|
<button onClick={handleAuth}>Authenticate</button>
|
|
111
120
|
|
|
112
121
|
<CortiEmbeddedReact
|
|
@@ -115,8 +124,8 @@ function App() {
|
|
|
115
124
|
visibility="visible"
|
|
116
125
|
onReady={handleReady}
|
|
117
126
|
onEvent={handleEvent}
|
|
118
|
-
onError={event => console.error(
|
|
119
|
-
style={{ width:
|
|
127
|
+
onError={event => console.error("Embedded error:", event.detail)}
|
|
128
|
+
style={{ width: "100%", height: "500px" }}
|
|
120
129
|
/>
|
|
121
130
|
|
|
122
131
|
<pre>{JSON.stringify(status, null, 2)}</pre>
|
|
@@ -128,7 +137,7 @@ function App() {
|
|
|
128
137
|
### Show/Hide the Component
|
|
129
138
|
|
|
130
139
|
```javascript
|
|
131
|
-
const component = document.getElementById(
|
|
140
|
+
const component = document.getElementById("corti-component");
|
|
132
141
|
|
|
133
142
|
// Show the chat interface
|
|
134
143
|
component.show();
|
|
@@ -143,12 +152,22 @@ component.hide();
|
|
|
143
152
|
|
|
144
153
|
#### auth
|
|
145
154
|
|
|
155
|
+
Authentication is required before using the embedded app. The payload passed to
|
|
156
|
+
`component.auth(...)` should come directly from your identity provider token
|
|
157
|
+
response (for example, Keycloak/OIDC token endpoint response).
|
|
158
|
+
|
|
159
|
+
- API details and payload shape: https://docs.corti.ai/assistant/api-reference#auth
|
|
160
|
+
- End-to-end authentication guidance: https://docs.corti.ai/assistant/authentication
|
|
161
|
+
|
|
162
|
+
Use user-based authentication (OAuth2/OIDC). Client-credentials-only flows are
|
|
163
|
+
not supported for the embedded app.
|
|
164
|
+
|
|
146
165
|
```javascript
|
|
147
166
|
const authResponse = await component.auth({
|
|
148
|
-
//
|
|
167
|
+
// Use the full token response from your IdP
|
|
149
168
|
access_token: 'YOUR_JWT',
|
|
150
169
|
token_type: 'Bearer',
|
|
151
|
-
|
|
170
|
+
// include other token fields from your provider response (expires_in, refresh_token, etc.)
|
|
152
171
|
...
|
|
153
172
|
});
|
|
154
173
|
```
|
|
@@ -157,10 +176,10 @@ const authResponse = await component.auth({
|
|
|
157
176
|
|
|
158
177
|
```javascript
|
|
159
178
|
await component.configureSession({
|
|
160
|
-
defaultLanguage:
|
|
161
|
-
defaultOutputLanguage:
|
|
162
|
-
defaultTemplateKey:
|
|
163
|
-
defaultMode:
|
|
179
|
+
defaultLanguage: "en",
|
|
180
|
+
defaultOutputLanguage: "en",
|
|
181
|
+
defaultTemplateKey: "discharge-summary",
|
|
182
|
+
defaultMode: "virtual",
|
|
164
183
|
});
|
|
165
184
|
```
|
|
166
185
|
|
|
@@ -176,7 +195,7 @@ await component.addFacts([
|
|
|
176
195
|
#### navigate
|
|
177
196
|
|
|
178
197
|
```javascript
|
|
179
|
-
await component.navigate(
|
|
198
|
+
await component.navigate("/interactions/123");
|
|
180
199
|
```
|
|
181
200
|
|
|
182
201
|
#### createInteraction
|
|
@@ -185,14 +204,14 @@ await component.navigate('/interactions/123');
|
|
|
185
204
|
const created = await component.createInteraction({
|
|
186
205
|
assignedUserId: null,
|
|
187
206
|
encounter: {
|
|
188
|
-
identifier:
|
|
189
|
-
status:
|
|
190
|
-
type:
|
|
207
|
+
identifier: "enc-123",
|
|
208
|
+
status: "in-progress",
|
|
209
|
+
type: "consult",
|
|
191
210
|
period: { startedAt: new Date().toISOString() },
|
|
192
|
-
title:
|
|
211
|
+
title: "Visit for cough",
|
|
193
212
|
},
|
|
194
213
|
patient: {
|
|
195
|
-
identifier:
|
|
214
|
+
identifier: "pat-456",
|
|
196
215
|
},
|
|
197
216
|
});
|
|
198
217
|
```
|
|
@@ -208,7 +227,7 @@ await component.stopRecording();
|
|
|
208
227
|
#### getStatus (debugging)
|
|
209
228
|
|
|
210
229
|
```javascript
|
|
211
|
-
console.log(component.getStatus());
|
|
230
|
+
console.log(await component.getStatus());
|
|
212
231
|
```
|
|
213
232
|
|
|
214
233
|
## Architecture
|
|
@@ -225,7 +244,7 @@ The component uses a `PostMessageHandler` utility class that:
|
|
|
225
244
|
The React component (`CortiEmbeddedReact`) is available as an additional export and provides:
|
|
226
245
|
|
|
227
246
|
- **Hook-based API access**: `useCortiEmbeddedApi(ref)` exposes instance-bound methods (`auth`, `navigate`, `createInteraction`, etc.)
|
|
228
|
-
- **Generic event stream**: `onEvent` receives
|
|
247
|
+
- **Generic event stream**: `onEvent` receives the wrapper's `event` `CustomEvent`, with `event.detail` shaped as `{ name, payload }`
|
|
229
248
|
- **Status hook**: `useCortiEmbeddedStatus(ref)` keeps latest status/reactive state
|
|
230
249
|
- **Multi-instance safety**: API methods are scoped to the ref you pass
|
|
231
250
|
- **React Props**: Standard React props like `className`, `style`, etc.
|
|
@@ -239,15 +258,19 @@ import {
|
|
|
239
258
|
type CortiEmbeddedReactRef,
|
|
240
259
|
useCortiEmbeddedApi,
|
|
241
260
|
useCortiEmbeddedStatus,
|
|
242
|
-
} from
|
|
261
|
+
} from "@corti/embedded-web/react";
|
|
243
262
|
```
|
|
244
263
|
|
|
245
264
|
### Event Listener Setup
|
|
246
265
|
|
|
247
|
-
- Use `onEvent`
|
|
248
|
-
-
|
|
266
|
+
- Use `onEvent` as the catch-all listener for the wrapper's generic `event` stream.
|
|
267
|
+
- `onEvent` receives the raw `event` `CustomEvent`, and `event.detail` has the following shape: `{ name: string; payload: unknown }`.
|
|
268
|
+
- That generic stream includes `embedded.ready` and other forwarded embedded events listed in our documentation.
|
|
269
|
+
- `onReady` is a convenience listener for the raw `embedded.ready` `CustomEvent`.
|
|
270
|
+
- Raw `ready`, `loaded`, and `error.triggered` are not forwarded through `onEvent`.
|
|
249
271
|
- Full event catalog and payload details are documented at:
|
|
250
272
|
- https://docs.corti.ai/assistant/events
|
|
273
|
+
- `onEvent`, `onReady`, and `onError` pass through the raw `CustomEvent`.
|
|
251
274
|
|
|
252
275
|
```tsx
|
|
253
276
|
<CortiEmbeddedReact
|
|
@@ -255,7 +278,7 @@ import {
|
|
|
255
278
|
onEvent={event => {
|
|
256
279
|
console.log(event.detail.name, event.detail.payload);
|
|
257
280
|
}}
|
|
258
|
-
onReady={
|
|
281
|
+
onReady={event => console.log("Ready", event.detail)}
|
|
259
282
|
onError={event => console.error(event.detail)}
|
|
260
283
|
/>
|
|
261
284
|
```
|
|
@@ -277,7 +300,7 @@ function Example() {
|
|
|
277
300
|
const api = useCortiEmbeddedApi(ref);
|
|
278
301
|
|
|
279
302
|
const run = async () => {
|
|
280
|
-
await api.auth({ access_token: '...', token_type: 'Bearer'
|
|
303
|
+
await api.auth({ access_token: '...', token_type: 'Bearer' });
|
|
281
304
|
const created = await api.createInteraction({ encounter: { ... } });
|
|
282
305
|
await api.navigate(`/session/${created.id}`);
|
|
283
306
|
};
|
|
@@ -295,7 +318,7 @@ For detailed React usage examples, see [docs/react-usage.md](./docs/react-usage.
|
|
|
295
318
|
|
|
296
319
|
## Package Structure
|
|
297
320
|
|
|
298
|
-
- **Default export**: Web component only (`dist/web-bundle.js
|
|
321
|
+
- **Default export**: Web component only (`dist/web-bundle.js`, readable non-minified bundle)
|
|
299
322
|
- **React export**: Web component + React component (`@corti/embedded-web/react`)
|
|
300
323
|
- **No dependencies**: Web component bundle has zero external dependencies
|
|
301
324
|
- **Peer dependencies**: React components require React as peer dependency only
|
package/dist/CortiEmbedded.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { Corti } from
|
|
2
|
-
import { LitElement, type PropertyValues } from
|
|
3
|
-
import type { ConfigureAppPayload,
|
|
1
|
+
import type { Corti } from "@corti/sdk";
|
|
2
|
+
import { LitElement, type PropertyValues } from "lit";
|
|
3
|
+
import type { ConfigureAppPayload, ConfigureAppResponse, CreateInteractionPayload, SetCredentialsPayload, CortiEmbeddedAPI, InteractionDetails, SessionConfig, User, GetStatusResponse, GetTemplatesResponse, KeycloakTokenResponse } from "./types";
|
|
4
4
|
export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAPI {
|
|
5
5
|
static styles: import("lit").CSSResult[];
|
|
6
6
|
visibility: string;
|
|
7
7
|
baseURL: string;
|
|
8
8
|
private postMessageHandler;
|
|
9
9
|
private normalizedBaseURL;
|
|
10
|
+
private getIframeAllowPolicy;
|
|
10
11
|
connectedCallback(): void;
|
|
11
12
|
disconnectedCallback(): void;
|
|
12
13
|
private setupPostMessageHandler;
|
|
@@ -22,7 +23,7 @@ export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAP
|
|
|
22
23
|
* @param credentials Authentication credentials
|
|
23
24
|
* @returns Promise resolving to user information
|
|
24
25
|
*/
|
|
25
|
-
auth(credentials:
|
|
26
|
+
auth(credentials: KeycloakTokenResponse): Promise<User>;
|
|
26
27
|
/**
|
|
27
28
|
* Create a new interaction
|
|
28
29
|
* @param encounter Encounter request data
|