@gravity-ui/aikit 2.3.0 → 2.4.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 (56) hide show
  1. package/build/cjs/components/organisms/AssistantMessage/defaultMessageTypeRegistry.js +6 -0
  2. package/build/cjs/components/organisms/AssistantMessage/defaultMessageTypeRegistry.js.map +1 -1
  3. package/build/cjs/hooks/index.d.ts +2 -0
  4. package/build/cjs/hooks/index.js +2 -0
  5. package/build/cjs/hooks/index.js.map +1 -1
  6. package/build/cjs/hooks/useToolResultContinuation.d.ts +31 -0
  7. package/build/cjs/hooks/useToolResultContinuation.js +91 -0
  8. package/build/cjs/hooks/useToolResultContinuation.js.map +1 -0
  9. package/build/cjs/hooks/useToolset.d.ts +24 -0
  10. package/build/cjs/hooks/useToolset.js +26 -0
  11. package/build/cjs/hooks/useToolset.js.map +1 -0
  12. package/build/cjs/package.json +1 -1
  13. package/build/cjs/utils/index.d.ts +1 -0
  14. package/build/cjs/utils/index.js +1 -0
  15. package/build/cjs/utils/index.js.map +1 -1
  16. package/build/cjs/utils/messageTypeRegistry.d.ts +8 -1
  17. package/build/cjs/utils/messageTypeRegistry.js +14 -2
  18. package/build/cjs/utils/messageTypeRegistry.js.map +1 -1
  19. package/build/cjs/utils/toolset/i18n/en.json +3 -0
  20. package/build/cjs/utils/toolset/i18n/index.d.ts +13 -0
  21. package/build/cjs/utils/toolset/i18n/index.js +10 -0
  22. package/build/cjs/utils/toolset/i18n/index.js.map +1 -0
  23. package/build/cjs/utils/toolset/i18n/ru.json +3 -0
  24. package/build/cjs/utils/toolset/index.d.ts +142 -0
  25. package/build/cjs/utils/toolset/index.js +183 -0
  26. package/build/cjs/utils/toolset/index.js.map +1 -0
  27. package/build/esm/components/organisms/AssistantMessage/defaultMessageTypeRegistry.js +6 -0
  28. package/build/esm/components/organisms/AssistantMessage/defaultMessageTypeRegistry.js.map +1 -1
  29. package/build/esm/hooks/index.d.ts +2 -0
  30. package/build/esm/hooks/index.js +2 -0
  31. package/build/esm/hooks/index.js.map +1 -1
  32. package/build/esm/hooks/useToolResultContinuation.d.ts +31 -0
  33. package/build/esm/hooks/useToolResultContinuation.js +87 -0
  34. package/build/esm/hooks/useToolResultContinuation.js.map +1 -0
  35. package/build/esm/hooks/useToolset.d.ts +24 -0
  36. package/build/esm/hooks/useToolset.js +23 -0
  37. package/build/esm/hooks/useToolset.js.map +1 -0
  38. package/build/esm/package.json +1 -1
  39. package/build/esm/utils/index.d.ts +1 -0
  40. package/build/esm/utils/index.js +1 -0
  41. package/build/esm/utils/index.js.map +1 -1
  42. package/build/esm/utils/messageTypeRegistry.d.ts +8 -1
  43. package/build/esm/utils/messageTypeRegistry.js +14 -2
  44. package/build/esm/utils/messageTypeRegistry.js.map +1 -1
  45. package/build/esm/utils/toolset/i18n/en.json +3 -0
  46. package/build/esm/utils/toolset/i18n/index.d.ts +13 -0
  47. package/build/esm/utils/toolset/i18n/index.js +6 -0
  48. package/build/esm/utils/toolset/i18n/index.js.map +1 -0
  49. package/build/esm/utils/toolset/i18n/ru.json +3 -0
  50. package/build/esm/utils/toolset/index.d.ts +142 -0
  51. package/build/esm/utils/toolset/index.js +176 -0
  52. package/build/esm/utils/toolset/index.js.map +1 -0
  53. package/docs/GENUI.md +627 -0
  54. package/docs/HOOKS.md +65 -11
  55. package/llms.txt +2 -1
  56. package/package.json +11 -1
package/docs/HOOKS.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # Hooks
2
2
 
3
- AIKit exports 7 public hooks. All are re-exported from the package root and from the `@gravity-ui/aikit/hooks` subpath.
4
-
5
- | Hook | Purpose |
6
- | ----------------------------------------------------------- | ------------------------------------------------------------ |
7
- | [`useDateFormatter`](#usedateformatter) | Format chat timestamps with locale and relative-date logic |
8
- | [`useToolMessage`](#usetoolmessage) | Tool-message state machine (expand/collapse based on status) |
9
- | [`useSmartScroll`](#usesmartscroll) | Auto-scroll to bottom while respecting user scroll-up |
10
- | [`useScrollPreservation`](#usescrollpreservation) | Preserve scroll position when items are prepended |
11
- | [`useAutoCollapseOnSuccess`](#useautocollapseonsuccess) | Collapse a section when its async operation succeeds |
12
- | [`useAutoCollapseOnCancelled`](#useautocollapseoncancelled) | Collapse a section when its async operation is cancelled |
13
- | [`useFileUploadStore`](#usefileuploadstore) | Standalone file-upload store with progress/error states |
3
+ AIKit exports 8 public hooks. All are re-exported from the package root and from the `@gravity-ui/aikit/hooks` subpath.
4
+
5
+ | Hook | Purpose |
6
+ | ----------------------------------------------------------- | ------------------------------------------------------------------------------ |
7
+ | [`useDateFormatter`](#usedateformatter) | Format chat timestamps with locale and relative-date logic |
8
+ | [`useToolMessage`](#usetoolmessage) | Tool-message state machine (expand/collapse based on status) |
9
+ | [`useSmartScroll`](#usesmartscroll) | Auto-scroll to bottom while respecting user scroll-up |
10
+ | [`useScrollPreservation`](#usescrollpreservation) | Preserve scroll position when items are prepended |
11
+ | [`useAutoCollapseOnSuccess`](#useautocollapseonsuccess) | Collapse a section when its async operation succeeds |
12
+ | [`useAutoCollapseOnCancelled`](#useautocollapseoncancelled) | Collapse a section when its async operation is cancelled |
13
+ | [`useFileUploadStore`](#usefileuploadstore) | Standalone file-upload store with progress/error states |
14
+ | [`useToolset`](#usetoolset) | Wire a toolset into the chat: renderer registry + history merge for tool calls |
14
15
 
15
16
  ## `useDateFormatter`
16
17
 
@@ -129,3 +130,56 @@ type UseFileUploadStoreReturn<Meta> = {
129
130
  ```
130
131
 
131
132
  See `src/hooks/useFileUploadStore.ts` for the complete type signature.
133
+
134
+ ## `useToolset`
135
+
136
+ Wires a `Toolset` into the chat: returns a `MessageRendererRegistry` whose `tool`
137
+ dispatcher renders your tool components, and a `handleToolResult` callback that
138
+ merges results into history via `applyToolResult`. It does not run model
139
+ continuation side effects; pair it with `useToolResultContinuation` when you
140
+ need to re-send the updated conversation after a tool completes.
141
+
142
+ ```typescript
143
+ function useToolset<TCustom extends TMessageContent = never>(
144
+ options: UseToolsetOptions<TCustom>,
145
+ ): UseToolsetReturn;
146
+
147
+ type UseToolsetOptions<TCustom> = {
148
+ toolset: Toolset;
149
+ setMessages: Dispatch<SetStateAction<TChatMessage<TCustom>[]>>;
150
+ registry?: MessageRendererRegistry;
151
+ };
152
+
153
+ type UseToolsetReturn = {
154
+ messageRendererRegistry: MessageRendererRegistry;
155
+ handleToolResult: (event: ToolsetResultEvent) => void;
156
+ };
157
+ ```
158
+
159
+ ## `useToolResultContinuation`
160
+
161
+ Observes `messages` and calls `onSettled` once when a tool part moves from a
162
+ pending status (`loading`, `waitingConfirmation`, `waitingSubmission`) to a
163
+ terminal status (`success`, `error`, `cancelled`). Tools that are already
164
+ terminal in the first observed snapshot do not fire, so replay/restore is silent
165
+ by default.
166
+
167
+ ```typescript
168
+ function useToolResultContinuation<TCustom extends TMessageContent = never>(
169
+ options: UseToolResultContinuationOptions<TCustom>,
170
+ ): void;
171
+
172
+ type UseToolResultContinuationOptions<TCustom> = {
173
+ messages: TChatMessage<TCustom>[];
174
+ onSettled: (event: ToolSettledEvent<TCustom>) => void;
175
+ };
176
+
177
+ type ToolSettledEvent<TCustom> = {
178
+ toolCallId: string;
179
+ toolName: string;
180
+ status: 'success' | 'error' | 'cancelled';
181
+ messages: TChatMessage<TCustom>[];
182
+ };
183
+ ```
184
+
185
+ See [GENUI.md](./GENUI.md) for an end-to-end example with a live model adapter.
package/llms.txt CHANGED
@@ -88,6 +88,7 @@ Tree-shaken imports: `@gravity-ui/aikit/PromptInput`, `/Header`, `/MessageList`,
88
88
  - [useAutoCollapseOnSuccess](https://github.com/gravity-ui/aikit/blob/main/src/hooks/useAutoCollapseOnSuccess.ts): auto-collapse a section on success status
89
89
  - [useAutoCollapseOnCancelled](https://github.com/gravity-ui/aikit/blob/main/src/hooks/useAutoCollapseOnCancelled.ts): auto-collapse a section on cancelled status
90
90
  - [useFileUploadStore](https://github.com/gravity-ui/aikit/blob/main/src/hooks/useFileUploadStore.ts): headless file-upload store with progress/error states
91
+ - [useToolset](https://github.com/gravity-ui/aikit/blob/main/src/hooks/useToolset.ts): wire a toolset into the chat — renderer registry + history merge for tool calls
91
92
 
92
93
  ## Theming & i18n
93
94
 
@@ -103,6 +104,6 @@ Tree-shaken imports: `@gravity-ui/aikit/PromptInput`, `/Header`, `/MessageList`,
103
104
  - [Live Storybook](https://preview.gravity-ui.com/aikit/): interactive component playground
104
105
  - [Project Structure](https://github.com/gravity-ui/aikit/blob/main/docs/PROJECT_STRUCTURE.md): source tree (for contributors)
105
106
  - [Components Catalog](https://github.com/gravity-ui/aikit/blob/main/docs/COMPONENTS.md): same component list as above, with table-style reference
106
- - [Hooks Reference](https://github.com/gravity-ui/aikit/blob/main/docs/HOOKS.md): detailed signatures for the 7 public hooks
107
+ - [Hooks Reference](https://github.com/gravity-ui/aikit/blob/main/docs/HOOKS.md): detailed signatures for the 8 public hooks
107
108
  - [AI Agent Integration](https://github.com/gravity-ui/aikit/blob/main/docs/AI_AGENTS.md): drop-in Cursor rule and Claude Code skill for consumer projects
108
109
  - [Issue tracker](https://github.com/gravity-ui/aikit/issues)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/aikit",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Gravity UI base kit for building ai assistant chats",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -98,6 +98,16 @@
98
98
  "default": "./build/cjs/utils/clipboardUtils.js"
99
99
  }
100
100
  },
101
+ "./utils/toolset": {
102
+ "import": {
103
+ "types": "./build/esm/utils/toolset/index.d.ts",
104
+ "default": "./build/esm/utils/toolset/index.js"
105
+ },
106
+ "require": {
107
+ "types": "./build/cjs/utils/toolset/index.d.ts",
108
+ "default": "./build/cjs/utils/toolset/index.js"
109
+ }
110
+ },
101
111
  "./adapters": {
102
112
  "import": {
103
113
  "types": "./build/esm/adapters/index.d.ts",