@ahmedramez-org/chat 0.0.0-stage → 0.6.0-beta.2
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 +373 -2
- package/contract/bridge.d.ts +119 -0
- package/contract/bridge.js +249 -0
- package/contract/conformance.d.ts +51 -0
- package/contract/conformance.js +335 -0
- package/contract/host.d.ts +213 -0
- package/contract/host.js +380 -0
- package/contract/index.d.ts +922 -0
- package/contract/index.js +94 -0
- package/contract/launch.d.ts +110 -0
- package/contract/launch.js +164 -0
- package/index.d.ts +51 -0
- package/index.js +424 -0
- package/package.json +77 -4
- package/react.d.ts +129 -0
- package/react.js +312 -0
- package/window.js +515 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** The host contract version: a host passes it as `version`, the embed bridge stamps it as `v`. */
|
|
2
|
+
export const CONTRACT_VERSION = 1;
|
|
3
|
+
/**
|
|
4
|
+
* The oldest host contract version the chat still mounts: a host's `version` from this one to
|
|
5
|
+
* `CONTRACT_VERSION` is accepted, anything else is `INCOMPATIBLE_HOST_CONTRACT`.
|
|
6
|
+
*/
|
|
7
|
+
export const MIN_CONTRACT_VERSION = 1;
|
|
8
|
+
/**
|
|
9
|
+
* The languages the chat speaks, each named in itself, with the tag a host sends as `locale`
|
|
10
|
+
* to choose it (any tag of the same language works too; others get English). For a host that
|
|
11
|
+
* offers the choice, as the app's account page does.
|
|
12
|
+
*/
|
|
13
|
+
export const CHAT_LANGUAGES = [
|
|
14
|
+
{ locale: 'en-US', label: 'English' },
|
|
15
|
+
{ locale: 'ar-EG', label: 'العربية' },
|
|
16
|
+
{ locale: 'de-DE', label: 'Deutsch' },
|
|
17
|
+
{ locale: 'es-ES', label: 'Español' },
|
|
18
|
+
{ locale: 'fr-FR', label: 'Français' },
|
|
19
|
+
{ locale: 'it-IT', label: 'Italiano' },
|
|
20
|
+
{ locale: 'ja-JP', label: '日本語' },
|
|
21
|
+
{ locale: 'zh-CN', label: '中文' },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* The built-in kinds the chat handles itself: its upload browser and contexts
|
|
25
|
+
* loaded through `connection.incortaApi`. `'insight'` is not one: insights come
|
|
26
|
+
* from the dashboard the host has open, so only a host source can list them.
|
|
27
|
+
*/
|
|
28
|
+
export const BUILT_IN_CONTEXT_KINDS = [
|
|
29
|
+
'file',
|
|
30
|
+
'business-view',
|
|
31
|
+
'physical-table',
|
|
32
|
+
'ai-container',
|
|
33
|
+
'knowledge-store',
|
|
34
|
+
];
|
|
35
|
+
/** The composer trigger characters the chat can serve itself. */
|
|
36
|
+
export const BUILT_IN_TRIGGERS = ['@', '#'];
|
|
37
|
+
/**
|
|
38
|
+
* Reads the namespaced-kind convention. Returns null for bare legacy kinds.
|
|
39
|
+
* Framework-free on purpose: hosts use this inside `canRender` to route by
|
|
40
|
+
* vendor without re-implementing the convention.
|
|
41
|
+
*/
|
|
42
|
+
export function parseArtifactKind(kind) {
|
|
43
|
+
const separator = kind.indexOf('.');
|
|
44
|
+
if (separator <= 0 || separator === kind.length - 1)
|
|
45
|
+
return null;
|
|
46
|
+
return { namespace: kind.slice(0, separator), name: kind.slice(separator + 1) };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* True when the artifact carries the given payload schema version (or is an
|
|
50
|
+
* unversioned legacy payload and `acceptUnversioned` allows it). The guard a
|
|
51
|
+
* host renderer should call first in `canRender`.
|
|
52
|
+
*/
|
|
53
|
+
export function artifactMatchesSchema(artifact, supportedVersion, options) {
|
|
54
|
+
if (artifact.schemaVersion === undefined)
|
|
55
|
+
return options?.acceptUnversioned ?? false;
|
|
56
|
+
return artifact.schemaVersion === supportedVersion;
|
|
57
|
+
}
|
|
58
|
+
export const SURFACE_NAMES = ['header', 'picker', 'history', 'model', 'canvas'];
|
|
59
|
+
export class ChatError extends Error {
|
|
60
|
+
code;
|
|
61
|
+
constructor(code, message, options) {
|
|
62
|
+
super(message, options);
|
|
63
|
+
this.name = 'ChatError';
|
|
64
|
+
this.code = code;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** What the class was called before its rename: a chat built then still throws it. */
|
|
68
|
+
const EARLIER_ERROR_NAME = 'NexusChatPublicError';
|
|
69
|
+
/**
|
|
70
|
+
* A `ChatError`, with `code` when given, from this copy of the contract or any
|
|
71
|
+
* other (another bundle's class is a different class, so this reads `name` and `code`). An
|
|
72
|
+
* earlier chat's error counts too: a host that loads one still reads its
|
|
73
|
+
* `INCOMPATIBLE_HOST_CONTRACT`, and says an update is needed instead of offering a retry.
|
|
74
|
+
*/
|
|
75
|
+
export function isChatError(error, code) {
|
|
76
|
+
if (typeof error !== 'object' || error === null)
|
|
77
|
+
return false;
|
|
78
|
+
const { name, code: actual } = error;
|
|
79
|
+
return ((name === 'ChatError' || name === EARLIER_ERROR_NAME) &&
|
|
80
|
+
typeof actual === 'string' &&
|
|
81
|
+
(code === undefined || actual === code));
|
|
82
|
+
}
|
|
83
|
+
export function assertCompatibleHost(options) {
|
|
84
|
+
const version = options.version;
|
|
85
|
+
if (typeof version !== 'number' ||
|
|
86
|
+
!Number.isInteger(version) ||
|
|
87
|
+
version < MIN_CONTRACT_VERSION ||
|
|
88
|
+
version > CONTRACT_VERSION) {
|
|
89
|
+
const supported = MIN_CONTRACT_VERSION === CONTRACT_VERSION
|
|
90
|
+
? `${CONTRACT_VERSION}`
|
|
91
|
+
: `${MIN_CONTRACT_VERSION} to ${CONTRACT_VERSION}`;
|
|
92
|
+
throw new ChatError('INCOMPATIBLE_HOST_CONTRACT', `The chat requires host contract ${supported}; received ${String(options.version)}.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The launch of an app's chat (a WebView, an extension's frame, Electron) in token mode: what
|
|
3
|
+
* its splash shows while the chat page loads, and what it shows when the page cannot. One pure
|
|
4
|
+
* reducer every app runs, so each launch reads the same: the splash alone at first, a status
|
|
5
|
+
* line once loading takes a while, a hint with Try again when it takes long, and a failure with
|
|
6
|
+
* its actions when it cannot load. Ids only: each app says them in its own words (the English
|
|
7
|
+
* ones below are the desktop app's and the extension's). Re-exported from `./host`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const LAUNCH_STEPS: readonly ["connecting", "signingIn", "loadingChats", "reconnecting"];
|
|
10
|
+
/** What the launch is doing, for the status line. */
|
|
11
|
+
export type LaunchStep = (typeof LAUNCH_STEPS)[number];
|
|
12
|
+
export declare const LAUNCH_FAILURES: readonly ["offline", "unreachable", "unavailable", "chatFailed", "incompatible"];
|
|
13
|
+
/** Why the chat could not load. */
|
|
14
|
+
export type LaunchFailure = (typeof LAUNCH_FAILURES)[number];
|
|
15
|
+
/** Every failure offers both: there is always a way on. */
|
|
16
|
+
export declare const LAUNCH_ACTIONS: readonly ["retry", "changeWorkspace"];
|
|
17
|
+
/** What a failure offers: load the chat again, or sign out to the form for another workspace. */
|
|
18
|
+
export type LaunchAction = (typeof LAUNCH_ACTIONS)[number];
|
|
19
|
+
/** The splash alone until then: a quick launch shows no status at all. */
|
|
20
|
+
export declare const LAUNCH_STATUS_AFTER_MS = 3000;
|
|
21
|
+
/** A status stays at least this long before the next replaces it. */
|
|
22
|
+
export declare const LAUNCH_STATUS_HOLD_MS = 600;
|
|
23
|
+
/** Then the status says it is reconnecting, with a hint and Try again. */
|
|
24
|
+
export declare const LAUNCH_HELP_AFTER_MS = 8000;
|
|
25
|
+
/** No chat by then: the launch fails (`chatFailed`). */
|
|
26
|
+
export declare const LAUNCH_DEADLINE_MS = 30000;
|
|
27
|
+
export type LaunchView = {
|
|
28
|
+
kind: 'splash';
|
|
29
|
+
}
|
|
30
|
+
/** `help`: the hint to check the connection, and Try again. */
|
|
31
|
+
| {
|
|
32
|
+
kind: 'status';
|
|
33
|
+
step: LaunchStep;
|
|
34
|
+
help: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'failed';
|
|
37
|
+
reason: LaunchFailure;
|
|
38
|
+
actions: readonly LaunchAction[];
|
|
39
|
+
}
|
|
40
|
+
/** The chat is up: the splash goes. */
|
|
41
|
+
| {
|
|
42
|
+
kind: 'ready';
|
|
43
|
+
};
|
|
44
|
+
export type LaunchEvent =
|
|
45
|
+
/** The chat page starts loading (the first load, or Try again). */
|
|
46
|
+
{
|
|
47
|
+
type: 'start';
|
|
48
|
+
} | {
|
|
49
|
+
type: 'step';
|
|
50
|
+
step: LaunchStep;
|
|
51
|
+
}
|
|
52
|
+
/** The chat is up (in an app that draws the header, once the header shows). */
|
|
53
|
+
| {
|
|
54
|
+
type: 'ready';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The chat could not load. Ignored once it is up (its errors show in the chat) and over a
|
|
58
|
+
* failure already shown, except `incompatible`, which is heard in any state: the chat cannot
|
|
59
|
+
* go on, and Try again cannot help.
|
|
60
|
+
*/
|
|
61
|
+
| {
|
|
62
|
+
type: 'fail';
|
|
63
|
+
reason: LaunchFailure;
|
|
64
|
+
}
|
|
65
|
+
/** The chat that was up ended and cannot start again (no token could be read). */
|
|
66
|
+
| {
|
|
67
|
+
type: 'ended';
|
|
68
|
+
reason: LaunchFailure;
|
|
69
|
+
}
|
|
70
|
+
/** The time the state asked for (`wakeAt`) came. */
|
|
71
|
+
| {
|
|
72
|
+
type: 'tick';
|
|
73
|
+
};
|
|
74
|
+
export interface LaunchState {
|
|
75
|
+
view: LaunchView;
|
|
76
|
+
/** When the view changes on its own: send `tick` then. None once ready or failed. */
|
|
77
|
+
wakeAt?: number;
|
|
78
|
+
startedAt: number;
|
|
79
|
+
/** The step last reported, shown once the status shows and the hold allows. */
|
|
80
|
+
step: LaunchStep;
|
|
81
|
+
/** When the status shown now came. */
|
|
82
|
+
shownAt: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The launch at `at` (a clock in ms, `Date.now()`), after `event`. Starts from `undefined`;
|
|
86
|
+
* `start` begins again from any state. Pure: the caller keeps one timer for `wakeAt`
|
|
87
|
+
* (`createLaunch` does).
|
|
88
|
+
*/
|
|
89
|
+
export declare function reduceLaunch(state: LaunchState | undefined, event: LaunchEvent, at: number): LaunchState;
|
|
90
|
+
/** A failure the chat page's HTTP status says: a gateway's 502, 503 or 504, or another error. */
|
|
91
|
+
export declare function launchFailureOfStatus(status: number): LaunchFailure;
|
|
92
|
+
/**
|
|
93
|
+
* The launch with its timer, for an app: `send` events as they happen, `onChange` hears each
|
|
94
|
+
* new view. `stop` when the screen goes.
|
|
95
|
+
*/
|
|
96
|
+
export declare function createLaunch(onChange: (view: LaunchView) => void, { now }?: {
|
|
97
|
+
now?: () => number;
|
|
98
|
+
}): {
|
|
99
|
+
send: (event: LaunchEvent) => void;
|
|
100
|
+
view: () => LaunchView;
|
|
101
|
+
stop: () => void;
|
|
102
|
+
};
|
|
103
|
+
/** The desktop app's and the extension's words for a launch (the mobile app has its catalogs). */
|
|
104
|
+
export declare const LAUNCH_STEP_TEXT: Record<LaunchStep, string>;
|
|
105
|
+
export declare const LAUNCH_FAILURE_TEXT: Record<LaunchFailure, {
|
|
106
|
+
title: string;
|
|
107
|
+
detail: string;
|
|
108
|
+
}>;
|
|
109
|
+
export declare const LAUNCH_HELP_TEXT = "This is taking longer than usual";
|
|
110
|
+
export declare const LAUNCH_ACTION_TEXT: Record<LaunchAction, string>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The launch of an app's chat (a WebView, an extension's frame, Electron) in token mode: what
|
|
3
|
+
* its splash shows while the chat page loads, and what it shows when the page cannot. One pure
|
|
4
|
+
* reducer every app runs, so each launch reads the same: the splash alone at first, a status
|
|
5
|
+
* line once loading takes a while, a hint with Try again when it takes long, and a failure with
|
|
6
|
+
* its actions when it cannot load. Ids only: each app says them in its own words (the English
|
|
7
|
+
* ones below are the desktop app's and the extension's). Re-exported from `./host`.
|
|
8
|
+
*/
|
|
9
|
+
export const LAUNCH_STEPS = ['connecting', 'signingIn', 'loadingChats', 'reconnecting'];
|
|
10
|
+
export const LAUNCH_FAILURES = [
|
|
11
|
+
/** The device has no connection. */
|
|
12
|
+
'offline',
|
|
13
|
+
/** The Incorta instance did not answer (no route, DNS, TLS, refused). */
|
|
14
|
+
'unreachable',
|
|
15
|
+
/** Its gateway answered 502, 503 or 504 (down or restarting). */
|
|
16
|
+
'unavailable',
|
|
17
|
+
/** The chat page answered but the chat did not start (a failed load, or the deadline). */
|
|
18
|
+
'chatFailed',
|
|
19
|
+
/** The app and the chat page speak different contract versions (`bridge.ts`): one needs an update. */
|
|
20
|
+
'incompatible',
|
|
21
|
+
];
|
|
22
|
+
/** Every failure offers both: there is always a way on. */
|
|
23
|
+
export const LAUNCH_ACTIONS = ['retry', 'changeWorkspace'];
|
|
24
|
+
/** The splash alone until then: a quick launch shows no status at all. */
|
|
25
|
+
export const LAUNCH_STATUS_AFTER_MS = 3000;
|
|
26
|
+
/** A status stays at least this long before the next replaces it. */
|
|
27
|
+
export const LAUNCH_STATUS_HOLD_MS = 600;
|
|
28
|
+
/** Then the status says it is reconnecting, with a hint and Try again. */
|
|
29
|
+
export const LAUNCH_HELP_AFTER_MS = 8000;
|
|
30
|
+
/** No chat by then: the launch fails (`chatFailed`). */
|
|
31
|
+
export const LAUNCH_DEADLINE_MS = 30_000;
|
|
32
|
+
const failed = (reason, at) => ({
|
|
33
|
+
view: { kind: 'failed', reason, actions: LAUNCH_ACTIONS },
|
|
34
|
+
startedAt: at,
|
|
35
|
+
step: 'connecting',
|
|
36
|
+
shownAt: at,
|
|
37
|
+
});
|
|
38
|
+
/** What a loading launch shows at `at`, and when that changes on its own. */
|
|
39
|
+
function settle(state, at) {
|
|
40
|
+
const elapsed = at - state.startedAt;
|
|
41
|
+
if (elapsed >= LAUNCH_DEADLINE_MS)
|
|
42
|
+
return failed('chatFailed', at);
|
|
43
|
+
const deadline = state.startedAt + LAUNCH_DEADLINE_MS;
|
|
44
|
+
if (elapsed < LAUNCH_STATUS_AFTER_MS) {
|
|
45
|
+
return { ...state, view: { kind: 'splash' }, wakeAt: state.startedAt + LAUNCH_STATUS_AFTER_MS };
|
|
46
|
+
}
|
|
47
|
+
const help = elapsed >= LAUNCH_HELP_AFTER_MS;
|
|
48
|
+
const wanted = help ? 'reconnecting' : state.step;
|
|
49
|
+
const shown = state.view.kind === 'status' ? state.view : undefined;
|
|
50
|
+
let step = wanted;
|
|
51
|
+
let shownAt = at;
|
|
52
|
+
let wakeAt = help ? deadline : state.startedAt + LAUNCH_HELP_AFTER_MS;
|
|
53
|
+
if (shown && shown.step !== wanted && at - state.shownAt < LAUNCH_STATUS_HOLD_MS) {
|
|
54
|
+
// Held: the status shown stays its minimum, then the newest step takes its place.
|
|
55
|
+
step = shown.step;
|
|
56
|
+
shownAt = state.shownAt;
|
|
57
|
+
wakeAt = Math.min(wakeAt, state.shownAt + LAUNCH_STATUS_HOLD_MS);
|
|
58
|
+
}
|
|
59
|
+
else if (shown?.step === wanted)
|
|
60
|
+
shownAt = state.shownAt;
|
|
61
|
+
// The hint comes with the reconnecting step, not under a step still held.
|
|
62
|
+
return {
|
|
63
|
+
...state,
|
|
64
|
+
view: { kind: 'status', step, help: help && step === 'reconnecting' },
|
|
65
|
+
shownAt,
|
|
66
|
+
wakeAt,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The launch at `at` (a clock in ms, `Date.now()`), after `event`. Starts from `undefined`;
|
|
71
|
+
* `start` begins again from any state. Pure: the caller keeps one timer for `wakeAt`
|
|
72
|
+
* (`createLaunch` does).
|
|
73
|
+
*/
|
|
74
|
+
export function reduceLaunch(state, event, at) {
|
|
75
|
+
if (!state || event.type === 'start') {
|
|
76
|
+
return settle({ view: { kind: 'splash' }, startedAt: at, step: 'connecting', shownAt: at }, at);
|
|
77
|
+
}
|
|
78
|
+
const { kind } = state.view;
|
|
79
|
+
const loading = kind === 'splash' || kind === 'status';
|
|
80
|
+
switch (event.type) {
|
|
81
|
+
case 'step':
|
|
82
|
+
return loading ? settle({ ...state, step: event.step }, at) : state;
|
|
83
|
+
case 'ready':
|
|
84
|
+
// A chat that came up after all (a token that came late) lifts a failure too.
|
|
85
|
+
return kind === 'ready' ? state : { ...state, view: { kind: 'ready' }, wakeAt: undefined };
|
|
86
|
+
case 'fail':
|
|
87
|
+
// A page of another version says so in any state: past the deadline, or once a chat is up.
|
|
88
|
+
return loading || event.reason === 'incompatible' ? failed(event.reason, at) : state;
|
|
89
|
+
case 'ended':
|
|
90
|
+
// Over a failure too: it says what really happened (offline, say).
|
|
91
|
+
return failed(event.reason, at);
|
|
92
|
+
case 'tick':
|
|
93
|
+
return loading ? settle(state, at) : state;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** A failure the chat page's HTTP status says: a gateway's 502, 503 or 504, or another error. */
|
|
97
|
+
export function launchFailureOfStatus(status) {
|
|
98
|
+
return status === 502 || status === 503 || status === 504 ? 'unavailable' : 'chatFailed';
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The launch with its timer, for an app: `send` events as they happen, `onChange` hears each
|
|
102
|
+
* new view. `stop` when the screen goes.
|
|
103
|
+
*/
|
|
104
|
+
export function createLaunch(onChange, { now = Date.now } = {}) {
|
|
105
|
+
let state = reduceLaunch(undefined, { type: 'start' }, now());
|
|
106
|
+
let timer;
|
|
107
|
+
const arm = () => {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
timer =
|
|
110
|
+
state.wakeAt === undefined
|
|
111
|
+
? undefined
|
|
112
|
+
: setTimeout(() => send({ type: 'tick' }), Math.max(0, state.wakeAt - now()));
|
|
113
|
+
};
|
|
114
|
+
function send(event) {
|
|
115
|
+
const before = state.view;
|
|
116
|
+
state = reduceLaunch(state, event, now());
|
|
117
|
+
arm();
|
|
118
|
+
// Each tick builds the view again: only a different one is news.
|
|
119
|
+
if (JSON.stringify(state.view) !== JSON.stringify(before))
|
|
120
|
+
onChange(state.view);
|
|
121
|
+
else
|
|
122
|
+
state = { ...state, view: before };
|
|
123
|
+
}
|
|
124
|
+
arm();
|
|
125
|
+
return {
|
|
126
|
+
send,
|
|
127
|
+
view: () => state.view,
|
|
128
|
+
stop: () => clearTimeout(timer),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The desktop app's and the extension's words for a launch (the mobile app has its catalogs). */
|
|
132
|
+
export const LAUNCH_STEP_TEXT = {
|
|
133
|
+
connecting: 'Connecting to {host}…',
|
|
134
|
+
signingIn: 'Signing you in…',
|
|
135
|
+
loadingChats: 'Loading your chats…',
|
|
136
|
+
reconnecting: 'Reconnecting…',
|
|
137
|
+
};
|
|
138
|
+
export const LAUNCH_FAILURE_TEXT = {
|
|
139
|
+
offline: {
|
|
140
|
+
title: "You're offline",
|
|
141
|
+
detail: 'Check your internet connection, then try again.',
|
|
142
|
+
},
|
|
143
|
+
unreachable: {
|
|
144
|
+
title: "Couldn't reach {host}",
|
|
145
|
+
detail: 'Check your connection, or try again in a few minutes.',
|
|
146
|
+
},
|
|
147
|
+
unavailable: {
|
|
148
|
+
title: "{host} isn't responding",
|
|
149
|
+
detail: 'It may be restarting. Try again in a few minutes.',
|
|
150
|
+
},
|
|
151
|
+
chatFailed: {
|
|
152
|
+
title: "Couldn't load the chat",
|
|
153
|
+
detail: 'Something went wrong. Try again.',
|
|
154
|
+
},
|
|
155
|
+
incompatible: {
|
|
156
|
+
title: 'Update needed',
|
|
157
|
+
detail: "This version of the app doesn't work with your Incorta's chat. Update the app, or ask your admin.",
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
export const LAUNCH_HELP_TEXT = 'This is taking longer than usual';
|
|
161
|
+
export const LAUNCH_ACTION_TEXT = {
|
|
162
|
+
retry: 'Try again',
|
|
163
|
+
changeWorkspace: 'Change workspace',
|
|
164
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HostTheme, ChatHandle, ChatMount, ChatOptions } from './contract/index.js';
|
|
2
|
+
|
|
3
|
+
export type * from './contract/index.js';
|
|
4
|
+
|
|
5
|
+
export interface ChatSource {
|
|
6
|
+
/** IncortaCopilot's root as this page reaches it; the chat loads from `<url>/nexus-chat/`. */
|
|
7
|
+
url?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Where the chat files are served instead (pinned): any URL that serves a
|
|
10
|
+
* release's extracted `nexus-chat-dist.tar.gz`. Absent: from Copilot.
|
|
11
|
+
*/
|
|
12
|
+
assetsUrl?: string;
|
|
13
|
+
/** Deadline for loading the chat, retry included. Default 20 000 ms. */
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The host contract options; `version` is filled in for you. */
|
|
18
|
+
export type MountChatOptions = Omit<ChatOptions, 'version'> & Omit<ChatSource, 'url'>;
|
|
19
|
+
|
|
20
|
+
/** The host contract version this connector speaks: the value of `CONTRACT_VERSION` in `@incorta/chat/contract`. */
|
|
21
|
+
export const CONTRACT_VERSION: 1;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Loads the chat once per source (one retry, one deadline) and resolves to its `mount`. A load
|
|
25
|
+
* that fails rejects with a `ChatError` (`isChatError` from
|
|
26
|
+
* `@incorta/chat/contract`): code `'LOAD_TIMEOUT'` when the deadline passes, `'LOAD_FAILED'`
|
|
27
|
+
* when the retry failed too (the failure as `cause`).
|
|
28
|
+
*/
|
|
29
|
+
export function loadChat(source: ChatSource): Promise<ChatMount>;
|
|
30
|
+
|
|
31
|
+
/** Forgets a loaded chat, so the next load fetches it again (after it failed while running). */
|
|
32
|
+
export function forgetChat(source: ChatSource): void;
|
|
33
|
+
|
|
34
|
+
/** The version the last loaded chat reports (for error reports); undefined before a load. */
|
|
35
|
+
export function loadedChatVersion(): string | undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Loads the chat and mounts it into `element`. Rejects as `loadChat` does, or with the
|
|
39
|
+
* chat's own mount error. The handle always has `attach` and `openSession` (an older chat's
|
|
40
|
+
* refuses and ignores them), and its `unmount` releases any session hold the chat still had.
|
|
41
|
+
*/
|
|
42
|
+
export function mountChat(element: HTMLElement, options: MountChatOptions): Promise<ChatHandle>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @internal The skeleton `mountChat` and `<IncortaChat>` draw over a box
|
|
46
|
+
* while the chat loads. Not part of the package's API.
|
|
47
|
+
*/
|
|
48
|
+
export function showChatSkeleton(
|
|
49
|
+
box: HTMLElement,
|
|
50
|
+
theme?: HostTheme,
|
|
51
|
+
): { setTheme(theme?: HostTheme): void; done(): void; remove(): void };
|