@corti/embedded-web 0.1.1 → 0.3.1

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.
Files changed (53) hide show
  1. package/README.md +92 -50
  2. package/dist/CortiEmbedded.d.ts +34 -7
  3. package/dist/CortiEmbedded.js +274 -106
  4. package/dist/CortiEmbedded.js.map +1 -1
  5. package/dist/bundle.js +1699 -20
  6. package/dist/corti-embedded.d.ts +17 -1
  7. package/dist/corti-embedded.js +4 -3
  8. package/dist/corti-embedded.js.map +1 -1
  9. package/dist/index.d.ts +5 -5
  10. package/dist/index.js +5 -5
  11. package/dist/index.js.map +1 -1
  12. package/dist/public-types.d.ts +185 -0
  13. package/dist/public-types.js +2 -0
  14. package/dist/public-types.js.map +1 -0
  15. package/dist/react/CortiEmbeddedReact.d.ts +32 -23
  16. package/dist/react/CortiEmbeddedReact.js +69 -21
  17. package/dist/react/CortiEmbeddedReact.js.map +1 -1
  18. package/dist/react/index.d.ts +2 -2
  19. package/dist/react/index.js +1 -1
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/styles/base.js +1 -1
  22. package/dist/styles/base.js.map +1 -1
  23. package/dist/styles/container-styles.js +2 -2
  24. package/dist/styles/container-styles.js.map +1 -1
  25. package/dist/styles/theme.js +2 -2
  26. package/dist/styles/theme.js.map +1 -1
  27. package/dist/types/api.d.ts +36 -22
  28. package/dist/types/api.js.map +1 -1
  29. package/dist/types/config.d.ts +16 -2
  30. package/dist/types/config.js.map +1 -1
  31. package/dist/types/index.js +1 -1
  32. package/dist/types/index.js.map +1 -1
  33. package/dist/types/payloads.d.ts +36 -4
  34. package/dist/types/payloads.js.map +1 -1
  35. package/dist/types/protocol.d.ts +9 -4
  36. package/dist/types/protocol.js.map +1 -1
  37. package/dist/types/responses.d.ts +10 -2
  38. package/dist/types/responses.js.map +1 -1
  39. package/dist/utils/PostMessageHandler.d.ts +19 -70
  40. package/dist/utils/PostMessageHandler.js +98 -201
  41. package/dist/utils/PostMessageHandler.js.map +1 -1
  42. package/dist/utils/baseUrl.js +8 -8
  43. package/dist/utils/baseUrl.js.map +1 -1
  44. package/dist/utils/embedUrl.js +3 -3
  45. package/dist/utils/embedUrl.js.map +1 -1
  46. package/dist/utils/errorFormatter.js +44 -20
  47. package/dist/utils/errorFormatter.js.map +1 -1
  48. package/dist/web-bundle.js +1555 -13
  49. package/dist/web-index.d.ts +3 -3
  50. package/dist/web-index.js +4 -4
  51. package/dist/web-index.js.map +1 -1
  52. package/package.json +20 -20
  53. 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
- base-url="https://assistant.eu.corti.app" <!-- REQUIRED -->
25
+ baseurl="https://assistant.eu.corti.app" <!-- REQUIRED -->
26
26
  ></corti-embedded>
27
27
  ```
28
28
 
@@ -43,22 +43,29 @@ const interaction = await myComponent.createInteraction({
43
43
  }
44
44
  });
45
45
 
46
- await myComponent.configureSession({"defaultTemplateKey": "soap_note"});
46
+ await myComponent.setInteractionOptions({
47
+ templates: {
48
+ defaultTemplate: {
49
+ behaviour: "fallback",
50
+ template: { source: "standard", id: "soap_note" },
51
+ },
52
+ },
53
+ });
47
54
  await myComponent.addFacts([{"text": "Chest pain", "group": "other"}]);
48
- await myComponent.navigate('/interactions/123');
55
+ await myComponent.navigate({ path: "/interactions/123" });
49
56
  await myComponent.show()
50
57
  ```
51
58
 
52
59
  #### Generic Event Listener (Web Component)
53
60
 
54
- Use `embedded-event` as the canonical event stream for web component integrations.
61
+ Use `event` as the canonical event stream for web component integrations (formerly `embedded-event`).
55
62
 
56
63
  - Event detail shape is `{ name: string; payload: unknown }`.
57
64
  - Full event catalog and payload details are documented at:
58
65
  - https://docs.corti.ai/assistant/events
59
66
 
60
67
  ```js
61
- myComponent.addEventListener('embedded-event', event => {
68
+ myComponent.addEventListener("event", event => {
62
69
  const { detail } = event;
63
70
  console.log(detail.name, detail.payload);
64
71
  });
@@ -67,55 +74,62 @@ myComponent.addEventListener('embedded-event', event => {
67
74
  ### React Component
68
75
 
69
76
  ```tsx
70
- import React, { useRef } from 'react';
77
+ import React, { useRef } from "react";
71
78
  import {
72
79
  CortiEmbeddedReact,
73
80
  type CortiEmbeddedReactRef,
81
+ type CortiEmbeddedEvent,
82
+ type CortiEmbeddedReadyEvent,
74
83
  useCortiEmbeddedApi,
75
84
  useCortiEmbeddedStatus,
76
- } from '@corti/embedded-web/react';
85
+ } from "@corti/embedded-web/react";
77
86
 
78
87
  function App() {
79
88
  const cortiRef = useRef<CortiEmbeddedReactRef>(null);
80
89
  const api = useCortiEmbeddedApi(cortiRef);
81
90
  const { status } = useCortiEmbeddedStatus(cortiRef);
82
91
 
83
- const handleReady = () => {
84
- console.log('Corti component is ready!');
92
+ const handleReady = (event: CortiEmbeddedReadyEvent) => {
93
+ console.log("Corti component is ready!", event.detail);
85
94
  };
86
95
 
87
- const handleEvent = (
88
- event: CustomEvent<{ name: string; payload: unknown }>,
89
- ) => {
90
- console.log('Event name:', event.detail.name);
91
- console.log('Event payload:', event.detail.payload);
96
+ const handleEvent = (event: CortiEmbeddedEvent) => {
97
+ console.log("Event name:", event.detail.name);
98
+ console.log("Event payload:", event.detail.payload);
92
99
  };
93
100
 
94
101
  const handleAuth = async () => {
95
102
  try {
96
103
  const user = await api.auth({
97
- access_token: 'your-token',
98
- token_type: 'Bearer',
104
+ access_token: "your-token",
105
+ token_type: "Bearer",
99
106
  // ... rest of the token response
100
107
  });
101
- console.log('Authenticated:', user);
102
-
103
- await api.configureSession({ defaultTemplateKey: 'soap_note' });
108
+ console.log("Authenticated:", user);
109
+
110
+ await api.setInteractionOptions({
111
+ templates: {
112
+ defaultTemplate: {
113
+ behaviour: "fallback",
114
+ template: { source: "standard", id: "soap_note" },
115
+ },
116
+ },
117
+ });
104
118
  await api.createInteraction({
105
119
  encounter: {
106
120
  identifier: `encounter-${Date.now()}`,
107
- status: 'planned',
108
- type: 'first_consultation',
121
+ status: "planned",
122
+ type: "first_consultation",
109
123
  period: { startedAt: new Date().toISOString() },
110
124
  },
111
125
  });
112
126
  } catch (error) {
113
- console.error('Auth failed:', error);
127
+ console.error("Auth failed:", error);
114
128
  }
115
129
  };
116
130
 
117
131
  return (
118
- <div style={{ height: '100vh' }}>
132
+ <div style={{ height: "100vh" }}>
119
133
  <button onClick={handleAuth}>Authenticate</button>
120
134
 
121
135
  <CortiEmbeddedReact
@@ -124,8 +138,8 @@ function App() {
124
138
  visibility="visible"
125
139
  onReady={handleReady}
126
140
  onEvent={handleEvent}
127
- onError={event => console.error('Embedded error:', event.detail)}
128
- style={{ width: '100%', height: '500px' }}
141
+ onError={event => console.error("Embedded error:", event.detail)}
142
+ style={{ width: "100%", height: "500px" }}
129
143
  />
130
144
 
131
145
  <pre>{JSON.stringify(status, null, 2)}</pre>
@@ -137,7 +151,7 @@ function App() {
137
151
  ### Show/Hide the Component
138
152
 
139
153
  ```javascript
140
- const component = document.getElementById('corti-component');
154
+ const component = document.getElementById("corti-component");
141
155
 
142
156
  // Show the chat interface
143
157
  component.show();
@@ -154,7 +168,7 @@ component.hide();
154
168
 
155
169
  Authentication is required before using the embedded app. The payload passed to
156
170
  `component.auth(...)` should come directly from your identity provider token
157
- response (for example, Keycloak/OIDC token endpoint response), plus `mode`.
171
+ response (for example, Keycloak/OIDC token endpoint response).
158
172
 
159
173
  - API details and payload shape: https://docs.corti.ai/assistant/api-reference#auth
160
174
  - End-to-end authentication guidance: https://docs.corti.ai/assistant/authentication
@@ -164,23 +178,45 @@ not supported for the embedded app.
164
178
 
165
179
  ```javascript
166
180
  const authResponse = await component.auth({
167
- // Use the full token response from your IdP + mode
181
+ // Use the full token response from your IdP
168
182
  access_token: 'YOUR_JWT',
169
183
  token_type: 'Bearer',
170
184
  // include other token fields from your provider response (expires_in, refresh_token, etc.)
171
- mode: 'stateful',
172
185
  ...
173
186
  });
174
187
  ```
175
188
 
176
- #### configureSession
189
+ #### configureApp
190
+
191
+ ```javascript
192
+ await component.configureApp({
193
+ ui: {
194
+ aiChat: true,
195
+ navigation: false,
196
+ },
197
+ appearance: {
198
+ primaryColor: "#000000",
199
+ },
200
+ });
201
+ ```
202
+
203
+ #### setInteractionOptions
177
204
 
178
205
  ```javascript
179
- await component.configureSession({
180
- defaultLanguage: 'en',
181
- defaultOutputLanguage: 'en',
182
- defaultTemplateKey: 'discharge-summary',
183
- defaultMode: 'virtual',
206
+ await component.setInteractionOptions({
207
+ mode: {
208
+ fallback: "virtual",
209
+ options: ["in-person", "virtual"],
210
+ },
211
+ spokenLanguage: {
212
+ fallback: "en",
213
+ },
214
+ templates: {
215
+ defaultTemplate: {
216
+ behaviour: "fallback",
217
+ template: { source: "standard", id: "discharge-summary" },
218
+ },
219
+ },
184
220
  });
185
221
  ```
186
222
 
@@ -196,7 +232,7 @@ await component.addFacts([
196
232
  #### navigate
197
233
 
198
234
  ```javascript
199
- await component.navigate('/interactions/123');
235
+ await component.navigate({ path: "/interactions/123" });
200
236
  ```
201
237
 
202
238
  #### createInteraction
@@ -205,14 +241,14 @@ await component.navigate('/interactions/123');
205
241
  const created = await component.createInteraction({
206
242
  assignedUserId: null,
207
243
  encounter: {
208
- identifier: 'enc-123',
209
- status: 'in-progress',
210
- type: 'consult',
244
+ identifier: "enc-123",
245
+ status: "in-progress",
246
+ type: "consult",
211
247
  period: { startedAt: new Date().toISOString() },
212
- title: 'Visit for cough',
248
+ title: "Visit for cough",
213
249
  },
214
250
  patient: {
215
- identifier: 'pat-456',
251
+ identifier: "pat-456",
216
252
  },
217
253
  });
218
254
  ```
@@ -228,7 +264,7 @@ await component.stopRecording();
228
264
  #### getStatus (debugging)
229
265
 
230
266
  ```javascript
231
- console.log(component.getStatus());
267
+ console.log(await component.getStatus());
232
268
  ```
233
269
 
234
270
  ## Architecture
@@ -245,7 +281,7 @@ The component uses a `PostMessageHandler` utility class that:
245
281
  The React component (`CortiEmbeddedReact`) is available as an additional export and provides:
246
282
 
247
283
  - **Hook-based API access**: `useCortiEmbeddedApi(ref)` exposes instance-bound methods (`auth`, `navigate`, `createInteraction`, etc.)
248
- - **Generic event stream**: `onEvent` receives all embedded events as `{ name, payload }`
284
+ - **Generic event stream**: `onEvent` receives the wrapper's `event` `CustomEvent`, with `event.detail` shaped as `{ name, payload }`
249
285
  - **Status hook**: `useCortiEmbeddedStatus(ref)` keeps latest status/reactive state
250
286
  - **Multi-instance safety**: API methods are scoped to the ref you pass
251
287
  - **React Props**: Standard React props like `className`, `style`, etc.
@@ -259,15 +295,19 @@ import {
259
295
  type CortiEmbeddedReactRef,
260
296
  useCortiEmbeddedApi,
261
297
  useCortiEmbeddedStatus,
262
- } from '@corti/embedded-web/react';
298
+ } from "@corti/embedded-web/react";
263
299
  ```
264
300
 
265
301
  ### Event Listener Setup
266
302
 
267
- - Use `onEvent` for all embedded events.
268
- - Event detail shape is `{ name: string; payload: unknown }`.
303
+ - Use `onEvent` as the catch-all listener for the wrapper's generic `event` stream.
304
+ - `onEvent` receives the raw `event` `CustomEvent`, and `event.detail` has the following shape: `{ name: string; payload: unknown }`.
305
+ - That generic stream includes `embedded.ready` and other forwarded embedded events listed in our documentation.
306
+ - `onReady` is a convenience listener for the raw `embedded.ready` `CustomEvent`.
307
+ - Raw `ready`, `loaded`, and `error.triggered` are not forwarded through `onEvent`.
269
308
  - Full event catalog and payload details are documented at:
270
309
  - https://docs.corti.ai/assistant/events
310
+ - `onEvent`, `onReady`, and `onError` pass through the raw `CustomEvent`.
271
311
 
272
312
  ```tsx
273
313
  <CortiEmbeddedReact
@@ -275,7 +315,7 @@ import {
275
315
  onEvent={event => {
276
316
  console.log(event.detail.name, event.detail.payload);
277
317
  }}
278
- onReady={() => console.log('Ready')}
318
+ onReady={event => console.log("Ready", event.detail)}
279
319
  onError={event => console.error(event.detail)}
280
320
  />
281
321
  ```
@@ -297,9 +337,9 @@ function Example() {
297
337
  const api = useCortiEmbeddedApi(ref);
298
338
 
299
339
  const run = async () => {
300
- await api.auth({ access_token: '...', token_type: 'Bearer', mode: 'stateful' });
340
+ await api.auth({ access_token: '...', token_type: 'Bearer' });
301
341
  const created = await api.createInteraction({ encounter: { ... } });
302
- await api.navigate(`/session/${created.id}`);
342
+ await api.navigate({ path: `/session/${created.id}` });
303
343
  };
304
344
 
305
345
  return (
@@ -313,9 +353,11 @@ function Example() {
313
353
 
314
354
  For detailed React usage examples, see [docs/react-usage.md](./docs/react-usage.md).
315
355
 
356
+ For configuration migration details, see [docs/migration-guide.md](./docs/migration-guide.md) and [docs/deprecation-timeline.md](./docs/deprecation-timeline.md).
357
+
316
358
  ## Package Structure
317
359
 
318
- - **Default export**: Web component only (`dist/web-bundle.js`)
360
+ - **Default export**: Web component only (`dist/web-bundle.js`, readable non-minified bundle)
319
361
  - **React export**: Web component + React component (`@corti/embedded-web/react`)
320
362
  - **No dependencies**: Web component bundle has zero external dependencies
321
363
  - **Peer dependencies**: React components require React as peer dependency only
@@ -1,18 +1,32 @@
1
- import type { Corti } from '@corti/sdk';
2
- import { LitElement, type PropertyValues } from 'lit';
3
- import type { ConfigureAppPayload, SetCredentialsPayload, AuthCredentials, ConfigureAppResponse, CortiEmbeddedAPI, InteractionDetails, CreateInteractionPayload, SessionConfig, User, GetStatusResponse, GetTemplatesResponse } from './types';
1
+ import type { Corti } from "@corti/sdk";
2
+ import { LitElement, type PropertyValues } from "lit";
3
+ import type { ConfigureApplicationPayload, ConfigureApplicationResponse, ConfigurePayload, ConfigureResponse, CreateInteractionPayload, NavigatePayload, SetInteractionOptionsPayload, SetCredentialsPayload, CortiEmbeddedAPI, InteractionDetails, SessionConfig, User, GetStatusResponse, GetTemplatesResponse, KeycloakTokenResponse } from "./public-types.js";
4
+ type DOMEventListener = ((event: Event) => void) | {
5
+ handleEvent(event: Event): void;
6
+ };
7
+ type DOMAddEventListenerOptions = boolean | {
8
+ capture?: boolean;
9
+ once?: boolean;
10
+ passive?: boolean;
11
+ signal?: AbortSignal;
12
+ };
4
13
  export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAPI {
5
14
  static styles: import("lit").CSSResult[];
6
15
  visibility: string;
7
16
  baseURL: string;
8
17
  private postMessageHandler;
9
18
  private normalizedBaseURL;
19
+ private warnedDeprecatedEventSubscriptions;
20
+ addEventListener(type: string, callback: DOMEventListener, options?: DOMAddEventListenerOptions): void;
21
+ private warnDeprecatedEventSubscription;
22
+ private getIframeAllowPolicy;
10
23
  connectedCallback(): void;
11
24
  disconnectedCallback(): void;
12
25
  private setupPostMessageHandler;
13
26
  private dispatchPublicEvent;
14
27
  private dispatchEmbeddedEvent;
15
28
  private dispatchErrorEvent;
29
+ private static warnDeprecatedAPI;
16
30
  private isRealIframeLoad;
17
31
  private handleIframeLoad;
18
32
  private getIframe;
@@ -22,7 +36,7 @@ export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAP
22
36
  * @param credentials Authentication credentials
23
37
  * @returns Promise resolving to user information
24
38
  */
25
- auth(credentials: AuthCredentials): Promise<User>;
39
+ auth(credentials: KeycloakTokenResponse): Promise<User>;
26
40
  /**
27
41
  * Create a new interaction
28
42
  * @param encounter Encounter request data
@@ -43,10 +57,10 @@ export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAP
43
57
  addFacts(facts: Corti.FactsCreateInput[]): Promise<void>;
44
58
  /**
45
59
  * Navigate to a specific path within the embedded UI
46
- * @param path Path to navigate to
60
+ * @param payload Navigation request payload or legacy path string
47
61
  * @returns Promise that resolves when navigation is complete
48
62
  */
49
- navigate(path: string): Promise<void>;
63
+ navigate(payload: NavigatePayload | string): Promise<void>;
50
64
  /**
51
65
  * Start recording
52
66
  * @returns Promise that resolves when recording starts
@@ -67,7 +81,19 @@ export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAP
67
81
  * @param config Component configuration
68
82
  * @returns Promise that resolves when configuration is applied
69
83
  */
70
- configure(config: ConfigureAppPayload): Promise<ConfigureAppResponse>;
84
+ configureApp(config: ConfigureApplicationPayload): Promise<ConfigureApplicationResponse>;
85
+ /**
86
+ * Configure the component
87
+ * @param config Component configuration
88
+ * @returns Promise that resolves when configuration is applied
89
+ */
90
+ configure(config: ConfigurePayload): Promise<ConfigureResponse>;
91
+ /**
92
+ * Set one-shot interaction options for the embedded instance.
93
+ * @param config Interaction/session-level options
94
+ * @returns Promise that resolves when options are applied
95
+ */
96
+ setInteractionOptions(config: SetInteractionOptionsPayload): Promise<void>;
71
97
  /**
72
98
  * Set authentication credentials without triggering auth flow
73
99
  * @param credentials Authentication credentials to store
@@ -104,3 +130,4 @@ export declare class CortiEmbedded extends LitElement implements CortiEmbeddedAP
104
130
  };
105
131
  render(): import("lit-html").TemplateResult<1>;
106
132
  }
133
+ export {};