@assistant-ui/react 0.12.1 → 0.12.3

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 (115) hide show
  1. package/dist/client/Suggestions.d.ts +11 -0
  2. package/dist/client/Suggestions.d.ts.map +1 -0
  3. package/dist/client/Suggestions.js +43 -0
  4. package/dist/client/Suggestions.js.map +1 -0
  5. package/dist/client/Tools.d.ts.map +1 -1
  6. package/dist/client/Tools.js +5 -1
  7. package/dist/client/Tools.js.map +1 -1
  8. package/dist/context/providers/SuggestionByIndexProvider.d.ts +6 -0
  9. package/dist/context/providers/SuggestionByIndexProvider.d.ts.map +1 -0
  10. package/dist/context/providers/SuggestionByIndexProvider.js +14 -0
  11. package/dist/context/providers/SuggestionByIndexProvider.js.map +1 -0
  12. package/dist/context/providers/index.d.ts +1 -0
  13. package/dist/context/providers/index.d.ts.map +1 -1
  14. package/dist/context/providers/index.js +1 -0
  15. package/dist/context/providers/index.js.map +1 -1
  16. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts +5 -0
  17. package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
  18. package/dist/legacy-runtime/AssistantRuntimeProvider.js +2 -4
  19. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  20. package/dist/legacy-runtime/RuntimeAdapter.js +2 -1
  21. package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -1
  22. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  23. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +3 -5
  24. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  25. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts +10 -12
  26. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.d.ts.map +1 -1
  27. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js +14 -19
  28. package/dist/legacy-runtime/runtime-cores/assistant-transport/utils.js.map +1 -1
  29. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
  30. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +32 -4
  31. package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
  32. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.d.ts.map +1 -1
  33. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.js +3 -0
  34. package/dist/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.js.map +1 -1
  35. package/dist/model-context/index.d.ts +1 -0
  36. package/dist/model-context/index.d.ts.map +1 -1
  37. package/dist/model-context/index.js +1 -0
  38. package/dist/model-context/index.js.map +1 -1
  39. package/dist/primitives/assistantModal/AssistantModalRoot.js +1 -1
  40. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  41. package/dist/primitives/index.d.ts +1 -0
  42. package/dist/primitives/index.d.ts.map +1 -1
  43. package/dist/primitives/index.js +1 -0
  44. package/dist/primitives/index.js.map +1 -1
  45. package/dist/primitives/message/MessageParts.d.ts +11 -0
  46. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  47. package/dist/primitives/message/MessageParts.js +18 -2
  48. package/dist/primitives/message/MessageParts.js.map +1 -1
  49. package/dist/primitives/suggestion/SuggestionDescription.d.ts +18 -0
  50. package/dist/primitives/suggestion/SuggestionDescription.d.ts.map +1 -0
  51. package/dist/primitives/suggestion/SuggestionDescription.js +19 -0
  52. package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -0
  53. package/dist/primitives/suggestion/SuggestionTitle.d.ts +18 -0
  54. package/dist/primitives/suggestion/SuggestionTitle.d.ts.map +1 -0
  55. package/dist/primitives/suggestion/SuggestionTitle.js +19 -0
  56. package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -0
  57. package/dist/primitives/suggestion/SuggestionTrigger.d.ts +49 -0
  58. package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -0
  59. package/dist/primitives/suggestion/SuggestionTrigger.js +45 -0
  60. package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -0
  61. package/dist/primitives/suggestion/index.d.ts +4 -0
  62. package/dist/primitives/suggestion/index.d.ts.map +1 -0
  63. package/dist/primitives/suggestion/index.js +4 -0
  64. package/dist/primitives/suggestion/index.js.map +1 -0
  65. package/dist/primitives/thread/ThreadSuggestions.d.ts +53 -0
  66. package/dist/primitives/thread/ThreadSuggestions.d.ts.map +1 -0
  67. package/dist/primitives/thread/ThreadSuggestions.js +58 -0
  68. package/dist/primitives/thread/ThreadSuggestions.js.map +1 -0
  69. package/dist/primitives/thread/index.d.ts +1 -0
  70. package/dist/primitives/thread/index.d.ts.map +1 -1
  71. package/dist/primitives/thread/index.js +1 -0
  72. package/dist/primitives/thread/index.js.map +1 -1
  73. package/dist/types/scopes/index.d.ts +2 -0
  74. package/dist/types/scopes/index.d.ts.map +1 -1
  75. package/dist/types/scopes/suggestion.d.ts +20 -0
  76. package/dist/types/scopes/suggestion.d.ts.map +1 -0
  77. package/dist/types/scopes/suggestion.js +2 -0
  78. package/dist/types/scopes/suggestion.js.map +1 -0
  79. package/dist/types/scopes/suggestions.d.ts +20 -0
  80. package/dist/types/scopes/suggestions.d.ts.map +1 -0
  81. package/dist/types/scopes/suggestions.js +2 -0
  82. package/dist/types/scopes/suggestions.js.map +1 -0
  83. package/dist/types/store-augmentation.d.ts +4 -0
  84. package/dist/types/store-augmentation.d.ts.map +1 -1
  85. package/dist/utils/idUtils.d.ts +2 -0
  86. package/dist/utils/idUtils.d.ts.map +1 -1
  87. package/dist/utils/idUtils.js +3 -0
  88. package/dist/utils/idUtils.js.map +1 -1
  89. package/package.json +10 -10
  90. package/src/client/Suggestions.ts +74 -0
  91. package/src/client/Tools.ts +10 -1
  92. package/src/context/providers/SuggestionByIndexProvider.tsx +23 -0
  93. package/src/context/providers/index.ts +1 -0
  94. package/src/legacy-runtime/AssistantRuntimeProvider.tsx +8 -5
  95. package/src/legacy-runtime/RuntimeAdapter.ts +2 -1
  96. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +3 -4
  97. package/src/legacy-runtime/runtime-cores/assistant-transport/utils.ts +19 -24
  98. package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +42 -7
  99. package/src/legacy-runtime/runtime-cores/remote-thread-list/BaseSubscribable.tsx +3 -0
  100. package/src/model-context/index.ts +2 -0
  101. package/src/primitives/assistantModal/AssistantModalRoot.tsx +1 -1
  102. package/src/primitives/index.ts +1 -0
  103. package/src/primitives/message/MessageParts.tsx +45 -1
  104. package/src/primitives/suggestion/SuggestionDescription.tsx +33 -0
  105. package/src/primitives/suggestion/SuggestionTitle.tsx +33 -0
  106. package/src/primitives/suggestion/SuggestionTrigger.tsx +79 -0
  107. package/src/primitives/suggestion/index.ts +3 -0
  108. package/src/primitives/thread/ThreadSuggestions.tsx +109 -0
  109. package/src/primitives/thread/index.ts +4 -0
  110. package/src/tests/external-message-converter.test.ts +105 -16
  111. package/src/types/scopes/index.ts +12 -0
  112. package/src/types/scopes/suggestion.ts +20 -0
  113. package/src/types/scopes/suggestions.ts +21 -0
  114. package/src/types/store-augmentation.ts +4 -0
  115. package/src/utils/idUtils.tsx +4 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestions.d.ts","sourceRoot":"","sources":["../../../src/types/scopes/suggestions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAqB;AAEtD,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,IAAI,gBAAgB,CAAC;IAC7B,UAAU,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,iBAAiB,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,kBAAkB,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=suggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestions.js","sourceRoot":"","sources":["../../../src/types/scopes/suggestions.ts"],"names":[],"mappings":""}
@@ -8,6 +8,8 @@ import type { ComposerClientSchema } from "./scopes/composer.js";
8
8
  import type { AttachmentClientSchema } from "./scopes/attachment.js";
9
9
  import type { ToolsClientSchema } from "./scopes/tools.js";
10
10
  import type { ModelContextClientSchema } from "./scopes/modelContext.js";
11
+ import type { SuggestionsClientSchema } from "./scopes/suggestions.js";
12
+ import type { SuggestionClientSchema } from "./scopes/suggestion.js";
11
13
  declare module "@assistant-ui/store" {
12
14
  interface ClientRegistry {
13
15
  threads: ThreadsClientSchema;
@@ -19,6 +21,8 @@ declare module "@assistant-ui/store" {
19
21
  attachment: AttachmentClientSchema;
20
22
  tools: ToolsClientSchema;
21
23
  modelContext: ModelContextClientSchema;
24
+ suggestions: SuggestionsClientSchema;
25
+ suggestion: SuggestionClientSchema;
22
26
  }
23
27
  }
24
28
  //# sourceMappingURL=store-augmentation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-augmentation.d.ts","sourceRoot":"","sources":["../../src/types/store-augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,4BAAyB;AAC5D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAgC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAAwB;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,4BAAyB;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,yBAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,6BAA0B;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA4B;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAuB;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,iCAA8B;AAEtE,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,cAAc;QACtB,OAAO,EAAE,mBAAmB,CAAC;QAC7B,cAAc,EAAE,0BAA0B,CAAC;QAC3C,MAAM,EAAE,kBAAkB,CAAC;QAC3B,OAAO,EAAE,mBAAmB,CAAC;QAC7B,IAAI,EAAE,gBAAgB,CAAC;QACvB,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,UAAU,EAAE,sBAAsB,CAAC;QACnC,KAAK,EAAE,iBAAiB,CAAC;QACzB,YAAY,EAAE,wBAAwB,CAAC;KACxC;CACF"}
1
+ {"version":3,"file":"store-augmentation.d.ts","sourceRoot":"","sources":["../../src/types/store-augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,4BAAyB;AAC5D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAgC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAAwB;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,4BAAyB;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,yBAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,6BAA0B;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA4B;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAuB;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,iCAA8B;AACtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,gCAA6B;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,+BAA4B;AAElE,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,cAAc;QACtB,OAAO,EAAE,mBAAmB,CAAC;QAC7B,cAAc,EAAE,0BAA0B,CAAC;QAC3C,MAAM,EAAE,kBAAkB,CAAC;QAC3B,OAAO,EAAE,mBAAmB,CAAC;QAC7B,IAAI,EAAE,gBAAgB,CAAC;QACvB,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,UAAU,EAAE,sBAAsB,CAAC;QACnC,KAAK,EAAE,iBAAiB,CAAC;QACzB,YAAY,EAAE,wBAAwB,CAAC;QACvC,WAAW,EAAE,uBAAuB,CAAC;QACrC,UAAU,EAAE,sBAAsB,CAAC;KACpC;CACF"}
@@ -1,4 +1,6 @@
1
1
  export declare const generateId: (size?: number) => string;
2
2
  export declare const generateOptimisticId: () => string;
3
3
  export declare const isOptimisticId: (id: string) => boolean;
4
+ export declare const generateErrorMessageId: () => string;
5
+ export declare const isErrorMessageId: (id: string) => boolean;
4
6
  //# sourceMappingURL=idUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"idUtils.d.ts","sourceRoot":"","sources":["../../src/utils/idUtils.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,2BAGtB,CAAC;AAGF,eAAO,MAAM,oBAAoB,cAA6C,CAAC;AAC/E,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,YAAoC,CAAC"}
1
+ {"version":3,"file":"idUtils.d.ts","sourceRoot":"","sources":["../../src/utils/idUtils.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,2BAGtB,CAAC;AAGF,eAAO,MAAM,oBAAoB,cAA6C,CAAC;AAC/E,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,YAAoC,CAAC;AAG9E,eAAO,MAAM,sBAAsB,cAAwC,CAAC;AAC5E,eAAO,MAAM,gBAAgB,GAAI,IAAI,MAAM,YAA+B,CAAC"}
@@ -3,4 +3,7 @@ export const generateId = customAlphabet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZab
3
3
  const optimisticPrefix = "__optimistic__";
4
4
  export const generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
5
5
  export const isOptimisticId = (id) => id.startsWith(optimisticPrefix);
6
+ const errorPrefix = "__error__";
7
+ export const generateErrorMessageId = () => `${errorPrefix}${generateId()}`;
8
+ export const isErrorMessageId = (id) => id.startsWith(errorPrefix);
6
9
  //# sourceMappingURL=idUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"idUtils.js","sourceRoot":"","sources":["../../src/utils/idUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CACtC,gEAAgE,EAChE,CAAC,CACF,CAAC;AAEF,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,GAAG,gBAAgB,GAAG,UAAU,EAAE,EAAE,CAAC;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC"}
1
+ {"version":3,"file":"idUtils.js","sourceRoot":"","sources":["../../src/utils/idUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CACtC,gEAAgE,EAChE,CAAC,CACF,CAAC;AAEF,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,GAAG,gBAAgB,GAAG,UAAU,EAAE,EAAE,CAAC;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;AAE9E,MAAM,WAAW,GAAG,WAAW,CAAC;AAChC,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,GAAG,WAAW,GAAG,UAAU,EAAE,EAAE,CAAC;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "TypeScript/React library for AI Chat",
5
5
  "keywords": [
6
6
  "radix-ui",
@@ -49,9 +49,9 @@
49
49
  ],
50
50
  "sideEffects": false,
51
51
  "dependencies": {
52
- "assistant-cloud": "^0.1.13",
53
- "@assistant-ui/tap": "^0.4.0",
54
- "@assistant-ui/store": "^0.1.0",
52
+ "assistant-cloud": "^0.1.15",
53
+ "@assistant-ui/tap": "^0.4.2",
54
+ "@assistant-ui/store": "^0.1.2",
55
55
  "@radix-ui/primitive": "^1.1.3",
56
56
  "@radix-ui/react-compose-refs": "^1.1.2",
57
57
  "@radix-ui/react-context": "^1.1.3",
@@ -61,10 +61,10 @@
61
61
  "@radix-ui/react-slot": "^1.2.4",
62
62
  "@radix-ui/react-use-callback-ref": "^1.1.1",
63
63
  "@radix-ui/react-use-escape-keydown": "^1.1.1",
64
- "assistant-stream": "^0.2.47",
64
+ "assistant-stream": "^0.3.0",
65
65
  "nanoid": "^5.1.6",
66
66
  "react-textarea-autosize": "^8.5.9",
67
- "zod": "^4.3.5",
67
+ "zod": "^4.3.6",
68
68
  "zustand": "^5.0.10"
69
69
  },
70
70
  "peerDependencies": {
@@ -83,12 +83,12 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/json-schema": "^7.0.15",
86
- "@types/node": "^25.0.9",
86
+ "@types/node": "^25.0.10",
87
87
  "@types/react": "^19.2.9",
88
88
  "@types/react-dom": "^19.2.3",
89
- "react": "^19.2.3",
90
- "react-dom": "^19.2.3",
91
- "vitest": "^4.0.17",
89
+ "react": "^19.2.4",
90
+ "react-dom": "^19.2.4",
91
+ "vitest": "^4.0.18",
92
92
  "@assistant-ui/x-buildutils": "0.0.1"
93
93
  },
94
94
  "publishConfig": {
@@ -0,0 +1,74 @@
1
+ import { resource, tapState, withKey } from "@assistant-ui/tap";
2
+ import { type ClientOutput, tapClientLookup } from "@assistant-ui/store";
3
+ import type { SuggestionsState, SuggestionState } from "../types/scopes";
4
+
5
+ export type SuggestionConfig =
6
+ | string
7
+ | { title: string; label: string; prompt: string };
8
+
9
+ const SuggestionClient = resource(
10
+ (state: SuggestionState): ClientOutput<"suggestion"> => {
11
+ return {
12
+ state,
13
+ methods: {
14
+ getState: () => state,
15
+ },
16
+ };
17
+ },
18
+ );
19
+
20
+ const SuggestionsResource = resource(
21
+ (suggestions?: SuggestionConfig[]): ClientOutput<"suggestions"> => {
22
+ const [state] = tapState<SuggestionsState>(() => {
23
+ const normalizedSuggestions = (suggestions ?? []).map((s) => {
24
+ if (typeof s === "string") {
25
+ return {
26
+ title: s,
27
+ label: "",
28
+ prompt: s,
29
+ };
30
+ }
31
+ return {
32
+ title: s.title,
33
+ label: s.label,
34
+ prompt: s.prompt,
35
+ };
36
+ });
37
+
38
+ return {
39
+ suggestions: normalizedSuggestions,
40
+ };
41
+ });
42
+
43
+ const suggestionClients = tapClientLookup(
44
+ () =>
45
+ state.suggestions.map((suggestion, index) =>
46
+ withKey(index, SuggestionClient(suggestion)),
47
+ ),
48
+ [state.suggestions],
49
+ );
50
+
51
+ return {
52
+ state,
53
+ methods: {
54
+ getState: () => state,
55
+ suggestion: ({ index }: { index: number }) => {
56
+ return suggestionClients.get({ index });
57
+ },
58
+ },
59
+ };
60
+ },
61
+ );
62
+
63
+ export const Suggestions: {
64
+ (): import("@assistant-ui/tap").ResourceElement<
65
+ ClientOutput<"suggestions">,
66
+ undefined
67
+ >;
68
+ (
69
+ suggestions: SuggestionConfig[],
70
+ ): import("@assistant-ui/tap").ResourceElement<
71
+ ClientOutput<"suggestions">,
72
+ SuggestionConfig[]
73
+ >;
74
+ } = SuggestionsResource as any;
@@ -1,9 +1,14 @@
1
1
  import { resource, tapState, tapEffect, tapCallback } from "@assistant-ui/tap";
2
- import { tapAssistantClientRef, type ClientOutput } from "@assistant-ui/store";
2
+ import {
3
+ tapAssistantClientRef,
4
+ type ClientOutput,
5
+ attachDefaultPeers,
6
+ } from "@assistant-ui/store";
3
7
  import { ToolsState } from "../types/scopes";
4
8
  import type { Tool } from "assistant-stream";
5
9
  import { type Toolkit } from "../model-context/toolbox";
6
10
  import { ToolCallMessagePartComponent } from "../types";
11
+ import { ModelContext } from "./ModelContextClient";
7
12
 
8
13
  export const Tools = resource(
9
14
  ({ toolkit }: { toolkit?: Toolkit }): ClientOutput<"tools"> => {
@@ -86,3 +91,7 @@ export const Tools = resource(
86
91
  };
87
92
  },
88
93
  );
94
+
95
+ attachDefaultPeers(Tools, {
96
+ modelContext: ModelContext(),
97
+ });
@@ -0,0 +1,23 @@
1
+ "use client";
2
+
3
+ import { type FC, type PropsWithChildren } from "react";
4
+ import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
5
+
6
+ export type SuggestionByIndexProviderProps = PropsWithChildren<{
7
+ index: number;
8
+ }>;
9
+
10
+ export const SuggestionByIndexProvider: FC<SuggestionByIndexProviderProps> = ({
11
+ index,
12
+ children,
13
+ }) => {
14
+ const aui = useAui({
15
+ suggestion: Derived({
16
+ source: "suggestions",
17
+ query: { index },
18
+ get: (aui) => aui.suggestions().suggestion({ index }),
19
+ }),
20
+ });
21
+
22
+ return <AuiProvider value={aui}>{children}</AuiProvider>;
23
+ };
@@ -4,6 +4,7 @@ export {
4
4
  ThreadListItemRuntimeProvider,
5
5
  } from "./ThreadListItemProvider";
6
6
  export { MessageByIndexProvider } from "./MessageByIndexProvider";
7
+ export { SuggestionByIndexProvider } from "./SuggestionByIndexProvider";
7
8
  export { PartByIndexProvider } from "./PartByIndexProvider";
8
9
  export {
9
10
  MessageAttachmentByIndexProvider,
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { FC, memo, PropsWithChildren } from "react";
4
- import { useAui, AuiProvider } from "@assistant-ui/store";
4
+ import { useAui, AuiProvider, AssistantClient } from "@assistant-ui/store";
5
5
  import { AssistantRuntime } from "./runtime/AssistantRuntime";
6
6
  import { AssistantRuntimeCore } from "./runtime-cores/core/AssistantRuntimeCore";
7
7
  import { RuntimeAdapter } from "./RuntimeAdapter";
@@ -13,6 +13,11 @@ export namespace AssistantRuntimeProvider {
13
13
  * The runtime to provide to the rest of your app.
14
14
  */
15
15
  runtime: AssistantRuntime;
16
+
17
+ /**
18
+ * The aui instance to extend. If not provided, a new aui instance will be created.
19
+ */
20
+ aui?: AssistantClient;
16
21
  }>;
17
22
  }
18
23
 
@@ -22,10 +27,8 @@ const getRenderComponent = (runtime: AssistantRuntime) => {
22
27
 
23
28
  export const AssistantRuntimeProviderImpl: FC<
24
29
  AssistantRuntimeProvider.Props
25
- > = ({ children, runtime }) => {
26
- const aui = useAui({
27
- threads: RuntimeAdapter(runtime),
28
- });
30
+ > = ({ children, aui: parent = null, runtime }) => {
31
+ const aui = useAui({ threads: RuntimeAdapter(runtime) }, { parent: parent });
29
32
 
30
33
  const RenderComponent = getRenderComponent(runtime);
31
34
 
@@ -7,7 +7,7 @@ import {
7
7
  attachDefaultPeers,
8
8
  } from "@assistant-ui/store";
9
9
  import { ModelContext } from "../client/ModelContextClient";
10
- import { Tools } from "../model-context";
10
+ import { Tools, Suggestions } from "../model-context";
11
11
 
12
12
  export const RuntimeAdapter = resource((runtime: AssistantRuntime) => {
13
13
  const clientRef = tapAssistantClientRef();
@@ -29,6 +29,7 @@ export const RuntimeAdapter = resource((runtime: AssistantRuntime) => {
29
29
  attachDefaultPeers(RuntimeAdapter, {
30
30
  modelContext: ModelContext(),
31
31
  tools: Tools({}),
32
+ suggestions: Suggestions(),
32
33
  threadListItem: Derived({
33
34
  source: "threads",
34
35
  query: { type: "main" },
@@ -15,6 +15,7 @@ import {
15
15
  DataStreamDecoder,
16
16
  AssistantTransportDecoder,
17
17
  unstable_createInitialMessage as createInitialMessage,
18
+ toToolsJSONSchema,
18
19
  } from "assistant-stream";
19
20
  import {
20
21
  AssistantTransportOptions,
@@ -28,7 +29,7 @@ import { useCommandQueue } from "./commandQueue";
28
29
  import { useRunManager } from "./runManager";
29
30
  import { useConvertedState } from "./useConvertedState";
30
31
  import { ToolExecutionStatus, useToolInvocations } from "./useToolInvocations";
31
- import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils";
32
+ import { createRequestHeaders } from "./utils";
32
33
  import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
33
34
  import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory";
34
35
  import { useAui, useAuiState } from "@assistant-ui/store";
@@ -115,9 +116,7 @@ const useAssistantTransportThreadRuntime = <T,>(
115
116
  commands,
116
117
  state: agentStateRef.current,
117
118
  system: context.system,
118
- tools: context.tools
119
- ? toAISDKTools(getEnabledTools(context.tools))
120
- : undefined,
119
+ tools: context.tools ? toToolsJSONSchema(context.tools) : undefined,
121
120
  threadId,
122
121
  ...(parentIdRef.current !== undefined && {
123
122
  parentId: parentIdRef.current,
@@ -1,42 +1,37 @@
1
- import { Tool } from "assistant-stream";
2
- import type { JSONSchema7 } from "json-schema";
3
- import { z } from "zod";
1
+ import { Tool, toToolsJSONSchema, type ToolJSONSchema } from "assistant-stream";
4
2
 
5
- // Convert tools to AI SDK format
6
- export const toAISDKTools = (tools: Record<string, Tool>) => {
7
- return Object.fromEntries(
8
- Object.entries(tools).map(([name, tool]) => [
9
- name,
10
- {
11
- ...(tool.description ? { description: tool.description } : undefined),
12
- parameters: (tool.parameters instanceof z.ZodType
13
- ? z.toJSONSchema(tool.parameters)
14
- : tool.parameters) as JSONSchema7,
15
- },
16
- ]),
17
- );
18
- };
3
+ /**
4
+ * @deprecated Use `toToolsJSONSchema` from `assistant-stream` instead.
5
+ */
6
+ export function toAISDKTools(
7
+ tools: Record<string, Tool>,
8
+ ): Record<string, ToolJSONSchema> {
9
+ return toToolsJSONSchema(tools, { filter: () => true });
10
+ }
19
11
 
20
- // Filter enabled tools
21
- export const getEnabledTools = (tools: Record<string, Tool>) => {
12
+ /**
13
+ * @deprecated Use `toToolsJSONSchema` from `assistant-stream` instead, which includes filtering by default.
14
+ */
15
+ export function getEnabledTools(
16
+ tools: Record<string, Tool>,
17
+ ): Record<string, Tool> {
22
18
  return Object.fromEntries(
23
19
  Object.entries(tools).filter(
24
20
  ([, tool]) => !tool.disabled && tool.type !== "backend",
25
21
  ),
26
22
  );
27
- };
23
+ }
28
24
 
29
- // Create headers for fetch request
30
- export const createRequestHeaders = async (
25
+ export async function createRequestHeaders(
31
26
  headersValue:
32
27
  | Record<string, string>
33
28
  | Headers
34
29
  | (() => Promise<Record<string, string> | Headers>),
35
- ): Promise<Headers> => {
30
+ ): Promise<Headers> {
36
31
  const resolvedHeaders =
37
32
  typeof headersValue === "function" ? await headersValue() : headersValue;
38
33
 
39
34
  const headers = new Headers(resolvedHeaders);
40
35
  headers.set("Content-Type", "application/json");
41
36
  return headers;
42
- };
37
+ }
@@ -11,6 +11,8 @@ import { getAutoStatus, isAutoStatus } from "./auto-status";
11
11
  import { ThreadMessage, ToolCallMessagePart } from "../../../types";
12
12
  import { ToolExecutionStatus } from "../assistant-transport/useToolInvocations";
13
13
  import { ReadonlyJSONValue } from "assistant-stream/utils";
14
+ import { generateErrorMessageId } from "../../../utils/idUtils";
15
+ import { ThreadAssistantMessage } from "../../../types/AssistantTypes";
14
16
 
15
17
  export namespace useExternalMessageConverter {
16
18
  export type Message =
@@ -262,6 +264,28 @@ const chunkExternalMessages = <T,>(
262
264
  return results;
263
265
  };
264
266
 
267
+ function createErrorAssistantMessage(
268
+ error: ReadonlyJSONValue,
269
+ ): ThreadAssistantMessage {
270
+ return Object.assign<ThreadAssistantMessage, { [symbolInnerMessage]: [] }>(
271
+ {
272
+ id: generateErrorMessageId(),
273
+ role: "assistant",
274
+ content: [],
275
+ status: { type: "incomplete", reason: "error", error },
276
+ createdAt: new Date(),
277
+ metadata: {
278
+ unstable_state: null,
279
+ unstable_annotations: [],
280
+ unstable_data: [],
281
+ custom: {},
282
+ steps: [],
283
+ },
284
+ },
285
+ { [symbolInnerMessage]: [] },
286
+ );
287
+ }
288
+
265
289
  export const convertExternalMessages = <T extends WeakKey>(
266
290
  messages: T[],
267
291
  callback: useExternalMessageConverter.Callback<T>,
@@ -278,14 +302,9 @@ export const convertExternalMessages = <T extends WeakKey>(
278
302
 
279
303
  const chunks = chunkExternalMessages(callbackResults);
280
304
 
281
- return chunks.map((message, idx) => {
305
+ const result = chunks.map((message, idx) => {
282
306
  const isLast = idx === chunks.length - 1;
283
307
  const joined = joinExternalMessages(message.outputs);
284
- const hasSuspendedToolCalls =
285
- typeof joined.content === "object" &&
286
- joined.content.some(
287
- (c) => c.type === "tool-call" && c.result === undefined,
288
- );
289
308
  const hasPendingToolCalls =
290
309
  typeof joined.content === "object" &&
291
310
  joined.content.some(
@@ -294,7 +313,7 @@ export const convertExternalMessages = <T extends WeakKey>(
294
313
  const autoStatus = getAutoStatus(
295
314
  isLast,
296
315
  isRunning,
297
- hasSuspendedToolCalls,
316
+ hasPendingToolCalls,
298
317
  hasPendingToolCalls,
299
318
  isLast ? metadata.error : undefined,
300
319
  );
@@ -306,6 +325,15 @@ export const convertExternalMessages = <T extends WeakKey>(
306
325
  (newMessage as any)[symbolInnerMessage] = message.inputs;
307
326
  return newMessage;
308
327
  });
328
+
329
+ if (metadata.error) {
330
+ const lastMessage = result.at(-1);
331
+ if (!lastMessage || lastMessage.role !== "assistant") {
332
+ result.push(createErrorAssistantMessage(metadata.error));
333
+ }
334
+ }
335
+
336
+ return result;
309
337
  };
310
338
 
311
339
  export const useExternalMessageConverter = <T extends WeakKey>({
@@ -411,6 +439,13 @@ export const useExternalMessageConverter = <T extends WeakKey>({
411
439
  symbolInnerMessage
412
440
  ] = messages;
413
441
 
442
+ if (state.metadata.error) {
443
+ const lastMessage = threadMessages.at(-1);
444
+ if (!lastMessage || lastMessage.role !== "assistant") {
445
+ threadMessages.push(createErrorAssistantMessage(state.metadata.error));
446
+ }
447
+ }
448
+
414
449
  return threadMessages;
415
450
  }, [state, messages, isRunning, joinStrategy]);
416
451
  };
@@ -31,6 +31,9 @@ export class BaseSubscribable {
31
31
  if (errors.length === 1) {
32
32
  throw errors[0];
33
33
  } else {
34
+ for (const error of errors) {
35
+ console.error(error);
36
+ }
34
37
  throw new AggregateError(errors);
35
38
  }
36
39
  }
@@ -23,5 +23,7 @@ export type { Toolkit, ToolDefinition } from "./toolbox";
23
23
 
24
24
  export { Tools } from "../client/Tools";
25
25
 
26
+ export { Suggestions, type SuggestionConfig } from "../client/Suggestions";
27
+
26
28
  export * from "./registry";
27
29
  export * from "./frame";
@@ -28,7 +28,7 @@ const useAssistantModalOpenState = ({
28
28
  return aui.on("thread.runStart", () => {
29
29
  setOpen(true);
30
30
  });
31
- }, [unstable_openOnRunStart, setOpen, aui]);
31
+ }, [unstable_openOnRunStart, aui]);
32
32
 
33
33
  return state;
34
34
  };
@@ -8,6 +8,7 @@ export * as MessagePartPrimitive from "./messagePart";
8
8
  export * as ErrorPrimitive from "./error";
9
9
  export * as MessagePrimitive from "./message";
10
10
  export * as ThreadPrimitive from "./thread";
11
+ export * as SuggestionPrimitive from "./suggestion";
11
12
  export * as ThreadListPrimitive from "./threadList";
12
13
  export * as ThreadListItemPrimitive from "./threadListItem";
13
14
  export * as ThreadListItemMorePrimitive from "./threadListItemMore";
@@ -242,6 +242,17 @@ export namespace MessagePrimitiveParts {
242
242
  ReasoningGroup?: ReasoningGroupComponent;
243
243
  }
244
244
  | undefined;
245
+ /**
246
+ * When enabled, shows the Empty component if the last part in the message
247
+ * is anything other than Text or Reasoning.
248
+ *
249
+ * This can be useful to ensure there's always a visible element at the end
250
+ * of messages that end with non-text content like tool calls or images.
251
+ *
252
+ * @experimental This API is experimental and may change in future versions.
253
+ * @default true
254
+ */
255
+ unstable_showEmptyOnNonTextEnd?: boolean | undefined;
245
256
  };
246
257
  }
247
258
 
@@ -429,6 +440,30 @@ const EmptyParts = memo(
429
440
  prev.components?.Text === next.components?.Text,
430
441
  );
431
442
 
443
+ const ConditionalEmptyImpl: FC<{
444
+ components: MessagePrimitiveParts.Props["components"];
445
+ enabled: boolean;
446
+ }> = ({ components, enabled }) => {
447
+ const shouldShowEmpty = useAuiState(({ message }) => {
448
+ if (!enabled) return false;
449
+ if (message.parts.length === 0) return false;
450
+
451
+ const lastPart = message.parts[message.parts.length - 1];
452
+ return lastPart?.type !== "text" && lastPart?.type !== "reasoning";
453
+ });
454
+
455
+ if (!shouldShowEmpty) return null;
456
+ return <EmptyParts components={components} />;
457
+ };
458
+
459
+ const ConditionalEmpty = memo(
460
+ ConditionalEmptyImpl,
461
+ (prev, next) =>
462
+ prev.enabled === next.enabled &&
463
+ prev.components?.Empty === next.components?.Empty &&
464
+ prev.components?.Text === next.components?.Text,
465
+ );
466
+
432
467
  /**
433
468
  * Renders the parts of a message with support for multiple content types.
434
469
  *
@@ -455,6 +490,7 @@ const EmptyParts = memo(
455
490
  */
456
491
  export const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({
457
492
  components,
493
+ unstable_showEmptyOnNonTextEnd = true,
458
494
  }) => {
459
495
  const contentLength = useAuiState(({ message }) => message.parts.length);
460
496
  const messageRanges = useMessagePartsGroups();
@@ -520,7 +556,15 @@ export const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({
520
556
  });
521
557
  }, [messageRanges, components, contentLength]);
522
558
 
523
- return <>{partsElements}</>;
559
+ return (
560
+ <>
561
+ {partsElements}
562
+ <ConditionalEmpty
563
+ components={components}
564
+ enabled={unstable_showEmptyOnNonTextEnd}
565
+ />
566
+ </>
567
+ );
524
568
  };
525
569
 
526
570
  MessagePrimitiveParts.displayName = "MessagePrimitive.Parts";
@@ -0,0 +1,33 @@
1
+ "use client";
2
+
3
+ import { Primitive } from "@radix-ui/react-primitive";
4
+ import { type ElementRef, forwardRef, ComponentPropsWithoutRef } from "react";
5
+ import { useAuiState } from "@assistant-ui/store";
6
+
7
+ export namespace SuggestionPrimitiveDescription {
8
+ export type Element = ElementRef<typeof Primitive.span>;
9
+ export type Props = ComponentPropsWithoutRef<typeof Primitive.span>;
10
+ }
11
+
12
+ /**
13
+ * Renders the description/label of the suggestion.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * <SuggestionPrimitive.Description />
18
+ * ```
19
+ */
20
+ export const SuggestionPrimitiveDescription = forwardRef<
21
+ SuggestionPrimitiveDescription.Element,
22
+ SuggestionPrimitiveDescription.Props
23
+ >((props, ref) => {
24
+ const label = useAuiState(({ suggestion }) => suggestion.label);
25
+
26
+ return (
27
+ <Primitive.span {...props} ref={ref}>
28
+ {props.children ?? label}
29
+ </Primitive.span>
30
+ );
31
+ });
32
+
33
+ SuggestionPrimitiveDescription.displayName = "SuggestionPrimitive.Description";
@@ -0,0 +1,33 @@
1
+ "use client";
2
+
3
+ import { Primitive } from "@radix-ui/react-primitive";
4
+ import { type ElementRef, forwardRef, ComponentPropsWithoutRef } from "react";
5
+ import { useAuiState } from "@assistant-ui/store";
6
+
7
+ export namespace SuggestionPrimitiveTitle {
8
+ export type Element = ElementRef<typeof Primitive.span>;
9
+ export type Props = ComponentPropsWithoutRef<typeof Primitive.span>;
10
+ }
11
+
12
+ /**
13
+ * Renders the title of the suggestion.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * <SuggestionPrimitive.Title />
18
+ * ```
19
+ */
20
+ export const SuggestionPrimitiveTitle = forwardRef<
21
+ SuggestionPrimitiveTitle.Element,
22
+ SuggestionPrimitiveTitle.Props
23
+ >((props, ref) => {
24
+ const title = useAuiState(({ suggestion }) => suggestion.title);
25
+
26
+ return (
27
+ <Primitive.span {...props} ref={ref}>
28
+ {props.children ?? title}
29
+ </Primitive.span>
30
+ );
31
+ });
32
+
33
+ SuggestionPrimitiveTitle.displayName = "SuggestionPrimitive.Title";