@corti/embedded-web 0.1.1 → 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 +47 -44
- 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 +17 -28
- 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 -201
- 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 -20
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ npm install @corti/embedded-web
|
|
|
22
22
|
```html
|
|
23
23
|
<corti-embedded
|
|
24
24
|
id="corti-component"
|
|
25
|
-
|
|
25
|
+
baseurl="https://assistant.eu.corti.app" <!-- REQUIRED -->
|
|
26
26
|
></corti-embedded>
|
|
27
27
|
```
|
|
28
28
|
|
|
@@ -51,14 +51,14 @@ await myComponent.show()
|
|
|
51
51
|
|
|
52
52
|
#### Generic Event Listener (Web Component)
|
|
53
53
|
|
|
54
|
-
Use `
|
|
54
|
+
Use `event` as the canonical event stream for web component integrations (formerly `embedded-event`).
|
|
55
55
|
|
|
56
56
|
- Event detail shape is `{ name: string; payload: unknown }`.
|
|
57
57
|
- Full event catalog and payload details are documented at:
|
|
58
58
|
- https://docs.corti.ai/assistant/events
|
|
59
59
|
|
|
60
60
|
```js
|
|
61
|
-
myComponent.addEventListener(
|
|
61
|
+
myComponent.addEventListener("event", event => {
|
|
62
62
|
const { detail } = event;
|
|
63
63
|
console.log(detail.name, detail.payload);
|
|
64
64
|
});
|
|
@@ -67,55 +67,55 @@ myComponent.addEventListener('embedded-event', event => {
|
|
|
67
67
|
### React Component
|
|
68
68
|
|
|
69
69
|
```tsx
|
|
70
|
-
import React, { useRef } from
|
|
70
|
+
import React, { useRef } from "react";
|
|
71
71
|
import {
|
|
72
72
|
CortiEmbeddedReact,
|
|
73
73
|
type CortiEmbeddedReactRef,
|
|
74
|
+
type CortiEmbeddedEvent,
|
|
75
|
+
type CortiEmbeddedReadyEvent,
|
|
74
76
|
useCortiEmbeddedApi,
|
|
75
77
|
useCortiEmbeddedStatus,
|
|
76
|
-
} from
|
|
78
|
+
} from "@corti/embedded-web/react";
|
|
77
79
|
|
|
78
80
|
function App() {
|
|
79
81
|
const cortiRef = useRef<CortiEmbeddedReactRef>(null);
|
|
80
82
|
const api = useCortiEmbeddedApi(cortiRef);
|
|
81
83
|
const { status } = useCortiEmbeddedStatus(cortiRef);
|
|
82
84
|
|
|
83
|
-
const handleReady = () => {
|
|
84
|
-
console.log(
|
|
85
|
+
const handleReady = (event: CortiEmbeddedReadyEvent) => {
|
|
86
|
+
console.log("Corti component is ready!", event.detail);
|
|
85
87
|
};
|
|
86
88
|
|
|
87
|
-
const handleEvent = (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
console.log('Event name:', event.detail.name);
|
|
91
|
-
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);
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const handleAuth = async () => {
|
|
95
95
|
try {
|
|
96
96
|
const user = await api.auth({
|
|
97
|
-
access_token:
|
|
98
|
-
token_type:
|
|
97
|
+
access_token: "your-token",
|
|
98
|
+
token_type: "Bearer",
|
|
99
99
|
// ... rest of the token response
|
|
100
100
|
});
|
|
101
|
-
console.log(
|
|
101
|
+
console.log("Authenticated:", user);
|
|
102
102
|
|
|
103
|
-
await api.configureSession({ defaultTemplateKey:
|
|
103
|
+
await api.configureSession({ defaultTemplateKey: "soap_note" });
|
|
104
104
|
await api.createInteraction({
|
|
105
105
|
encounter: {
|
|
106
106
|
identifier: `encounter-${Date.now()}`,
|
|
107
|
-
status:
|
|
108
|
-
type:
|
|
107
|
+
status: "planned",
|
|
108
|
+
type: "first_consultation",
|
|
109
109
|
period: { startedAt: new Date().toISOString() },
|
|
110
110
|
},
|
|
111
111
|
});
|
|
112
112
|
} catch (error) {
|
|
113
|
-
console.error(
|
|
113
|
+
console.error("Auth failed:", error);
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
return (
|
|
118
|
-
<div style={{ height:
|
|
118
|
+
<div style={{ height: "100vh" }}>
|
|
119
119
|
<button onClick={handleAuth}>Authenticate</button>
|
|
120
120
|
|
|
121
121
|
<CortiEmbeddedReact
|
|
@@ -124,8 +124,8 @@ function App() {
|
|
|
124
124
|
visibility="visible"
|
|
125
125
|
onReady={handleReady}
|
|
126
126
|
onEvent={handleEvent}
|
|
127
|
-
onError={event => console.error(
|
|
128
|
-
style={{ width:
|
|
127
|
+
onError={event => console.error("Embedded error:", event.detail)}
|
|
128
|
+
style={{ width: "100%", height: "500px" }}
|
|
129
129
|
/>
|
|
130
130
|
|
|
131
131
|
<pre>{JSON.stringify(status, null, 2)}</pre>
|
|
@@ -137,7 +137,7 @@ function App() {
|
|
|
137
137
|
### Show/Hide the Component
|
|
138
138
|
|
|
139
139
|
```javascript
|
|
140
|
-
const component = document.getElementById(
|
|
140
|
+
const component = document.getElementById("corti-component");
|
|
141
141
|
|
|
142
142
|
// Show the chat interface
|
|
143
143
|
component.show();
|
|
@@ -154,7 +154,7 @@ component.hide();
|
|
|
154
154
|
|
|
155
155
|
Authentication is required before using the embedded app. The payload passed to
|
|
156
156
|
`component.auth(...)` should come directly from your identity provider token
|
|
157
|
-
response (for example, Keycloak/OIDC token endpoint response)
|
|
157
|
+
response (for example, Keycloak/OIDC token endpoint response).
|
|
158
158
|
|
|
159
159
|
- API details and payload shape: https://docs.corti.ai/assistant/api-reference#auth
|
|
160
160
|
- End-to-end authentication guidance: https://docs.corti.ai/assistant/authentication
|
|
@@ -164,11 +164,10 @@ not supported for the embedded app.
|
|
|
164
164
|
|
|
165
165
|
```javascript
|
|
166
166
|
const authResponse = await component.auth({
|
|
167
|
-
// Use the full token response from your IdP
|
|
167
|
+
// Use the full token response from your IdP
|
|
168
168
|
access_token: 'YOUR_JWT',
|
|
169
169
|
token_type: 'Bearer',
|
|
170
170
|
// include other token fields from your provider response (expires_in, refresh_token, etc.)
|
|
171
|
-
mode: 'stateful',
|
|
172
171
|
...
|
|
173
172
|
});
|
|
174
173
|
```
|
|
@@ -177,10 +176,10 @@ const authResponse = await component.auth({
|
|
|
177
176
|
|
|
178
177
|
```javascript
|
|
179
178
|
await component.configureSession({
|
|
180
|
-
defaultLanguage:
|
|
181
|
-
defaultOutputLanguage:
|
|
182
|
-
defaultTemplateKey:
|
|
183
|
-
defaultMode:
|
|
179
|
+
defaultLanguage: "en",
|
|
180
|
+
defaultOutputLanguage: "en",
|
|
181
|
+
defaultTemplateKey: "discharge-summary",
|
|
182
|
+
defaultMode: "virtual",
|
|
184
183
|
});
|
|
185
184
|
```
|
|
186
185
|
|
|
@@ -196,7 +195,7 @@ await component.addFacts([
|
|
|
196
195
|
#### navigate
|
|
197
196
|
|
|
198
197
|
```javascript
|
|
199
|
-
await component.navigate(
|
|
198
|
+
await component.navigate("/interactions/123");
|
|
200
199
|
```
|
|
201
200
|
|
|
202
201
|
#### createInteraction
|
|
@@ -205,14 +204,14 @@ await component.navigate('/interactions/123');
|
|
|
205
204
|
const created = await component.createInteraction({
|
|
206
205
|
assignedUserId: null,
|
|
207
206
|
encounter: {
|
|
208
|
-
identifier:
|
|
209
|
-
status:
|
|
210
|
-
type:
|
|
207
|
+
identifier: "enc-123",
|
|
208
|
+
status: "in-progress",
|
|
209
|
+
type: "consult",
|
|
211
210
|
period: { startedAt: new Date().toISOString() },
|
|
212
|
-
title:
|
|
211
|
+
title: "Visit for cough",
|
|
213
212
|
},
|
|
214
213
|
patient: {
|
|
215
|
-
identifier:
|
|
214
|
+
identifier: "pat-456",
|
|
216
215
|
},
|
|
217
216
|
});
|
|
218
217
|
```
|
|
@@ -228,7 +227,7 @@ await component.stopRecording();
|
|
|
228
227
|
#### getStatus (debugging)
|
|
229
228
|
|
|
230
229
|
```javascript
|
|
231
|
-
console.log(component.getStatus());
|
|
230
|
+
console.log(await component.getStatus());
|
|
232
231
|
```
|
|
233
232
|
|
|
234
233
|
## Architecture
|
|
@@ -245,7 +244,7 @@ The component uses a `PostMessageHandler` utility class that:
|
|
|
245
244
|
The React component (`CortiEmbeddedReact`) is available as an additional export and provides:
|
|
246
245
|
|
|
247
246
|
- **Hook-based API access**: `useCortiEmbeddedApi(ref)` exposes instance-bound methods (`auth`, `navigate`, `createInteraction`, etc.)
|
|
248
|
-
- **Generic event stream**: `onEvent` receives
|
|
247
|
+
- **Generic event stream**: `onEvent` receives the wrapper's `event` `CustomEvent`, with `event.detail` shaped as `{ name, payload }`
|
|
249
248
|
- **Status hook**: `useCortiEmbeddedStatus(ref)` keeps latest status/reactive state
|
|
250
249
|
- **Multi-instance safety**: API methods are scoped to the ref you pass
|
|
251
250
|
- **React Props**: Standard React props like `className`, `style`, etc.
|
|
@@ -259,15 +258,19 @@ import {
|
|
|
259
258
|
type CortiEmbeddedReactRef,
|
|
260
259
|
useCortiEmbeddedApi,
|
|
261
260
|
useCortiEmbeddedStatus,
|
|
262
|
-
} from
|
|
261
|
+
} from "@corti/embedded-web/react";
|
|
263
262
|
```
|
|
264
263
|
|
|
265
264
|
### Event Listener Setup
|
|
266
265
|
|
|
267
|
-
- Use `onEvent`
|
|
268
|
-
-
|
|
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`.
|
|
269
271
|
- Full event catalog and payload details are documented at:
|
|
270
272
|
- https://docs.corti.ai/assistant/events
|
|
273
|
+
- `onEvent`, `onReady`, and `onError` pass through the raw `CustomEvent`.
|
|
271
274
|
|
|
272
275
|
```tsx
|
|
273
276
|
<CortiEmbeddedReact
|
|
@@ -275,7 +278,7 @@ import {
|
|
|
275
278
|
onEvent={event => {
|
|
276
279
|
console.log(event.detail.name, event.detail.payload);
|
|
277
280
|
}}
|
|
278
|
-
onReady={
|
|
281
|
+
onReady={event => console.log("Ready", event.detail)}
|
|
279
282
|
onError={event => console.error(event.detail)}
|
|
280
283
|
/>
|
|
281
284
|
```
|
|
@@ -297,7 +300,7 @@ function Example() {
|
|
|
297
300
|
const api = useCortiEmbeddedApi(ref);
|
|
298
301
|
|
|
299
302
|
const run = async () => {
|
|
300
|
-
await api.auth({ access_token: '...', token_type: 'Bearer'
|
|
303
|
+
await api.auth({ access_token: '...', token_type: 'Bearer' });
|
|
301
304
|
const created = await api.createInteraction({ encounter: { ... } });
|
|
302
305
|
await api.navigate(`/session/${created.id}`);
|
|
303
306
|
};
|
|
@@ -315,7 +318,7 @@ For detailed React usage examples, see [docs/react-usage.md](./docs/react-usage.
|
|
|
315
318
|
|
|
316
319
|
## Package Structure
|
|
317
320
|
|
|
318
|
-
- **Default export**: Web component only (`dist/web-bundle.js
|
|
321
|
+
- **Default export**: Web component only (`dist/web-bundle.js`, readable non-minified bundle)
|
|
319
322
|
- **React export**: Web component + React component (`@corti/embedded-web/react`)
|
|
320
323
|
- **No dependencies**: Web component bundle has zero external dependencies
|
|
321
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
|