@assistant-ui/react 0.7.86 → 0.7.88
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.
- package/dist/api/AssistantRuntime.d.ts +10 -3
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +9 -6
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +9 -8
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/model-context/ModelContextTypes.d.ts +1 -1
- package/dist/model-context/ModelContextTypes.d.ts.map +1 -1
- package/dist/model-context/ModelContextTypes.js +2 -1
- package/dist/model-context/ModelContextTypes.js.map +1 -1
- package/dist/model-context/ModelContextTypes.mjs +2 -1
- package/dist/model-context/ModelContextTypes.mjs.map +1 -1
- package/dist/model-context/index.d.ts +2 -0
- package/dist/model-context/index.d.ts.map +1 -1
- package/dist/model-context/index.js +6 -0
- package/dist/model-context/index.js.map +1 -1
- package/dist/model-context/index.mjs +4 -0
- package/dist/model-context/index.mjs.map +1 -1
- package/dist/model-context/makeAssistantReadable.d.ts +6 -0
- package/dist/model-context/makeAssistantReadable.d.ts.map +1 -0
- package/dist/model-context/makeAssistantReadable.js +86 -0
- package/dist/model-context/makeAssistantReadable.js.map +1 -0
- package/dist/model-context/makeAssistantReadable.mjs +69 -0
- package/dist/model-context/makeAssistantReadable.mjs.map +1 -0
- package/dist/model-context/tool.d.ts +12 -0
- package/dist/model-context/tool.d.ts.map +1 -0
- package/dist/model-context/tool.js +33 -0
- package/dist/model-context/tool.js.map +1 -0
- package/dist/model-context/tool.mjs +8 -0
- package/dist/model-context/tool.mjs.map +1 -0
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js +2 -0
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs +2 -0
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts +1 -1
- package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts.map +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts +1 -1
- package/dist/runtimes/edge/useEdgeRuntime.d.ts.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.d.ts +2 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.js +1 -5
- package/dist/runtimes/external-store/useExternalStoreRuntime.js.map +1 -1
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs +1 -5
- package/dist/runtimes/external-store/useExternalStoreRuntime.mjs.map +1 -1
- package/dist/runtimes/index.d.ts +1 -0
- package/dist/runtimes/index.d.ts.map +1 -1
- package/dist/runtimes/index.js +9 -0
- package/dist/runtimes/index.js.map +1 -1
- package/dist/runtimes/index.mjs +4 -0
- package/dist/runtimes/index.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +0 -4
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +2 -23
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +2 -23
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts +2 -6
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +2 -19
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +2 -21
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +4 -4
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +4 -4
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts +2 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs +1 -1
- package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.mjs.map +1 -1
- package/dist/runtimes/utils/MessageRepository.d.ts +7 -2
- package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js +26 -0
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.mjs +26 -1
- package/dist/runtimes/utils/MessageRepository.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/AssistantRuntime.ts +16 -22
- package/src/model-context/ModelContextTypes.ts +4 -2
- package/src/model-context/index.ts +3 -0
- package/src/model-context/makeAssistantReadable.tsx +81 -0
- package/src/model-context/tool.ts +26 -0
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +2 -1
- package/src/runtimes/external-store/useExternalStoreRuntime.tsx +1 -5
- package/src/runtimes/index.ts +2 -0
- package/src/runtimes/local/LocalRuntimeCore.tsx +1 -33
- package/src/runtimes/local/useLocalRuntime.tsx +2 -29
- package/src/runtimes/remote-thread-list/useRemoteThreadListRuntime.tsx +1 -1
- package/src/runtimes/utils/MessageRepository.tsx +33 -3
@@ -4,7 +4,6 @@ import { useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { ExternalStoreRuntimeCore } from "./ExternalStoreRuntimeCore";
|
5
5
|
import { ExternalStoreAdapter } from "./ExternalStoreAdapter";
|
6
6
|
import { AssistantRuntimeImpl } from "../../api/AssistantRuntime";
|
7
|
-
import { ThreadRuntimeImpl } from "../../api/ThreadRuntime";
|
8
7
|
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider";
|
9
8
|
|
10
9
|
export const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {
|
@@ -21,8 +20,5 @@ export const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => {
|
|
21
20
|
return runtime.registerModelContextProvider(modelContext);
|
22
21
|
}, [modelContext, runtime]);
|
23
22
|
|
24
|
-
return useMemo(
|
25
|
-
() => AssistantRuntimeImpl.create(runtime, ThreadRuntimeImpl),
|
26
|
-
[runtime],
|
27
|
-
);
|
23
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
28
24
|
};
|
package/src/runtimes/index.ts
CHANGED
@@ -1,28 +1,9 @@
|
|
1
|
-
import type { CoreMessage } from "../../types/AssistantTypes";
|
2
1
|
import { BaseAssistantRuntimeCore } from "../core/BaseAssistantRuntimeCore";
|
3
2
|
import { LocalThreadRuntimeCore } from "./LocalThreadRuntimeCore";
|
4
3
|
import { LocalRuntimeOptionsBase } from "./LocalRuntimeOptions";
|
5
4
|
import { LocalThreadListRuntimeCore } from "./LocalThreadListRuntimeCore";
|
6
5
|
import { ExportedMessageRepository } from "../utils/MessageRepository";
|
7
6
|
import { ThreadMessageLike } from "../external-store";
|
8
|
-
import { fromThreadMessageLike } from "../external-store/ThreadMessageLike";
|
9
|
-
import { generateId } from "../../internal";
|
10
|
-
import { getAutoStatus } from "../external-store/auto-status";
|
11
|
-
|
12
|
-
const getExportFromInitialMessages = (
|
13
|
-
initialMessages: readonly ThreadMessageLike[],
|
14
|
-
): ExportedMessageRepository => {
|
15
|
-
const messages = initialMessages.map((i, idx) => {
|
16
|
-
const isLast = idx === initialMessages.length - 1;
|
17
|
-
return fromThreadMessageLike(i, generateId(), getAutoStatus(isLast, false));
|
18
|
-
});
|
19
|
-
return {
|
20
|
-
messages: messages.map((m, idx) => ({
|
21
|
-
parentId: messages[idx - 1]?.id ?? null,
|
22
|
-
message: m,
|
23
|
-
})),
|
24
|
-
};
|
25
|
-
};
|
26
7
|
|
27
8
|
export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
28
9
|
public readonly threads;
|
@@ -45,20 +26,7 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
|
45
26
|
if (initialMessages) {
|
46
27
|
this.threads
|
47
28
|
.getMainThreadRuntimeCore()
|
48
|
-
.import(
|
29
|
+
.import(ExportedMessageRepository.fromArray(initialMessages));
|
49
30
|
}
|
50
31
|
}
|
51
|
-
|
52
|
-
public reset({
|
53
|
-
initialMessages,
|
54
|
-
}: {
|
55
|
-
initialMessages?: readonly CoreMessage[] | undefined;
|
56
|
-
} = {}) {
|
57
|
-
this.threads.switchToNewThread();
|
58
|
-
if (!initialMessages) return;
|
59
|
-
|
60
|
-
this.threads
|
61
|
-
.getMainThreadRuntimeCore()
|
62
|
-
.import(getExportFromInitialMessages(initialMessages));
|
63
|
-
}
|
64
32
|
}
|
@@ -4,37 +4,10 @@ import { useEffect, useMemo, useState } from "react";
|
|
4
4
|
import type { ChatModelAdapter } from "./ChatModelAdapter";
|
5
5
|
import { LocalRuntimeCore } from "./LocalRuntimeCore";
|
6
6
|
import { LocalRuntimeOptions } from "./LocalRuntimeOptions";
|
7
|
-
import {
|
8
|
-
AssistantRuntime,
|
9
|
-
AssistantRuntimeImpl,
|
10
|
-
} from "../../api/AssistantRuntime";
|
11
|
-
import { ThreadRuntimeImpl } from "../../internal";
|
12
7
|
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider";
|
13
8
|
import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
|
14
9
|
import { useCloudThreadListAdapter } from "../remote-thread-list/adapter/cloud";
|
15
|
-
|
16
|
-
export type LocalRuntime = AssistantRuntime & {
|
17
|
-
reset: (options?: Parameters<LocalRuntimeCore["reset"]>[0]) => void;
|
18
|
-
};
|
19
|
-
|
20
|
-
class LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime {
|
21
|
-
private constructor(private core: LocalRuntimeCore) {
|
22
|
-
super(core, ThreadRuntimeImpl);
|
23
|
-
}
|
24
|
-
|
25
|
-
public override __internal_bindMethods() {
|
26
|
-
super.__internal_bindMethods();
|
27
|
-
this.reset = this.reset.bind(this);
|
28
|
-
}
|
29
|
-
|
30
|
-
public reset(options?: Parameters<LocalRuntimeCore["reset"]>[0]) {
|
31
|
-
this.core.reset(options);
|
32
|
-
}
|
33
|
-
|
34
|
-
public static override create(_core: LocalRuntimeCore): LocalRuntime {
|
35
|
-
return new LocalRuntimeImpl(_core);
|
36
|
-
}
|
37
|
-
}
|
10
|
+
import { AssistantRuntimeImpl } from "../../internal";
|
38
11
|
|
39
12
|
const useLocalThreadRuntime = (
|
40
13
|
adapter: ChatModelAdapter,
|
@@ -65,7 +38,7 @@ const useLocalThreadRuntime = (
|
|
65
38
|
return runtime.registerModelContextProvider(modelContext);
|
66
39
|
}, [modelContext, runtime]);
|
67
40
|
|
68
|
-
return useMemo(() =>
|
41
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
69
42
|
};
|
70
43
|
|
71
44
|
export const useLocalRuntime = (
|
@@ -34,5 +34,5 @@ export const useRemoteThreadListRuntime = (
|
|
34
34
|
runtime.threads.__internal_setOptions(options);
|
35
35
|
runtime.threads.__internal_load();
|
36
36
|
}, [runtime, options]);
|
37
|
-
return useMemo(() => AssistantRuntimeImpl
|
37
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
38
38
|
};
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import type { CoreMessage, ThreadMessage } from "../../types/AssistantTypes";
|
2
|
-
import { generateOptimisticId } from "../../utils/idUtils";
|
2
|
+
import { generateId, generateOptimisticId } from "../../utils/idUtils";
|
3
3
|
import { fromCoreMessage } from "../edge/converters/fromCoreMessage";
|
4
|
+
import { ThreadMessageLike } from "../external-store";
|
5
|
+
import { getAutoStatus } from "../external-store/auto-status";
|
6
|
+
import { fromThreadMessageLike } from "../external-store/ThreadMessageLike";
|
4
7
|
|
5
8
|
type RepositoryParent = {
|
6
9
|
children: string[];
|
@@ -18,13 +21,30 @@ export type ExportedMessageRepositoryItem = {
|
|
18
21
|
parentId: string | null;
|
19
22
|
};
|
20
23
|
|
21
|
-
export
|
24
|
+
export type ExportedMessageRepository = {
|
22
25
|
headId?: string | null;
|
23
26
|
messages: Array<{
|
24
27
|
message: ThreadMessage;
|
25
28
|
parentId: string | null;
|
26
29
|
}>;
|
27
|
-
}
|
30
|
+
};
|
31
|
+
|
32
|
+
export const ExportedMessageRepository = {
|
33
|
+
fromArray: (
|
34
|
+
messages: readonly ThreadMessageLike[],
|
35
|
+
): ExportedMessageRepository => {
|
36
|
+
const conv = messages.map((m) =>
|
37
|
+
fromThreadMessageLike(m, generateId(), getAutoStatus(false, false)),
|
38
|
+
);
|
39
|
+
|
40
|
+
return {
|
41
|
+
messages: conv.map((m, idx) => ({
|
42
|
+
parentId: idx > 0 ? conv[idx - 1]!.id : null,
|
43
|
+
message: m,
|
44
|
+
})),
|
45
|
+
};
|
46
|
+
},
|
47
|
+
};
|
28
48
|
|
29
49
|
const findHead = (
|
30
50
|
message: RepositoryMessage | RepositoryParent,
|
@@ -287,6 +307,16 @@ export class MessageRepository {
|
|
287
307
|
this._messages.dirty();
|
288
308
|
}
|
289
309
|
|
310
|
+
clear(): void {
|
311
|
+
this.messages.clear();
|
312
|
+
this.head = null;
|
313
|
+
this.root = {
|
314
|
+
children: [],
|
315
|
+
next: null,
|
316
|
+
};
|
317
|
+
this._messages.dirty();
|
318
|
+
}
|
319
|
+
|
290
320
|
export(): ExportedMessageRepository {
|
291
321
|
const exportItems: ExportedMessageRepository["messages"] = [];
|
292
322
|
|