@object-ui/plugin-chatbot 17.6.0 → 18.0.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +2814 -0
  2. package/README.md +84 -28
  3. package/dist/AiPendingActionsInbox.d.ts +8 -2
  4. package/dist/AiPendingActionsInbox.d.ts.map +1 -1
  5. package/dist/ChatbotEnhanced.d.ts +235 -101
  6. package/dist/ChatbotEnhanced.d.ts.map +1 -1
  7. package/dist/FloatingChatbot.d.ts +1 -1
  8. package/dist/FloatingChatbot.d.ts.map +1 -1
  9. package/dist/chatMessageAdapter.d.ts +18 -6
  10. package/dist/chatMessageAdapter.d.ts.map +1 -1
  11. package/dist/elements/conversation.d.ts +1 -1
  12. package/dist/elements/conversation.d.ts.map +1 -1
  13. package/dist/elements/index.d.ts +10 -10
  14. package/dist/elements/message.d.ts +1 -1
  15. package/dist/elements/message.d.ts.map +1 -1
  16. package/dist/elements/prompt-input.d.ts +10 -2
  17. package/dist/elements/prompt-input.d.ts.map +1 -1
  18. package/dist/elements/tool.d.ts +13 -1
  19. package/dist/elements/tool.d.ts.map +1 -1
  20. package/dist/index.d.ts +48 -59
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +3217 -1945
  23. package/dist/index.umd.cjs +3 -3
  24. package/dist/mapMessages.d.ts +309 -6
  25. package/dist/mapMessages.d.ts.map +1 -1
  26. package/dist/recordLink.d.ts +34 -0
  27. package/dist/recordLink.d.ts.map +1 -0
  28. package/dist/tool-display.d.ts +97 -26
  29. package/dist/tool-display.d.ts.map +1 -1
  30. package/dist/useAgents.d.ts +5 -0
  31. package/dist/useAgents.d.ts.map +1 -1
  32. package/dist/useAiApprovalsTranslation.d.ts +76 -0
  33. package/dist/useAiApprovalsTranslation.d.ts.map +1 -0
  34. package/dist/useAiModels.d.ts +3 -1
  35. package/dist/useAiModels.d.ts.map +1 -1
  36. package/dist/useHitlInChat.d.ts +2 -2
  37. package/dist/useHitlInChat.d.ts.map +1 -1
  38. package/dist/useObjectChat.d.ts +94 -27
  39. package/dist/useObjectChat.d.ts.map +1 -1
  40. package/dist/usePendingActions.d.ts +5 -0
  41. package/dist/usePendingActions.d.ts.map +1 -1
  42. package/package.json +11 -15
package/README.md CHANGED
@@ -21,11 +21,17 @@ npm install @object-ui/plugin-chatbot
21
21
 
22
22
  ### Basic (Local/Demo Mode)
23
23
 
24
+ `ChatbotEnhancedMessage` is this package's runtime message contract, and `role` on it is
25
+ the closed union `'user' | 'assistant' | 'system'`. Annotate the state with it:
26
+ an unannotated array literal widens `role` to `string`, which `<Chatbot>` then
27
+ refuses.
28
+
24
29
  ```tsx
25
- import { Chatbot } from '@object-ui/plugin-chatbot';
30
+ import { useState } from 'react';
31
+ import { Chatbot, type ChatbotEnhancedMessage } from '@object-ui/plugin-chatbot';
26
32
 
27
33
  function App() {
28
- const [messages, setMessages] = useState([
34
+ const [messages, setMessages] = useState<ChatbotEnhancedMessage[]>([
29
35
  {
30
36
  id: '1',
31
37
  role: 'assistant',
@@ -34,7 +40,7 @@ function App() {
34
40
  ]);
35
41
 
36
42
  const handleSend = (content: string) => {
37
- const newMessage = {
43
+ const newMessage: ChatbotEnhancedMessage = {
38
44
  id: Date.now().toString(),
39
45
  role: 'user',
40
46
  content
@@ -114,7 +120,7 @@ function MyChat() {
114
120
 
115
121
  `messages` — and the `onSend(content, messages)` callback fed from it — is
116
122
  typed `ObjectChatMessage[]`, exported from this package. It is deliberately
117
- neither of the two `ChatMessage` types nearby, because neither is true of both
123
+ neither of the two message contracts nearby, because neither is true of both
118
124
  modes (objectui#4424):
119
125
 
120
126
  - **Not `@object-ui/types`' authoring `ChatMessage`.** In API mode the values
@@ -124,15 +130,20 @@ modes (objectui#4424):
124
130
  card, the "Review N changes" affordance, the plan card, the build panel and
125
131
  the inline charts. The authoring contract declares none of them, so rebuilding
126
132
  a message field-by-field from it deletes all of them, and the compiler agrees.
127
- - **Not this package's runtime `ChatMessage` either.** In local mode an authored
133
+ API mode also produces the AI SDK's three approval states
134
+ (`'approval-requested'` / `'approval-responded'` / `'output-denied'`), which
135
+ the authoring contract refuses — they are runtime-only (objectui#10018).
136
+ - **Not this package's runtime `ChatbotEnhancedMessage` either.** In local mode an authored
128
137
  `'tool'` role and the legacy `'partial-call'` / `'call'` / `'result'` tool
129
138
  states pass through untouched; they are folded only at the render seam
130
139
  (`toRuntimeMessages`, `chatMessageAdapter.ts`).
131
140
 
132
- `ObjectChatMessage` is a subtype of the authoring `ChatMessage`, so anything
133
- already typed against that keeps compiling — naming `ObjectChatMessage` is what
134
- lets you *read* the keys above. `timestamp` is always a `string` here: both
135
- modes absorb an authored `Date` before emitting.
141
+ `ObjectChatMessage` is **not** a subtype of the authoring `ChatMessage`
142
+ (objectui#10018): its tool invocations can carry those three runtime-only
143
+ approval states. So an `onSend` callback that declares its parameter as the
144
+ authoring `ChatMessage[]` does not type-check — declare `ObjectChatMessage[]`,
145
+ which is also what lets you *read* the keys above. `timestamp` is always a
146
+ `string` here: both modes absorb an authored `Date` before emitting.
136
147
 
137
148
  ## Schema-Driven Usage
138
149
 
@@ -191,6 +202,14 @@ safe side gutters, stays above the mobile bottom navigation area, and hides the
191
202
  FAB while open so the close button in the panel header is the only active
192
203
  dismiss control.
193
204
 
205
+ A host that wants to signal a waiting approval outside the chat can pass
206
+ `ChatbotEnhanced` the optional `onPlanApprovalPendingChange` callback. It is
207
+ called with `true` while the thread's newest proposed plan still offers
208
+ "Build it", and with `false` otherwise: no plan, the user approved it, or its
209
+ build ran. It fires once on mount and again on every change. The console uses
210
+ it to put a marker on its chat launchers while the chat is closed
211
+ (objectui#11666).
212
+
194
213
  During a conversation, the chat surface renders an inline assistant responding
195
214
  indicator while the backend is streaming, keeps message actions quiet until
196
215
  hover/focus, and summarizes backend failures into a compact retryable notice
@@ -280,9 +299,9 @@ import { AIElements } from '@object-ui/plugin-chatbot';
280
299
  </AIElements.Conversation>;
281
300
  ```
282
301
 
283
- ### The `ChatMessage` type
302
+ ### The `ChatbotEnhancedMessage` type
284
303
 
285
- `ChatMessage` is this package's one message contract — the shape
304
+ `ChatbotEnhancedMessage` is this package's one message contract — the shape
286
305
  `<ChatbotEnhanced>` renders and the mappers below produce. On top of the core
287
306
  `id` / `role` / `content` / `timestamp` / `avatar` / `avatarFallback` fields it
288
307
  carries the streaming and agent-process keys (`streaming`, `toolInvocations`,
@@ -290,21 +309,24 @@ carries the streaming and agent-process keys (`streaming`, `toolInvocations`,
290
309
  `charts`), all optional.
291
310
 
292
311
  ```tsx
293
- import type { ChatMessage } from '@object-ui/plugin-chatbot';
312
+ import type { ChatbotEnhancedMessage } from '@object-ui/plugin-chatbot';
294
313
  ```
295
314
 
296
- > This barrel used to export **two** different `ChatMessage` types: a minimal
297
- > one declared here, plus the enhanced shape aliased as
298
- > `ChatbotEnhancedMessage`. Reaching for the natural name got you the narrow
299
- > contract with no compiler complaint (objectui#4383). The minimal shape is
300
- > retired; `ChatbotEnhancedMessage` is now a **deprecated alias of the same
301
- > type**, kept only so existing importers keep compiling.
315
+ Its tool invocations are `ChatbotEnhancedToolInvocation`, also exported here.
316
+
317
+ `ChatMessage` is **not** exported from this package. That name belongs to
318
+ `@object-ui/types`, where it is the **JSON/SDUI schema** type
319
+ (`ChatbotSchema['messages']`, `role` includes `'tool'`, `timestamp` may be a
320
+ `Date`) — the authoring contract, not the React runtime one. Import the schema
321
+ type from `@object-ui/types` and the runtime type from this package.
302
322
 
303
- Note that `@object-ui/types` also exports a `ChatMessage`. That one is the
304
- **JSON/SDUI schema** type (`ChatbotSchema['messages']`, `role` includes
305
- `'tool'`, `timestamp` may be a `Date`) — the authoring contract, not the React
306
- runtime one. Import the schema type from `@object-ui/types` and the runtime
307
- type from this package.
323
+ > Migrating: this package used to publish the runtime shape as `ChatMessage`
324
+ > too, with `ChatbotEnhancedMessage` a deprecated alias of it (objectui#4383).
325
+ > One name for two contracts across the two packages let an auto-import pick
326
+ > the wrong one, so the runtime name is now `ChatbotEnhancedMessage` alone
327
+ > (objectui#6349). Replace `import { type ChatMessage } from
328
+ > '@object-ui/plugin-chatbot'` with `ChatbotEnhancedMessage` — the shape is
329
+ > unchanged.
308
330
 
309
331
  ### Authoring → runtime: `toRuntimeMessages`
310
332
 
@@ -326,7 +348,7 @@ function MyAuthoredChat({ messages }: { messages: AuthoredChatMessage[] }) {
326
348
  |---|---|---|---|
327
349
  | `role` | `'user' \| 'assistant' \| 'system' \| 'tool'` | `'user' \| 'assistant' \| 'system'` | a `'tool'` message **is an assistant message**: it renders as an assistant bubble with its content shown. `'system'` keeps its own role (`<Chatbot>` renders it as a centred pill). |
328
350
  | `timestamp` | `string \| Date` | `string` | a `Date` becomes its ISO 8601 string. The runtime renders the timestamp straight into a React child, where an object throws. |
329
- | `toolInvocations[].state` | AI SDK v6 states **+ legacy** `'partial-call' \| 'call' \| 'result'` | v6 states only | the legacy spellings map to `'input-streaming'` / `'input-available'` / `'output-available'` — the mapping the authoring type's own docs declare. |
351
+ | `toolInvocations[].state` | AI SDK v6 states **except** the three approval states, **+ legacy** `'partial-call' \| 'call' \| 'result'` | v6 states only | the legacy spellings map to `'input-streaming'` / `'input-available'` / `'output-available'` — the mapping the authoring type's own docs declare. `'approval-requested'` / `'approval-responded'` / `'output-denied'` are runtime-only and not authorable (objectui#10018); the adapter's input still admits them, because API-mode values carry them. |
330
352
  | everything else | — | — | passed through untouched, including keys the runtime contract does not declare. |
331
353
 
332
354
  The three registered SDUI renderers (`chatbot`, `chatbot-enhanced`,
@@ -346,18 +368,24 @@ of writing your own — they handle `parts: [{ type: 'text' | 'reasoning'
346
368
 
347
369
  ```tsx
348
370
  import { useChat } from '@ai-sdk/react';
371
+ import { DefaultChatTransport } from 'ai';
349
372
  import {
350
373
  ChatbotEnhanced,
351
374
  uiMessagesToChatMessages,
375
+ type ChatbotEnhancedProps,
352
376
  } from '@object-ui/plugin-chatbot';
353
377
 
378
+ declare const handleSend: ChatbotEnhancedProps['onSendMessage'];
379
+
354
380
  function MyChat() {
355
- const { messages, status } = useChat({ api: '/api/chat' });
381
+ const { messages, status } = useChat({
382
+ transport: new DefaultChatTransport({ api: '/api/chat' }),
383
+ });
356
384
  const isStreaming = status === 'streaming' || status === 'submitted';
357
385
  return (
358
386
  <ChatbotEnhanced
359
387
  messages={uiMessagesToChatMessages(messages, { isStreaming })}
360
- onSend={/* … */}
388
+ onSendMessage={handleSend}
361
389
  />
362
390
  );
363
391
  }
@@ -375,11 +403,35 @@ chat routes can use `surface="plain"` to remove the outer panel border and let
375
403
  messages, controls, and the prompt input sit in a continuous workspace:
376
404
 
377
405
  ```tsx
406
+ import { ChatbotEnhanced, type ChatbotEnhancedMessage } from '@object-ui/plugin-chatbot';
407
+
408
+ declare const messages: ChatbotEnhancedMessage[];
409
+
378
410
  <ChatbotEnhanced
379
411
  messages={messages}
380
412
  surface="plain"
381
413
  hideClearBar
382
- />
414
+ />;
415
+ ```
416
+
417
+ A host can add its own row to the prompt area with `promptHeaderSlot`. The row
418
+ is laid out in flow directly above the prompt input (and outside its form), so
419
+ the conversation gives up the room and the row never covers the input or the
420
+ last message. Content that renders nothing takes no space. Use it for standing
421
+ affordances such as an "unpublished changes" bar; `promptOverlaySlot` stays the
422
+ absolute-positioned overlay for slash-command palettes.
423
+
424
+ ```tsx
425
+ import { ChatbotEnhanced, type ChatbotEnhancedMessage } from '@object-ui/plugin-chatbot';
426
+
427
+ declare const messages: ChatbotEnhancedMessage[];
428
+ declare const pendingChanges: number;
429
+
430
+ <ChatbotEnhanced
431
+ messages={messages}
432
+ surface="plain"
433
+ promptHeaderSlot={pendingChanges > 0 ? <div>{pendingChanges} changes are not published yet</div> : null}
434
+ />;
383
435
  ```
384
436
 
385
437
  ### Agent process visibility
@@ -394,10 +446,14 @@ Use `processVisibility="debug"` for developer or admin trace surfaces that need
394
446
  the full reasoning panel, raw tool names, tool parameters, and tool results:
395
447
 
396
448
  ```tsx
449
+ import { ChatbotEnhanced, type ChatbotEnhancedMessage } from '@object-ui/plugin-chatbot';
450
+
451
+ declare const messages: ChatbotEnhancedMessage[];
452
+
397
453
  <ChatbotEnhanced
398
454
  messages={messages}
399
455
  processVisibility="debug"
400
- />
456
+ />;
401
457
  ```
402
458
 
403
459
  Use `processVisibility="hidden"` when a host wants to suppress non-interactive
@@ -38,9 +38,15 @@ export interface AiPendingActionsInboxProps {
38
38
  conversationId?: string;
39
39
  /** Visual style. `card` (default) wraps in a Card; `bare` renders without. */
40
40
  variant?: 'card' | 'bare';
41
- /** Optional title shown in the card header. */
41
+ /**
42
+ * Optional title shown in the card header. Defaults to the locale pack's
43
+ * `aiApprovals.title` — a lookup, so it cannot be a default parameter value.
44
+ */
42
45
  title?: string;
43
- /** Optional description shown in the card header. */
46
+ /**
47
+ * Optional description shown in the card header. Defaults to the locale
48
+ * pack's `aiApprovals.description`; pass `''` to hide it.
49
+ */
44
50
  description?: string;
45
51
  /** Class name applied to the outer wrapper. */
46
52
  className?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"AiPendingActionsInbox.d.ts","sourceRoot":"","sources":["../src/AiPendingActionsInbox.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAoD/B,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,SAA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