@m6d/cortex-angular 0.7.0 → 0.9.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 +129 -0
- package/fesm2022/m6d-cortex-angular.mjs +2775 -1398
- package/package.json +1 -1
- package/theme.css +9 -0
- package/types/m6d-cortex-angular.d.ts +171 -10
package/README.md
CHANGED
|
@@ -51,6 +51,135 @@ No root-level providers needed — each widget instance is fully self-contained.
|
|
|
51
51
|
|
|
52
52
|
`transport.getHeaders` can return any request headers needed by the host app. WebSocket auth continues to derive the `token` query param from a bearer `Authorization` header when present.
|
|
53
53
|
|
|
54
|
+
## Custom parts
|
|
55
|
+
|
|
56
|
+
Put an `ng-template` marked `cortexSlot` inside the widget to draw one of its
|
|
57
|
+
parts yourself: `header`, `landing` (the blank chat) or `threadList` (the
|
|
58
|
+
history's list). Each replaces the widget's default and receives the same
|
|
59
|
+
context the default is drawn from, typed by the slot name. Use only the slots
|
|
60
|
+
you need:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
64
|
+
import { CortexChatWidgetComponent, CortexSlotDirective } from '@m6d/cortex-angular';
|
|
65
|
+
|
|
66
|
+
@Component({
|
|
67
|
+
imports: [CortexChatWidgetComponent, CortexSlotDirective, NgTemplateOutlet],
|
|
68
|
+
template: `
|
|
69
|
+
<cortex-chat-widget [config]="config">
|
|
70
|
+
<ng-template cortexSlot="header" let-chat>
|
|
71
|
+
<div class="cortex-widget__chat-header">
|
|
72
|
+
@if (chat.screen === 'threads') {
|
|
73
|
+
<button class="cortex-widget__header-btn" (click)="chat.closeHistory()">←</button>
|
|
74
|
+
} @else {
|
|
75
|
+
<button class="cortex-widget__header-btn" (click)="chat.openHistory()">☰</button>
|
|
76
|
+
}
|
|
77
|
+
<div class="cortex-widget__chat-title-wrap">
|
|
78
|
+
<p class="cortex-widget__chat-title">{{ chat.title ?? chat.agentName }}</p>
|
|
79
|
+
</div>
|
|
80
|
+
<button class="cortex-widget__header-btn" (click)="chat.newChat()">+</button>
|
|
81
|
+
</div>
|
|
82
|
+
</ng-template>
|
|
83
|
+
|
|
84
|
+
<ng-template cortexSlot="landing" let-landing>
|
|
85
|
+
<div class="cortex-widget__landing">
|
|
86
|
+
<h1>{{ landing.greeting }}</h1>
|
|
87
|
+
@for (suggestion of landing.suggestions; track $index) {
|
|
88
|
+
<button (click)="landing.send(suggestion.prompt)">{{ suggestion.title }}</button>
|
|
89
|
+
}
|
|
90
|
+
<ng-container *ngTemplateOutlet="landing.composer" />
|
|
91
|
+
</div>
|
|
92
|
+
</ng-template>
|
|
93
|
+
|
|
94
|
+
<ng-template cortexSlot="threadList" let-list>
|
|
95
|
+
<div class="cortex-widget__threads-list">
|
|
96
|
+
@for (thread of list.threads; track thread.id) {
|
|
97
|
+
<button (click)="list.openThread(thread)">{{ thread.title }}</button>
|
|
98
|
+
}
|
|
99
|
+
</div>
|
|
100
|
+
</ng-template>
|
|
101
|
+
</cortex-chat-widget>
|
|
102
|
+
`,
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
A slot replaces the whole part, so its root sits where the default's did: in
|
|
107
|
+
the chat or history screen's column, under the header. The defaults' classes
|
|
108
|
+
are there to reuse: `cortex-widget__chat-header`, `cortex-widget__chat-title`
|
|
109
|
+
and `cortex-widget__header-btn` for a header, `cortex-widget__landing` for a
|
|
110
|
+
centered landing, `cortex-widget__threads-list` for a scrolling list. Utility
|
|
111
|
+
classes such as Tailwind's apply inside the widget; its own reset sits in
|
|
112
|
+
`@layer base.cortex`, below them. `ThreadSummary` and `Suggestion` are exported
|
|
113
|
+
for typing your own rows and chips.
|
|
114
|
+
|
|
115
|
+
### `header`
|
|
116
|
+
|
|
117
|
+
One header serves both screens; `screen` says which is showing.
|
|
118
|
+
|
|
119
|
+
| Field | Type | Description |
|
|
120
|
+
| -------------- | --------------------- | -------------------------------------------------------------- |
|
|
121
|
+
| `screen` | `'chat' \| 'threads'` | Which screen the header is on |
|
|
122
|
+
| `viewMode` | `'helper' \| 'full'` | The configured view mode |
|
|
123
|
+
| `title` | `string \| null` | The open thread's title; `null` on a new chat |
|
|
124
|
+
| `agentName` | `string \| undefined` | `agentName` in the widget's locale |
|
|
125
|
+
| `threadCount` | `number` | How many conversations the history lists; 0 while it loads |
|
|
126
|
+
| `isWorking` | `boolean` | The agent is answering |
|
|
127
|
+
| `debug` | `{ shown, on }` | Whether `showDebugButton` is set, and whether debug mode is on |
|
|
128
|
+
| `newChat` | `() => void` | Starts a new chat |
|
|
129
|
+
| `openHistory` | `() => void` | Shows the history: its screen, or the sidebar in full mode |
|
|
130
|
+
| `closeHistory` | `() => void` | Returns to the open chat |
|
|
131
|
+
| `toggleDebug` | `() => void` | Switches debug mode |
|
|
132
|
+
|
|
133
|
+
### `landing`
|
|
134
|
+
|
|
135
|
+
Shown while no thread is open. The first send opens a thread and swaps the
|
|
136
|
+
landing for it.
|
|
137
|
+
|
|
138
|
+
| Field | Type | Description |
|
|
139
|
+
| ------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
140
|
+
| `greeting` | `string` | The agent's greeting in the widget's locale, or the built-in one |
|
|
141
|
+
| `suggestions` | `{ title, prompt }[]` | Empty until the handshake answers, and for an agent that takes no messages |
|
|
142
|
+
| `threads` | `ThreadSummary[] \| undefined` | Newest first; `undefined` while the first load is out |
|
|
143
|
+
| `composer` | `TemplateRef` | The widget's composer, or its "messages disabled" notice; place it with `ngTemplateOutlet` |
|
|
144
|
+
| `send` | `(prompt: string) => void` | Sends a first message; does nothing until the handshake answers, or for an agent that takes no messages |
|
|
145
|
+
| `openThread` | `(thread: ThreadSummary) => void` | Opens a thread |
|
|
146
|
+
|
|
147
|
+
### `threadList`
|
|
148
|
+
|
|
149
|
+
The history's list. Its header is the `header` slot.
|
|
150
|
+
|
|
151
|
+
| Field | Type | Description |
|
|
152
|
+
| ------------------ | --------------------------------- | ----------------------------------------------------- |
|
|
153
|
+
| `threads` | `ThreadSummary[] \| undefined` | Newest first; `undefined` while the first load is out |
|
|
154
|
+
| `selectedThreadId` | `string \| undefined` | The open thread's id; `undefined` on a new chat |
|
|
155
|
+
| `openThread` | `(thread: ThreadSummary) => void` | Opens a thread |
|
|
156
|
+
| `deleteThread` | `(threadId: string) => void` | Deletes a thread |
|
|
157
|
+
| `newChat` | `() => void` | Starts a new chat |
|
|
158
|
+
|
|
159
|
+
## Theming
|
|
160
|
+
|
|
161
|
+
Every token in `theme.css` can be overridden on `:root` or on any ancestor of
|
|
162
|
+
the widget. Beside the colors, radius and `--cortex-font-size`, four tokens
|
|
163
|
+
ship unset and fall back when you leave them out:
|
|
164
|
+
|
|
165
|
+
| Token | Falls back to | Styles |
|
|
166
|
+
| -------------------------------- | --------------------------- | ------------------------------------ |
|
|
167
|
+
| `--cortex-font-size-message` | `--cortex-font-size` | Message bubbles and the composer |
|
|
168
|
+
| `--cortex-font-size-header` | `--cortex-font-size` | The chat and history titles |
|
|
169
|
+
| `--cortex-color-send-empty` | `transparent` | The send button with nothing to send |
|
|
170
|
+
| `--cortex-color-send-empty-text` | `--cortex-color-text-muted` | Its icon |
|
|
171
|
+
|
|
172
|
+
The composer resets its own focus and disabled styles, so a host's global
|
|
173
|
+
`textarea:focus` ring or disabled fill does not reach it.
|
|
174
|
+
|
|
175
|
+
## Tables
|
|
176
|
+
|
|
177
|
+
A markdown table in an answer scrolls sideways instead of squeezing its
|
|
178
|
+
columns. Once it has finished arriving, hovering it (or focusing into it)
|
|
179
|
+
shows two actions at its top end: expand, which opens it in a dialog with room
|
|
180
|
+
for every column, and export, which downloads it as an `.xlsx` file. Numbers
|
|
181
|
+
export as numbers; the header row is bold.
|
|
182
|
+
|
|
54
183
|
## Client tools
|
|
55
184
|
|
|
56
185
|
Control-Center tools published with type "embedded" render inside the chat
|