Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions src/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Public API types for SDK consumers

import type { ConfigureAppPayload } from "./config.js";
import type { ConfigureAppPayload, ConfigurePayload } from "./config.js";
import type {
AuthChangedEventPayload,
DocumentEventPayload,
Expand All @@ -16,18 +16,20 @@ import type {
Fact,
KeycloakTokenResponse,
NavigatePayload,
SetInteractionOptionsPayload,
SetCredentialsPayload,
} from "./payloads.js";
import type { DefaultMode } from "./protocol.js";
import type {
AuthResponse,
ConfigureAppResponse,
ConfigureResponse,
CreateInteractionResponse,
GetStatusResponse,
GetTemplatesResponse,
} from "./responses.js";

export type { ConfigureAppPayload } from "./config.js";
export type { ConfigureAppPayload, ConfigurePayload } from "./config.js";
// Re-export common types for public API
export type { UserInfo } from "./responses.js";

Expand Down Expand Up @@ -77,12 +79,12 @@ export interface EmbeddedEventData {
// Window API Types
export interface CortiEmbeddedV1API {
auth(payload: KeycloakTokenResponse): Promise<AuthResponse>;
createInteraction(
payload: CreateInteractionPayload,
): Promise<CreateInteractionResponse>;
createInteraction(payload: CreateInteractionPayload): Promise<CreateInteractionResponse>;
addFacts(payload: AddFactsPayload): Promise<void>;
configureApp(payload: ConfigureAppPayload): Promise<ConfigureAppResponse>;
configureSession(payload: ConfigureSessionPayload): Promise<void>;
configure(payload: ConfigureAppPayload): Promise<ConfigureAppResponse>;
setInteractionOptions(payload: SetInteractionOptionsPayload): Promise<void>;
configure(payload: ConfigurePayload): Promise<ConfigureResponse>;
navigate(payload: NavigatePayload): Promise<void>;
startRecording(): Promise<void>;
stopRecording(): Promise<void>;
Expand All @@ -94,6 +96,13 @@ export interface CortiEmbeddedWindowAPI {
v1: CortiEmbeddedV1API;
}

// Extend Window interface
declare global {
interface Window {
CortiEmbedded?: CortiEmbeddedWindowAPI;
}
}

/**
* Event listener function type
*/
Expand All @@ -115,9 +124,7 @@ export interface CortiEmbeddedAPI {
* @param encounter Encounter request data
* @returns Promise resolving to interaction details
*/
createInteraction(
encounter: CreateInteractionPayload,
): Promise<InteractionDetails>;
createInteraction(encounter: CreateInteractionPayload): Promise<InteractionDetails>;

/**
* Configure the current session
Expand Down Expand Up @@ -164,19 +171,37 @@ export interface CortiEmbeddedAPI {
*/
getTemplates(): Promise<GetTemplatesResponse>;

/**
* Configure the embedded application
* @param config Application-level configuration
* @returns Promise that resolves when configuration is applied
*/
configureApp(config: ConfigureAppPayload): Promise<ConfigureAppResponse>;

/**
* Configure the application
* @param config Application configuration
* @returns Promise that resolves when configuration is applied
*/
configure(config: ConfigureAppPayload): Promise<ConfigureAppResponse>;
configure(config: ConfigurePayload): Promise<ConfigureResponse>;

/**
* Set one-shot interaction options for the embedded instance.
*
* Each call patches the provided interaction-options branches onto the current
* snapshot for the embedded instance. Omitted branches preserve their existing
* values from previous calls.
* @param config Interaction/session-level options
* @returns Promise that resolves when options are applied
*/
setInteractionOptions(config: SetInteractionOptionsPayload): Promise<void>;

/**
* Set authentication credentials without triggering auth flow
* @param credentials Authentication credentials to store
* @returns Promise that resolves when credentials are set
*/
setCredentials(credentials: SetCredentialsPayload): Promise<void>;
setCredentials(credentials: { password: string }): Promise<void>;

/**
* Show the embedded UI
Expand Down
20 changes: 18 additions & 2 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ export interface AppearanceConfig {
primaryColor: string | null;
}

export interface FeaturesConfig {
export interface UIConfig {
interactionTitle: boolean;
aiChat: boolean;
documentFeedback: boolean;
navigation: boolean;
}

export interface ConfigureFeaturesConfig {
interactionTitle: boolean;
aiChat: boolean;
documentFeedback: boolean;
Expand All @@ -24,9 +31,18 @@ export interface NetworkConfig {
websocketBaseUrl?: string | null;
}

export interface ConfigurePayload {
debug?: boolean;
appearance?: Partial<AppearanceConfig>;
features?: Partial<ConfigureFeaturesConfig>;
locale?: Partial<LocaleConfig>;
network?: Partial<NetworkConfig>;
}

export interface ConfigureAppPayload {
debug?: boolean;
ui?: Partial<UIConfig>;
appearance?: Partial<AppearanceConfig>;
features?: Partial<FeaturesConfig>;
locale?: Partial<LocaleConfig>;
network?: Partial<NetworkConfig>;
}
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Main exports for @corti/embedded-types
// Main exports for @assistant/embedded-types

// Public API types
export * from "./api.js";
Expand Down
43 changes: 43 additions & 0 deletions src/types/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,49 @@ export interface ConfigureSessionPayload {
defaultMode?: DefaultMode;
}

export interface InteractionModeOptions {
fallback: DefaultMode;
options: DefaultMode[];
}

export interface SpokenLanguageOptions {
fallback: string;
}

export interface InteractionTemplateReference {
source: "standard";
id: string;
}

export interface DefaultInteractionTemplateOptions {
behaviour: "fallback";
template: InteractionTemplateReference;
}

export interface InteractionTemplateSources {
personal?: {
enabled: boolean;
};
}

export interface InteractionTemplateOptions {
sources?: InteractionTemplateSources;
defaultTemplate?: DefaultInteractionTemplateOptions;
}

export interface InteractionDocumentOptions {
actions?: {
sync?: boolean;
};
}

export interface SetInteractionOptionsPayload {
mode?: InteractionModeOptions;
spokenLanguage?: SpokenLanguageOptions;
templates?: InteractionTemplateOptions;
documents?: InteractionDocumentOptions;
}

// Navigate payload
export interface NavigatePayload {
path: string;
Expand Down
22 changes: 14 additions & 8 deletions src/types/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

export type APIVersion = "v1";

export type MessageType =
| "CORTI_EMBEDDED"
| "CORTI_EMBEDDED_RESPONSE"
| "CORTI_EMBEDDED_EVENT";
export type MessageType = "CORTI_EMBEDDED" | "CORTI_EMBEDDED_RESPONSE" | "CORTI_EMBEDDED_EVENT";

export type DefaultMode = "virtual" | "in-person";

export type EmbeddedAction =
| "auth"
| "createInteraction"
| "addFacts"
| "configureApp"
| "configureSession"
| "setInteractionOptions"
| "navigate"
| "startRecording"
| "stopRecording"
Expand Down Expand Up @@ -92,6 +91,14 @@ export interface ConfigureSessionRequest extends EmbeddedRequest {
action: "configureSession";
}

export interface ConfigureAppRequest extends EmbeddedRequest {
action: "configureApp";
}

export interface SetInteractionOptionsRequest extends EmbeddedRequest {
action: "setInteractionOptions";
}

export interface NavigateRequest extends EmbeddedRequest {
action: "navigate";
}
Expand Down Expand Up @@ -170,9 +177,11 @@ export type AnyEmbeddedRequest =
| AuthRequest
| CreateInteractionRequest
| AddFactsRequest
| ConfigureAppRequest
| ConfigureSessionRequest
| GetTemplatesRequest
| NavigateRequest
| SetInteractionOptionsRequest
| StartRecordingRequest
| StopRecordingRequest
| GetStatusRequest
Expand All @@ -196,7 +205,4 @@ export type AnyDeprecatedEmbeddedEvent =

export type AnyEvent = EmbeddedEventMessage | AnyDeprecatedEmbeddedEvent;

export type AnyEmbeddedMessage =
| AnyEmbeddedRequest
| AnyEmbeddedResponse
| AnyDeprecatedEmbeddedEvent;
export type AnyEmbeddedMessage = AnyEmbeddedRequest | AnyEmbeddedResponse | AnyEvent;
19 changes: 17 additions & 2 deletions src/types/responses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Response types for embedded API

import type { AppearanceConfig, FeaturesConfig, LocaleConfig, NetworkConfig } from "./config.js";
import type {
AppearanceConfig,
ConfigureFeaturesConfig,
LocaleConfig,
NetworkConfig,
UIConfig,
} from "./config.js";
import type { EmbeddedInterviewDetails } from "./generated/interview-details.js";

export interface UserInfo {
Expand Down Expand Up @@ -49,9 +55,18 @@ export interface GetTemplatesResponse {
templates: EmbeddedTemplate[];
}

export interface ConfigureResponse {
debug?: boolean;
appearance: AppearanceConfig;
features: ConfigureFeaturesConfig;
locale: LocaleConfig;
network: NetworkConfig;
}

export interface ConfigureAppResponse {
debug?: boolean;
appearance: AppearanceConfig;
features: FeaturesConfig;
ui: UIConfig;
locale: LocaleConfig;
network: NetworkConfig;
}
Loading