@assistant-ui/react-ink 0.0.1 → 0.0.2

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.
@@ -1,80 +1 @@
1
- import { useState, useEffect, useMemo, useRef, useCallback } from "react";
2
- import {
3
- BaseAssistantRuntimeCore,
4
- AssistantRuntimeImpl,
5
- type RemoteThreadListOptions,
6
- } from "@assistant-ui/core/internal";
7
- import type {
8
- AssistantRuntimeCore,
9
- AssistantRuntime,
10
- } from "@assistant-ui/core";
11
- import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore";
12
- import { useAui } from "@assistant-ui/store";
13
-
14
- class RemoteThreadListRuntimeCore
15
- extends BaseAssistantRuntimeCore
16
- implements AssistantRuntimeCore
17
- {
18
- public readonly threads;
19
-
20
- constructor(options: RemoteThreadListOptions) {
21
- super();
22
- this.threads = new RemoteThreadListThreadListRuntimeCore(
23
- options,
24
- this._contextProvider,
25
- );
26
- }
27
-
28
- public get RenderComponent() {
29
- return this.threads.__internal_RenderComponent;
30
- }
31
- }
32
-
33
- const useRemoteThreadListRuntimeImpl = (
34
- options: RemoteThreadListOptions,
35
- ): AssistantRuntime => {
36
- const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
37
- useEffect(() => {
38
- runtime.threads.__internal_setOptions(options);
39
- runtime.threads.__internal_load();
40
- }, [runtime, options]);
41
- return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
42
- };
43
-
44
- export const useRemoteThreadListRuntime = (
45
- options: RemoteThreadListOptions,
46
- ): AssistantRuntime => {
47
- const runtimeHookRef = useRef(options.runtimeHook);
48
- runtimeHookRef.current = options.runtimeHook;
49
-
50
- const stableRuntimeHook = useCallback(() => {
51
- return runtimeHookRef.current();
52
- }, []);
53
-
54
- const stableOptions = useMemo<RemoteThreadListOptions>(
55
- () => ({
56
- adapter: options.adapter,
57
- allowNesting: options.allowNesting,
58
- runtimeHook: stableRuntimeHook,
59
- }),
60
- [options.adapter, options.allowNesting, stableRuntimeHook],
61
- );
62
-
63
- const aui = useAui();
64
- const isNested = aui.threadListItem.source !== null;
65
-
66
- if (isNested) {
67
- if (!stableOptions.allowNesting) {
68
- throw new Error(
69
- "useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. " +
70
- "Set allowNesting: true to allow nesting (the inner runtime will become a no-op).",
71
- );
72
- }
73
-
74
- // If allowNesting is true and already inside a thread list context,
75
- // just call the runtimeHook directly (no-op behavior)
76
- return stableRuntimeHook();
77
- }
78
-
79
- return useRemoteThreadListRuntimeImpl(stableOptions);
80
- };
1
+ export { useRemoteThreadListRuntime } from "@assistant-ui/core/react";