@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.
- package/README.md +92 -50
- package/dist/CortiEmbedded.d.ts +34 -7
- package/dist/CortiEmbedded.js +274 -106
- package/dist/CortiEmbedded.js.map +1 -1
- package/dist/bundle.js +1699 -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 +5 -5
- package/dist/index.js.map +1 -1
- package/dist/public-types.d.ts +185 -0
- package/dist/public-types.js +2 -0
- package/dist/public-types.js.map +1 -0
- package/dist/react/CortiEmbeddedReact.d.ts +32 -23
- package/dist/react/CortiEmbeddedReact.js +69 -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 +36 -22
- package/dist/types/api.js.map +1 -1
- package/dist/types/config.d.ts +16 -2
- package/dist/types/config.js.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/payloads.d.ts +36 -4
- package/dist/types/payloads.js.map +1 -1
- package/dist/types/protocol.d.ts +9 -4
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/responses.d.ts +10 -2
- package/dist/types/responses.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 +1555 -13
- package/dist/web-index.d.ts +3 -3
- package/dist/web-index.js +4 -4
- package/dist/web-index.js.map +1 -1
- package/package.json +20 -20
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/corti-embedded.d.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import type { CortiEmbeddedAPI, CortiEmbeddedWindowAPI } from "./public-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Type representing the corti-embedded custom element in the DOM.
|
|
4
|
+
* When this package is installed, tag-name based APIs like
|
|
5
|
+
* document.querySelector('corti-embedded') and document.createElement('corti-embedded')
|
|
6
|
+
* are automatically typed via HTMLElementTagNameMap. Other lookups such as getElementById
|
|
7
|
+
* still return HTMLElement | null and require a cast or narrowing to CortiEmbeddedElement.
|
|
8
|
+
*/
|
|
9
|
+
export type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI;
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
CortiEmbedded?: CortiEmbeddedWindowAPI;
|
|
13
|
+
}
|
|
14
|
+
interface HTMLElementTagNameMap {
|
|
15
|
+
"corti-embedded": CortiEmbeddedElement;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/corti-embedded.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CortiEmbedded } from
|
|
1
|
+
import { CortiEmbedded } from "./CortiEmbedded.js";
|
|
2
2
|
// Register the main component
|
|
3
|
-
if (!customElements.get(
|
|
4
|
-
customElements.define(
|
|
3
|
+
if (!customElements.get("corti-embedded")) {
|
|
4
|
+
customElements.define("corti-embedded", CortiEmbedded);
|
|
5
|
+
}
|
|
5
6
|
//# sourceMappingURL=corti-embedded.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"corti-embedded.js","sourceRoot":"","sources":["../src/corti-embedded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"corti-embedded.js","sourceRoot":"","sources":["../src/corti-embedded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,8BAA8B;AAC9B,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;IAC1C,cAAc,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { CortiEmbedded } from \"./CortiEmbedded.js\";\nimport type {\n CortiEmbeddedAPI,\n CortiEmbeddedWindowAPI,\n} from \"./public-types.js\";\n\n// Register the main component\nif (!customElements.get(\"corti-embedded\")) {\n customElements.define(\"corti-embedded\", CortiEmbedded);\n}\n\n/**\n * Type representing the corti-embedded custom element in the DOM.\n * When this package is installed, tag-name based APIs like\n * document.querySelector('corti-embedded') and document.createElement('corti-embedded')\n * are automatically typed via HTMLElementTagNameMap. Other lookups such as getElementById\n * still return HTMLElement | null and require a cast or narrowing to CortiEmbeddedElement.\n */\nexport type CortiEmbeddedElement = HTMLElement & CortiEmbeddedAPI;\n\n// Extend Window interface\ndeclare global {\n interface Window {\n CortiEmbedded?: CortiEmbeddedWindowAPI;\n }\n interface HTMLElementTagNameMap {\n \"corti-embedded\": CortiEmbeddedElement;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { CortiEmbedded } from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export type { PostMessageHandlerCallbacks } from
|
|
1
|
+
import "./corti-embedded.js";
|
|
2
|
+
export { CortiEmbedded } from "./CortiEmbedded.js";
|
|
3
|
+
export * from "./react/index.js";
|
|
4
|
+
export * from "./public-types.js";
|
|
5
|
+
export type { PostMessageHandlerCallbacks } from "./utils/PostMessageHandler.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { CortiEmbedded } from
|
|
1
|
+
import "./corti-embedded.js";
|
|
2
|
+
export { CortiEmbedded } from "./CortiEmbedded.js";
|
|
3
3
|
// Export React components
|
|
4
|
-
export * from
|
|
5
|
-
// Export
|
|
6
|
-
export * from
|
|
4
|
+
export * from "./react/index.js";
|
|
5
|
+
// Export hand-owned public types only. The src/types folder is generated.
|
|
6
|
+
export * from "./public-types.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,0BAA0B;AAC1B,cAAc,kBAAkB,CAAC;AAEjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,0BAA0B;AAC1B,cAAc,kBAAkB,CAAC;AAEjC,0EAA0E;AAC1E,cAAc,mBAAmB,CAAC","sourcesContent":["import \"./corti-embedded.js\";\n\nexport { CortiEmbedded } from \"./CortiEmbedded.js\";\n\n// Export React components\nexport * from \"./react/index.js\";\n\n// Export hand-owned public types only. The src/types folder is generated.\nexport * from \"./public-types.js\";\n\n// Export PostMessageHandler types for advanced usage\nexport type { PostMessageHandlerCallbacks } from \"./utils/PostMessageHandler.js\";\n"]}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { ConfigureAppPayload as GeneratedConfigureApplicationPayload, ConfigureFeaturesConfig, ConfigurePayload } from "./types/config.js";
|
|
2
|
+
import type { AuthChangedEventPayload, DocumentEventPayload, ErrorEventPayload, InteractionCreatedEventPayload, NavigationChangedEventPayload, UsageEventPayload } from "./types/events.js";
|
|
3
|
+
import type { AddFactsPayload, ConfigureSessionPayload, CreateInteractionPayload, Fact, KeycloakTokenResponse, NavigatePayload, SetCredentialsPayload, SetInteractionOptionsPayload } from "./types/payloads.js";
|
|
4
|
+
import type { DefaultMode } from "./types/protocol.js";
|
|
5
|
+
import type { AuthResponse, ConfigureAppResponse as GeneratedConfigureApplicationResponse, ConfigureResponse, CreateInteractionResponse, GetStatusResponse, GetTemplatesResponse } from "./types/responses.js";
|
|
6
|
+
export type { AppearanceConfig, ConfigureFeaturesConfig, ConfigurePayload, LocaleConfig, NetworkConfig, UIConfig, } from "./types/config.js";
|
|
7
|
+
export type { AuthChangedEventPayload, DocumentEventPayload, ErrorEventPayload, InteractionCreatedEventPayload, NavigationChangedEventPayload, UsageEventPayload, } from "./types/events.js";
|
|
8
|
+
export type { AddFactsPayload, ConfigureSessionPayload, CreateInteractionPayload, Fact, KeycloakTokenResponse, NavigatePayload, SetCredentialsPayload, SetInteractionOptionsPayload, } from "./types/payloads.js";
|
|
9
|
+
export type { AnyDeprecatedEmbeddedEvent, AnyEmbeddedMessage, AnyEmbeddedRequest, AnyEmbeddedResponse, AnyEvent, APIVersion, BaseMessage, DeprecatedEmbeddedEvent, EmbeddedAction, EmbeddedEventMessage, EmbeddedRequest, EmbeddedResponse, MessageType, } from "./types/protocol.js";
|
|
10
|
+
export type { AuthResponse, ConfigureResponse, CreateInteractionResponse, EmbeddedTemplate, GetStatusResponse, GetTemplatesResponse, UserInfo, } from "./types/responses.js";
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use ConfigureFeaturesConfig instead.
|
|
13
|
+
*/
|
|
14
|
+
export type FeaturesConfig = ConfigureFeaturesConfig;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use ConfigurePayload for configure() or ConfigureApplicationPayload for configureApp().
|
|
17
|
+
*/
|
|
18
|
+
export type ConfigureAppPayload = ConfigurePayload;
|
|
19
|
+
export type ConfigureApplicationPayload = GeneratedConfigureApplicationPayload;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use ConfigureResponse for configure() or ConfigureApplicationResponse for configureApp().
|
|
22
|
+
*/
|
|
23
|
+
export type ConfigureAppResponse = ConfigureResponse;
|
|
24
|
+
export type ConfigureApplicationResponse = GeneratedConfigureApplicationResponse;
|
|
25
|
+
/**
|
|
26
|
+
* User information returned from authentication
|
|
27
|
+
*/
|
|
28
|
+
export interface User {
|
|
29
|
+
id: string;
|
|
30
|
+
email: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Details of a created interaction
|
|
34
|
+
*/
|
|
35
|
+
export interface InteractionDetails {
|
|
36
|
+
id: string;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Session configuration options
|
|
41
|
+
*/
|
|
42
|
+
export interface SessionConfig {
|
|
43
|
+
defaultLanguage?: string;
|
|
44
|
+
defaultOutputLanguage?: string;
|
|
45
|
+
defaultTemplateKey?: string;
|
|
46
|
+
defaultMode?: DefaultMode;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Event data types for component events
|
|
50
|
+
*/
|
|
51
|
+
export interface EmbeddedEventData {
|
|
52
|
+
ready: undefined;
|
|
53
|
+
"auth-changed": AuthChangedEventPayload;
|
|
54
|
+
"interaction-created": InteractionCreatedEventPayload;
|
|
55
|
+
"recording-started": undefined;
|
|
56
|
+
"recording-stopped": undefined;
|
|
57
|
+
"document-generated": DocumentEventPayload;
|
|
58
|
+
"document-updated": DocumentEventPayload;
|
|
59
|
+
"document-synced": DocumentEventPayload;
|
|
60
|
+
"navigation-changed": NavigationChangedEventPayload;
|
|
61
|
+
usage: UsageEventPayload;
|
|
62
|
+
error: ErrorEventPayload;
|
|
63
|
+
}
|
|
64
|
+
export interface CortiEmbeddedV1API {
|
|
65
|
+
auth(payload: KeycloakTokenResponse): Promise<AuthResponse>;
|
|
66
|
+
createInteraction(payload: CreateInteractionPayload): Promise<CreateInteractionResponse>;
|
|
67
|
+
addFacts(payload: AddFactsPayload): Promise<void>;
|
|
68
|
+
configureApp(payload: ConfigureApplicationPayload): Promise<ConfigureApplicationResponse>;
|
|
69
|
+
configureSession(payload: ConfigureSessionPayload): Promise<void>;
|
|
70
|
+
setInteractionOptions(payload: SetInteractionOptionsPayload): Promise<void>;
|
|
71
|
+
configure(payload: ConfigurePayload): Promise<ConfigureResponse>;
|
|
72
|
+
navigate(payload: NavigatePayload): Promise<void>;
|
|
73
|
+
startRecording(): Promise<void>;
|
|
74
|
+
stopRecording(): Promise<void>;
|
|
75
|
+
setCredentials(payload: SetCredentialsPayload): Promise<void>;
|
|
76
|
+
getStatus(): Promise<GetStatusResponse>;
|
|
77
|
+
getTemplates(): Promise<GetTemplatesResponse>;
|
|
78
|
+
}
|
|
79
|
+
export interface CortiEmbeddedWindowAPI {
|
|
80
|
+
v1: CortiEmbeddedV1API;
|
|
81
|
+
}
|
|
82
|
+
declare global {
|
|
83
|
+
interface Window {
|
|
84
|
+
CortiEmbedded?: CortiEmbeddedWindowAPI;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Event listener function type
|
|
89
|
+
*/
|
|
90
|
+
export type EventListener<T = unknown> = (data: T) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Public API interface for the Corti Embedded component
|
|
93
|
+
*/
|
|
94
|
+
export interface CortiEmbeddedAPI {
|
|
95
|
+
/**
|
|
96
|
+
* Authenticate with the Corti system
|
|
97
|
+
* @param credentials Authentication credentials
|
|
98
|
+
* @returns Promise resolving to user information
|
|
99
|
+
*/
|
|
100
|
+
auth(credentials: KeycloakTokenResponse): Promise<User>;
|
|
101
|
+
/**
|
|
102
|
+
* Create a new interaction
|
|
103
|
+
* @param encounter Encounter request data
|
|
104
|
+
* @returns Promise resolving to interaction details
|
|
105
|
+
*/
|
|
106
|
+
createInteraction(encounter: CreateInteractionPayload): Promise<InteractionDetails>;
|
|
107
|
+
/**
|
|
108
|
+
* Configure the current session
|
|
109
|
+
* @param config Session configuration
|
|
110
|
+
* @returns Promise that resolves when configuration is complete
|
|
111
|
+
* @deprecated Use setInteractionOptions() instead. See https://docs.corti.ai/assistant/deprecation-timeline.
|
|
112
|
+
*/
|
|
113
|
+
configureSession(config: SessionConfig): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Add facts to the current session
|
|
116
|
+
* @param facts Array of facts to add
|
|
117
|
+
* @returns Promise that resolves when facts are added
|
|
118
|
+
*/
|
|
119
|
+
addFacts(facts: Fact[]): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Navigate to a specific path within the embedded UI
|
|
122
|
+
* @param payload Navigation request payload or legacy path string
|
|
123
|
+
* @returns Promise that resolves when navigation is complete
|
|
124
|
+
*/
|
|
125
|
+
navigate(payload: NavigatePayload | string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Start recording
|
|
128
|
+
* @returns Promise that resolves when recording starts
|
|
129
|
+
*/
|
|
130
|
+
startRecording(): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Stop recording
|
|
133
|
+
* @returns Promise that resolves when recording stops
|
|
134
|
+
*/
|
|
135
|
+
stopRecording(): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Get current component status
|
|
138
|
+
* @returns Promise resolving to current status
|
|
139
|
+
*/
|
|
140
|
+
getStatus(): Promise<GetStatusResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Get all templates available to the current user
|
|
143
|
+
* @returns Promise resolving to list of templates
|
|
144
|
+
*/
|
|
145
|
+
getTemplates(): Promise<GetTemplatesResponse>;
|
|
146
|
+
/**
|
|
147
|
+
* Configure the embedded application
|
|
148
|
+
* @param config Application-level configuration
|
|
149
|
+
* @returns Promise that resolves when configuration is applied
|
|
150
|
+
*/
|
|
151
|
+
configureApp(config: ConfigureApplicationPayload): Promise<ConfigureApplicationResponse>;
|
|
152
|
+
/**
|
|
153
|
+
* Configure the application
|
|
154
|
+
* @param config Application configuration
|
|
155
|
+
* @returns Promise that resolves when configuration is applied
|
|
156
|
+
* @deprecated Use configureApp() and setInteractionOptions() instead. See https://docs.corti.ai/assistant/deprecation-timeline.
|
|
157
|
+
*/
|
|
158
|
+
configure(config: ConfigurePayload): Promise<ConfigureResponse>;
|
|
159
|
+
/**
|
|
160
|
+
* Set one-shot interaction options for the embedded instance.
|
|
161
|
+
*
|
|
162
|
+
* Each call replaces the full interaction-options snapshot for the embedded
|
|
163
|
+
* instance. Omitted branches reset to their defaults rather than preserving
|
|
164
|
+
* values from a previous call.
|
|
165
|
+
* @param config Interaction/session-level options
|
|
166
|
+
* @returns Promise that resolves when options are applied
|
|
167
|
+
*/
|
|
168
|
+
setInteractionOptions(config: SetInteractionOptionsPayload): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Set authentication credentials without triggering auth flow
|
|
171
|
+
* @param credentials Authentication credentials to store
|
|
172
|
+
* @returns Promise that resolves when credentials are set
|
|
173
|
+
*/
|
|
174
|
+
setCredentials(credentials: {
|
|
175
|
+
password: string;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Show the embedded UI
|
|
179
|
+
*/
|
|
180
|
+
show(): void;
|
|
181
|
+
/**
|
|
182
|
+
* Hide the embedded UI
|
|
183
|
+
*/
|
|
184
|
+
hide(): void;
|
|
185
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-types.js","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AppearanceConfig,\n ConfigureAppPayload as GeneratedConfigureApplicationPayload,\n ConfigureFeaturesConfig,\n ConfigurePayload,\n LocaleConfig,\n NetworkConfig,\n UIConfig,\n} from \"./types/config.js\";\nimport type {\n AuthChangedEventPayload,\n DocumentEventPayload,\n ErrorEventPayload,\n InteractionCreatedEventPayload,\n NavigationChangedEventPayload,\n UsageEventPayload,\n} from \"./types/events.js\";\nimport type {\n AddFactsPayload,\n ConfigureSessionPayload,\n CreateInteractionPayload,\n Fact,\n KeycloakTokenResponse,\n NavigatePayload,\n SetCredentialsPayload,\n SetInteractionOptionsPayload,\n} from \"./types/payloads.js\";\nimport type { DefaultMode } from \"./types/protocol.js\";\nimport type {\n AuthResponse,\n ConfigureAppResponse as GeneratedConfigureApplicationResponse,\n ConfigureResponse,\n CreateInteractionResponse,\n GetStatusResponse,\n GetTemplatesResponse,\n} from \"./types/responses.js\";\n\nexport type {\n AppearanceConfig,\n ConfigureFeaturesConfig,\n ConfigurePayload,\n LocaleConfig,\n NetworkConfig,\n UIConfig,\n} from \"./types/config.js\";\nexport type {\n AuthChangedEventPayload,\n DocumentEventPayload,\n ErrorEventPayload,\n InteractionCreatedEventPayload,\n NavigationChangedEventPayload,\n UsageEventPayload,\n} from \"./types/events.js\";\nexport type {\n AddFactsPayload,\n ConfigureSessionPayload,\n CreateInteractionPayload,\n Fact,\n KeycloakTokenResponse,\n NavigatePayload,\n SetCredentialsPayload,\n SetInteractionOptionsPayload,\n} from \"./types/payloads.js\";\nexport type {\n AnyDeprecatedEmbeddedEvent,\n AnyEmbeddedMessage,\n AnyEmbeddedRequest,\n AnyEmbeddedResponse,\n AnyEvent,\n APIVersion,\n BaseMessage,\n DeprecatedEmbeddedEvent,\n EmbeddedAction,\n EmbeddedEventMessage,\n EmbeddedRequest,\n EmbeddedResponse,\n MessageType,\n} from \"./types/protocol.js\";\nexport type {\n AuthResponse,\n ConfigureResponse,\n CreateInteractionResponse,\n EmbeddedTemplate,\n GetStatusResponse,\n GetTemplatesResponse,\n UserInfo,\n} from \"./types/responses.js\";\n\n/**\n * @deprecated Use ConfigureFeaturesConfig instead.\n */\nexport type FeaturesConfig = ConfigureFeaturesConfig;\n\n/**\n * @deprecated Use ConfigurePayload for configure() or ConfigureApplicationPayload for configureApp().\n */\nexport type ConfigureAppPayload = ConfigurePayload;\n\nexport type ConfigureApplicationPayload = GeneratedConfigureApplicationPayload;\n\n/**\n * @deprecated Use ConfigureResponse for configure() or ConfigureApplicationResponse for configureApp().\n */\nexport type ConfigureAppResponse = ConfigureResponse;\n\nexport type ConfigureApplicationResponse = GeneratedConfigureApplicationResponse;\n\n/**\n * User information returned from authentication\n */\nexport interface User {\n id: string;\n email: string;\n}\n\n/**\n * Details of a created interaction\n */\nexport interface InteractionDetails {\n id: string;\n createdAt: string;\n}\n\n/**\n * Session configuration options\n */\nexport interface SessionConfig {\n defaultLanguage?: string;\n defaultOutputLanguage?: string;\n defaultTemplateKey?: string;\n defaultMode?: DefaultMode;\n}\n\n/**\n * Event data types for component events\n */\nexport interface EmbeddedEventData {\n ready: undefined;\n \"auth-changed\": AuthChangedEventPayload;\n \"interaction-created\": InteractionCreatedEventPayload;\n \"recording-started\": undefined;\n \"recording-stopped\": undefined;\n \"document-generated\": DocumentEventPayload;\n \"document-updated\": DocumentEventPayload;\n \"document-synced\": DocumentEventPayload;\n \"navigation-changed\": NavigationChangedEventPayload;\n usage: UsageEventPayload;\n error: ErrorEventPayload;\n}\n\n// Window API Types\nexport interface CortiEmbeddedV1API {\n auth(payload: KeycloakTokenResponse): Promise<AuthResponse>;\n createInteraction(\n payload: CreateInteractionPayload,\n ): Promise<CreateInteractionResponse>;\n addFacts(payload: AddFactsPayload): Promise<void>;\n configureApp(\n payload: ConfigureApplicationPayload,\n ): Promise<ConfigureApplicationResponse>;\n configureSession(payload: ConfigureSessionPayload): Promise<void>;\n setInteractionOptions(payload: SetInteractionOptionsPayload): Promise<void>;\n configure(payload: ConfigurePayload): Promise<ConfigureResponse>;\n navigate(payload: NavigatePayload): Promise<void>;\n startRecording(): Promise<void>;\n stopRecording(): Promise<void>;\n setCredentials(payload: SetCredentialsPayload): Promise<void>;\n getStatus(): Promise<GetStatusResponse>;\n getTemplates(): Promise<GetTemplatesResponse>;\n}\n\nexport interface CortiEmbeddedWindowAPI {\n v1: CortiEmbeddedV1API;\n}\n\ndeclare global {\n interface Window {\n CortiEmbedded?: CortiEmbeddedWindowAPI;\n }\n}\n\n/**\n * Event listener function type\n */\nexport type EventListener<T = unknown> = (data: T) => void;\n\n/**\n * Public API interface for the Corti Embedded component\n */\nexport interface CortiEmbeddedAPI {\n /**\n * Authenticate with the Corti system\n * @param credentials Authentication credentials\n * @returns Promise resolving to user information\n */\n auth(credentials: KeycloakTokenResponse): Promise<User>;\n\n /**\n * Create a new interaction\n * @param encounter Encounter request data\n * @returns Promise resolving to interaction details\n */\n createInteraction(\n encounter: CreateInteractionPayload,\n ): Promise<InteractionDetails>;\n\n /**\n * Configure the current session\n * @param config Session configuration\n * @returns Promise that resolves when configuration is complete\n * @deprecated Use setInteractionOptions() instead. See https://docs.corti.ai/assistant/deprecation-timeline.\n */\n configureSession(config: SessionConfig): Promise<void>;\n\n /**\n * Add facts to the current session\n * @param facts Array of facts to add\n * @returns Promise that resolves when facts are added\n */\n addFacts(facts: Fact[]): Promise<void>;\n\n /**\n * Navigate to a specific path within the embedded UI\n * @param payload Navigation request payload or legacy path string\n * @returns Promise that resolves when navigation is complete\n */\n navigate(payload: NavigatePayload | string): Promise<void>;\n\n /**\n * Start recording\n * @returns Promise that resolves when recording starts\n */\n startRecording(): Promise<void>;\n\n /**\n * Stop recording\n * @returns Promise that resolves when recording stops\n */\n stopRecording(): Promise<void>;\n\n /**\n * Get current component status\n * @returns Promise resolving to current status\n */\n getStatus(): Promise<GetStatusResponse>;\n\n /**\n * Get all templates available to the current user\n * @returns Promise resolving to list of templates\n */\n getTemplates(): Promise<GetTemplatesResponse>;\n\n /**\n * Configure the embedded application\n * @param config Application-level configuration\n * @returns Promise that resolves when configuration is applied\n */\n configureApp(\n config: ConfigureApplicationPayload,\n ): Promise<ConfigureApplicationResponse>;\n\n /**\n * Configure the application\n * @param config Application configuration\n * @returns Promise that resolves when configuration is applied\n * @deprecated Use configureApp() and setInteractionOptions() instead. See https://docs.corti.ai/assistant/deprecation-timeline.\n */\n configure(config: ConfigurePayload): Promise<ConfigureResponse>;\n\n /**\n * Set one-shot interaction options for the embedded instance.\n *\n * Each call replaces the full interaction-options snapshot for the embedded\n * instance. Omitted branches reset to their defaults rather than preserving\n * values from a previous call.\n * @param config Interaction/session-level options\n * @returns Promise that resolves when options are applied\n */\n setInteractionOptions(config: SetInteractionOptionsPayload): Promise<void>;\n\n /**\n * Set authentication credentials without triggering auth flow\n * @param credentials Authentication credentials to store\n * @returns Promise that resolves when credentials are set\n */\n setCredentials(credentials: { password: string }): Promise<void>;\n\n /**\n * Show the embedded UI\n */\n show(): void;\n\n /**\n * Hide the embedded UI\n */\n hide(): void;\n}"]}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "../corti-embedded.js";
|
|
3
|
+
import type { CortiEmbedded } from "../CortiEmbedded.js";
|
|
4
|
+
import type { CortiEmbeddedAPI } from "../public-types.js";
|
|
4
5
|
export interface CortiEmbeddedEventDetail {
|
|
5
6
|
name: string;
|
|
6
7
|
payload: unknown;
|
|
7
8
|
}
|
|
9
|
+
export type CortiEmbeddedEvent = CustomEvent<CortiEmbeddedEventDetail>;
|
|
10
|
+
export type CortiEmbeddedReadyEvent = CustomEvent<Record<string, unknown>>;
|
|
11
|
+
export interface CortiEmbeddedErrorDetail {
|
|
12
|
+
message: string;
|
|
13
|
+
code?: string;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
}
|
|
8
16
|
export interface CortiEmbeddedReactProps {
|
|
9
17
|
baseURL: string;
|
|
10
|
-
visibility?:
|
|
11
|
-
onEvent?: (event:
|
|
12
|
-
onReady?: (event:
|
|
13
|
-
onError?: (event: CustomEvent<
|
|
18
|
+
visibility?: "visible" | "hidden";
|
|
19
|
+
onEvent?: (event: CortiEmbeddedEvent) => void;
|
|
20
|
+
onReady?: (event: CortiEmbeddedReadyEvent) => void;
|
|
21
|
+
onError?: (event: CustomEvent<CortiEmbeddedErrorDetail>) => void;
|
|
14
22
|
className?: string;
|
|
15
23
|
style?: React.CSSProperties;
|
|
16
24
|
}
|
|
17
25
|
export type CortiEmbeddedReactRef = CortiEmbedded & CortiEmbeddedAPI;
|
|
18
|
-
export * from
|
|
26
|
+
export * from "../public-types.js";
|
|
19
27
|
export declare const CortiEmbeddedReact: React.ForwardRefExoticComponent<CortiEmbeddedReactProps & React.RefAttributes<CortiEmbeddedReactRef>>;
|
|
20
28
|
export interface UseCortiEmbeddedStatusOptions {
|
|
21
29
|
enabled?: boolean;
|
|
@@ -23,26 +31,27 @@ export interface UseCortiEmbeddedStatusOptions {
|
|
|
23
31
|
shouldRefreshOnEvent?: (event: CortiEmbeddedEventDetail) => boolean;
|
|
24
32
|
}
|
|
25
33
|
export interface UseCortiEmbeddedStatusResult {
|
|
26
|
-
status: Awaited<ReturnType<CortiEmbeddedReactRef[
|
|
34
|
+
status: Awaited<ReturnType<CortiEmbeddedReactRef["getStatus"]>> | null;
|
|
27
35
|
isLoading: boolean;
|
|
28
36
|
error: unknown;
|
|
29
37
|
lastEvent: CortiEmbeddedEventDetail | null;
|
|
30
|
-
refresh: () => Promise<void>;
|
|
31
38
|
}
|
|
32
39
|
export declare function useCortiEmbeddedStatus(ref: React.RefObject<CortiEmbeddedReactRef | null>, options?: UseCortiEmbeddedStatusOptions): UseCortiEmbeddedStatusResult;
|
|
33
40
|
export interface UseCortiEmbeddedApiResult {
|
|
34
|
-
auth: (...args: Parameters<CortiEmbeddedReactRef[
|
|
35
|
-
createInteraction: (...args: Parameters<CortiEmbeddedReactRef[
|
|
36
|
-
configureSession: (...args: Parameters<CortiEmbeddedReactRef[
|
|
37
|
-
addFacts: (...args: Parameters<CortiEmbeddedReactRef[
|
|
38
|
-
navigate: (...args: Parameters<CortiEmbeddedReactRef[
|
|
39
|
-
startRecording: (...args: Parameters<CortiEmbeddedReactRef[
|
|
40
|
-
stopRecording: (...args: Parameters<CortiEmbeddedReactRef[
|
|
41
|
-
getStatus: (...args: Parameters<CortiEmbeddedReactRef[
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
auth: (...args: Parameters<CortiEmbeddedReactRef["auth"]>) => ReturnType<CortiEmbeddedReactRef["auth"]>;
|
|
42
|
+
createInteraction: (...args: Parameters<CortiEmbeddedReactRef["createInteraction"]>) => ReturnType<CortiEmbeddedReactRef["createInteraction"]>;
|
|
43
|
+
configureSession: (...args: Parameters<CortiEmbeddedReactRef["configureSession"]>) => ReturnType<CortiEmbeddedReactRef["configureSession"]>;
|
|
44
|
+
addFacts: (...args: Parameters<CortiEmbeddedReactRef["addFacts"]>) => ReturnType<CortiEmbeddedReactRef["addFacts"]>;
|
|
45
|
+
navigate: (...args: Parameters<CortiEmbeddedReactRef["navigate"]>) => ReturnType<CortiEmbeddedReactRef["navigate"]>;
|
|
46
|
+
startRecording: (...args: Parameters<CortiEmbeddedReactRef["startRecording"]>) => ReturnType<CortiEmbeddedReactRef["startRecording"]>;
|
|
47
|
+
stopRecording: (...args: Parameters<CortiEmbeddedReactRef["stopRecording"]>) => ReturnType<CortiEmbeddedReactRef["stopRecording"]>;
|
|
48
|
+
getStatus: (...args: Parameters<CortiEmbeddedReactRef["getStatus"]>) => ReturnType<CortiEmbeddedReactRef["getStatus"]>;
|
|
49
|
+
configureApp: (...args: Parameters<CortiEmbeddedReactRef["configureApp"]>) => ReturnType<CortiEmbeddedReactRef["configureApp"]>;
|
|
50
|
+
configure: (...args: Parameters<CortiEmbeddedReactRef["configure"]>) => ReturnType<CortiEmbeddedReactRef["configure"]>;
|
|
51
|
+
setInteractionOptions: (...args: Parameters<CortiEmbeddedReactRef["setInteractionOptions"]>) => ReturnType<CortiEmbeddedReactRef["setInteractionOptions"]>;
|
|
52
|
+
getTemplates: (...args: Parameters<CortiEmbeddedReactRef["getTemplates"]>) => ReturnType<CortiEmbeddedReactRef["getTemplates"]>;
|
|
53
|
+
setCredentials: (...args: Parameters<CortiEmbeddedReactRef["setCredentials"]>) => ReturnType<CortiEmbeddedReactRef["setCredentials"]>;
|
|
54
|
+
show: (...args: Parameters<CortiEmbeddedReactRef["show"]>) => ReturnType<CortiEmbeddedReactRef["show"]>;
|
|
55
|
+
hide: (...args: Parameters<CortiEmbeddedReactRef["hide"]>) => ReturnType<CortiEmbeddedReactRef["hide"]>;
|
|
47
56
|
}
|
|
48
57
|
export declare function useCortiEmbeddedApi(ref: React.RefObject<CortiEmbeddedReactRef | null>): UseCortiEmbeddedApiResult;
|
|
@@ -1,25 +1,73 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { CortiEmbedded } from '../CortiEmbedded.js';
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "../corti-embedded.js";
|
|
4
3
|
// Export public types
|
|
5
|
-
export * from
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
export * from "../public-types.js";
|
|
5
|
+
// Renders the custom element directly so React sets the ref to the actual
|
|
6
|
+
// CortiEmbedded DOM instance. This avoids the @lit/react wrapper chain that
|
|
7
|
+
// was preventing the ref from reaching the DOM node in React 19.
|
|
8
|
+
export const CortiEmbeddedReact = React.forwardRef(({ onEvent, onReady, onError, baseURL, visibility, className, style }, forwardedRef) => {
|
|
9
|
+
const internalRef = React.useRef(null);
|
|
10
|
+
const hasEmittedReadyRef = React.useRef(false);
|
|
11
|
+
// "Latest ref" pattern: update on every render so handlers are always
|
|
12
|
+
// current without re-attaching event listeners.
|
|
13
|
+
const onEventRef = React.useRef(onEvent);
|
|
14
|
+
const onReadyRef = React.useRef(onReady);
|
|
15
|
+
const onErrorRef = React.useRef(onError);
|
|
16
|
+
onEventRef.current = onEvent;
|
|
17
|
+
onReadyRef.current = onReady;
|
|
18
|
+
onErrorRef.current = onError;
|
|
19
|
+
// Expose the DOM element to the consumer's forwarded ref. Native element
|
|
20
|
+
// refs are set during React's mutation phase, before layout effects run,
|
|
21
|
+
// so internalRef.current is always populated when this executes.
|
|
22
|
+
React.useImperativeHandle(forwardedRef, () => internalRef.current, []);
|
|
23
|
+
// Keep LitElement reactive properties in sync with React props.
|
|
24
|
+
React.useLayoutEffect(() => {
|
|
25
|
+
if (internalRef.current)
|
|
26
|
+
internalRef.current.baseURL = baseURL;
|
|
27
|
+
}, [baseURL]);
|
|
28
|
+
React.useLayoutEffect(() => {
|
|
29
|
+
if (internalRef.current == null || visibility === undefined)
|
|
30
|
+
return;
|
|
31
|
+
internalRef.current.visibility = visibility;
|
|
32
|
+
}, [visibility]);
|
|
33
|
+
// Attach DOM event listeners once on mount. The latest-ref pattern above
|
|
34
|
+
// ensures handlers always call the current prop without re-attaching.
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const el = internalRef.current;
|
|
37
|
+
if (!el)
|
|
38
|
+
return undefined;
|
|
39
|
+
const handleEvent = (e) => onEventRef.current?.(e);
|
|
40
|
+
const handleReady = (e) => {
|
|
41
|
+
if (hasEmittedReadyRef.current)
|
|
42
|
+
return;
|
|
43
|
+
hasEmittedReadyRef.current = true;
|
|
44
|
+
onReadyRef.current?.(e);
|
|
45
|
+
};
|
|
46
|
+
const handleError = (e) => onErrorRef.current?.(e);
|
|
47
|
+
el.addEventListener("event", handleEvent);
|
|
48
|
+
el.addEventListener("embedded.ready", handleReady);
|
|
49
|
+
el.addEventListener("error", handleError);
|
|
50
|
+
return () => {
|
|
51
|
+
el.removeEventListener("event", handleEvent);
|
|
52
|
+
el.removeEventListener("embedded.ready", handleReady);
|
|
53
|
+
el.removeEventListener("error", handleError);
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
return React.createElement("corti-embedded", {
|
|
57
|
+
ref: internalRef,
|
|
58
|
+
baseurl: baseURL,
|
|
59
|
+
...(visibility !== undefined ? { visibility } : {}),
|
|
60
|
+
...(className !== undefined ? { className } : {}),
|
|
61
|
+
style,
|
|
62
|
+
});
|
|
16
63
|
});
|
|
64
|
+
CortiEmbeddedReact.displayName = "CortiEmbeddedReact";
|
|
17
65
|
export function useCortiEmbeddedStatus(ref, options = {}) {
|
|
18
66
|
const { enabled = true, onError, shouldRefreshOnEvent = event => {
|
|
19
67
|
const normalized = event.name.toLowerCase();
|
|
20
|
-
if (normalized.includes(
|
|
68
|
+
if (normalized.includes("getstatus"))
|
|
21
69
|
return false;
|
|
22
|
-
if (normalized.includes(
|
|
70
|
+
if (normalized.includes("statusreturned"))
|
|
23
71
|
return false;
|
|
24
72
|
return true;
|
|
25
73
|
}, } = options;
|
|
@@ -68,21 +116,20 @@ export function useCortiEmbeddedStatus(ref, options = {}) {
|
|
|
68
116
|
return;
|
|
69
117
|
refresh();
|
|
70
118
|
};
|
|
71
|
-
target.addEventListener(
|
|
72
|
-
return () => target.removeEventListener(
|
|
119
|
+
target.addEventListener("event", handleEvent);
|
|
120
|
+
return () => target.removeEventListener("event", handleEvent);
|
|
73
121
|
}, [enabled, ref, refresh]);
|
|
74
122
|
return {
|
|
75
123
|
status,
|
|
76
124
|
isLoading,
|
|
77
125
|
error,
|
|
78
126
|
lastEvent,
|
|
79
|
-
refresh,
|
|
80
127
|
};
|
|
81
128
|
}
|
|
82
129
|
function getCortiEmbeddedInstanceFromRefOrThrow(ref) {
|
|
83
130
|
const instance = ref.current;
|
|
84
131
|
if (!instance) {
|
|
85
|
-
throw new Error(
|
|
132
|
+
throw new Error("No active corti-embedded instance found for this ref. Mount <CortiEmbeddedReact ref={...} /> first.");
|
|
86
133
|
}
|
|
87
134
|
return instance;
|
|
88
135
|
}
|
|
@@ -97,12 +144,13 @@ export function useCortiEmbeddedApi(ref) {
|
|
|
97
144
|
startRecording: (...args) => getInstance().startRecording(...args),
|
|
98
145
|
stopRecording: (...args) => getInstance().stopRecording(...args),
|
|
99
146
|
getStatus: (...args) => getInstance().getStatus(...args),
|
|
147
|
+
configureApp: (...args) => getInstance().configureApp(...args),
|
|
100
148
|
configure: (...args) => getInstance().configure(...args),
|
|
149
|
+
setInteractionOptions: (...args) => getInstance().setInteractionOptions(...args),
|
|
101
150
|
getTemplates: (...args) => getInstance().getTemplates(...args),
|
|
102
151
|
setCredentials: (...args) => getInstance().setCredentials(...args),
|
|
103
152
|
show: (...args) => getInstance().show(...args),
|
|
104
153
|
hide: (...args) => getInstance().hide(...args),
|
|
105
154
|
}), [getInstance]);
|
|
106
155
|
}
|
|
107
|
-
CortiEmbeddedReact.displayName = 'CortiEmbeddedReact';
|
|
108
156
|
//# sourceMappingURL=CortiEmbeddedReact.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CortiEmbeddedReact.js","sourceRoot":"","sources":["../../src/react/CortiEmbeddedReact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAyBpD,sBAAsB;AACtB,cAAc,mBAAmB,CAAC;AAElC,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;IAChD,OAAO,EAAE,gBAAgB;IACzB,YAAY,EAAE,aAAa;IAC3B,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,OAAO;KACjB;CACF,CAEA,CAAC;AAgBF,MAAM,UAAU,sBAAsB,CACpC,GAAkD,EAClD,UAAyC,EAAE;IAE3C,MAAM,EACJ,OAAO,GAAG,IAAI,EACd,OAAO,EACP,oBAAoB,GAAG,KAAK,CAAC,EAAE;QAC7B,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5C,IAAI,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAO,KAAK,CAAC;QACnD,IAAI,UAAU,CAAC,QAAQ,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,GAAG,IAAI,CAAC;QACxD,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QACxD,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;QAC9D,cAAc,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;QAClE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAC9C,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KAC/C,CAAC,EACF,CAAC,WAAW,CAAC,CACd,CAAC;AACJ,CAAC;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAC","sourcesContent":["import { createComponent } from '@lit/react';\nimport * as React from 'react';\nimport { CortiEmbedded } from '../CortiEmbedded.js';\nimport type { CortiEmbeddedAPI } from '../types';\n\nexport interface CortiEmbeddedEventDetail {\n name: string;\n payload: unknown;\n}\n\n// Props interface\nexport interface CortiEmbeddedReactProps {\n baseURL: string;\n visibility?: 'visible' | 'hidden';\n\n // Event handlers\n onEvent?: (event: CustomEvent<CortiEmbeddedEventDetail>) => void;\n onReady?: (event: CustomEvent<unknown>) => void;\n onError?: (event: CustomEvent<unknown>) => void;\n\n // Additional props\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport type CortiEmbeddedReactRef = CortiEmbedded & CortiEmbeddedAPI;\n\n// Export public types\nexport * from '../types/index.js';\n\n// Create the component directly without additional forwardRef wrapping\nexport const CortiEmbeddedReact = createComponent({\n tagName: 'corti-embedded',\n elementClass: CortiEmbedded,\n react: React,\n events: {\n onEvent: 'embedded-event',\n onReady: 'ready',\n onError: 'error',\n },\n}) as React.ForwardRefExoticComponent<\n CortiEmbeddedReactProps & React.RefAttributes<CortiEmbeddedReactRef>\n>;\n\nexport interface UseCortiEmbeddedStatusOptions {\n enabled?: boolean;\n onError?: (error: unknown) => void;\n shouldRefreshOnEvent?: (event: CortiEmbeddedEventDetail) => boolean;\n}\n\nexport interface UseCortiEmbeddedStatusResult {\n status: Awaited<ReturnType<CortiEmbeddedReactRef['getStatus']>> | null;\n isLoading: boolean;\n error: unknown;\n lastEvent: CortiEmbeddedEventDetail | null;\n refresh: () => Promise<void>;\n}\n\nexport function useCortiEmbeddedStatus(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n options: UseCortiEmbeddedStatusOptions = {},\n): UseCortiEmbeddedStatusResult {\n const {\n enabled = true,\n onError,\n shouldRefreshOnEvent = event => {\n const normalized = event.name.toLowerCase();\n if (normalized.includes('getstatus')) return false;\n if (normalized.includes('statusreturned')) return false;\n return true;\n },\n } = options;\n const [status, setStatus] =\n React.useState<UseCortiEmbeddedStatusResult['status']>(null);\n const [isLoading, setIsLoading] = React.useState(false);\n const [error, setError] = React.useState<unknown>(null);\n const [lastEvent, setLastEvent] =\n React.useState<UseCortiEmbeddedStatusResult['lastEvent']>(null);\n const onErrorRef = React.useRef(onError);\n const shouldRefreshOnEventRef = React.useRef(shouldRefreshOnEvent);\n const isRefreshingRef = React.useRef(false);\n\n React.useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n React.useEffect(() => {\n shouldRefreshOnEventRef.current = shouldRefreshOnEvent;\n }, [shouldRefreshOnEvent]);\n\n const refresh = React.useCallback(async () => {\n if (!enabled || !ref.current || isRefreshingRef.current) return;\n isRefreshingRef.current = true;\n setIsLoading(true);\n try {\n const nextStatus = await ref.current.getStatus();\n setStatus(nextStatus);\n setError(null);\n } catch (refreshError) {\n setError(refreshError);\n onErrorRef.current?.(refreshError);\n } finally {\n setIsLoading(false);\n isRefreshingRef.current = false;\n }\n }, [enabled, ref]);\n\n React.useEffect(() => {\n if (!enabled || !ref.current) return undefined;\n\n const target = ref.current;\n const handleEvent = (event: Event) => {\n const { detail } = event as CustomEvent<CortiEmbeddedEventDetail>;\n setLastEvent(detail);\n if (!shouldRefreshOnEventRef.current(detail)) return;\n if (isRefreshingRef.current) return;\n refresh();\n };\n\n target.addEventListener('embedded-event', handleEvent);\n return () => target.removeEventListener('embedded-event', handleEvent);\n }, [enabled, ref, refresh]);\n\n return {\n status,\n isLoading,\n error,\n lastEvent,\n refresh,\n };\n}\n\nexport interface UseCortiEmbeddedApiResult {\n auth: (\n ...args: Parameters<CortiEmbeddedReactRef['auth']>\n ) => ReturnType<CortiEmbeddedReactRef['auth']>;\n createInteraction: (\n ...args: Parameters<CortiEmbeddedReactRef['createInteraction']>\n ) => ReturnType<CortiEmbeddedReactRef['createInteraction']>;\n configureSession: (\n ...args: Parameters<CortiEmbeddedReactRef['configureSession']>\n ) => ReturnType<CortiEmbeddedReactRef['configureSession']>;\n addFacts: (\n ...args: Parameters<CortiEmbeddedReactRef['addFacts']>\n ) => ReturnType<CortiEmbeddedReactRef['addFacts']>;\n navigate: (\n ...args: Parameters<CortiEmbeddedReactRef['navigate']>\n ) => ReturnType<CortiEmbeddedReactRef['navigate']>;\n startRecording: (\n ...args: Parameters<CortiEmbeddedReactRef['startRecording']>\n ) => ReturnType<CortiEmbeddedReactRef['startRecording']>;\n stopRecording: (\n ...args: Parameters<CortiEmbeddedReactRef['stopRecording']>\n ) => ReturnType<CortiEmbeddedReactRef['stopRecording']>;\n getStatus: (\n ...args: Parameters<CortiEmbeddedReactRef['getStatus']>\n ) => ReturnType<CortiEmbeddedReactRef['getStatus']>;\n configure: (\n ...args: Parameters<CortiEmbeddedReactRef['configure']>\n ) => ReturnType<CortiEmbeddedReactRef['configure']>;\n getTemplates: (\n ...args: Parameters<CortiEmbeddedReactRef['getTemplates']>\n ) => ReturnType<CortiEmbeddedReactRef['getTemplates']>;\n setCredentials: (\n ...args: Parameters<CortiEmbeddedReactRef['setCredentials']>\n ) => ReturnType<CortiEmbeddedReactRef['setCredentials']>;\n show: (\n ...args: Parameters<CortiEmbeddedReactRef['show']>\n ) => ReturnType<CortiEmbeddedReactRef['show']>;\n hide: (\n ...args: Parameters<CortiEmbeddedReactRef['hide']>\n ) => ReturnType<CortiEmbeddedReactRef['hide']>;\n}\n\nfunction getCortiEmbeddedInstanceFromRefOrThrow(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n): CortiEmbeddedReactRef {\n const instance = ref.current;\n if (!instance) {\n throw new Error(\n 'No active corti-embedded instance found for this ref. Mount <CortiEmbeddedReact ref={...} /> first.',\n );\n }\n return instance;\n}\n\nexport function useCortiEmbeddedApi(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n): UseCortiEmbeddedApiResult {\n const getInstance = React.useCallback(\n () => getCortiEmbeddedInstanceFromRefOrThrow(ref),\n [ref],\n );\n\n return React.useMemo(\n () => ({\n auth: (...args) => getInstance().auth(...args),\n createInteraction: (...args) => getInstance().createInteraction(...args),\n configureSession: (...args) => getInstance().configureSession(...args),\n addFacts: (...args) => getInstance().addFacts(...args),\n navigate: (...args) => getInstance().navigate(...args),\n startRecording: (...args) => getInstance().startRecording(...args),\n stopRecording: (...args) => getInstance().stopRecording(...args),\n getStatus: (...args) => getInstance().getStatus(...args),\n configure: (...args) => getInstance().configure(...args),\n getTemplates: (...args) => getInstance().getTemplates(...args),\n setCredentials: (...args) => getInstance().setCredentials(...args),\n show: (...args) => getInstance().show(...args),\n hide: (...args) => getInstance().hide(...args),\n }),\n [getInstance],\n );\n}\n\nCortiEmbeddedReact.displayName = 'CortiEmbeddedReact';\n"]}
|
|
1
|
+
{"version":3,"file":"CortiEmbeddedReact.js","sourceRoot":"","sources":["../../src/react/CortiEmbeddedReact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAmC9B,sBAAsB;AACtB,cAAc,oBAAoB,CAAC;A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IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KAC/C,CAAC,EACF,CAAC,WAAW,CAAC,CACd,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\nimport \"../corti-embedded.js\";\nimport type { CortiEmbedded } from \"../CortiEmbedded.js\";\nimport type { CortiEmbeddedAPI } from \"../public-types.js\";\n\nexport interface CortiEmbeddedEventDetail {\n name: string;\n payload: unknown;\n}\n\nexport type CortiEmbeddedEvent = CustomEvent<CortiEmbeddedEventDetail>;\nexport type CortiEmbeddedReadyEvent = CustomEvent<Record<string, unknown>>;\n\nexport interface CortiEmbeddedErrorDetail {\n message: string;\n code?: string;\n details?: unknown;\n}\n\n// Props interface\nexport interface CortiEmbeddedReactProps {\n baseURL: string;\n visibility?: \"visible\" | \"hidden\";\n\n // Event handlers receive the raw CustomEvent emitted by the custom element.\n onEvent?: (event: CortiEmbeddedEvent) => void;\n onReady?: (event: CortiEmbeddedReadyEvent) => void;\n onError?: (event: CustomEvent<CortiEmbeddedErrorDetail>) => void;\n\n // Additional props\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport type CortiEmbeddedReactRef = CortiEmbedded & CortiEmbeddedAPI;\n\n// Export public types\nexport * from \"../public-types.js\";\n\n// Renders the custom element directly so React sets the ref to the actual\n// CortiEmbedded DOM instance. This avoids the @lit/react wrapper chain that\n// was preventing the ref from reaching the DOM node in React 19.\nexport const CortiEmbeddedReact = React.forwardRef<\n CortiEmbeddedReactRef,\n CortiEmbeddedReactProps\n>(\n (\n { onEvent, onReady, onError, baseURL, visibility, className, style },\n forwardedRef,\n ) => {\n const internalRef = React.useRef<CortiEmbeddedReactRef | null>(null);\n const hasEmittedReadyRef = React.useRef(false);\n\n // \"Latest ref\" pattern: update on every render so handlers are always\n // current without re-attaching event listeners.\n const onEventRef = React.useRef(onEvent);\n const onReadyRef = React.useRef(onReady);\n const onErrorRef = React.useRef(onError);\n onEventRef.current = onEvent;\n onReadyRef.current = onReady;\n onErrorRef.current = onError;\n\n // Expose the DOM element to the consumer's forwarded ref. Native element\n // refs are set during React's mutation phase, before layout effects run,\n // so internalRef.current is always populated when this executes.\n React.useImperativeHandle(forwardedRef, () => internalRef.current!, []);\n\n // Keep LitElement reactive properties in sync with React props.\n React.useLayoutEffect(() => {\n if (internalRef.current) internalRef.current.baseURL = baseURL;\n }, [baseURL]);\n\n React.useLayoutEffect(() => {\n if (internalRef.current == null || visibility === undefined) return;\n internalRef.current.visibility = visibility;\n }, [visibility]);\n\n // Attach DOM event listeners once on mount. The latest-ref pattern above\n // ensures handlers always call the current prop without re-attaching.\n React.useEffect(() => {\n const el = internalRef.current;\n if (!el) return undefined;\n\n const handleEvent = (e: Event) =>\n onEventRef.current?.(e as CortiEmbeddedEvent);\n const handleReady = (e: Event) => {\n if (hasEmittedReadyRef.current) return;\n hasEmittedReadyRef.current = true;\n onReadyRef.current?.(e as CortiEmbeddedReadyEvent);\n };\n const handleError = (e: Event) =>\n onErrorRef.current?.(e as CustomEvent<CortiEmbeddedErrorDetail>);\n\n el.addEventListener(\"event\", handleEvent);\n el.addEventListener(\"embedded.ready\", handleReady);\n el.addEventListener(\"error\", handleError);\n return () => {\n el.removeEventListener(\"event\", handleEvent);\n el.removeEventListener(\"embedded.ready\", handleReady);\n el.removeEventListener(\"error\", handleError);\n };\n }, []);\n\n return React.createElement(\"corti-embedded\", {\n ref: internalRef,\n baseurl: baseURL,\n ...(visibility !== undefined ? { visibility } : {}),\n ...(className !== undefined ? { className } : {}),\n style,\n });\n },\n);\n\nCortiEmbeddedReact.displayName = \"CortiEmbeddedReact\";\n\nexport interface UseCortiEmbeddedStatusOptions {\n enabled?: boolean;\n onError?: (error: unknown) => void;\n shouldRefreshOnEvent?: (event: CortiEmbeddedEventDetail) => boolean;\n}\n\nexport interface UseCortiEmbeddedStatusResult {\n status: Awaited<ReturnType<CortiEmbeddedReactRef[\"getStatus\"]>> | null;\n isLoading: boolean;\n error: unknown;\n lastEvent: CortiEmbeddedEventDetail | null;\n}\n\nexport function useCortiEmbeddedStatus(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n options: UseCortiEmbeddedStatusOptions = {},\n): UseCortiEmbeddedStatusResult {\n const {\n enabled = true,\n onError,\n shouldRefreshOnEvent = event => {\n const normalized = event.name.toLowerCase();\n if (normalized.includes(\"getstatus\")) return false;\n if (normalized.includes(\"statusreturned\")) return false;\n return true;\n },\n } = options;\n const [status, setStatus] =\n React.useState<UseCortiEmbeddedStatusResult[\"status\"]>(null);\n const [isLoading, setIsLoading] = React.useState(false);\n const [error, setError] = React.useState<unknown>(null);\n const [lastEvent, setLastEvent] =\n React.useState<UseCortiEmbeddedStatusResult[\"lastEvent\"]>(null);\n const onErrorRef = React.useRef(onError);\n const shouldRefreshOnEventRef = React.useRef(shouldRefreshOnEvent);\n const isRefreshingRef = React.useRef(false);\n\n React.useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n React.useEffect(() => {\n shouldRefreshOnEventRef.current = shouldRefreshOnEvent;\n }, [shouldRefreshOnEvent]);\n\n const refresh = React.useCallback(async () => {\n if (!enabled || !ref.current || isRefreshingRef.current) return;\n isRefreshingRef.current = true;\n setIsLoading(true);\n try {\n const nextStatus = await ref.current.getStatus();\n setStatus(nextStatus);\n setError(null);\n } catch (refreshError) {\n setError(refreshError);\n onErrorRef.current?.(refreshError);\n } finally {\n setIsLoading(false);\n isRefreshingRef.current = false;\n }\n }, [enabled, ref]);\n\n React.useEffect(() => {\n if (!enabled || !ref.current) return undefined;\n\n const target = ref.current;\n const handleEvent = (event: Event) => {\n const { detail } = event as CustomEvent<CortiEmbeddedEventDetail>;\n setLastEvent(detail);\n if (!shouldRefreshOnEventRef.current(detail)) return;\n if (isRefreshingRef.current) return;\n refresh();\n };\n\n target.addEventListener(\"event\", handleEvent);\n return () => target.removeEventListener(\"event\", handleEvent);\n }, [enabled, ref, refresh]);\n\n return {\n status,\n isLoading,\n error,\n lastEvent,\n };\n}\n\nexport interface UseCortiEmbeddedApiResult {\n auth: (\n ...args: Parameters<CortiEmbeddedReactRef[\"auth\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"auth\"]>;\n createInteraction: (\n ...args: Parameters<CortiEmbeddedReactRef[\"createInteraction\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"createInteraction\"]>;\n configureSession: (\n ...args: Parameters<CortiEmbeddedReactRef[\"configureSession\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"configureSession\"]>;\n addFacts: (\n ...args: Parameters<CortiEmbeddedReactRef[\"addFacts\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"addFacts\"]>;\n navigate: (\n ...args: Parameters<CortiEmbeddedReactRef[\"navigate\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"navigate\"]>;\n startRecording: (\n ...args: Parameters<CortiEmbeddedReactRef[\"startRecording\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"startRecording\"]>;\n stopRecording: (\n ...args: Parameters<CortiEmbeddedReactRef[\"stopRecording\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"stopRecording\"]>;\n getStatus: (\n ...args: Parameters<CortiEmbeddedReactRef[\"getStatus\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"getStatus\"]>;\n configureApp: (\n ...args: Parameters<CortiEmbeddedReactRef[\"configureApp\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"configureApp\"]>;\n configure: (\n ...args: Parameters<CortiEmbeddedReactRef[\"configure\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"configure\"]>;\n setInteractionOptions: (\n ...args: Parameters<CortiEmbeddedReactRef[\"setInteractionOptions\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"setInteractionOptions\"]>;\n getTemplates: (\n ...args: Parameters<CortiEmbeddedReactRef[\"getTemplates\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"getTemplates\"]>;\n setCredentials: (\n ...args: Parameters<CortiEmbeddedReactRef[\"setCredentials\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"setCredentials\"]>;\n show: (\n ...args: Parameters<CortiEmbeddedReactRef[\"show\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"show\"]>;\n hide: (\n ...args: Parameters<CortiEmbeddedReactRef[\"hide\"]>\n ) => ReturnType<CortiEmbeddedReactRef[\"hide\"]>;\n}\n\nfunction getCortiEmbeddedInstanceFromRefOrThrow(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n): CortiEmbeddedReactRef {\n const instance = ref.current;\n if (!instance) {\n throw new Error(\n \"No active corti-embedded instance found for this ref. Mount <CortiEmbeddedReact ref={...} /> first.\",\n );\n }\n return instance;\n}\n\nexport function useCortiEmbeddedApi(\n ref: React.RefObject<CortiEmbeddedReactRef | null>,\n): UseCortiEmbeddedApiResult {\n const getInstance = React.useCallback(\n () => getCortiEmbeddedInstanceFromRefOrThrow(ref),\n [ref],\n );\n\n return React.useMemo(\n () => ({\n auth: (...args) => getInstance().auth(...args),\n createInteraction: (...args) => getInstance().createInteraction(...args),\n configureSession: (...args) => getInstance().configureSession(...args),\n addFacts: (...args) => getInstance().addFacts(...args),\n navigate: (...args) => getInstance().navigate(...args),\n startRecording: (...args) => getInstance().startRecording(...args),\n stopRecording: (...args) => getInstance().stopRecording(...args),\n getStatus: (...args) => getInstance().getStatus(...args),\n configureApp: (...args) => getInstance().configureApp(...args),\n configure: (...args) => getInstance().configure(...args),\n setInteractionOptions: (...args) =>\n getInstance().setInteractionOptions(...args),\n getTemplates: (...args) => getInstance().getTemplates(...args),\n setCredentials: (...args) => getInstance().setCredentials(...args),\n show: (...args) => getInstance().show(...args),\n hide: (...args) => getInstance().hide(...args),\n }),\n [getInstance],\n );\n}\n"]}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type { CortiEmbeddedReactProps, CortiEmbeddedReactRef, } from
|
|
1
|
+
export * from "./CortiEmbeddedReact.js";
|
|
2
|
+
export type { CortiEmbeddedReactProps, CortiEmbeddedReactRef, } from "./CortiEmbeddedReact.js";
|
package/dist/react/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./CortiEmbeddedReact.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC","sourcesContent":["export * from
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./CortiEmbeddedReact.js\";\nexport type {\n CortiEmbeddedReactProps,\n CortiEmbeddedReactRef,\n} from \"./CortiEmbeddedReact.js\";\n"]}
|
package/dist/styles/base.js
CHANGED
package/dist/styles/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/styles/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;;;;CAI5B,CAAC","sourcesContent":["import { css } from
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/styles/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;;;;CAI5B,CAAC","sourcesContent":["import { css } from \"lit\";\n\n/**\n * Base styles to be applied to all components within the application.\n */\nexport const baseStyles = css`\n * {\n box-sizing: border-box;\n }\n`;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { css } from
|
|
1
|
+
import { css } from "lit";
|
|
2
2
|
// Main container styles for the Corti Agent component
|
|
3
3
|
export const containerStyles = css `
|
|
4
4
|
:host {
|
|
@@ -19,7 +19,7 @@ export const containerStyles = css `
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/* Handle visibility state */
|
|
22
|
-
:host([visibility=
|
|
22
|
+
:host([visibility="hidden"]) {
|
|
23
23
|
display: none;
|
|
24
24
|
}
|
|
25
25
|
|