@m6d/cortex-react 0.13.0 → 0.14.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 +32 -27
- package/dist/index.d.ts +11 -5
- package/dist/index.js +15 -14
- package/dist/styles.css +31 -21
- package/package.json +4 -11
package/README.md
CHANGED
|
@@ -32,14 +32,14 @@ Each widget is self-contained, so one page can render several widgets with diffe
|
|
|
32
32
|
|
|
33
33
|
| Property | Type | Description |
|
|
34
34
|
| -------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
|
35
|
-
| `locale` | `'en' \| 'ar'` | Active locale (default: `'en'`)
|
|
35
|
+
| `locale` | `'en' \| 'ar'` | Active locale; the widget lays out in its direction (default: `'en'`) |
|
|
36
36
|
| `transport.baseUrl` | `string \| () => string` | The agent's URL, `<engine origin>/agents/<slug>` |
|
|
37
37
|
| `transport.getHeaders` | `() => Headers \| Promise<Headers>` | Request headers provider; `Headers` is `Record<string, string>` |
|
|
38
38
|
| `wsUrl` | `string \| false` | WebSocket URL override; `false` disables the socket (optional) |
|
|
39
39
|
| `viewMode` | `'helper' \| 'full'` | Compact panel or full layout with a sidebar (default: `'helper'`) |
|
|
40
40
|
| `theme` | `'light' \| 'dark' \| 'system'` | Color scheme (default: `'light'`) |
|
|
41
41
|
| `agentName` | `string \| { en, ar }` | Header title while no thread is selected (optional) |
|
|
42
|
-
| `
|
|
42
|
+
| `thread` | `string` | A thread id to open on mount (optional) |
|
|
43
43
|
| `mediaRenderers` | `Record<string, MediaRenderer>` | Replace or add the media fences the assistant can draw (optional) |
|
|
44
44
|
| `trustSameOriginEmbeds` | `boolean` | Allow embedded tool pages served from this page's own origin (default: `false`) |
|
|
45
45
|
| `hooks.onToolCall` | `(toolCall, context) => unknown` | Answers a client tool; return `undefined` for tools you do not own (optional) |
|
|
@@ -47,7 +47,7 @@ Each widget is self-contained, so one page can render several widgets with diffe
|
|
|
47
47
|
| `hooks.onThreadDeselected` | `(thread) => void \| Promise<void>` | Runs when a thread closes (optional) |
|
|
48
48
|
| `toolComponents` | `Record<string, ComponentType<CortexToolComponentInputs>>` | Custom React components for tool rendering (optional) |
|
|
49
49
|
|
|
50
|
-
`transport.getHeaders` returns the headers every call carries, usually a bearer `Authorization`. Called straight from another origin, the engine accepts only `Authorization` and the headers the widget sets itself; route anything else through a same-origin proxy. The WebSocket takes its `token` query param from a bearer `Authorization` header when there is one.
|
|
50
|
+
`transport.getHeaders` returns the headers every call carries, usually a bearer `Authorization`. Called straight from another origin, the engine accepts only `Authorization` and the headers the widget sets itself; route anything else through a same-origin proxy. The WebSocket takes its `token` query param from a bearer `Authorization` header when there is one. The debug toggle shows only when Cortex offers this caller the debug view: always to a console operator, and to everyone only where the engine runs with `ENGINE_DEBUG=true`. Anyone else gets only what the widget's normal view draws, and so does a `toolComponents` entry for one of the agent's server tools: the model's line for the user as the call's input, and only whether it failed (or a dataset read's row count) as its output.
|
|
51
51
|
|
|
52
52
|
## Custom parts
|
|
53
53
|
|
|
@@ -110,19 +110,19 @@ for typing your own rows and chips.
|
|
|
110
110
|
|
|
111
111
|
One header serves both screens; `screen` says which is showing.
|
|
112
112
|
|
|
113
|
-
| Field | Type | Description
|
|
114
|
-
| -------------- | --------------------- |
|
|
115
|
-
| `screen` | `'chat' \| 'threads'` | Which screen the header is on
|
|
116
|
-
| `viewMode` | `'helper' \| 'full'` | The configured view mode
|
|
117
|
-
| `title` | `string \| null` | The open thread's title; `null` on a new chat
|
|
118
|
-
| `agentName` | `string \| undefined` | `agentName` in the widget's locale
|
|
119
|
-
| `threadCount` | `number \| undefined` | How many conversations the history lists; undefined while it loads
|
|
120
|
-
| `isWorking` | `boolean` | The agent is answering
|
|
121
|
-
| `debug` | `{ shown, on }` | Whether
|
|
122
|
-
| `newChat` | `() => void` | Starts a new chat
|
|
123
|
-
| `openHistory` | `() => void` | Shows the history: its screen, or the sidebar in full mode
|
|
124
|
-
| `closeHistory` | `() => void` | Returns to the open chat
|
|
125
|
-
| `toggleDebug` | `() => void` | Switches debug mode
|
|
113
|
+
| Field | Type | Description |
|
|
114
|
+
| -------------- | --------------------- | -------------------------------------------------------------------- |
|
|
115
|
+
| `screen` | `'chat' \| 'threads'` | Which screen the header is on |
|
|
116
|
+
| `viewMode` | `'helper' \| 'full'` | The configured view mode |
|
|
117
|
+
| `title` | `string \| null` | The open thread's title; `null` on a new chat |
|
|
118
|
+
| `agentName` | `string \| undefined` | `agentName` in the widget's locale |
|
|
119
|
+
| `threadCount` | `number \| undefined` | How many conversations the history lists; undefined while it loads |
|
|
120
|
+
| `isWorking` | `boolean` | The agent is answering |
|
|
121
|
+
| `debug` | `{ shown, on }` | Whether Cortex offers the debug view, and whether it is on |
|
|
122
|
+
| `newChat` | `() => void` | Starts a new chat; absent until Cortex confirms the caller may write |
|
|
123
|
+
| `openHistory` | `() => void` | Shows the history: its screen, or the sidebar in full mode |
|
|
124
|
+
| `closeHistory` | `() => void` | Returns to the open chat |
|
|
125
|
+
| `toggleDebug` | `() => void` | Switches debug mode |
|
|
126
126
|
|
|
127
127
|
### `landing`
|
|
128
128
|
|
|
@@ -143,13 +143,13 @@ landing for it.
|
|
|
143
143
|
|
|
144
144
|
The history's list. Its header is the `header` slot.
|
|
145
145
|
|
|
146
|
-
| Field | Type | Description
|
|
147
|
-
| ------------------ | --------------------------------- |
|
|
148
|
-
| `threads` | `ThreadSummary[] \| undefined` | Newest first; `undefined` while the first load is out
|
|
149
|
-
| `selectedThreadId` | `string \| undefined` | The open thread's id; `undefined` on a new chat
|
|
150
|
-
| `openThread` | `(thread: ThreadSummary) => void` | Opens a thread
|
|
151
|
-
| `deleteThread` | `(threadId: string) => void` | Deletes a thread
|
|
152
|
-
| `newChat` | `() => void` | Starts a new chat
|
|
146
|
+
| Field | Type | Description |
|
|
147
|
+
| ------------------ | --------------------------------- | -------------------------------------------------------------------- |
|
|
148
|
+
| `threads` | `ThreadSummary[] \| undefined` | Newest first; `undefined` while the first load is out |
|
|
149
|
+
| `selectedThreadId` | `string \| undefined` | The open thread's id; `undefined` on a new chat |
|
|
150
|
+
| `openThread` | `(thread: ThreadSummary) => void` | Opens a thread |
|
|
151
|
+
| `deleteThread` | `(threadId: string) => void` | Deletes a thread; absent until Cortex confirms the caller may write |
|
|
152
|
+
| `newChat` | `() => void` | Starts a new chat; absent until Cortex confirms the caller may write |
|
|
153
153
|
|
|
154
154
|
## Theming
|
|
155
155
|
|
|
@@ -197,7 +197,10 @@ That is how a tool of type `client` ("Answered by your app" in the console)
|
|
|
197
197
|
works: return its output from `hooks.onToolCall` for that tool name, or draw it
|
|
198
198
|
with a tool component. A `hooks.onToolCall` must return `undefined` for tool
|
|
199
199
|
names it does not own, since answering an unknown pending call would settle an
|
|
200
|
-
embedded flow before the user completes it.
|
|
200
|
+
embedded flow before the user completes it. A tool component draws a pending
|
|
201
|
+
call only once Cortex confirms the caller may send; until then, and always for
|
|
202
|
+
an operator inspecting a thread, the call shows as the widget's own line, and
|
|
203
|
+
the component draws it once it settles.
|
|
201
204
|
|
|
202
205
|
## Media blocks
|
|
203
206
|
|
|
@@ -221,8 +224,10 @@ root that takes its colors from your `--cortex-color-*` theme, and draws each
|
|
|
221
224
|
writes is its `media` setting in Cortex; reports are off by default.
|
|
222
225
|
|
|
223
226
|
`mediaRenderers` swaps a renderer or adds a fence tag of your own. A renderer
|
|
224
|
-
draws a closed fence's source into the host element and
|
|
225
|
-
its context carries the widget's
|
|
227
|
+
(`MediaRenderer`) draws a closed fence's source into the host element and
|
|
228
|
+
returns its teardown; its context (`MediaRenderContext`) carries the widget's
|
|
229
|
+
color `scheme` and `locale`. The field's map of tags to renderers is
|
|
230
|
+
`MediaRenderers`. The package exports all three types:
|
|
226
231
|
|
|
227
232
|
```ts
|
|
228
233
|
mediaRenderers: {
|
|
@@ -238,4 +243,4 @@ mediaRenderers: {
|
|
|
238
243
|
## Requirements
|
|
239
244
|
|
|
240
245
|
- React 18 or later
|
|
241
|
-
- Peer dependencies: `@tanstack/ai`, `@tanstack/ai-client`,
|
|
246
|
+
- Peer dependencies: `@tanstack/ai`, `@tanstack/ai-client`, `marked`, `dompurify`, `highlight.js`, plus the lazily loaded `mermaid`, `vega`, `vega-lite`, `vega-embed`, `leaflet`
|
package/dist/index.d.ts
CHANGED
|
@@ -121,7 +121,11 @@ export type CortexConfig = {
|
|
|
121
121
|
* or a map keyed by locale (`{ en: 'Support', ar: 'الدعم' }`).
|
|
122
122
|
*/
|
|
123
123
|
agentName?: Localized<string>;
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* A thread to open when the widget mounts, by id, once the thread list holds
|
|
126
|
+
* it: a deep link into one conversation, such as the console's inspector.
|
|
127
|
+
*/
|
|
128
|
+
thread?: string;
|
|
125
129
|
/**
|
|
126
130
|
* Render embedded tool pages served from this page's own origin with their
|
|
127
131
|
* full identity — which, same-origin, means no effective sandbox at all: such
|
|
@@ -149,12 +153,13 @@ export type CortexHeaderContext = {
|
|
|
149
153
|
/** How many conversations the history lists; undefined while the first load is out. */
|
|
150
154
|
threadCount: number | undefined;
|
|
151
155
|
isWorking: boolean;
|
|
152
|
-
/** Whether
|
|
156
|
+
/** Whether Cortex offers this caller the debug view, and whether it is on. */
|
|
153
157
|
debug: {
|
|
154
158
|
shown: boolean;
|
|
155
159
|
on: boolean;
|
|
156
160
|
};
|
|
157
|
-
|
|
161
|
+
/** Absent until the handshake says the caller may write; an operator inspecting a thread only reads. */
|
|
162
|
+
newChat?: () => void;
|
|
158
163
|
/** Shows the history: the history screen, or in full mode the sidebar where it is hidden. */
|
|
159
164
|
openHistory: () => void;
|
|
160
165
|
/** Returns to the open chat from wherever `openHistory` went. */
|
|
@@ -192,8 +197,9 @@ export type CortexThreadListContext = {
|
|
|
192
197
|
/** The open thread's id; undefined on a new chat. */
|
|
193
198
|
selectedThreadId: string | undefined;
|
|
194
199
|
openThread: (thread: ThreadSummary) => void;
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
/** Both absent until the handshake says the caller may write; an operator inspecting a thread only reads. */
|
|
201
|
+
deleteThread?: (threadId: string) => void;
|
|
202
|
+
newChat?: () => void;
|
|
197
203
|
};
|
|
198
204
|
/** Each part of the widget a consumer can draw itself, with the context it receives. */
|
|
199
205
|
export type CortexSlotContexts<View> = {
|