@m6d/cortex-web 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -2
- package/dist/index.d.ts +288 -0
- package/dist/index.js +1602 -0
- package/dist/styles.css +4843 -0
- package/dist/theme.css +287 -0
- package/package.json +77 -5
package/README.md
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @m6d/cortex-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-free chat widget for Cortex agents: a `<cortex-chat>` custom element for any page, with or without a framework. It is the same widget as `@m6d/cortex-react` and `@m6d/cortex-angular`, built on the same core and stylesheet.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @m6d/cortex-web
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Importing the package registers `<cortex-chat>`. The widget draws into the page's own DOM, so its stylesheets load globally.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import '@m6d/cortex-web';
|
|
15
|
+
import '@m6d/cortex-web/styles.css';
|
|
16
|
+
import '@m6d/cortex-web/theme.css';
|
|
17
|
+
import type { CortexWebConfig } from '@m6d/cortex-web';
|
|
18
|
+
|
|
19
|
+
const config = {
|
|
20
|
+
locale: 'en',
|
|
21
|
+
transport: {
|
|
22
|
+
baseUrl:
|
|
23
|
+
'https://engine.cortex.example.com/orgs/default/projects/default/envs/production/agents/support',
|
|
24
|
+
getHeaders: () => ({ Authorization: `Bearer ${token}` }),
|
|
25
|
+
},
|
|
26
|
+
} satisfies CortexWebConfig;
|
|
27
|
+
|
|
28
|
+
const chat = document.createElement('cortex-chat');
|
|
29
|
+
chat.config = config;
|
|
30
|
+
document.body.append(chat);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`config` is a `CortexWebConfig`: the shared config, with `toolComponents` as elements (below). `@m6d/cortex-react`'s README describes each field, the agent's URL and auth. The widget talks to Cortex only while it is on the page with a config, and removing it closes everything. Size the element itself, as `cortex-chat { height: 100svh }` or a class.
|
|
34
|
+
|
|
35
|
+
`theme.css` lists every `--cx-*` color token with its default. Override any of them on `:root` or on an ancestor of the widget; `@m6d/cortex-react`'s README covers theming.
|
|
36
|
+
|
|
37
|
+
`slots` draws a part yourself: `header`, `landing` or `threadList`, each a custom element class you defined. The widget creates one per place and sets its `context` on every change, the same contexts `@m6d/cortex-react`'s README lists. The landing's `composer` is an element to place.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import type { CortexHeaderContext } from '@m6d/cortex-web';
|
|
41
|
+
|
|
42
|
+
class AcmeHeader extends HTMLElement {
|
|
43
|
+
set context(header: CortexHeaderContext) {
|
|
44
|
+
this.textContent = header.title;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
customElements.define('acme-header', AcmeHeader);
|
|
48
|
+
chat.slots = { header: AcmeHeader };
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The default header is `<cortex-chat-header>`, so a `header` slot can draw it with a changed context, such as an empty `title` under a page that already names the thread. Its title is a level-2 heading. `titleLevel` picks another level, or `false` for plain text where the widget sits before the page's own `h1`.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
class UntitledHeader extends HTMLElement {
|
|
55
|
+
private readonly header = document.createElement('cortex-chat-header');
|
|
56
|
+
|
|
57
|
+
set context(header: CortexHeaderContext) {
|
|
58
|
+
this.header.context = { ...header, title: '' };
|
|
59
|
+
this.header.titleLevel = 3;
|
|
60
|
+
if (!this.hasChildNodes()) this.append(this.header);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`config.toolComponents` draws calls to a tool yourself, the same way: a custom element class by tool name. The widget makes one per call and sets its `context` (`CortexToolComponentInputs`) on every change; `context.setOutput` answers the call.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import type { CortexToolComponentInputs } from '@m6d/cortex-web';
|
|
69
|
+
|
|
70
|
+
class AcmeConfirm extends HTMLElement {
|
|
71
|
+
private call?: CortexToolComponentInputs;
|
|
72
|
+
|
|
73
|
+
set context(call: CortexToolComponentInputs) {
|
|
74
|
+
this.call = call;
|
|
75
|
+
if (this.childElementCount) return;
|
|
76
|
+
const confirm = document.createElement('button');
|
|
77
|
+
confirm.textContent = 'Confirm';
|
|
78
|
+
confirm.addEventListener('click', () => void this.call?.setOutput({ confirmed: true }));
|
|
79
|
+
this.append(confirm);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
customElements.define('acme-confirm', AcmeConfirm);
|
|
83
|
+
|
|
84
|
+
chat.config = { ...config, toolComponents: { confirmOrder: AcmeConfirm } };
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`config.mediaRenderers` swaps how a fenced block draws, or adds a fence tag of your own, as `@m6d/cortex-react`'s README describes. A renderer (`MediaRenderer`) draws the closed fence's source into the host element it is given and returns its teardown; its context carries the widget's `scheme` and `locale`.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
chat.config = {
|
|
91
|
+
...config,
|
|
92
|
+
mediaRenderers: {
|
|
93
|
+
map: async (host, source, { scheme }) => {
|
|
94
|
+
// draw with Google Maps, Mapbox, MapLibre, ...
|
|
95
|
+
return () => {
|
|
96
|
+
/* dispose */
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Requirements
|
|
104
|
+
|
|
105
|
+
- Peer dependencies: `@tanstack/ai`, `@tanstack/ai-client`, `marked`, `dompurify`, plus the lazily loaded `highlight.js`, `mermaid`, `vega`, `vega-lite`, `vega-embed`, `leaflet`
|
|
106
|
+
|
|
107
|
+
## Structure
|
|
108
|
+
|
|
109
|
+
Each Angular component (`packages/cortex-angular/src/lib/components/**`) is one Lit element here, in the same folder under `src/components/`, its file named as the Angular component's (`chat-header.ts`). It keeps the component's boundaries, `cx-*` classes, translation keys and `@cortex/client` helpers. Behavior stays in `@cortex/client`; an element only draws.
|
|
110
|
+
|
|
111
|
+
- **Element.** It extends `LightElement`, which draws into the light DOM, so the shared stylesheet styles it unchanged. It draws only while on the page, its first draw and every draw its parent's changes inside the parent's, so the parent's `updated` sees its whole subtree. Its tag is the Angular selector; an attribute selector (`div[cortexThreadRow]`) becomes `cortex-` and the file's name. One whose host is a native element (`button[cortexFoldedSteps]`) draws that element inside itself. The root keeps the package's name: `<cortex-chat>` (`cortex-chat.ts`) is Angular's `cortex-chat-widget`.
|
|
112
|
+
- **Host.** Angular's `host` classes and attributes are set on the element in `willUpdate`. A file ends with `customElements.define`, and imports each element it draws, for its definition.
|
|
113
|
+
- **Inputs.** An Angular input is a reactive property: an entry in `static properties` with `attribute: false`, and a `declare` field, so `useDefineForClassFields` leaves Lit's accessor in place. Defaults go in the constructor. Internal state is the same with `state: true`. A parent binds it as `.name=${value}`. An input named as an `HTMLElement` member (`animate`, `part`, `role`, `id`) takes a name of its own (`animateIn`, `messagePart`, `messageRole`, `fileId`), and one that only sets a host attribute (`dir`) is bound as that attribute.
|
|
114
|
+
- **Outputs.** An Angular output is an event the element dispatches on itself (`open`, `deleted`), heard as `@open=${...}`.
|
|
115
|
+
- **The chat.** `<cortex-chat>` provides `chatContext` (`@lit/context`): the config, `locale`, `t`, `scheme` and the store (`widget`), the `CortexContextValue` React's widget provides too. An element reads it through `this.chat = new ChatController(this)`: `this.chat.value.t(key)`. One that reads the store passes a selector, `new ChatController(this, (state, { widget }) => ...)`, and reads `this.chat.selected`. It redraws only when that changes, by reference or, for an object, field by field (React's `useWidgetState` compares by reference only), so a streamed chunk redraws only what it changed. The draft is `widget.getDraft()`. A subagent's screen provides its subtree its own store, as Angular's does.
|
|
116
|
+
- **Actions.** An element calls the store itself (`widget.retry`, `widget.setDraft`); nothing goes back as an event.
|
|
117
|
+
- **Icons.** `icon(name, { size, className })` draws one of the shared icons: Angular's `svg[cortexIcon]`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ToolCallPart, UIMessage } from '@tanstack/ai';
|
|
4
|
+
|
|
5
|
+
declare const LOCALES: readonly [
|
|
6
|
+
"en",
|
|
7
|
+
"ar"
|
|
8
|
+
];
|
|
9
|
+
export type Locale = (typeof LOCALES)[number];
|
|
10
|
+
export type ThreadSummary = {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string | null;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
isRunning: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* No run is live and a run parked on the thread waits on its user: a
|
|
18
|
+
* call to approve, or a client tool's answer (a location, an embedded
|
|
19
|
+
* page). Never set while `isRunning`.
|
|
20
|
+
*/
|
|
21
|
+
waitsOnUser: boolean;
|
|
22
|
+
/** Present on a headless thread a trigger owns. Widgets never list these. */
|
|
23
|
+
trigger?: {
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Body of `POST /threads`. Only a console operator's request is read: its
|
|
29
|
+
* test thread keeps `variables` as the session the agent's server would
|
|
30
|
+
* otherwise fill per end user.
|
|
31
|
+
*/
|
|
32
|
+
export type CreateThreadRequest = {
|
|
33
|
+
variables?: Record<string, string | number | boolean>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* One landing-page chip: the widget shows `title` and sends `prompt` as the
|
|
37
|
+
* first message when clicked. The two may be the same text.
|
|
38
|
+
*/
|
|
39
|
+
export type Suggestion = {
|
|
40
|
+
title: string;
|
|
41
|
+
prompt: string;
|
|
42
|
+
};
|
|
43
|
+
export type CortexHeaders = Record<string, string>;
|
|
44
|
+
/**
|
|
45
|
+
* How the widget reaches Cortex. `baseUrl` is the agent's URL,
|
|
46
|
+
* `<engine origin>/orgs/<org>/projects/<project>/envs/<env>/agents/<agent>`. It may be a thunk so a
|
|
47
|
+
* consumer with a reactive origin (an Angular Signal is itself a
|
|
48
|
+
* `() => string`) is read at the moment of each request rather than
|
|
49
|
+
* captured once.
|
|
50
|
+
*/
|
|
51
|
+
export type CortexTransport = {
|
|
52
|
+
baseUrl: string | (() => string);
|
|
53
|
+
/**
|
|
54
|
+
* The headers every call carries, usually the end user's bearer. Left out
|
|
55
|
+
* for an anonymous agent: the widget signs in as a visitor, and Cortex
|
|
56
|
+
* gives it an id it keeps and sends from then on.
|
|
57
|
+
*/
|
|
58
|
+
getHeaders?: () => CortexHeaders | Promise<CortexHeaders>;
|
|
59
|
+
/**
|
|
60
|
+
* Sent with every thread the widget creates. The console's playground puts
|
|
61
|
+
* a test thread's variables here; Cortex honours it only from a verified
|
|
62
|
+
* console operator.
|
|
63
|
+
*/
|
|
64
|
+
threadBody?: CreateThreadRequest;
|
|
65
|
+
};
|
|
66
|
+
export type CortexViewMode = "helper" | "full";
|
|
67
|
+
export type CortexTheme = "light" | "dark" | "system";
|
|
68
|
+
export type CortexToolCallContext = {
|
|
69
|
+
threadId: string;
|
|
70
|
+
};
|
|
71
|
+
/** A tool call Cortex left for the client to answer. */
|
|
72
|
+
export type CortexToolCall = {
|
|
73
|
+
toolCallId: string;
|
|
74
|
+
toolName: string;
|
|
75
|
+
input: unknown;
|
|
76
|
+
};
|
|
77
|
+
export type CortexHooks = {
|
|
78
|
+
onToolCall?: (toolCall: CortexToolCall, context: CortexToolCallContext) => unknown;
|
|
79
|
+
onThreadSelected?: (thread: ThreadSummary) => Promise<void> | void;
|
|
80
|
+
onThreadDeselected?: (thread: ThreadSummary) => Promise<void> | void;
|
|
81
|
+
};
|
|
82
|
+
/** What the widget hands a consumer-supplied tool component, in every SDK. */
|
|
83
|
+
export type CortexToolComponentInputs = {
|
|
84
|
+
toolCallPart: ToolCallPart;
|
|
85
|
+
message: UIMessage;
|
|
86
|
+
/** Answers the call. Rejects when the delivery failed, so a component can say so and let the user retry. */
|
|
87
|
+
setOutput: (output: unknown) => Promise<void>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The platform-neutral part of the widget's configuration. Each SDK extends it
|
|
91
|
+
* with the fields whose types are bound to its platform's views:
|
|
92
|
+
* `toolComponents`, and `mediaRenderers`, drawing into a DOM
|
|
93
|
+
* (`CortexBrowserConfig`) or, in React Native, as native views.
|
|
94
|
+
*/
|
|
95
|
+
export type CortexConfig = {
|
|
96
|
+
/** Defaults to `'en'`. */
|
|
97
|
+
locale?: Locale;
|
|
98
|
+
transport: CortexTransport;
|
|
99
|
+
/**
|
|
100
|
+
* WebSocket endpoint override, derived from `transport.baseUrl` by default.
|
|
101
|
+
* `false` disables the socket entirely (chat still works fully over SSE;
|
|
102
|
+
* only cross-tab notify events are lost) — required behind proxies that do
|
|
103
|
+
* not forward `/ws`, which would otherwise reconnect forever.
|
|
104
|
+
*/
|
|
105
|
+
wsUrl?: string | false;
|
|
106
|
+
viewMode?: CortexViewMode;
|
|
107
|
+
/** Color scheme; `'system'` follows the OS preference. Defaults to `'light'`. */
|
|
108
|
+
theme?: CortexTheme;
|
|
109
|
+
/**
|
|
110
|
+
* A thread to open when the widget mounts, by id, once the thread list holds
|
|
111
|
+
* it: a deep link into one conversation, such as the console's inspector.
|
|
112
|
+
*/
|
|
113
|
+
thread?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Render embedded tool pages served from this page's own origin with their
|
|
116
|
+
* full identity — which, same-origin, means no effective sandbox at all: such
|
|
117
|
+
* an embed can reach into the host page. By default they are refused
|
|
118
|
+
* (rendered inert), because embed URLs come from the tool's definition in
|
|
119
|
+
* Cortex, and whoever administers that is not necessarily whoever owns this
|
|
120
|
+
* site. Enable only when both are the same party and the embeds are this
|
|
121
|
+
* site's own pages, so the embeds need no origin of their own.
|
|
122
|
+
*/
|
|
123
|
+
trustSameOriginEmbeds?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Offer the header's debug switch (tool inputs and outputs, reasoning,
|
|
126
|
+
* model calls) where Cortex sends this caller the debug view. Off by
|
|
127
|
+
* default, so a page for end users never shows it; an operator's
|
|
128
|
+
* inspector turns it on.
|
|
129
|
+
*/
|
|
130
|
+
debugToggle?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The page's own container already names the widget, such as a dialog
|
|
133
|
+
* titled for it, so the chat screen drops its landmark and the name a
|
|
134
|
+
* screen reader would otherwise say twice. The history keeps its own.
|
|
135
|
+
*/
|
|
136
|
+
namedByHost?: boolean;
|
|
137
|
+
hooks?: CortexHooks;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* What the header receives, the consumer's own or the widget's: where the widget
|
|
141
|
+
* is, what to show, and the actions the default header offers. One header
|
|
142
|
+
* serves both screens; `screen` says which is showing.
|
|
143
|
+
*/
|
|
144
|
+
export type CortexHeaderContext = {
|
|
145
|
+
screen: "chat" | "threads";
|
|
146
|
+
viewMode: CortexViewMode;
|
|
147
|
+
/**
|
|
148
|
+
* The open thread's title, else the agent's display name in the widget's
|
|
149
|
+
* locale, else the built-in "New Chat"; empty while the handshake is out.
|
|
150
|
+
*/
|
|
151
|
+
title: string;
|
|
152
|
+
/** How many conversations the history lists; undefined while the first load is out. */
|
|
153
|
+
threadCount: number | undefined;
|
|
154
|
+
isWorking: boolean;
|
|
155
|
+
/** Whether Cortex offers this caller the debug view, and whether it is on. */
|
|
156
|
+
debug: {
|
|
157
|
+
shown: boolean;
|
|
158
|
+
on: boolean;
|
|
159
|
+
};
|
|
160
|
+
/** Absent until the handshake says the caller may write; an operator inspecting a thread only reads. */
|
|
161
|
+
newChat?: () => void;
|
|
162
|
+
/** Shows the history: the history screen, or in full mode the sidebar where it is hidden. */
|
|
163
|
+
openHistory: () => void;
|
|
164
|
+
/** Whether full mode's history sidebar is slid in over the chat (`openHistory` on a narrow viewport). */
|
|
165
|
+
historyOpen: boolean;
|
|
166
|
+
/** Returns to the open chat from wherever `openHistory` went. */
|
|
167
|
+
closeHistory: () => void;
|
|
168
|
+
toggleDebug: () => void;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* What the blank-chat landing receives, the consumer's own or the widget's. The
|
|
172
|
+
* composer arrives ready to place as the SDK's own view type (`View`), so a
|
|
173
|
+
* custom landing keeps the widget's attachments and send rules. Each SDK
|
|
174
|
+
* exports it as `CortexLandingContext` with its view type filled in.
|
|
175
|
+
*/
|
|
176
|
+
export type LandingContext<View> = {
|
|
177
|
+
/** The agent's greeting in the widget's locale, or the built-in one; empty until the handshake answers. */
|
|
178
|
+
greeting: string;
|
|
179
|
+
/** Empty until the handshake answers, and for an agent that takes no messages. */
|
|
180
|
+
suggestions: Suggestion[];
|
|
181
|
+
/** Newest first; undefined while the first load is out. */
|
|
182
|
+
threads: ThreadSummary[] | undefined;
|
|
183
|
+
/** The composer, or the notice an agent that takes no messages shows instead; empty until the handshake answers. */
|
|
184
|
+
composer: View;
|
|
185
|
+
/**
|
|
186
|
+
* Sends a first message, which opens a thread and swaps the landing for it.
|
|
187
|
+
* Does nothing until the handshake answers, or for an agent that takes no messages.
|
|
188
|
+
*/
|
|
189
|
+
send: (prompt: string) => void;
|
|
190
|
+
openThread: (thread: ThreadSummary) => void;
|
|
191
|
+
/** Shows the whole history: its screen, or the sidebar in full mode, as the header's `openHistory`. */
|
|
192
|
+
openHistory: () => void;
|
|
193
|
+
};
|
|
194
|
+
/** What the history's list receives, the consumer's own or the widget's. Its header is the header slot. */
|
|
195
|
+
export type CortexThreadListContext = {
|
|
196
|
+
/** Newest first; undefined while the first load is out. */
|
|
197
|
+
threads: ThreadSummary[] | undefined;
|
|
198
|
+
/** The open thread's id; undefined on a new chat. */
|
|
199
|
+
selectedThreadId: string | undefined;
|
|
200
|
+
openThread: (thread: ThreadSummary) => void;
|
|
201
|
+
/**
|
|
202
|
+
* Both absent until the handshake says the caller may write; an operator
|
|
203
|
+
* inspecting a thread only reads. `deleteThread` deletes for good, so the
|
|
204
|
+
* caller confirms first; it rejects when Cortex refuses, leaving the list
|
|
205
|
+
* and the open thread as they were.
|
|
206
|
+
*/
|
|
207
|
+
deleteThread?: (threadId: string) => Promise<void>;
|
|
208
|
+
newChat?: () => void;
|
|
209
|
+
};
|
|
210
|
+
/** Each part of the widget a consumer can draw itself, with the context it receives. */
|
|
211
|
+
export type CortexSlotContexts<View> = {
|
|
212
|
+
header: CortexHeaderContext;
|
|
213
|
+
landing: LandingContext<View>;
|
|
214
|
+
threadList: CortexThreadListContext;
|
|
215
|
+
};
|
|
216
|
+
export type ColorScheme = "light" | "dark";
|
|
217
|
+
export type MediaRenderContext = {
|
|
218
|
+
scheme: ColorScheme;
|
|
219
|
+
locale: Locale;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Draws a closed media fence's `source` into `host`, resolves once drawn, and
|
|
223
|
+
* returns the teardown. A consumer's `mediaRenderers` config entry has this
|
|
224
|
+
* shape too: one per fence language, replacing the built-in of the same name
|
|
225
|
+
* or adding a language of its own. The same source can be drawn twice at once,
|
|
226
|
+
* inline and in its expanded view, so a renderer keeps no state that two
|
|
227
|
+
* drawings would share.
|
|
228
|
+
*/
|
|
229
|
+
export type MediaRenderer = (host: HTMLElement, source: string, context: MediaRenderContext) => Promise<() => void>;
|
|
230
|
+
export type MediaRenderers = Partial<Record<string, MediaRenderer>>;
|
|
231
|
+
/** The configuration every SDK that draws into a DOM shares; each extends it with its framework's fields. */
|
|
232
|
+
export type CortexBrowserConfig = CortexConfig & {
|
|
233
|
+
/**
|
|
234
|
+
* Replaces or extends the media fences the assistant's replies draw. Keyed by
|
|
235
|
+
* fence tag; `map` swaps the built-in Leaflet map for another provider.
|
|
236
|
+
*/
|
|
237
|
+
mediaRenderers?: MediaRenderers;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* A custom element class the widget creates, defined (`customElements.define`)
|
|
241
|
+
* before the widget draws it; it sets `context` on every change.
|
|
242
|
+
*/
|
|
243
|
+
export type CortexElement<Context> = new () => HTMLElement & {
|
|
244
|
+
context: Context;
|
|
245
|
+
};
|
|
246
|
+
export type CortexWebConfig = CortexBrowserConfig & {
|
|
247
|
+
/**
|
|
248
|
+
* The elements drawing calls to these tools, by tool name: one made per
|
|
249
|
+
* call and kept through its streamed changes, so its own DOM and focus
|
|
250
|
+
* stay; its `context` is the call, answered through `setOutput`.
|
|
251
|
+
*/
|
|
252
|
+
toolComponents?: Record<string, CortexElement<CortexToolComponentInputs>>;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* `<cortex-chat>`, as `document.createElement('cortex-chat')` types it: the
|
|
256
|
+
* agent it talks to (`config`), and the parts the consumer draws (`slots`).
|
|
257
|
+
*/
|
|
258
|
+
export type CortexChatElement = HTMLElement & {
|
|
259
|
+
config: CortexWebConfig | undefined;
|
|
260
|
+
slots: CortexWebSlots | undefined;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* `<cortex-chat-header>`, the default header, which a `header` slot may draw
|
|
264
|
+
* with a changed `context`. Its titles are level-2 headings; `titleLevel`
|
|
265
|
+
* sets another level, or `false` for plain text.
|
|
266
|
+
*/
|
|
267
|
+
export type CortexChatHeaderElement = HTMLElement & {
|
|
268
|
+
context: CortexHeaderContext;
|
|
269
|
+
titleLevel: 1 | 2 | 3 | 4 | 5 | 6 | false | undefined;
|
|
270
|
+
};
|
|
271
|
+
/** The landing's context, its composer an element to place. */
|
|
272
|
+
export type CortexLandingContext = LandingContext<HTMLElement>;
|
|
273
|
+
/**
|
|
274
|
+
* The parts of the widget a consumer draws itself: each a custom element
|
|
275
|
+
* class taking the part's context as its `context`, the same type as the
|
|
276
|
+
* widget's default.
|
|
277
|
+
*/
|
|
278
|
+
export type CortexWebSlots = {
|
|
279
|
+
[Slot in keyof CortexSlotContexts<HTMLElement>]?: CortexElement<CortexSlotContexts<HTMLElement>[Slot]>;
|
|
280
|
+
};
|
|
281
|
+
declare global {
|
|
282
|
+
interface HTMLElementTagNameMap {
|
|
283
|
+
"cortex-chat": CortexChatElement;
|
|
284
|
+
"cortex-chat-header": CortexChatHeaderElement;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export {};
|