@assistant-ui/react-ag-ui 0.0.43 → 0.0.45

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 (41) hide show
  1. package/dist/agUiExtras.d.ts +0 -1
  2. package/dist/agUiExtras.d.ts.map +1 -1
  3. package/dist/hooks.d.ts +15 -9
  4. package/dist/hooks.d.ts.map +1 -1
  5. package/dist/hooks.js +17 -8
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +2 -2
  9. package/dist/runtime/AgUiThreadRuntimeCore.d.ts +26 -4
  10. package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
  11. package/dist/runtime/AgUiThreadRuntimeCore.js +296 -89
  12. package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
  13. package/dist/runtime/adapter/conversions.d.ts +0 -1
  14. package/dist/runtime/adapter/conversions.d.ts.map +1 -1
  15. package/dist/runtime/adapter/conversions.js +24 -5
  16. package/dist/runtime/adapter/conversions.js.map +1 -1
  17. package/dist/runtime/adapter/run-aggregator.d.ts +0 -1
  18. package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
  19. package/dist/runtime/adapter/run-aggregator.js +36 -7
  20. package/dist/runtime/adapter/run-aggregator.js.map +1 -1
  21. package/dist/runtime/adapter/subscriber.d.ts +0 -1
  22. package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
  23. package/dist/runtime/event-parser.d.ts +0 -1
  24. package/dist/runtime/event-parser.d.ts.map +1 -1
  25. package/dist/runtime/event-parser.js +18 -9
  26. package/dist/runtime/event-parser.js.map +1 -1
  27. package/dist/runtime/logger.d.ts.map +1 -1
  28. package/dist/runtime/types.d.ts +13 -1
  29. package/dist/runtime/types.d.ts.map +1 -1
  30. package/dist/useAgUiRuntime.d.ts +0 -1
  31. package/dist/useAgUiRuntime.d.ts.map +1 -1
  32. package/dist/useAgUiRuntime.js +8 -2
  33. package/dist/useAgUiRuntime.js.map +1 -1
  34. package/package.json +6 -6
  35. package/src/hooks.ts +29 -7
  36. package/src/index.ts +2 -0
  37. package/src/runtime/AgUiThreadRuntimeCore.ts +390 -108
  38. package/src/runtime/adapter/conversions.ts +71 -15
  39. package/src/runtime/adapter/run-aggregator.ts +69 -5
  40. package/src/runtime/types.ts +17 -0
  41. package/src/useAgUiRuntime.ts +8 -1
package/src/hooks.ts CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useAui } from "@assistant-ui/store";
4
4
  import type { CreateAppendMessage } from "@assistant-ui/core";
5
+ import type { ReadonlyJSONValue } from "assistant-stream/utils";
5
6
  import { agUiExtras } from "./agUiExtras";
6
7
  import type { AgUiInterrupt, AgUiResumeEntry } from "./runtime/types";
7
8
 
@@ -25,13 +26,17 @@ export const useAgUiSubmitInterruptResponses = () => {
25
26
  };
26
27
 
27
28
  /**
28
- * Returns a function that discards the pending AG-UI interrupts and appends the
29
- * given user message, starting a fresh run. Use this when the user sends a new
30
- * message instead of resolving the interrupt(s): every open interrupt is
31
- * reported to the agent as cancelled. The message accepts a plain string or a
32
- * partial `AppendMessage` (the parent defaults to the current head). Pass
33
- * `responses` to override the status of specific interrupts; the rest still
34
- * default to cancelled.
29
+ * Returns a function that discards the pending AG-UI interrupts or pending
30
+ * client-side tool calls and appends the given user message, starting a fresh
31
+ * run. Use this when the user sends a new message instead of resolving them:
32
+ * every open interrupt is reported to the agent as cancelled, and every
33
+ * unresolved client-side tool call receives an error result. The message
34
+ * accepts a plain string or a partial `AppendMessage` (the parent defaults to
35
+ * the current head). Pass `responses` to override the status of specific
36
+ * interrupts; the rest still default to cancelled. `responses` throws when
37
+ * tool calls rather than interrupts are pending. Unlike the
38
+ * `autoCancelPendingToolCalls` runtime option, this hook cancels regardless
39
+ * of that option's value.
35
40
  */
36
41
  export const useAgUiSteerAway = () => {
37
42
  const aui = useAui();
@@ -40,3 +45,20 @@ export const useAgUiSteerAway = () => {
40
45
  responses?: readonly AgUiResumeEntry[],
41
46
  ): Promise<void> => agUiExtras.get(aui).steerAway(message, responses);
42
47
  };
48
+
49
+ export const useAgUiState = <TState = ReadonlyJSONValue>():
50
+ | TState
51
+ | undefined =>
52
+ agUiExtras.use((e) => e.state as TState | undefined, undefined);
53
+
54
+ export const useAgUiSetState = <TState = ReadonlyJSONValue>() => {
55
+ const aui = useAui();
56
+ return (next: TState | ((prev: TState | undefined) => TState)): void =>
57
+ agUiExtras
58
+ .get(aui)
59
+ .setState(
60
+ next as
61
+ | ReadonlyJSONValue
62
+ | ((prev: ReadonlyJSONValue | undefined) => ReadonlyJSONValue),
63
+ );
64
+ };
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ export {
4
4
  useAgUiInterrupts,
5
5
  useAgUiSubmitInterruptResponses,
6
6
  useAgUiSteerAway,
7
+ useAgUiState,
8
+ useAgUiSetState,
7
9
  } from "./hooks";
8
10
  export { fromAgUiMessages } from "./runtime/adapter/conversions";
9
11
  export type { FromAgUiMessagesOptions } from "./runtime/adapter/conversions";