@aintela/chat 0.2.47 → 0.2.48
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 +29 -0
- package/dist/components.js +3739 -3644
- package/dist/components.js.map +1 -1
- package/dist/index.js +98 -96
- package/dist/src/components/AiChat/useTurnOpen.d.ts +18 -0
- package/dist/src/components/Library/TurnAwareButton.d.ts +46 -0
- package/dist/src/components/Library/TurnAwareButton.test.d.ts +1 -0
- package/dist/src/components/Library/turnAwareButtonState.d.ts +42 -0
- package/dist/src/components/Library/turnAwareButtonState.test.d.ts +1 -0
- package/dist/src/components/index.d.ts +4 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -77,12 +77,41 @@ manifest export and the generation:
|
|
|
77
77
|
"gen:uitools": "dotnet run --project ../path/to/Server.UiToolsManifest -- src/agent/generated/uitools.manifest.json && aia-gen-uitools src/agent/generated/uitools.manifest.json src/agent/generated"
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
### `TurnAwareButton` — controls drawn inside a chat message
|
|
81
|
+
|
|
82
|
+
A UI-tool component is rendered **while the agent is still streaming its turn** (a
|
|
83
|
+
`present_tripstretch` card appears mid-sentence), and acting on it then races the run
|
|
84
|
+
that is still writing to the session. Use `TurnAwareButton` instead of MUI's `Button`
|
|
85
|
+
for any control inside a chat-rendered component: while the turn is open it is
|
|
86
|
+
disabled **and spinning**. The spinner is the point — someone clicking a card mid-turn
|
|
87
|
+
has usually just not noticed the agent is still writing, so the button both refuses
|
|
88
|
+
the click and shows why, instead of sitting there inertly dead.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { TurnAwareButton } from '@aintela/chat';
|
|
92
|
+
|
|
93
|
+
// Return the promise so the button keeps waiting across the gap between sending and
|
|
94
|
+
// the server's `open_turn` — otherwise it briefly offers itself for a second click.
|
|
95
|
+
<TurnAwareButton variant="contained" onClick={() => sendMessage('escolhi a opção 2')}>
|
|
96
|
+
selecionar ida
|
|
97
|
+
</TurnAwareButton>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Outside an `<AiChat>` provider there is no turn, so it behaves exactly like `Button` —
|
|
101
|
+
a component shared between the chat and a plain page needs no branch. The same live
|
|
102
|
+
flag is available on its own as `useTurnOpen()`
|
|
103
|
+
(prefer it over `UiToolContext.onGoing`, which is a per-surface snapshot: `false`
|
|
104
|
+
forever on a card that has settled into history, even while a later turn streams).
|
|
105
|
+
|
|
80
106
|
## Testing
|
|
81
107
|
|
|
82
108
|
Vitest runs the unit + integration suite. Co-located `*.test.ts` files
|
|
83
109
|
live next to the source they cover; shared fixtures + fakes live under
|
|
84
110
|
`tests/` and are imported via the `@tests/*` path alias.
|
|
85
111
|
|
|
112
|
+
The default environment is `node`; a test that needs a DOM opts in per file with a
|
|
113
|
+
`// @vitest-environment happy-dom` pragma (see `TurnAwareButton.test.tsx`).
|
|
114
|
+
|
|
86
115
|
```bash
|
|
87
116
|
npm test # one-shot run
|
|
88
117
|
npm run test:watch # watch mode
|