@assistant-ui/react 0.10.24 → 0.10.26
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/{ContentPartRuntime.d.ts → MessagePartRuntime.d.ts} +14 -14
- package/dist/api/{ContentPartRuntime.d.ts.map → MessagePartRuntime.d.ts.map} +1 -1
- package/dist/api/{ContentPartRuntime.js → MessagePartRuntime.js} +6 -6
- package/dist/api/{ContentPartRuntime.js.map → MessagePartRuntime.js.map} +1 -1
- package/dist/api/MessageRuntime.d.ts +8 -8
- package/dist/api/MessageRuntime.js +17 -17
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/RuntimePathTypes.d.ts +2 -2
- package/dist/api/ThreadListRuntime.d.ts +3 -0
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +5 -1
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +5 -0
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +1 -0
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/index.d.ts +2 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/cloud/auiV0.d.ts +2 -2
- package/dist/cloud/auiV0.js +1 -1
- package/dist/cloud/auiV0.js.map +1 -1
- package/dist/context/providers/MessagePartRuntimeProvider.d.ts +9 -0
- package/dist/context/providers/{ContentPartRuntimeProvider.d.ts.map → MessagePartRuntimeProvider.d.ts.map} +1 -1
- package/dist/context/providers/{ContentPartRuntimeProvider.js → MessagePartRuntimeProvider.js} +9 -9
- package/dist/context/providers/MessagePartRuntimeProvider.js.map +1 -0
- package/dist/context/providers/{TextContentPartProvider.d.ts → TextMessagePartProvider.d.ts} +3 -3
- package/dist/context/providers/{TextContentPartProvider.d.ts.map → TextMessagePartProvider.d.ts.map} +1 -1
- package/dist/context/providers/{TextContentPartProvider.js → TextMessagePartProvider.js} +19 -19
- package/dist/context/providers/{TextContentPartProvider.js.map → TextMessagePartProvider.js.map} +1 -1
- package/dist/context/providers/index.d.ts +2 -1
- package/dist/context/providers/index.d.ts.map +1 -1
- package/dist/context/providers/index.js +4 -2
- package/dist/context/providers/index.js.map +1 -1
- package/dist/context/react/AttachmentContext.d.ts +72 -72
- package/dist/context/react/MessagePartContext.d.ts +41 -0
- package/dist/context/react/{ContentPartContext.d.ts.map → MessagePartContext.d.ts.map} +1 -1
- package/dist/context/react/MessagePartContext.js +25 -0
- package/dist/context/react/MessagePartContext.js.map +1 -0
- package/dist/context/react/index.d.ts +1 -1
- package/dist/context/react/index.js +3 -3
- package/dist/context/react/index.js.map +1 -1
- package/dist/context/stores/AssistantToolUIs.d.ts +3 -3
- package/dist/context/stores/AssistantToolUIs.js.map +1 -1
- package/dist/model-context/useAssistantTool.d.ts +2 -2
- package/dist/model-context/useAssistantTool.js.map +1 -1
- package/dist/model-context/useAssistantToolUI.d.ts +2 -2
- package/dist/model-context/useAssistantToolUI.js.map +1 -1
- package/dist/model-context/useInlineRender.d.ts +2 -2
- package/dist/model-context/useInlineRender.js.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalContent.d.ts +2 -0
- package/dist/primitives/assistantModal/AssistantModalContent.d.ts.map +1 -1
- package/dist/primitives/assistantModal/AssistantModalContent.js +2 -1
- package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
- package/dist/primitives/index.d.ts +12 -6
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +23 -11
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts +116 -0
- package/dist/primitives/message/MessageParts.d.ts.map +1 -0
- package/dist/primitives/message/MessageParts.js +208 -0
- package/dist/primitives/message/MessageParts.js.map +1 -0
- package/dist/primitives/message/index.d.ts +2 -1
- package/dist/primitives/message/index.d.ts.map +1 -1
- package/dist/primitives/message/index.js +4 -2
- package/dist/primitives/message/index.js.map +1 -1
- package/dist/primitives/{contentPart/ContentPartImage.d.ts → messagePart/MessagePartImage.d.ts} +8 -8
- package/dist/primitives/{contentPart/ContentPartImage.d.ts.map → messagePart/MessagePartImage.d.ts.map} +1 -1
- package/dist/primitives/messagePart/MessagePartImage.js +16 -0
- package/dist/primitives/messagePart/MessagePartImage.js.map +1 -0
- package/dist/primitives/messagePart/MessagePartInProgress.d.ts +6 -0
- package/dist/primitives/{contentPart/ContentPartInProgress.d.ts.map → messagePart/MessagePartInProgress.d.ts.map} +1 -1
- package/dist/primitives/messagePart/MessagePartInProgress.js +13 -0
- package/dist/primitives/messagePart/MessagePartInProgress.js.map +1 -0
- package/dist/primitives/{contentPart/ContentPartText.d.ts → messagePart/MessagePartText.d.ts} +6 -6
- package/dist/primitives/{contentPart/ContentPartText.d.ts.map → messagePart/MessagePartText.d.ts.map} +1 -1
- package/dist/primitives/messagePart/MessagePartText.js +18 -0
- package/dist/primitives/{contentPart/ContentPartText.js.map → messagePart/MessagePartText.js.map} +1 -1
- package/dist/primitives/messagePart/index.d.ts +4 -0
- package/dist/primitives/{contentPart → messagePart}/index.d.ts.map +1 -1
- package/dist/primitives/messagePart/index.js +10 -0
- package/dist/primitives/messagePart/index.js.map +1 -0
- package/dist/primitives/messagePart/useMessagePartFile.d.ts +5 -0
- package/dist/primitives/messagePart/useMessagePartFile.d.ts.map +1 -0
- package/dist/primitives/messagePart/useMessagePartFile.js +18 -0
- package/dist/primitives/messagePart/useMessagePartFile.js.map +1 -0
- package/dist/primitives/messagePart/useMessagePartImage.d.ts +5 -0
- package/dist/primitives/messagePart/useMessagePartImage.d.ts.map +1 -0
- package/dist/primitives/messagePart/useMessagePartImage.js +18 -0
- package/dist/primitives/messagePart/useMessagePartImage.js.map +1 -0
- package/dist/primitives/messagePart/useMessagePartReasoning.d.ts +5 -0
- package/dist/primitives/messagePart/useMessagePartReasoning.d.ts.map +1 -0
- package/dist/primitives/messagePart/useMessagePartReasoning.js +18 -0
- package/dist/primitives/messagePart/useMessagePartReasoning.js.map +1 -0
- package/dist/primitives/messagePart/useMessagePartSource.d.ts +5 -0
- package/dist/primitives/messagePart/useMessagePartSource.d.ts.map +1 -0
- package/dist/primitives/messagePart/useMessagePartSource.js +18 -0
- package/dist/primitives/messagePart/useMessagePartSource.js.map +1 -0
- package/dist/primitives/messagePart/useMessagePartText.d.ts +7 -0
- package/dist/primitives/messagePart/useMessagePartText.d.ts.map +1 -0
- package/dist/primitives/messagePart/useMessagePartText.js +18 -0
- package/dist/primitives/messagePart/useMessagePartText.js.map +1 -0
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +2 -0
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +3 -0
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +3 -8
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ThreadMessageLike.d.ts +3 -3
- package/dist/runtimes/external-store/ThreadMessageLike.js +4 -4
- package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
- package/dist/runtimes/external-store/createMessageConverter.js +3 -3
- package/dist/runtimes/external-store/createMessageConverter.js.map +1 -1
- package/dist/runtimes/external-store/external-message-converter.js.map +1 -1
- package/dist/runtimes/local/ChatModelAdapter.d.ts +4 -4
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +1 -0
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +3 -0
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +2 -0
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +12 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +1 -0
- package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +3 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +3 -0
- package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/utils/MessageRepository.js +1 -1
- package/dist/runtimes/utils/MessageRepository.js.map +1 -1
- package/dist/tests/setup.js +8 -8
- package/dist/tests/setup.js.map +1 -1
- package/dist/types/AssistantTypes.d.ts +15 -15
- package/dist/types/AttachmentTypes.d.ts +3 -3
- package/dist/types/MessagePartComponentTypes.d.ts +25 -0
- package/dist/types/{ContentPartComponentTypes.d.ts.map → MessagePartComponentTypes.d.ts.map} +1 -1
- package/dist/types/MessagePartComponentTypes.js +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/getThreadMessageText.js.map +1 -1
- package/dist/utils/smooth/SmoothContext.js +3 -3
- package/dist/utils/smooth/SmoothContext.js.map +1 -1
- package/dist/utils/smooth/useSmooth.d.ts +3 -3
- package/dist/utils/smooth/useSmooth.js.map +1 -1
- package/dist/utils/useToolArgsFieldStatus.js +3 -3
- package/dist/utils/useToolArgsFieldStatus.js.map +1 -1
- package/package.json +8 -8
- package/src/api/{ContentPartRuntime.ts → MessagePartRuntime.ts} +20 -20
- package/src/api/MessageRuntime.ts +32 -32
- package/src/api/RuntimePathTypes.ts +2 -2
- package/src/api/ThreadListRuntime.ts +8 -0
- package/src/api/ThreadRuntime.ts +6 -0
- package/src/api/index.ts +11 -3
- package/src/cloud/auiV0.ts +3 -3
- package/src/context/providers/MessagePartRuntimeProvider.tsx +42 -0
- package/src/context/providers/{TextContentPartProvider.tsx → TextMessagePartProvider.tsx} +27 -27
- package/src/context/providers/index.ts +4 -1
- package/src/context/react/MessagePartContext.ts +37 -0
- package/src/context/react/index.ts +1 -1
- package/src/context/stores/AssistantToolUIs.ts +4 -4
- package/src/model-context/useAssistantTool.tsx +2 -2
- package/src/model-context/useAssistantToolUI.tsx +2 -2
- package/src/model-context/useInlineRender.tsx +3 -3
- package/src/primitives/assistantModal/AssistantModalContent.tsx +5 -1
- package/src/primitives/index.ts +14 -6
- package/src/primitives/message/MessageParts.tsx +423 -0
- package/src/primitives/message/index.ts +2 -1
- package/src/primitives/messagePart/MessagePartImage.tsx +39 -0
- package/src/primitives/messagePart/MessagePartInProgress.tsx +19 -0
- package/src/primitives/{contentPart/ContentPartText.tsx → messagePart/MessagePartText.tsx} +10 -10
- package/src/primitives/messagePart/index.ts +3 -0
- package/src/primitives/messagePart/useMessagePartFile.tsx +18 -0
- package/src/primitives/messagePart/useMessagePartImage.tsx +18 -0
- package/src/primitives/messagePart/useMessagePartReasoning.tsx +18 -0
- package/src/primitives/messagePart/useMessagePartSource.tsx +18 -0
- package/src/primitives/messagePart/useMessagePartText.tsx +18 -0
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +1 -0
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +1 -0
- package/src/runtimes/core/ThreadRuntimeCore.tsx +1 -0
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +2 -0
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -0
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -8
- package/src/runtimes/external-store/ThreadMessageLike.tsx +21 -21
- package/src/runtimes/external-store/createMessageConverter.tsx +3 -3
- package/src/runtimes/external-store/external-message-converter.tsx +2 -2
- package/src/runtimes/local/ChatModelAdapter.tsx +13 -13
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +4 -0
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +30 -15
- package/src/runtimes/remote-thread-list/EMPTY_THREAD_CORE.tsx +1 -0
- package/src/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +4 -0
- package/src/runtimes/utils/MessageRepository.tsx +1 -1
- package/src/tests/MessageRepository.test.ts +6 -6
- package/src/types/AssistantTypes.ts +24 -24
- package/src/types/AttachmentTypes.ts +3 -3
- package/src/types/MessagePartComponentTypes.tsx +52 -0
- package/src/types/index.ts +69 -28
- package/src/utils/getThreadMessageText.tsx +2 -2
- package/src/utils/smooth/SmoothContext.tsx +7 -7
- package/src/utils/smooth/useSmooth.tsx +7 -7
- package/src/utils/useToolArgsFieldStatus.tsx +3 -3
- package/dist/context/providers/ContentPartRuntimeProvider.d.ts +0 -9
- package/dist/context/providers/ContentPartRuntimeProvider.js.map +0 -1
- package/dist/context/react/ContentPartContext.d.ts +0 -41
- package/dist/context/react/ContentPartContext.js +0 -25
- package/dist/context/react/ContentPartContext.js.map +0 -1
- package/dist/primitives/contentPart/ContentPartImage.js +0 -16
- package/dist/primitives/contentPart/ContentPartImage.js.map +0 -1
- package/dist/primitives/contentPart/ContentPartInProgress.d.ts +0 -6
- package/dist/primitives/contentPart/ContentPartInProgress.js +0 -13
- package/dist/primitives/contentPart/ContentPartInProgress.js.map +0 -1
- package/dist/primitives/contentPart/ContentPartText.js +0 -18
- package/dist/primitives/contentPart/index.d.ts +0 -4
- package/dist/primitives/contentPart/index.js +0 -10
- package/dist/primitives/contentPart/index.js.map +0 -1
- package/dist/primitives/contentPart/useContentPartFile.d.ts +0 -5
- package/dist/primitives/contentPart/useContentPartFile.d.ts.map +0 -1
- package/dist/primitives/contentPart/useContentPartFile.js +0 -18
- package/dist/primitives/contentPart/useContentPartFile.js.map +0 -1
- package/dist/primitives/contentPart/useContentPartImage.d.ts +0 -5
- package/dist/primitives/contentPart/useContentPartImage.d.ts.map +0 -1
- package/dist/primitives/contentPart/useContentPartImage.js +0 -18
- package/dist/primitives/contentPart/useContentPartImage.js.map +0 -1
- package/dist/primitives/contentPart/useContentPartReasoning.d.ts +0 -5
- package/dist/primitives/contentPart/useContentPartReasoning.d.ts.map +0 -1
- package/dist/primitives/contentPart/useContentPartReasoning.js +0 -18
- package/dist/primitives/contentPart/useContentPartReasoning.js.map +0 -1
- package/dist/primitives/contentPart/useContentPartSource.d.ts +0 -5
- package/dist/primitives/contentPart/useContentPartSource.d.ts.map +0 -1
- package/dist/primitives/contentPart/useContentPartSource.js +0 -18
- package/dist/primitives/contentPart/useContentPartSource.js.map +0 -1
- package/dist/primitives/contentPart/useContentPartText.d.ts +0 -7
- package/dist/primitives/contentPart/useContentPartText.d.ts.map +0 -1
- package/dist/primitives/contentPart/useContentPartText.js +0 -18
- package/dist/primitives/contentPart/useContentPartText.js.map +0 -1
- package/dist/primitives/message/MessageContent.d.ts +0 -64
- package/dist/primitives/message/MessageContent.d.ts.map +0 -1
- package/dist/primitives/message/MessageContent.js +0 -141
- package/dist/primitives/message/MessageContent.js.map +0 -1
- package/dist/types/ContentPartComponentTypes.d.ts +0 -25
- package/dist/types/ContentPartComponentTypes.js +0 -1
- package/src/context/providers/ContentPartRuntimeProvider.tsx +0 -42
- package/src/context/react/ContentPartContext.ts +0 -37
- package/src/primitives/contentPart/ContentPartImage.tsx +0 -39
- package/src/primitives/contentPart/ContentPartInProgress.tsx +0 -19
- package/src/primitives/contentPart/index.ts +0 -3
- package/src/primitives/contentPart/useContentPartFile.tsx +0 -18
- package/src/primitives/contentPart/useContentPartImage.tsx +0 -18
- package/src/primitives/contentPart/useContentPartReasoning.tsx +0 -18
- package/src/primitives/contentPart/useContentPartSource.tsx +0 -18
- package/src/primitives/contentPart/useContentPartText.tsx +0 -18
- package/src/primitives/message/MessageContent.tsx +0 -277
- package/src/types/ContentPartComponentTypes.tsx +0 -52
- /package/dist/types/{ContentPartComponentTypes.js.map → MessagePartComponentTypes.js.map} +0 -0
@@ -1,34 +1,34 @@
|
|
1
|
-
import {
|
1
|
+
import { ThreadAssistantMessagePart, ThreadUserMessagePart, MessagePartStatus, ToolCallMessagePartStatus } from "../types/AssistantTypes";
|
2
2
|
import { ThreadRuntimeCoreBinding } from "./ThreadRuntime";
|
3
3
|
import { MessageStateBinding } from "./MessageRuntime";
|
4
4
|
import { SubscribableWithState } from "./subscribable/Subscribable";
|
5
5
|
import { Unsubscribe } from "../types";
|
6
|
-
import {
|
6
|
+
import { MessagePartRuntimePath } from "./RuntimePathTypes";
|
7
7
|
import { ToolResponse } from "assistant-stream";
|
8
|
-
export type
|
9
|
-
readonly status:
|
8
|
+
export type MessagePartState = (ThreadUserMessagePart | ThreadAssistantMessagePart) & {
|
9
|
+
readonly status: MessagePartStatus | ToolCallMessagePartStatus;
|
10
10
|
};
|
11
|
-
type
|
12
|
-
export type
|
11
|
+
type MessagePartSnapshotBinding = SubscribableWithState<MessagePartState, MessagePartRuntimePath>;
|
12
|
+
export type MessagePartRuntime = {
|
13
13
|
/**
|
14
|
-
* Add tool result to a tool call
|
14
|
+
* Add tool result to a tool call message part that has no tool result yet.
|
15
15
|
* This is useful when you are collecting a tool result via user input ("human tool calls").
|
16
16
|
*/
|
17
17
|
addToolResult(result: any | ToolResponse<any>): void;
|
18
|
-
readonly path:
|
19
|
-
getState():
|
18
|
+
readonly path: MessagePartRuntimePath;
|
19
|
+
getState(): MessagePartState;
|
20
20
|
subscribe(callback: () => void): Unsubscribe;
|
21
21
|
};
|
22
|
-
export declare class
|
22
|
+
export declare class MessagePartRuntimeImpl implements MessagePartRuntime {
|
23
23
|
private contentBinding;
|
24
24
|
private messageApi?;
|
25
25
|
private threadApi?;
|
26
|
-
get path():
|
27
|
-
constructor(contentBinding:
|
26
|
+
get path(): MessagePartRuntimePath;
|
27
|
+
constructor(contentBinding: MessagePartSnapshotBinding, messageApi?: MessageStateBinding | undefined, threadApi?: ThreadRuntimeCoreBinding | undefined);
|
28
28
|
protected __internal_bindMethods(): void;
|
29
|
-
getState():
|
29
|
+
getState(): MessagePartState;
|
30
30
|
addToolResult(result: any | ToolResponse<any>): void;
|
31
31
|
subscribe(callback: () => void): Unsubscribe;
|
32
32
|
}
|
33
33
|
export {};
|
34
|
-
//# sourceMappingURL=
|
34
|
+
//# sourceMappingURL=MessagePartRuntime.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"
|
1
|
+
{"version":3,"file":"MessagePartRuntime.d.ts","sourceRoot":"","sources":["../../src/api/MessagePartRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,MAAM,gBAAgB,GAAG,CAC3B,qBAAqB,GACrB,0BAA0B,CAC7B,GAAG;IACF,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,yBAAyB,CAAC;CAChE,CAAC;AAEF,KAAK,0BAA0B,GAAG,qBAAqB,CACrD,gBAAgB,EAChB,sBAAsB,CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAErD,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,IAAI,gBAAgB,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;CAC9C,CAAC;AAEF,qBAAa,sBAAuB,YAAW,kBAAkB;IAM7D,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,SAAS,CAAC;IAPpB,IAAW,IAAI,2BAEd;gBAGS,cAAc,EAAE,0BAA0B,EAC1C,UAAU,CAAC,EAAE,mBAAmB,YAAA,EAChC,SAAS,CAAC,EAAE,wBAAwB,YAAA;IAG9C,SAAS,CAAC,sBAAsB;IAMzB,QAAQ;IAIR,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC;IA8B7C,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;CAGtC"}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
// src/api/
|
1
|
+
// src/api/MessagePartRuntime.ts
|
2
2
|
import { ToolResponse } from "assistant-stream";
|
3
|
-
var
|
3
|
+
var MessagePartRuntimeImpl = class {
|
4
4
|
constructor(contentBinding, messageApi, threadApi) {
|
5
5
|
this.contentBinding = contentBinding;
|
6
6
|
this.messageApi = messageApi;
|
@@ -19,9 +19,9 @@ var ContentPartRuntimeImpl = class {
|
|
19
19
|
}
|
20
20
|
addToolResult(result) {
|
21
21
|
const state = this.contentBinding.getState();
|
22
|
-
if (!state) throw new Error("
|
22
|
+
if (!state) throw new Error("Message part is not available");
|
23
23
|
if (state.type !== "tool-call")
|
24
|
-
throw new Error("Tried to add tool result to non-tool
|
24
|
+
throw new Error("Tried to add tool result to non-tool message part");
|
25
25
|
if (!this.messageApi)
|
26
26
|
throw new Error(
|
27
27
|
"Message API is not available. This is likely a bug in assistant-ui."
|
@@ -46,6 +46,6 @@ var ContentPartRuntimeImpl = class {
|
|
46
46
|
}
|
47
47
|
};
|
48
48
|
export {
|
49
|
-
|
49
|
+
MessagePartRuntimeImpl
|
50
50
|
};
|
51
|
-
//# sourceMappingURL=
|
51
|
+
//# sourceMappingURL=MessagePartRuntime.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/
|
1
|
+
{"version":3,"sources":["../../src/api/MessagePartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { MessagePartRuntimePath } from \"./RuntimePathTypes\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n /**\n * Add tool result to a tool call message part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any | ToolResponse<any>): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: MessagePartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {}\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";AAWA,SAAS,oBAAoB;AA0BtB,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EARH,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAQU,yBAAyB;AACjC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAiC;AACpD,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,UAAM,WAAW,aAAa,WAAW,MAAM;AAC/C,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA,QAAQ,SAAS;AAAA,MACjB,UAAU,SAAS;AAAA,MACnB,SAAS,SAAS;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { SpeechState, SubmittedFeedback } from "../runtimes/core/ThreadRuntimeCore";
|
2
|
-
import { ThreadMessage,
|
3
|
-
import { RunConfig,
|
2
|
+
import { ThreadMessage, ThreadAssistantMessagePart, ThreadUserMessagePart, Unsubscribe } from "../types";
|
3
|
+
import { RunConfig, ToolCallMessagePartStatus } from "../types/AssistantTypes";
|
4
4
|
import { AttachmentRuntime, MessageAttachmentRuntimeImpl } from "./AttachmentRuntime";
|
5
5
|
import { EditComposerRuntime, EditComposerRuntimeImpl } from "./ComposerRuntime";
|
6
|
-
import {
|
6
|
+
import { MessagePartRuntime, MessagePartRuntimeImpl } from "./MessagePartRuntime";
|
7
7
|
import { MessageRuntimePath } from "./RuntimePathTypes";
|
8
8
|
import { ThreadRuntimeCoreBinding } from "./ThreadRuntime";
|
9
9
|
import { SubscribableWithState } from "./subscribable/Subscribable";
|
10
|
-
export declare const
|
10
|
+
export declare const toMessagePartStatus: (message: ThreadMessage, partIndex: number, part: ThreadUserMessagePart | ThreadAssistantMessagePart) => ToolCallMessagePartStatus;
|
11
11
|
export type MessageState = ThreadMessage & {
|
12
12
|
readonly parentId: string | null;
|
13
13
|
readonly isLast: boolean;
|
@@ -45,8 +45,8 @@ export type MessageRuntime = {
|
|
45
45
|
}): void;
|
46
46
|
unstable_getCopyText(): string;
|
47
47
|
subscribe(callback: () => void): Unsubscribe;
|
48
|
-
|
49
|
-
|
48
|
+
getMessagePartByIndex(idx: number): MessagePartRuntime;
|
49
|
+
getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;
|
50
50
|
getAttachmentByIndex(idx: number): AttachmentRuntime & {
|
51
51
|
source: "message";
|
52
52
|
};
|
@@ -72,8 +72,8 @@ export declare class MessageRuntimeImpl implements MessageRuntime {
|
|
72
72
|
}): void;
|
73
73
|
unstable_getCopyText(): string;
|
74
74
|
subscribe(callback: () => void): Unsubscribe;
|
75
|
-
|
76
|
-
|
75
|
+
getMessagePartByIndex(idx: number): MessagePartRuntimeImpl;
|
76
|
+
getMessagePartByToolCallId(toolCallId: string): MessagePartRuntimeImpl;
|
77
77
|
getAttachmentByIndex(idx: number): MessageAttachmentRuntimeImpl;
|
78
78
|
}
|
79
79
|
export {};
|
@@ -8,15 +8,15 @@ import {
|
|
8
8
|
EditComposerRuntimeImpl
|
9
9
|
} from "./ComposerRuntime.js";
|
10
10
|
import {
|
11
|
-
|
12
|
-
} from "./
|
11
|
+
MessagePartRuntimeImpl
|
12
|
+
} from "./MessagePartRuntime.js";
|
13
13
|
import { NestedSubscriptionSubject } from "./subscribable/NestedSubscriptionSubject.js";
|
14
14
|
import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE.js";
|
15
15
|
import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject.js";
|
16
16
|
var COMPLETE_STATUS = Object.freeze({
|
17
17
|
type: "complete"
|
18
18
|
});
|
19
|
-
var
|
19
|
+
var toMessagePartStatus = (message, partIndex, part) => {
|
20
20
|
if (message.role !== "assistant") return COMPLETE_STATUS;
|
21
21
|
if (part.type === "tool-call") {
|
22
22
|
if (!part.result) {
|
@@ -29,12 +29,12 @@ var toContentPartStatus = (message, partIndex, part) => {
|
|
29
29
|
if (message.status.type === "requires-action") return COMPLETE_STATUS;
|
30
30
|
return isLastPart ? message.status : COMPLETE_STATUS;
|
31
31
|
};
|
32
|
-
var
|
32
|
+
var getMessagePartState = (message, partIndex) => {
|
33
33
|
const part = message.content[partIndex];
|
34
34
|
if (!part) {
|
35
35
|
return SKIP_UPDATE;
|
36
36
|
}
|
37
|
-
const status =
|
37
|
+
const status = toMessagePartStatus(message, partIndex, part);
|
38
38
|
return Object.freeze({
|
39
39
|
...part,
|
40
40
|
...{ [symbolInnerMessage]: part[symbolInnerMessage] },
|
@@ -65,8 +65,8 @@ var MessageRuntimeImpl = class {
|
|
65
65
|
this.reload = this.reload.bind(this);
|
66
66
|
this.getState = this.getState.bind(this);
|
67
67
|
this.subscribe = this.subscribe.bind(this);
|
68
|
-
this.
|
69
|
-
this.
|
68
|
+
this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);
|
69
|
+
this.getMessagePartByToolCallId = this.getMessagePartByToolCallId.bind(this);
|
70
70
|
this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);
|
71
71
|
this.unstable_getCopyText = this.unstable_getCopyText.bind(this);
|
72
72
|
this.speak = this.speak.bind(this);
|
@@ -142,17 +142,17 @@ var MessageRuntimeImpl = class {
|
|
142
142
|
subscribe(callback) {
|
143
143
|
return this._core.subscribe(callback);
|
144
144
|
}
|
145
|
-
|
146
|
-
if (idx < 0) throw new Error("
|
147
|
-
return new
|
145
|
+
getMessagePartByIndex(idx) {
|
146
|
+
if (idx < 0) throw new Error("Message part index must be >= 0");
|
147
|
+
return new MessagePartRuntimeImpl(
|
148
148
|
new ShallowMemoizeSubject({
|
149
149
|
path: {
|
150
150
|
...this.path,
|
151
151
|
ref: this.path.ref + `${this.path.ref}.content[${idx}]`,
|
152
|
-
|
152
|
+
messagePartSelector: { type: "index", index: idx }
|
153
153
|
},
|
154
154
|
getState: () => {
|
155
|
-
return
|
155
|
+
return getMessagePartState(this.getState(), idx);
|
156
156
|
},
|
157
157
|
subscribe: (callback) => this._core.subscribe(callback)
|
158
158
|
}),
|
@@ -160,13 +160,13 @@ var MessageRuntimeImpl = class {
|
|
160
160
|
this._threadBinding
|
161
161
|
);
|
162
162
|
}
|
163
|
-
|
164
|
-
return new
|
163
|
+
getMessagePartByToolCallId(toolCallId) {
|
164
|
+
return new MessagePartRuntimeImpl(
|
165
165
|
new ShallowMemoizeSubject({
|
166
166
|
path: {
|
167
167
|
...this.path,
|
168
168
|
ref: this.path.ref + `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,
|
169
|
-
|
169
|
+
messagePartSelector: { type: "toolCallId", toolCallId }
|
170
170
|
},
|
171
171
|
getState: () => {
|
172
172
|
const state = this._core.getState();
|
@@ -174,7 +174,7 @@ var MessageRuntimeImpl = class {
|
|
174
174
|
(part) => part.type === "tool-call" && part.toolCallId === toolCallId
|
175
175
|
);
|
176
176
|
if (idx === -1) return SKIP_UPDATE;
|
177
|
-
return
|
177
|
+
return getMessagePartState(state, idx);
|
178
178
|
},
|
179
179
|
subscribe: (callback) => this._core.subscribe(callback)
|
180
180
|
}),
|
@@ -207,6 +207,6 @@ var MessageRuntimeImpl = class {
|
|
207
207
|
};
|
208
208
|
export {
|
209
209
|
MessageRuntimeImpl,
|
210
|
-
|
210
|
+
toMessagePartStatus
|
211
211
|
};
|
212
212
|
//# sourceMappingURL=MessageRuntime.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallContentPartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n};\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";AAIA,SAAS,0BAA0B;AAYnC,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OAEK;AAGP,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAGtC,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAEM,IAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,MAAI,KAAK,SAAS,aAAa;AAC7B,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,QAAQ;AAAA,IACjB,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,KAAK,IAAI,GAAG,QAAQ,QAAQ,SAAS,CAAC;AACvE,MAAI,QAAQ,OAAO,SAAS,kBAAmB,QAAO;AACtD,SAAO,aAAc,QAAQ,SAA+B;AAC9D;AAEA,IAAM,sBAAsB,CAC1B,SACA,cACmC;AACnC,QAAM,OAAO,QAAQ,QAAQ,SAAS;AACtC,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAGA,QAAM,SAAS,oBAAoB,SAAS,WAAW,IAAI;AAC3D,SAAO,OAAO,OAAO;AAAA,IACnB,GAAG;AAAA,IACH,GAAG,EAAE,CAAC,kBAAkB,GAAI,KAAa,kBAAkB,EAAE;AAAA,IAC7D;AAAA,EACF,CAAC;AACH;AA0DO,IAAM,qBAAN,MAAmD;AAAA,EAKxD,YACU,OACA,gBACR;AAFQ;AACA;AAER,SAAK,WAA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AC,SACC,KAAK,SAAS,eAAe,KAAK,eAAe;AAAA,UACrD;AACA,cAAI,QAAQ,GAAI,QAAO;AACvB,iBAAO,oBAAoB,OAAO,GAAG;AAAA,QACvC;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,qBAAqB,KAAa;AACvC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
1
|
+
{"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n Unsubscribe,\n} from \"../types\";\nimport {\n MessagePartStatus,\n RunConfig,\n ToolCallMessagePartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n MessagePartRuntime,\n MessagePartRuntimeImpl,\n MessagePartState,\n} from \"./MessagePartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";AAIA,SAAS,0BAA0B;AAYnC,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OAEK;AAGP,SAAS,iCAAiC;AAC1C,SAAS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KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
@@ -31,8 +31,8 @@ export type MessageRuntimePath = ThreadRuntimePath & {
|
|
31
31
|
readonly index: number;
|
32
32
|
};
|
33
33
|
};
|
34
|
-
export type
|
35
|
-
readonly
|
34
|
+
export type MessagePartRuntimePath = MessageRuntimePath & {
|
35
|
+
readonly messagePartSelector: {
|
36
36
|
readonly type: "index";
|
37
37
|
readonly index: number;
|
38
38
|
} | {
|
@@ -7,9 +7,11 @@ export type ThreadListState = {
|
|
7
7
|
readonly newThread: string | undefined;
|
8
8
|
readonly threads: readonly string[];
|
9
9
|
readonly archivedThreads: readonly string[];
|
10
|
+
readonly isLoading: boolean;
|
10
11
|
};
|
11
12
|
export type ThreadListRuntime = {
|
12
13
|
getState(): ThreadListState;
|
14
|
+
readonly isLoading: boolean;
|
13
15
|
subscribe(callback: () => void): Unsubscribe;
|
14
16
|
readonly main: ThreadRuntime;
|
15
17
|
getById(threadId: string): ThreadRuntime;
|
@@ -30,6 +32,7 @@ export declare class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
30
32
|
switchToThread(threadId: string): Promise<void>;
|
31
33
|
switchToNewThread(): Promise<void>;
|
32
34
|
getState(): ThreadListState;
|
35
|
+
get isLoading(): boolean;
|
33
36
|
subscribe(callback: () => void): Unsubscribe;
|
34
37
|
private _mainThreadListItemRuntime;
|
35
38
|
readonly main: ThreadRuntime;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ThreadListRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ThreadListRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EAE1B,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,wBAAwB,EAEzB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;
|
1
|
+
{"version":3,"file":"ThreadListRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ThreadListRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EAE1B,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,wBAAwB,EAEzB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,C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AO,CAAC,0BAA0B,CAAC;IAEnC,SAAgB,IAAI,EAAE,aAAa,CAAC;IAEpC,IAAW,QAAQ,8BAElB;IAEM,OAAO,CAAC,QAAQ,EAAE,MAAM;IAcxB,cAAc,CAAC,GAAG,EAAE,MAAM;IAgB1B,sBAAsB,CAAC,GAAG,EAAE,MAAM;IAmBlC,WAAW,CAAC,QAAQ,EAAE,MAAM;CAepC"}
|
@@ -14,7 +14,8 @@ var getThreadListState = (threadList) => {
|
|
14
14
|
mainThreadId: threadList.mainThreadId,
|
15
15
|
newThread: threadList.newThreadId,
|
16
16
|
threads: threadList.threadIds,
|
17
|
-
archivedThreads: threadList.archivedThreadIds
|
17
|
+
archivedThreads: threadList.archivedThreadIds,
|
18
|
+
isLoading: threadList.isLoading
|
18
19
|
};
|
19
20
|
};
|
20
21
|
var getThreadListItemState = (threadList, threadId) => {
|
@@ -88,6 +89,9 @@ var ThreadListRuntimeImpl = class {
|
|
88
89
|
getState() {
|
89
90
|
return this._getState();
|
90
91
|
}
|
92
|
+
get isLoading() {
|
93
|
+
return this._core.isLoading;
|
94
|
+
}
|
91
95
|
subscribe(callback) {
|
92
96
|
return this._core.subscribe(callback);
|
93
97
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/ThreadListRuntime.ts"],"sourcesContent":["import { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { ThreadListRuntimeCore } from \"../runtimes/core/ThreadListRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n ThreadListItemState,\n} from \"./ThreadListItemRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n ThreadListItemRuntimeBinding,\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThread: string | undefined;\n readonly threads: readonly string[];\n readonly archivedThreads: readonly string[];\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(threadId: string): Promise<void>;\n switchToNewThread(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThread: threadList.newThreadId,\n threads: threadList.threadIds,\n archivedThreads: threadList.archivedThreadIds,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.threadId,\n threadId: threadData.threadId, // TODO remove in 0.8.0\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n isMain: threadData.threadId === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n constructor(\n private _core: ThreadListRuntimeCoreBinding,\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(threadId: string): Promise<void> {\n return this._core.switchToThread(threadId);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads[threadId=\" + JSON.stringify(threadId) + \"]\",\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AAGnC;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC;AAAA,EAIE;AAAA,OACK;AACP,SAAS,iCAAiC;AA0B1C,IAAM,qBAAqB,CACzB,eACoB;AACpB,SAAO;AAAA,IACL,cAAc,WAAW;AAAA,IACzB,WAAW,WAAW;AAAA,IACtB,SAAS,WAAW;AAAA,IACpB,iBAAiB,WAAW;AAAA,EAC9B;AACF;AAEA,IAAM,yBAAyB,CAC7B,YACA,aACsC;AACtC,MAAI,aAAa,OAAW,QAAO;AAEnC,QAAM,aAAa,WAAW,YAAY,QAAQ;AAClD,MAAI,CAAC,WAAY,QAAO;AACxB,SAAO;AAAA,IACL,IAAI,WAAW;AAAA,IACf,UAAU,WAAW;AAAA;AAAA,IACrB,UAAU,WAAW;AAAA,IACrB,YAAY,W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xD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,uBAAuB,KAAa;AACzC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,uBAAuB,GAAG;AAAA,UAC/B,gBAAgB,EAAE,MAAM,gBAAgB,OAAO,IAAI;AAAA,QACrD;AAAA,QACA,UAAU,MAAM;AACd,iBAAO;AAAA,YACL,KAAK;AAAA,YACL,KAAK,MAAM,kBAAkB,GAAG;AAAA,UAClC;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,YAAY,UAAkB;AACnC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,wBAAwB,QAAQ;AAAA,UACrC,gBAAgB,EAAE,MAAM,YAAY,SAAS;AAAA,QAC/C;AAAA,QACA,UAAU,MAAM;AACd,iBAAO,uBAAuB,KAAK,OAAO,QAAQ;AAAA,QACpD;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
|
1
|
+
{"version":3,"sources":["../../src/api/ThreadListRuntime.ts"],"sourcesContent":["import { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { ThreadListRuntimeCore } from \"../runtimes/core/ThreadListRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n ThreadListItemState,\n} from \"./ThreadListItemRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n ThreadListItemRuntimeBinding,\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThread: string | undefined;\n readonly threads: readonly string[];\n readonly archivedThreads: readonly string[];\n readonly isLoading: boolean;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n readonly isLoading: boolean;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(threadId: string): Promise<void>;\n switchToNewThread(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThread: threadList.newThreadId,\n threads: threadList.threadIds,\n archivedThreads: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.threadId,\n threadId: threadData.threadId, // TODO remove in 0.8.0\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n isMain: threadData.threadId === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n constructor(\n private _core: ThreadListRuntimeCoreBinding,\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(threadId: string): Promise<void> {\n return this._core.switchToThread(threadId);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public get isLoading() {\n return this._core.isLoading;\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads[threadId=\" + JSON.stringify(threadId) + \"]\",\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AAGnC;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC;AAAA,EAIE;AAAA,OACK;AACP,SAAS,iCAAiC;AA6B1C,IAAM,qBAAqB,CACzB,eACoB;AACpB,SAAO;AAAA,IACL,cAAc,WAAW;AAAA,IACzB,WAAW,WAAW;AAAA,IACtB,SAAS,WAAW;AAAA,IACpB,iBAAiB,WAAW;AAAA,IAC5B,WAAW,WAAW;AAAA,EACxB;AACF;AAEA,IAAM,yBAAyB,CAC7B,YACA,aACsC;AACtC,MAAI,aAAa,OAAW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,KAAK,eAAe,GAAG;AAAA,UACvB,gBAAgB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAC9C;AAAA,QACA,UAAU,MAAM;AACd,iBAAO,uBAAuB,KAAK,OAAO,KAAK,MAAM,UAAU,GAAG,CAAC;AAAA,QACrE;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,uBAAuB,KAAa;AACzC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,uBAAuB,GAAG;AAAA,UAC/B,gBAAgB,EAAE,MAAM,gBAAgB,OAAO,IAAI;AAAA,QACrD;AAAA,QACA,UAAU,MAAM;AACd,iBAAO;AAAA,YACL,KAAK;AAAA,YACL,KAAK,MAAM,kBAAkB,GAAG;AAAA,UAClC;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,YAAY,UAAkB;AACnC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,wBAAwB,QAAQ;AAAA,UACrC,gBAAgB,EAAE,MAAM,YAAY,SAAS;AAAA,QAC/C;AAAA,QACA,UAAU,MAAM;AACd,iBAAO,uBAAuB,KAAK,OAAO,QAAQ;AAAA,QACpD;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
|
@@ -49,6 +49,10 @@ export type ThreadState = {
|
|
49
49
|
* Whether the thread is disabled. Disabled threads cannot receive new messages.
|
50
50
|
*/
|
51
51
|
readonly isDisabled: boolean;
|
52
|
+
/**
|
53
|
+
* Whether the thread is loading its history.
|
54
|
+
*/
|
55
|
+
readonly isLoading: boolean;
|
52
56
|
/**
|
53
57
|
* Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.
|
54
58
|
*/
|
@@ -189,6 +193,7 @@ export declare class ThreadRuntimeImpl implements ThreadRuntime {
|
|
189
193
|
speech: SpeechState | undefined;
|
190
194
|
capabilities: Readonly<RuntimeCapabilities>;
|
191
195
|
isDisabled: boolean;
|
196
|
+
isLoading: boolean;
|
192
197
|
messages: readonly ThreadMessage[];
|
193
198
|
state: ReadonlyJSONValue;
|
194
199
|
suggestions: readonly ThreadSuggestion[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ThreadRuntime.d.ts","sourceRoot":"","sources":["../../src/api/ThreadRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,cAAc,EACd,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,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BAA4B;IAwCrD,SAAS,CAAC,sBAAsB;IAiBhC,SAAgB,QAAQ,4BAAC;IAElB,QAAQ;IAIR,MAAM,CAAC,OAAO,EAAE,mBAAmB;IAQnC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI;IAI9B,eAAe;IAIf,cAAc;IAId,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,oBAAoB;IAQ/D,kBAAkB,CAAC,MAAM,EAAE,qBAAqB;IAIhD,SAAS;IAIT,YAAY;IAIZ,MAAM;IAIN,MAAM,CAAC,IAAI,EAAE,yBAAyB;IAItC,kBAAkB,CAAC,GAAG,EAAE,MAAM;IAqB9B,eAAe,CAAC,SAAS,EAAE,MAAM;IAaxC,OAAO,CAAC,kBAAkB;IA4C1B,OAAO,CAAC,0BAA0B,CAG9B;IAEG,WAAW,CAChB,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,MAAM,IAAI,GACnB,WAAW;CAWf"}
|
@@ -57,6 +57,7 @@ var getThreadState = (runtime, threadListItemState) => {
|
|
57
57
|
metadata: threadListItemState,
|
58
58
|
capabilities: runtime.capabilities,
|
59
59
|
isDisabled: runtime.isDisabled,
|
60
|
+
isLoading: runtime.isLoading,
|
60
61
|
isRunning: lastMessage?.role !== "assistant" ? false : lastMessage.status.type === "running",
|
61
62
|
messages: runtime.messages,
|
62
63
|
state: runtime.state,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport { AppendMessage, ThreadMessage, Unsubscribe } from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport { ThreadListItemState } from \"./ThreadListItemRuntime\";\nimport { RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport { ModelContext } from \"../model-context\";\nimport { ChatModelRunOptions, ChatModelRunResult } from \"../runtimes\";\nimport { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n stream: message.stream,\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n unstable_resumeRun(config: CreateResumeRunConfig): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n /**\n * @deprecated This method was renamed to `getModelContext`.\n */\n getModelConfig(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.unstable_resumeRun = this.unstable_resumeRun.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.getMesssageByIndex = this.getMesssageByIndex.bind(this);\n this.getMesssageById = this.getMesssageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getModelConfig = this.getModelConfig.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public getModelConfig() {\n return this.getModelContext();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public unstable_resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAWA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AAiBnC,IAAM,oBAAoB,CAAC,YAAoD;AAC7E,SAAO;AAAA,IACL,UAAU,QAAQ,YAAY;AAAA,IAC9B,UAAU,QAAQ,YAAY;AAAA,IAC9B,WAAW,QAAQ,aAAa,CAAC;AAAA,IACjC,QAAQ,QAAQ;AAAA,EAClB;AACF;AAEA,IAAM,mBAAm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UAAU,MAAM;AACd,gBAAM,EAAE,SAAS,SAAS,IAAI,SAAS,KAAK,CAAC;AAE7C,gBAAM,EAAE,UAAU,QAAQ,YAAY,IACpC,KAAK,eAAe,SAAS;AAE/B,cAAI,CAAC,WAAW,aAAa,OAAW,QAAO;AAE/C,gBAAM,SAAS,KAAK,eAAe,SAAS;AAE5C,gBAAM,WAAW,OAAO,YAAY,QAAQ,EAAE;AAC9C,gBAAM,oBAAoB,OAAO,qBAAqB,QAAQ,EAAE;AAEhE,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG,EAAE,CAAC,kBAAkB,GAAI,QAAgB,kBAAkB,EAAE;AAAA,YAEhE,QAAQ,SAAS,GAAG,EAAE,GAAG,OAAO,QAAQ;AAAA,YACxC;AAAA,YAEA,cAAc,SAAS,QAAQ,QAAQ,EAAE,IAAI;AAAA,YAC7C,aAAa,SAAS;AAAA,YAEtB,QACE,aAAa,cAAc,QAAQ,KAAK,cAAc;AAAA,YAExD;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAACA,cAAa,KAAK,eAAe,UAAUA,SAAQ;AAAA,MACjE,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEQ,6BAA6B,oBAAI,IAGvC;AAAA,EAEK,YACL,OACA,UACa;AACb,QAAI,UAAU,KAAK,2BAA2B,IAAI,KAAK;AACvD,QAAI,CAAC,SAAS;AACZ,gBAAU,IAAI,yBAAyB;AAAA,QACrC;AAAA,QACA,SAAS,KAAK;AAAA,MAChB,CAAC;AACD,WAAK,2BAA2B,IAAI,OAAO,OAAO;AAAA,IACpD;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
|
1
|
+
{"version":3,"sources":["../../src/api/ThreadRuntime.ts"],"sourcesContent":["import {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { ExportedMessageRepository } from \"../runtimes/utils/MessageRepository\";\nimport { AppendMessage, ThreadMessage, Unsubscribe } from \"../types\";\nimport {\n MessageRuntime,\n MessageRuntimeImpl,\n MessageState,\n} from \"./MessageRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport {\n ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./RuntimePathTypes\";\nimport { ThreadListItemState } from \"./ThreadListItemRuntime\";\nimport { RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport { ModelContext } from \"../model-context\";\nimport { ChatModelRunOptions, ChatModelRunResult } from \"../runtimes\";\nimport { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n stream: message.stream,\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is loading its history.\n */\n readonly isLoading: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isLoading: runtime.isLoading,\n isRunning:\n lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\",\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n /**\n * @deprecated pass an object with `parentId` instead. This will be removed in 0.8.0.\n */\n startRun(parentId: string | null): void;\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n unstable_resumeRun(config: CreateResumeRunConfig): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n /**\n * @deprecated This method was renamed to `getModelContext`.\n */\n getModelConfig(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n getMesssageByIndex(idx: number): MessageRuntime;\n getMesssageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking: () => void;\n\n unstable_on(event: ThreadRuntimeEventType, callback: () => void): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.unstable_resumeRun = this.unstable_resumeRun.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.getMesssageByIndex = this.getMesssageByIndex.bind(this);\n this.getMesssageById = this.getMesssageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getModelConfig = this.getModelConfig.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public getModelConfig() {\n return this.getModelContext();\n }\n\n public startRun(configOrParentId: string | null | CreateStartRunConfig) {\n const config =\n configOrParentId === null || typeof configOrParentId === \"string\"\n ? { parentId: configOrParentId }\n : configOrParentId;\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public unstable_resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public getMesssageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n };\n },\n );\n }\n\n public getMesssageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined) return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n const submittedFeedback = thread.getSubmittedFeedback(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n\n submittedFeedback,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on(\n event: ThreadRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n}\n"],"mappings":";AAWA;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AAEtC;AAAA,EAEE;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,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WAAK,2BAA2B,IAAI,OAAO,OAAO;AAAA,IACpD;AACA,WAAO,QAAQ,UAAU,QAAQ;AAAA,EACnC;AACF;","names":["callback"]}
|
package/dist/api/index.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
export type { AssistantRuntime } from "./AssistantRuntime";
|
2
2
|
export type { ThreadRuntime, ThreadState, CreateAppendMessage, CreateStartRunConfig, } from "./ThreadRuntime";
|
3
3
|
export type { MessageRuntime, MessageState } from "./MessageRuntime";
|
4
|
-
export type {
|
4
|
+
export type { MessagePartRuntime, MessagePartState, } from "./MessagePartRuntime";
|
5
|
+
export type { MessagePartRuntime as MessageContentRuntime, MessagePartState as MessageContentState, } from "./MessagePartRuntime";
|
5
6
|
export type { ComposerRuntime, ThreadComposerRuntime, EditComposerRuntime, EditComposerState, ThreadComposerState, ComposerState, } from "./ComposerRuntime";
|
6
7
|
export type { AttachmentRuntime, AttachmentState } from "./AttachmentRuntime";
|
7
8
|
export type { ThreadListRuntime, ThreadListState } from "./ThreadListRuntime";
|