@assistant-ui/react-ag-ui 0.0.29 → 0.0.31

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 (33) hide show
  1. package/README.md +41 -0
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/runtime/AgUiThreadRuntimeCore.d.ts +11 -0
  5. package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
  6. package/dist/runtime/AgUiThreadRuntimeCore.js +186 -12
  7. package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
  8. package/dist/runtime/adapter/run-aggregator.d.ts +18 -5
  9. package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
  10. package/dist/runtime/adapter/run-aggregator.js +134 -39
  11. package/dist/runtime/adapter/run-aggregator.js.map +1 -1
  12. package/dist/runtime/adapter/subscriber.d.ts +5 -0
  13. package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
  14. package/dist/runtime/adapter/subscriber.js +55 -36
  15. package/dist/runtime/adapter/subscriber.js.map +1 -1
  16. package/dist/runtime/event-parser.d.ts +5 -1
  17. package/dist/runtime/event-parser.d.ts.map +1 -1
  18. package/dist/runtime/event-parser.js +48 -2
  19. package/dist/runtime/event-parser.js.map +1 -1
  20. package/dist/runtime/types.d.ts +22 -0
  21. package/dist/runtime/types.d.ts.map +1 -1
  22. package/dist/useAgUiRuntime.d.ts +6 -2
  23. package/dist/useAgUiRuntime.d.ts.map +1 -1
  24. package/dist/useAgUiRuntime.js +7 -1
  25. package/dist/useAgUiRuntime.js.map +1 -1
  26. package/package.json +4 -4
  27. package/src/index.ts +5 -0
  28. package/src/runtime/AgUiThreadRuntimeCore.ts +251 -11
  29. package/src/runtime/adapter/run-aggregator.ts +168 -44
  30. package/src/runtime/adapter/subscriber.ts +53 -43
  31. package/src/runtime/event-parser.ts +64 -3
  32. package/src/runtime/types.ts +31 -1
  33. package/src/useAgUiRuntime.ts +23 -3
@@ -15,12 +15,23 @@ import type {
15
15
  } from "@assistant-ui/core";
16
16
  import type { ReadonlyJSONValue } from "assistant-stream/utils";
17
17
  import { makeLogger } from "./runtime/logger";
18
- import type { UseAgUiRuntimeOptions } from "./runtime/types";
18
+ import type {
19
+ AgUiInterrupt,
20
+ AgUiResumeEntry,
21
+ UseAgUiRuntimeOptions,
22
+ } from "./runtime/types";
19
23
  import { AgUiThreadRuntimeCore } from "./runtime/AgUiThreadRuntimeCore";
20
24
 
25
+ export type AgUiAssistantRuntime = AssistantRuntime & {
26
+ unstable_getPendingInterrupts: () => readonly AgUiInterrupt[];
27
+ unstable_submitInterruptResponses: (
28
+ responses: readonly AgUiResumeEntry[],
29
+ ) => Promise<void>;
30
+ };
31
+
21
32
  export function useAgUiRuntime(
22
33
  options: UseAgUiRuntimeOptions,
23
- ): AssistantRuntime {
34
+ ): AgUiAssistantRuntime {
24
35
  const logger = useMemo(() => makeLogger(options.logger), [options.logger]);
25
36
  const [_version, setVersion] = useState(0);
26
37
  const notifyUpdate = useCallback(() => setVersion((v) => v + 1), []);
@@ -174,7 +185,16 @@ export function useAgUiRuntime(
174
185
  [adapterAdapters, core, _version, hasExecutingTools],
175
186
  );
176
187
 
177
- const runtime = useExternalStoreRuntime(store);
188
+ const baseRuntime = useExternalStoreRuntime(store);
189
+
190
+ const runtime = useMemo<AgUiAssistantRuntime>(() => {
191
+ const wrapper = Object.create(baseRuntime) as AgUiAssistantRuntime;
192
+ wrapper.unstable_getPendingInterrupts = () =>
193
+ core.getPendingInterrupts()?.interrupts ?? [];
194
+ wrapper.unstable_submitInterruptResponses = (responses) =>
195
+ core.submitInterruptResponses(responses);
196
+ return wrapper;
197
+ }, [baseRuntime, core]);
178
198
 
179
199
  useEffect(() => {
180
200
  core.attachRuntime(runtime);