@assistant-ui/core 0.3.1 → 0.3.3
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/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -7
- package/dist/internal.js +5 -6
- package/dist/react/AssistantProvider.d.ts +1 -1
- package/dist/react/AssistantProvider.d.ts.map +1 -1
- package/dist/react/AssistantProvider.js +35 -9
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
- package/dist/react/AssistantRuntimeProvider.js +1 -1
- package/dist/react/RuntimeAdapter.js +2 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +17 -33
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.js +1 -1
- package/dist/react/client/Interactables.js +1 -1
- package/dist/react/client/Tools.js +2 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +2 -2
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +2 -2
- package/dist/react/model-context/useAssistantInstructions.js +2 -2
- package/dist/react/model-context/useAssistantTool.js +2 -2
- package/dist/react/model-context/useAssistantToolUI.js +2 -2
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useInlineRender.js +1 -1
- package/dist/react/model-context/useInteractable.js +1 -1
- package/dist/react/model-context/useInteractableState.js +2 -2
- package/dist/react/model-context/useInteractableVersions.js +2 -2
- package/dist/react/model-context/useToolArgsStatus.js +2 -2
- package/dist/react/primitive-hooks/useActionBarCopy.js +52 -25
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -2
- package/dist/react/primitive-hooks/useActionBarFeedback.js +2 -2
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -2
- package/dist/react/primitive-hooks/useActionBarSpeak.js +2 -2
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -2
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +2 -2
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useComposerDictate.js +2 -2
- package/dist/react/primitive-hooks/useComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useMessageBranching.js +2 -2
- package/dist/react/primitive-hooks/useMessageReload.js +2 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -2
- package/dist/react/primitive-hooks/useThreadListNew.js +2 -2
- package/dist/react/primitive-hooks/useThreadMessageIds.js +1 -1
- package/dist/react/primitive-hooks/useVoice.js +2 -2
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +2 -2
- package/dist/react/primitives/composer/ComposerAttachments.js +2 -2
- package/dist/react/primitives/composer/ComposerIf.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +2 -2
- package/dist/react/primitives/message/MessageAttachments.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +3 -3
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +2 -2
- package/dist/react/primitives/message/MessageQuote.js +2 -2
- package/dist/react/primitives/part/PartMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadSuggestions.js +2 -2
- package/dist/react/primitives/threadList/ThreadListItems.js +2 -2
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +1 -1
- package/dist/react/providers/MessageByIdProvider.js +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +1 -1
- package/dist/react/providers/PartByIndexProvider.js +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +2 -2
- package/dist/react/providers/SuggestionByIndexProvider.js +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +2 -2
- package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.js +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +14 -13
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +3 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +22 -12
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +9 -23
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +24 -2
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +24 -5
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +7 -13
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/utils/useJSONEqual.js +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -1
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/internal.d.ts +4 -4
- package/dist/runtime/internal.js +4 -4
- package/dist/runtime/utils/thread-message-like.js +2 -2
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +5 -4
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +30 -24
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.js +1 -1
- package/dist/store/clients/no-op-composer-client.js +1 -1
- package/dist/store/clients/suggestions.js +2 -2
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +103 -91
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +2 -2
- package/dist/store/runtime-clients/message-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-runtime-client.js +2 -2
- package/dist/store/scopes/thread.d.ts +1 -1
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +11 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.js +2 -2
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/getGroupStatus.d.ts +9 -0
- package/dist/utils/getGroupStatus.d.ts.map +1 -0
- package/dist/utils/getGroupStatus.js +15 -0
- package/dist/utils/getGroupStatus.js.map +1 -0
- package/dist/utils/normalizePartStatus.d.ts +8 -0
- package/dist/utils/normalizePartStatus.d.ts.map +1 -0
- package/dist/utils/normalizePartStatus.js +39 -0
- package/dist/utils/normalizePartStatus.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -7
- package/src/react/AssistantProvider.tsx +28 -15
- package/src/react/AssistantRuntimeProvider.test.tsx +101 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +28 -7
- package/src/react/index.ts +4 -0
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +109 -14
- package/src/react/primitive-hooks/useActionBarCopy.ts +27 -2
- package/src/react/primitives/message/MessageGroupedParts.tsx +4 -4
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +16 -13
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +53 -10
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +7 -5
- package/src/react/runtimes/cloud/auiV0.ts +51 -12
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +9 -15
- package/src/runtime/api/message-runtime.test.ts +140 -0
- package/src/runtime/api/message-runtime.ts +10 -5
- package/src/runtime/utils/thread-message-like.ts +2 -2
- package/src/runtimes/remote-thread-list/types.ts +5 -4
- package/src/store/clients/chain-of-thought-client.ts +2 -7
- package/src/store/clients/thread-message-client.test.ts +84 -0
- package/src/store/clients/thread-message-client.ts +14 -4
- package/src/store/scopes/thread.ts +1 -1
- package/src/tests/auiV0Encode.test.ts +93 -0
- package/src/tests/remote-thread-list-reactive-threadId.test.ts +0 -92
- package/src/tests/thread-message-like.test.ts +15 -0
- package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +293 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +19 -0
- package/src/utils/data-url.test.ts +26 -2
- package/src/utils/data-url.ts +2 -2
- package/src/utils/getGroupStatus.test.ts +36 -0
- package/src/utils/getGroupStatus.ts +31 -0
- package/src/utils/normalizePartStatus.test.ts +59 -0
- package/src/utils/normalizePartStatus.ts +55 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComposerAttachmentByIndexProvider } from "../../providers/AttachmentByIndexProvider.js";
|
|
2
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/composer/ComposerAttachments.tsx
|
|
7
7
|
const getComponent = (components, attachment) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
3
3
|
//#region src/react/primitives/composer/ComposerIf.tsx
|
|
4
4
|
const useComposerIf = (props) => {
|
|
5
5
|
const $ = c(3);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueueItemByIndexProvider } from "../../providers/QueueItemByIndexProvider.js";
|
|
2
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
2
|
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
3
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/primitives/composer/ComposerQueue.tsx
|
|
6
6
|
const ComposerPrimitiveQueueInner = ({ children }) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { createElement } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { createElement } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/generativeUI/GenerativeUI.tsx
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageAttachmentByIndexProvider } from "../../providers/AttachmentByIndexProvider.js";
|
|
2
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/message/MessageAttachments.tsx
|
|
7
7
|
const getComponent = (components, attachment) => {
|
|
@@ -9,7 +9,8 @@ declare namespace MessagePrimitiveGroupedParts {
|
|
|
9
9
|
* A coalesced group of adjacent parts. Surfaced through the same
|
|
10
10
|
* `{ part }` channel as a leaf {@link EnrichedPartState} so consumers
|
|
11
11
|
* dispatch on a single `switch (part.type)`. `type` is the group key
|
|
12
|
-
* (always `"group-…"`); `status`
|
|
12
|
+
* (always `"group-…"`); `status` is running when any contained part runs,
|
|
13
|
+
* otherwise it mirrors the last contained part.
|
|
13
14
|
*/
|
|
14
15
|
type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {
|
|
15
16
|
readonly type: TKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageGroupedParts.d.ts","names":[],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"MessageGroupedParts.d.ts","names":[],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"mappings":";;;;;;kBAmBiB;;;;;;;;OAQH,UAAU;aACX,MAAM;aACN,QAAQ,oBAAoB;aAC5B;;;;;;;;;;;;OAaC;aACD;;;;;;;;;;;;;OAcC;OAEA,WAAW;;;;;;;aAOZ,MAAM,UAAU,QAAQ,oBAAoB;;;;;;;aAO5C,UAAU;;OAGT,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA8BP,UACP,MAAM,WACN,SAAS,4BACG;;;;;;;;;aAUL,YAAY;;;;;;;;;;;;aAaZ,WAAW,MAAM,WAAW,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmHtC;GAAgC,kCAA8B,SAAA,WAAA,YAIxE,6BAA6B,MAAM,QAAQ"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getGroupStatus } from "../../../utils/getGroupStatus.js";
|
|
2
3
|
import { MessagePartChildren } from "./MessageParts.js";
|
|
3
4
|
import { GROUPBY_MEMO_KEY, buildGroupTree } from "../../utils/groupParts.js";
|
|
4
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { Fragment, useMemo } from "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
6
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
import { useShallow } from "zustand/shallow";
|
|
8
9
|
//#region src/react/primitives/message/MessageGroupedParts.tsx
|
|
9
|
-
const COMPLETE_STATUS = Object.freeze({ type: "complete" });
|
|
10
10
|
const shouldShowIndicator = (mode, parts, isRunning) => {
|
|
11
11
|
if (!isRunning) return false;
|
|
12
12
|
switch (mode) {
|
|
@@ -36,7 +36,7 @@ const renderNode = (node, parts, render) => {
|
|
|
36
36
|
children: /* @__PURE__ */ jsx(PartChildrenSentinel, {})
|
|
37
37
|
})
|
|
38
38
|
}, node.idKey ? `part-${node.idKey}` : `part-${node.index}`);
|
|
39
|
-
const status = parts
|
|
39
|
+
const status = getGroupStatus(parts, node.indices);
|
|
40
40
|
return /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
41
41
|
part: {
|
|
42
42
|
type: node.key,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageGroupedParts.js","names":["Fragment","FC","ReactNode","useMemo","useAuiState","useShallow","PartState","MessagePartStatus","ToolCallMessagePartStatus","buildGroupTree","GROUPBY_MEMO_KEY","GroupByContext","GroupNode","MessagePartChildren","EnrichedPartState","MessagePrimitiveGroupedParts","GroupPart","type","TKey","status","indices","IndicatorPart","IndicatorMode","RenderInfo","part","children","Props","groupBy","context","indicator","info","COMPLETE_STATUS","Object","freeze","shouldShowIndicator","mode","parts","isRunning","length","last","undefined","PartChildrenSentinel","Error","renderNode","node","render","idKey","index","at","groupPart","key","nodeKey","map","child","s","message","toolUIs","tools","memoKey","memoDep","tree","toolCallId","displayName"],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, type FC, type ReactNode, useMemo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useShallow } from \"zustand/shallow\";\nimport type { PartState } from \"../../../store/scopes/part\";\nimport type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../../types/message\";\nimport {\n buildGroupTree,\n GROUPBY_MEMO_KEY,\n type GroupByContext,\n type GroupNode,\n} from \"../../utils/groupParts\";\nimport { MessagePartChildren, type EnrichedPartState } from \"./MessageParts\";\n\nexport namespace MessagePrimitiveGroupedParts {\n /**\n * A coalesced group of adjacent parts. Surfaced through the same\n * `{ part }` channel as a leaf {@link EnrichedPartState} so consumers\n * dispatch on a single `switch (part.type)`. `type` is the group key\n * (always `\"group-…\"`); `status` mirrors the last contained part.\n */\n export type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {\n readonly type: TKey;\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n readonly indices: readonly number[];\n };\n\n /**\n * Synthetic trailing slot for a streaming/loading affordance (a\n * \"thinking…\" dot, etc.). Surfaced through the same `{ part }` channel\n * as groups and leaf parts so a single `switch (part.type)` renders it\n * via `case \"indicator\"`.\n *\n * It is only ever emitted while the message is running, so its presence\n * alone means \"render your loading UI here\" — there's no `status` to\n * branch on.\n */\n export type IndicatorPart = {\n readonly type: \"indicator\";\n };\n\n /**\n * When to emit the synthetic {@link IndicatorPart}. It is **only** emitted\n * while the message is running (streaming); the mode further restricts\n * which running states qualify:\n * - `\"never\"` — never.\n * - `\"empty\"` — only when the message has no parts yet.\n * - `\"no-text\"` (default) — when the message has no parts yet or the last\n * part isn't `text`/`reasoning` (e.g. it ended on a tool call, so the\n * assistant likely isn't done).\n * - `\"always\"` — whenever the message is running, regardless of parts.\n */\n export type IndicatorMode = \"never\" | \"empty\" | \"no-text\" | \"always\";\n\n export type RenderInfo<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Either a coalesced group ({@link GroupPart}, identified by a\n * `group-…` `type`), a single enriched leaf part, or the synthetic\n * {@link IndicatorPart} (`type: \"indicator\"`). Use one switch over\n * `part.type` to handle all three.\n */\n readonly part: GroupPart<TKey> | EnrichedPartState | IndicatorPart;\n /**\n * For group nodes: the recursively-rendered subtree (subgroups +\n * leaf parts). For leaf parts: a sentinel that throws when rendered\n * — accidental fall-through (`default: return children;`) errors\n * loudly instead of silently rendering nothing.\n */\n readonly children: ReactNode;\n };\n\n export type Props<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Maps each part to a group-key path. Adjacent parts that share a\n * prefix coalesce into the same group. Return `[]` (or `null`) to\n * leave a part ungrouped.\n *\n * Group keys must start with `\"group-\"` so the renderer's\n * `switch (part.type)` can tell groups apart from real part types.\n *\n * **Prefer {@link groupPartByType}** for the common case of mapping by\n * `part.type` — it ships a stable memo fingerprint so the tree\n * survives unrelated re-renders. Use an inline function only when\n * the helper isn't expressive enough (e.g. branching on\n * `part.toolName` or part metadata).\n *\n * The second argument is a {@link GroupByContext} carrying the tool-UI\n * registry, for grouping that depends on it (e.g. standalone tool calls).\n *\n * @example\n * ```tsx\n * import { groupPartByType } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * ```\n */\n readonly groupBy: (\n part: PartState,\n context: GroupByContext,\n ) => readonly TKey[] | null;\n\n /**\n * Controls emission of the synthetic {@link IndicatorPart} — a\n * trailing `{ part: { type: \"indicator\", status } }` render call you\n * handle with `case \"indicator\"` to show loading/status UI.\n *\n * @default \"no-text\"\n * @see IndicatorMode\n */\n readonly indicator?: IndicatorMode;\n\n /**\n * Render function called once per group node, once per leaf part, and\n * (when the `indicator` condition is met) once for the trailing\n * {@link IndicatorPart}. Switch on `part.type`: `\"group-…\"` cases wrap\n * `children`; real part types (`\"text\"`, `\"tool-call\"`, …) render the\n * part directly; `\"indicator\"` renders status/loading UI.\n *\n * Leaf parts receive the same {@link EnrichedPartState} that\n * `<MessagePrimitive.Parts>` would produce (`toolUI`, `addResult`,\n * `resume`, `respondToApproval`, `dataRendererUI`).\n */\n readonly children: (info: RenderInfo<TKey>) => ReactNode;\n };\n}\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({ type: \"complete\" });\n\nconst shouldShowIndicator = (\n mode: MessagePrimitiveGroupedParts.IndicatorMode,\n parts: readonly PartState[],\n isRunning: boolean,\n): boolean => {\n // The indicator is a streaming affordance — never show it on a settled\n // message, whatever the mode.\n if (!isRunning) return false;\n\n switch (mode) {\n case \"never\":\n return false;\n case \"always\":\n return true;\n case \"empty\":\n return parts.length === 0;\n case \"no-text\": {\n const last = parts[parts.length - 1];\n return (\n last === undefined ||\n (last.type !== \"text\" && last.type !== \"reasoning\")\n );\n }\n }\n};\n\n/**\n * `children` placeholder passed for leaf-part renders. Leaf parts have no\n * inner subtree; rendering this sentinel signals the consumer wrote\n * `default: return children;` and accidentally fell through for a part —\n * surface the bug loudly instead of silently rendering nothing.\n */\nconst PartChildrenSentinel: FC = () => {\n throw new Error(\n \"MessagePrimitive.GroupedParts: rendered `children` under a leaf \" +\n \"part. `children` is only meaningful for `group-…` cases — add a \" +\n \"matching case for the part type or return `null` to skip it.\",\n );\n};\n\nconst renderNode = <TKey extends `group-${string}`>(\n node: GroupNode,\n parts: readonly PartState[],\n render: (info: MessagePrimitiveGroupedParts.RenderInfo<TKey>) => ReactNode,\n): ReactNode => {\n if (node.type === \"part\") {\n // Key by part identity when available, else absolute part index — never\n // the structural nodeKey, which leaves zombie fiber subscriptions when\n // parts reshape (#4051).\n return (\n <MessagePartChildren\n key={node.idKey ? `part-${node.idKey}` : `part-${node.index}`}\n index={node.index}\n >\n {({ part }) => render({ part, children: <PartChildrenSentinel /> })}\n </MessagePartChildren>\n );\n }\n\n const status = parts[node.indices.at(-1)!]?.status ?? COMPLETE_STATUS;\n const groupPart: MessagePrimitiveGroupedParts.GroupPart<TKey> = {\n type: node.key as TKey,\n status,\n indices: node.indices,\n };\n\n return (\n <Fragment key={node.idKey ?? node.nodeKey}>\n {render({\n part: groupPart,\n children: (\n <>{node.children.map((child) => renderNode(child, parts, render))}</>\n ),\n })}\n </Fragment>\n );\n};\n\n/**\n * Groups adjacent message parts into a tree of coalesced runs and\n * renders each node — group or part — through a single `children`\n * function.\n *\n * The render function receives `{ part, children }` where `part.type`\n * is either a `\"group-…\"` literal (for a group, `children` is the\n * recursively-rendered subtree) or a real part type (`\"text\"`,\n * `\"tool-call\"`, …) for a leaf (`children` is a sentinel that throws\n * if rendered — use `part.type` to distinguish).\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * {({ part, children }) => {\n * switch (part.type) {\n * case \"group-thought\": return <Thought>{children}</Thought>;\n * case \"group-reasoning\": return <Reasoning>{children}</Reasoning>;\n * case \"group-tool\": return <ToolStack>{children}</ToolStack>;\n * case \"text\": return <MarkdownText />;\n * case \"tool-call\": return part.toolUI ?? <ToolFallback {...part} />;\n * case \"indicator\": return <LoadingDots />;\n * default: return null;\n * }\n * }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const MessagePrimitiveGroupedParts = <TKey extends `group-${string}`>({\n groupBy,\n indicator = \"no-text\",\n children,\n}: MessagePrimitiveGroupedParts.Props<TKey>): ReactNode => {\n const parts = useAuiState(useShallow((s) => s.message.parts));\n // Handed to `groupBy` as its `context` argument (see GroupByContext).\n const toolUIs = useAuiState((s) => s.tools.toolUIs);\n // Subscribe to a boolean, not the status object: the tree only needs to\n // re-render when running-ness flips, and `\"never\"` opts out entirely.\n const isRunning = useAuiState((s) =>\n indicator === \"never\" ? false : s.message.status?.type === \"running\",\n );\n\n // Helpers like `groupPartByType` tag the function with `GROUPBY_MEMO_KEY`\n // (a stable string fingerprint of the helper config). When present,\n // memo on `[parts, memoKey]` so the tree survives unrelated renders.\n // For inline `groupBy`, fall back to recomputing each render — O(n)\n // and cheap.\n const memoKey = (groupBy as { [GROUPBY_MEMO_KEY]?: string })[\n GROUPBY_MEMO_KEY\n ];\n const memoDep = memoKey ?? groupBy;\n const tree = useMemo(() => {\n const context: GroupByContext = { toolUIs };\n return buildGroupTree(\n parts.map((part) => groupBy(part, context) ?? []),\n parts.map((part) =>\n part.type === \"tool-call\" ? part.toolCallId : undefined,\n ),\n );\n // oxlint-disable-next-line react/exhaustive-deps -- groupBy is captured via memoDep (either its identity or the helper's memoKey fingerprint); listing it directly would defeat the helper-tagged memo path\n }, [parts, memoDep, toolUIs]);\n\n return (\n <>\n {tree.map((node) => renderNode(node, parts, children))}\n {shouldShowIndicator(indicator, parts, isRunning) &&\n children({\n part: { type: \"indicator\" },\n children: <PartChildrenSentinel />,\n })}\n </>\n );\n};\n\nMessagePrimitiveGroupedParts.displayName = \"MessagePrimitive.GroupedParts\";\n"],"mappings":";;;;;;;;AAuIA,MAAM+B,kBAAqCC,OAAOC,OAAO,EAAEhB,MAAM,WAAW,CAAC;AAE7E,MAAMiB,uBACJC,MACAC,OACAC,cACY;CAGZ,IAAI,CAACA,WAAW,OAAO;CAEvB,QAAQF,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAOC,MAAME,WAAW;EAC1B,KAAK,WAAW;GACd,MAAMC,OAAOH,MAAMA,MAAME,SAAS;GAClC,OACEC,SAASC,KAAAA,KACRD,KAAKtB,SAAS,UAAUsB,KAAKtB,SAAS;EAE3C;CACF;AACF;;;;;;;AAQA,MAAMwB,6BAAiC;CACrC,MAAM,IAAIC,MACR,8LAGF;AACF;AAEA,MAAMC,cACJC,MACAR,OACAS,WACc;CACd,IAAID,KAAK3B,SAAS,QAIhB,OACE,oBAAC,qBAAD;EAEE,OAAO2B,KAAKG;EAEV,WAAA,EAAEvB,WAAWqB,OAAO;GAAErB;GAAMC,UAAU,oBAAC,sBAAD,CAAqB,CAAA;EAAI,CAAC;CAC/C,GAJdmB,KAAKE,QAAQ,QAAQF,KAAKE,UAAU,QAAQF,KAAKG,OAInC;CAIzB,MAAM5B,SAASiB,MAAMQ,KAAKxB,QAAQ4B,GAAG,EAAE,EAAG,EAAE7B,UAAUY;CAOtD,OACE,oBAA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ReactNode","useMemo","useAuiState","useShallow","PartState","MessagePartStatus","ToolCallMessagePartStatus","getGroupStatus","buildGroupTree","GROUPBY_MEMO_KEY","GroupByContext","GroupNode","MessagePartChildren","EnrichedPartState","MessagePrimitiveGroupedParts","GroupPart","type","TKey","status","indices","IndicatorPart","IndicatorMode","RenderInfo","part","children","Props","groupBy","context","indicator","info","shouldShowIndicator","mode","parts","isRunning","length","last","undefined","PartChildrenSentinel","Error","renderNode","node","render","idKey","index","groupPart","key","nodeKey","map","child","s","message","toolUIs","tools","memoKey","memoDep","tree","toolCallId","displayName"],"sources":["../../../../src/react/primitives/message/MessageGroupedParts.tsx"],"sourcesContent":["\"use client\";\n\nimport { Fragment, type FC, type ReactNode, useMemo } from \"react\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useShallow } from \"zustand/shallow\";\nimport type { PartState } from \"../../../store/scopes/part\";\nimport type {\n MessagePartStatus,\n ToolCallMessagePartStatus,\n} from \"../../../types/message\";\nimport { getGroupStatus } from \"../../../utils/getGroupStatus\";\nimport {\n buildGroupTree,\n GROUPBY_MEMO_KEY,\n type GroupByContext,\n type GroupNode,\n} from \"../../utils/groupParts\";\nimport { MessagePartChildren, type EnrichedPartState } from \"./MessageParts\";\n\nexport namespace MessagePrimitiveGroupedParts {\n /**\n * A coalesced group of adjacent parts. Surfaced through the same\n * `{ part }` channel as a leaf {@link EnrichedPartState} so consumers\n * dispatch on a single `switch (part.type)`. `type` is the group key\n * (always `\"group-…\"`); `status` is running when any contained part runs,\n * otherwise it mirrors the last contained part.\n */\n export type GroupPart<TKey extends `group-${string}` = `group-${string}`> = {\n readonly type: TKey;\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n readonly indices: readonly number[];\n };\n\n /**\n * Synthetic trailing slot for a streaming/loading affordance (a\n * \"thinking…\" dot, etc.). Surfaced through the same `{ part }` channel\n * as groups and leaf parts so a single `switch (part.type)` renders it\n * via `case \"indicator\"`.\n *\n * It is only ever emitted while the message is running, so its presence\n * alone means \"render your loading UI here\" — there's no `status` to\n * branch on.\n */\n export type IndicatorPart = {\n readonly type: \"indicator\";\n };\n\n /**\n * When to emit the synthetic {@link IndicatorPart}. It is **only** emitted\n * while the message is running (streaming); the mode further restricts\n * which running states qualify:\n * - `\"never\"` — never.\n * - `\"empty\"` — only when the message has no parts yet.\n * - `\"no-text\"` (default) — when the message has no parts yet or the last\n * part isn't `text`/`reasoning` (e.g. it ended on a tool call, so the\n * assistant likely isn't done).\n * - `\"always\"` — whenever the message is running, regardless of parts.\n */\n export type IndicatorMode = \"never\" | \"empty\" | \"no-text\" | \"always\";\n\n export type RenderInfo<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Either a coalesced group ({@link GroupPart}, identified by a\n * `group-…` `type`), a single enriched leaf part, or the synthetic\n * {@link IndicatorPart} (`type: \"indicator\"`). Use one switch over\n * `part.type` to handle all three.\n */\n readonly part: GroupPart<TKey> | EnrichedPartState | IndicatorPart;\n /**\n * For group nodes: the recursively-rendered subtree (subgroups +\n * leaf parts). For leaf parts: a sentinel that throws when rendered\n * — accidental fall-through (`default: return children;`) errors\n * loudly instead of silently rendering nothing.\n */\n readonly children: ReactNode;\n };\n\n export type Props<TKey extends `group-${string}` = `group-${string}`> = {\n /**\n * Maps each part to a group-key path. Adjacent parts that share a\n * prefix coalesce into the same group. Return `[]` (or `null`) to\n * leave a part ungrouped.\n *\n * Group keys must start with `\"group-\"` so the renderer's\n * `switch (part.type)` can tell groups apart from real part types.\n *\n * **Prefer {@link groupPartByType}** for the common case of mapping by\n * `part.type` — it ships a stable memo fingerprint so the tree\n * survives unrelated re-renders. Use an inline function only when\n * the helper isn't expressive enough (e.g. branching on\n * `part.toolName` or part metadata).\n *\n * The second argument is a {@link GroupByContext} carrying the tool-UI\n * registry, for grouping that depends on it (e.g. standalone tool calls).\n *\n * @example\n * ```tsx\n * import { groupPartByType } from \"@assistant-ui/react\";\n *\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * ```\n */\n readonly groupBy: (\n part: PartState,\n context: GroupByContext,\n ) => readonly TKey[] | null;\n\n /**\n * Controls emission of the synthetic {@link IndicatorPart} — a\n * trailing `{ part: { type: \"indicator\", status } }` render call you\n * handle with `case \"indicator\"` to show loading/status UI.\n *\n * @default \"no-text\"\n * @see IndicatorMode\n */\n readonly indicator?: IndicatorMode;\n\n /**\n * Render function called once per group node, once per leaf part, and\n * (when the `indicator` condition is met) once for the trailing\n * {@link IndicatorPart}. Switch on `part.type`: `\"group-…\"` cases wrap\n * `children`; real part types (`\"text\"`, `\"tool-call\"`, …) render the\n * part directly; `\"indicator\"` renders status/loading UI.\n *\n * Leaf parts receive the same {@link EnrichedPartState} that\n * `<MessagePrimitive.Parts>` would produce (`toolUI`, `addResult`,\n * `resume`, `respondToApproval`, `dataRendererUI`).\n */\n readonly children: (info: RenderInfo<TKey>) => ReactNode;\n };\n}\n\nconst shouldShowIndicator = (\n mode: MessagePrimitiveGroupedParts.IndicatorMode,\n parts: readonly PartState[],\n isRunning: boolean,\n): boolean => {\n // The indicator is a streaming affordance — never show it on a settled\n // message, whatever the mode.\n if (!isRunning) return false;\n\n switch (mode) {\n case \"never\":\n return false;\n case \"always\":\n return true;\n case \"empty\":\n return parts.length === 0;\n case \"no-text\": {\n const last = parts[parts.length - 1];\n return (\n last === undefined ||\n (last.type !== \"text\" && last.type !== \"reasoning\")\n );\n }\n }\n};\n\n/**\n * `children` placeholder passed for leaf-part renders. Leaf parts have no\n * inner subtree; rendering this sentinel signals the consumer wrote\n * `default: return children;` and accidentally fell through for a part —\n * surface the bug loudly instead of silently rendering nothing.\n */\nconst PartChildrenSentinel: FC = () => {\n throw new Error(\n \"MessagePrimitive.GroupedParts: rendered `children` under a leaf \" +\n \"part. `children` is only meaningful for `group-…` cases — add a \" +\n \"matching case for the part type or return `null` to skip it.\",\n );\n};\n\nconst renderNode = <TKey extends `group-${string}`>(\n node: GroupNode,\n parts: readonly PartState[],\n render: (info: MessagePrimitiveGroupedParts.RenderInfo<TKey>) => ReactNode,\n): ReactNode => {\n if (node.type === \"part\") {\n // Key by part identity when available, else absolute part index — never\n // the structural nodeKey, which leaves zombie fiber subscriptions when\n // parts reshape (#4051).\n return (\n <MessagePartChildren\n key={node.idKey ? `part-${node.idKey}` : `part-${node.index}`}\n index={node.index}\n >\n {({ part }) => render({ part, children: <PartChildrenSentinel /> })}\n </MessagePartChildren>\n );\n }\n\n const status = getGroupStatus(parts, node.indices);\n const groupPart: MessagePrimitiveGroupedParts.GroupPart<TKey> = {\n type: node.key as TKey,\n status,\n indices: node.indices,\n };\n\n return (\n <Fragment key={node.idKey ?? node.nodeKey}>\n {render({\n part: groupPart,\n children: (\n <>{node.children.map((child) => renderNode(child, parts, render))}</>\n ),\n })}\n </Fragment>\n );\n};\n\n/**\n * Groups adjacent message parts into a tree of coalesced runs and\n * renders each node — group or part — through a single `children`\n * function.\n *\n * The render function receives `{ part, children }` where `part.type`\n * is either a `\"group-…\"` literal (for a group, `children` is the\n * recursively-rendered subtree) or a real part type (`\"text\"`,\n * `\"tool-call\"`, …) for a leaf (`children` is a sentinel that throws\n * if rendered — use `part.type` to distinguish).\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * })}\n * >\n * {({ part, children }) => {\n * switch (part.type) {\n * case \"group-thought\": return <Thought>{children}</Thought>;\n * case \"group-reasoning\": return <Reasoning>{children}</Reasoning>;\n * case \"group-tool\": return <ToolStack>{children}</ToolStack>;\n * case \"text\": return <MarkdownText />;\n * case \"tool-call\": return part.toolUI ?? <ToolFallback {...part} />;\n * case \"indicator\": return <LoadingDots />;\n * default: return null;\n * }\n * }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const MessagePrimitiveGroupedParts = <TKey extends `group-${string}`>({\n groupBy,\n indicator = \"no-text\",\n children,\n}: MessagePrimitiveGroupedParts.Props<TKey>): ReactNode => {\n const parts = useAuiState(useShallow((s) => s.message.parts));\n // Handed to `groupBy` as its `context` argument (see GroupByContext).\n const toolUIs = useAuiState((s) => s.tools.toolUIs);\n // Subscribe to a boolean, not the status object: the tree only needs to\n // re-render when running-ness flips, and `\"never\"` opts out entirely.\n const isRunning = useAuiState((s) =>\n indicator === \"never\" ? false : s.message.status?.type === \"running\",\n );\n\n // Helpers like `groupPartByType` tag the function with `GROUPBY_MEMO_KEY`\n // (a stable string fingerprint of the helper config). When present,\n // memo on `[parts, memoKey]` so the tree survives unrelated renders.\n // For inline `groupBy`, fall back to recomputing each render — O(n)\n // and cheap.\n const memoKey = (groupBy as { [GROUPBY_MEMO_KEY]?: string })[\n GROUPBY_MEMO_KEY\n ];\n const memoDep = memoKey ?? groupBy;\n const tree = useMemo(() => {\n const context: GroupByContext = { toolUIs };\n return buildGroupTree(\n parts.map((part) => groupBy(part, context) ?? []),\n parts.map((part) =>\n part.type === \"tool-call\" ? part.toolCallId : undefined,\n ),\n );\n // oxlint-disable-next-line react/exhaustive-deps -- groupBy is captured via memoDep (either its identity or the helper's memoKey fingerprint); listing it directly would defeat the helper-tagged memo path\n }, [parts, memoDep, toolUIs]);\n\n return (\n <>\n {tree.map((node) => renderNode(node, parts, children))}\n {shouldShowIndicator(indicator, parts, isRunning) &&\n children({\n part: { type: \"indicator\" },\n children: <PartChildrenSentinel />,\n })}\n </>\n );\n};\n\nMessagePrimitiveGroupedParts.displayName = \"MessagePrimitive.GroupedParts\";\n"],"mappings":";;;;;;;;;AAyIA,MAAMgC,uBACJC,MACAC,OACAC,cACY;CAGZ,IAAI,CAACA,WAAW,OAAO;CAEvB,QAAQF,MAAR;EACE,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAOC,MAAME,WAAW;EAC1B,KAAK,WAAW;GACd,MAAMC,OAAOH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LwB,MAAMe,KAAKxB,SAASG,QAAQH,MAAMI,OAAO,KAAK,CAAA,CAAE,GAChDK,MAAMe,KAAKxB,WACTA,OAAKP,SAAS,cAAcO,OAAKiC,aAAapB,KAAAA,CAChD,CACF;CAEF,GAAG;EAACJ;EAbaN,QACfjB,qBAEyBiB;EAUPyB;CAAO,CAItBI,CAAI,CAACR,KAAKP,SAASD,WAAWC,MAAMR,OAAOR,QAAQ,CAAC,GACpDM,oBAAoBF,WAAWI,OAAOC,SAAS,KAC9CT,SAAS;EACPD,MAAM,EAAEP,MAAM,YAAY;EAC1BQ,UAAU,oBAAC,sBAAD,CAAqB,CAAA;CACjC,CAAC,CACL,EAAA,CAAA;AAEJ;AAEAV,6BAA6B2C,cAAc"}
|
|
@@ -4,9 +4,9 @@ import { TextMessagePartProvider } from "../../providers/TextMessagePartProvider
|
|
|
4
4
|
import { ChainOfThoughtByIndicesProvider } from "../../providers/ChainOfThoughtByIndicesProvider.js";
|
|
5
5
|
import { getMessageQuote } from "../../utils/getMessageQuote.js";
|
|
6
6
|
import { GenerativeUIRender } from "../generativeUI/GenerativeUI.js";
|
|
7
|
-
import { RenderChildrenWithAccessor, useAui, useAuiState } from "@assistant-ui/store";
|
|
8
|
-
import { memo } from "@assistant-ui/tap/react-shim";
|
|
9
7
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
8
|
+
import { memo } from "@assistant-ui/tap/react-shim";
|
|
9
|
+
import { RenderChildrenWithAccessor, useAui, useAuiState } from "@assistant-ui/store";
|
|
10
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { useShallow } from "zustand/shallow";
|
|
12
12
|
//#region src/react/primitives/message/MessageParts.tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getMessageQuote } from "../../utils/getMessageQuote.js";
|
|
2
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { memo } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/message/MessageQuote.tsx
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReadonlyThreadProvider } from "../../providers/ReadonlyThreadProvider.js";
|
|
2
2
|
import { ThreadPrimitiveMessagesImpl } from "../thread/ThreadMessages.js";
|
|
3
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
4
|
-
import { memo } from "@assistant-ui/tap/react-shim";
|
|
5
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
|
+
import { memo } from "@assistant-ui/tap/react-shim";
|
|
5
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/primitives/part/PartMessages.tsx
|
|
8
8
|
const usePartMessages = () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MessageByIndexProvider } from "../../providers/MessageByIndexProvider.js";
|
|
2
2
|
import { MessageByIdProvider } from "../../providers/MessageByIdProvider.js";
|
|
3
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
4
|
-
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
5
3
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
4
|
+
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
5
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/primitives/thread/ThreadMessages.tsx
|
|
8
8
|
const isComponentsSame = (prev, next) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SuggestionByIndexProvider } from "../../providers/SuggestionByIndexProvider.js";
|
|
2
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/thread/ThreadSuggestions.tsx
|
|
7
7
|
const SuggestionComponent = (t0) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ThreadListItemByIndexProvider } from "../../providers/ThreadListItemByIndexProvider.js";
|
|
2
|
-
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo, useMemo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { RenderChildrenWithAccessor, useAuiState } from "@assistant-ui/store";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/primitives/threadList/ThreadListItems.tsx
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
3
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/primitives/threadListItem/ThreadListItemTitle.tsx
|
|
5
5
|
const ThreadListItemPrimitiveTitle = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/AttachmentByIndexProvider.tsx
|
|
5
5
|
const MessageAttachmentByIndexProvider = (t0) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainOfThoughtClient } from "../../store/clients/chain-of-thought-client.js";
|
|
2
|
-
import { AuiProvider, useAui, useAuiState } from "@assistant-ui/store";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { AuiProvider, useAui, useAuiState } from "@assistant-ui/store";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/providers/ChainOfThoughtByIndicesProvider.tsx
|
|
6
6
|
const ChainOfThoughtByIndicesProvider = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/ChainOfThoughtPartByIndexProvider.tsx
|
|
5
5
|
const ChainOfThoughtPartByIndexProvider = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/MessageByIdProvider.tsx
|
|
5
5
|
const MessageByIdProvider = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/MessageByIndexProvider.tsx
|
|
5
5
|
const MessageByIndexProvider = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/PartByIndexProvider.tsx
|
|
5
5
|
const PartByIndexProvider = (t0) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/QueueItemByIndexProvider.tsx
|
|
5
5
|
const QueueItemByIndexProvider = (t0) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ThreadRuntimeImpl } from "../../runtime/api/thread-runtime.js";
|
|
2
2
|
import { ReadonlyThreadRuntimeCore } from "../../runtimes/readonly/ReadonlyThreadRuntimeCore.js";
|
|
3
3
|
import { ThreadClient } from "../../store/runtime-clients/thread-runtime-client.js";
|
|
4
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
5
|
-
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
6
4
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
|
+
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
8
|
//#region src/react/providers/ReadonlyThreadProvider.tsx
|
|
9
9
|
const READONLY_THREAD_PATH = Object.freeze({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/SuggestionByIndexProvider.tsx
|
|
5
5
|
const SuggestionByIndexProvider = (t0) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
2
|
-
import "@assistant-ui/tap/react-shim";
|
|
3
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import "@assistant-ui/tap/react-shim";
|
|
3
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
4
4
|
import { resource } from "@assistant-ui/tap";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
//#region src/react/providers/TextMessagePartProvider.tsx
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { AuiProvider, Derived, useAui } from "@assistant-ui/store";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/providers/ThreadListItemByIndexProvider.tsx
|
|
5
5
|
const ThreadListItemByIndexProvider = (t0) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ThreadListItemClient } from "../../store/runtime-clients/thread-list-item-runtime-client.js";
|
|
2
|
-
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/providers/ThreadListItemRuntimeProvider.tsx
|
|
6
6
|
const ThreadListItemRuntimeProvider = (t0) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;KAwBK,6BAA6B;cAcrB,4CAA4C;UAC/C;UAGA;UACA;UACA;EAGN,YAAA,aAAa,sBACb,QAAQ;EAOH,mBAAmB,mBAAgB,QAAA;;;eAPhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BH,qBAAqB,mBAAgB;;;eAxBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BnC,kBAAkB;EAMlB,eAAe,gBAAgB;UAS9B;UAoEA;EAqCD,iCAAiC;IACtC,UAAU,cAAc"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
2
2
|
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime.js";
|
|
3
3
|
import { ThreadListItemRuntimeProvider } from "../providers/ThreadListItemRuntimeProvider.js";
|
|
4
|
-
import { useAui } from "@assistant-ui/store";
|
|
5
|
-
import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
6
4
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
|
+
import { Fragment, memo, useCallback, useEffect, useEffectEvent, useLayoutEffect, useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
7
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
8
8
|
import { create } from "zustand";
|
|
9
9
|
//#region src/react/runtimes/RemoteThreadListHookInstanceManager.tsx
|
|
@@ -96,19 +96,20 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
96
96
|
const setGetInitializePromise = runtimeCore.__internal_setGetInitializePromise;
|
|
97
97
|
if (typeof setGetInitializePromise === "function") setGetInitializePromise.call(runtimeCore, () => initPromiseRef.current);
|
|
98
98
|
}, [threadBinding]);
|
|
99
|
+
const handleInitialize = useEffectEvent(() => {
|
|
100
|
+
if (hasInitializedRef.current) return;
|
|
101
|
+
if (aui.threadListItem.getState().status !== "new") return;
|
|
102
|
+
hasInitializedRef.current = true;
|
|
103
|
+
initPromiseRef.current = aui.threadListItem.initialize();
|
|
104
|
+
const dispose = runtime.thread.unstable_on("runEnd", () => {
|
|
105
|
+
dispose();
|
|
106
|
+
aui.threadListItem.generateTitle();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
99
109
|
useEffect(() => {
|
|
100
110
|
hasInitializedRef.current = false;
|
|
101
|
-
return runtime.threads.main.unstable_on("initialize",
|
|
102
|
-
|
|
103
|
-
if (aui.threadListItem.getState().status !== "new") return;
|
|
104
|
-
hasInitializedRef.current = true;
|
|
105
|
-
initPromiseRef.current = aui.threadListItem.initialize();
|
|
106
|
-
const dispose = runtime.thread.unstable_on("runEnd", () => {
|
|
107
|
-
dispose();
|
|
108
|
-
aui.threadListItem.generateTitle();
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}, [runtime, aui]);
|
|
111
|
+
return runtime.threads.main.unstable_on("initialize", handleInitialize);
|
|
112
|
+
}, [runtime]);
|
|
112
113
|
return /* @__PURE__ */ jsx(Fragment$1, { children });
|
|
113
114
|
};
|
|
114
115
|
_OuterActiveThreadProvider = memo(({ threadId, provider: Provider }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useCallback","useRef","useEffect","useLayoutEffect","memo","PropsWithChildren","ComponentType","useMemo","Fragment","UseBoundStore","StoreApi","create","useAui","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadListRuntimeCore","AssistantRuntime","BaseSubscribable","ThreadRuntimeImpl","ThreadListRuntimeImpl","RemoteThreadListHook","RemoteThreadListHookInstance","runtime","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","useRuntimeHook","useRuntime","instances","Map","useAliveThreadsKeysChanged","parent","constructor","runtimeHook","startThreadRuntime","threadId","has","set","setState","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","getThreadRuntimeCore","undefined","stopThreadRuntime","delete","_notifySubscribers","setRuntimeHook","newRuntimeHook","prevRuntimeHook","getState","_RuntimeBinder","children","threadBinding","thread","__internal_threadBinding","updateRuntime","aliveThread","isMounted","outerSubscribe","aui","initPromiseRef","hasInitializedRef","runtimeCore","setGetInitializePromise","Record","__internal_setGetInitializePromise","call","threads","main","unstable_on","state","threadListItem","status","initialize","generateTitle","_OuterActiveThreadProvider","provider","Provider","getItemById","process","env","NODE_ENV","id","setTimeout","console","warn","clearTimeout","__internal_RenderThreadRuntimes","Array","from","keys","map"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useCallback,\n useRef,\n useEffect,\n useLayoutEffect,\n memo,\n type PropsWithChildren,\n type ComponentType,\n useMemo,\n Fragment,\n} from \"react\";\nimport { type UseBoundStore, type StoreApi, create } from \"zustand\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport type { ThreadListRuntimeCore } from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeImpl } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\n\ntype RemoteThreadListHook = () => AssistantRuntime;\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private useRuntimeHook: UseBoundStore<\n StoreApi<{ useRuntime: RemoteThreadListHook }>\n >;\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private useAliveThreadsKeysChanged = create(() => ({}));\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.useRuntimeHook = create(() => ({ useRuntime: runtimeHook }));\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n this.instances.set(threadId, {});\n this.useAliveThreadsKeysChanged.setState({}, true);\n }\n\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (!instance.runtime) {\n return; // misc update\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public stopThreadRuntime(threadId: string) {\n this.instances.delete(threadId);\n this.useAliveThreadsKeysChanged.setState({}, true);\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n const prevRuntimeHook = this.useRuntimeHook.getState().useRuntime;\n if (prevRuntimeHook !== newRuntimeHook) {\n this.useRuntimeHook.setState({ useRuntime: newRuntimeHook }, true);\n }\n }\n\n // Rendered as a child of the user's Provider so the runtime hook can\n // read context the Provider injects (e.g. RuntimeAdapterProvider).\n private _RuntimeBinder: FC<PropsWithChildren<{ threadId: string }>> = ({\n threadId,\n children,\n }) => {\n const { useRuntime } = this.useRuntimeHook();\n const runtime = useRuntime();\n\n const threadBinding = (runtime.thread as ThreadRuntimeImpl)\n .__internal_threadBinding;\n\n const updateRuntime = useCallback(() => {\n const aliveThread = this.instances.get(threadId);\n if (!aliveThread)\n throw new Error(\n `Thread \"${threadId}\" runtime binding not found. This is a bug in assistant-ui.`,\n );\n\n aliveThread.runtime = threadBinding.getState();\n this._notifySubscribers();\n }, [threadId, threadBinding]);\n\n const isMounted = useRef(false);\n if (!isMounted.current) {\n updateRuntime();\n }\n\n useEffect(() => {\n isMounted.current = true;\n updateRuntime();\n return threadBinding.outerSubscribe(updateRuntime);\n }, [threadBinding, updateRuntime]);\n\n const aui = useAui();\n const initPromiseRef = useRef<Promise<unknown> | undefined>(undefined);\n const hasInitializedRef = useRef(false);\n\n useEffect(() => {\n const runtimeCore = threadBinding.getState();\n const setGetInitializePromise = (runtimeCore as Record<string, unknown>)\n .__internal_setGetInitializePromise;\n if (typeof setGetInitializePromise === \"function\") {\n setGetInitializePromise.call(runtimeCore, () => initPromiseRef.current);\n }\n }, [threadBinding]);\n\n useEffect(() => {\n hasInitializedRef.current = false;\n return runtime.threads.main.unstable_on(\"initialize\", () => {\n if (hasInitializedRef.current) return;\n\n const state = aui.threadListItem.getState();\n if (state.status !== \"new\") return;\n hasInitializedRef.current = true;\n\n initPromiseRef.current = aui.threadListItem.initialize();\n\n const dispose = runtime.thread.unstable_on(\"runEnd\", () => {\n dispose();\n aui.threadListItem.generateTitle();\n });\n });\n }, [runtime, aui]);\n\n return <>{children}</>;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime binder and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._RuntimeBinder threadId={threadId}>\n <ProviderRenderDetector detectorRef={detectorRef} />\n </this._RuntimeBinder>\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n this.useAliveThreadsKeysChanged(); // trigger re-render on alive threads change\n\n return Array.from(this.instances.keys()).map((threadId) => (\n <this._OuterActiveThreadProvider\n key={threadId}\n threadId={threadId}\n provider={provider}\n />\n ));\n };\n}\n"],"mappings":";;;;;;;;;AA6BA,MAAMyB,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI,WAAA;GACdJ,YAAWM,UAAW;EAAH;EAClBD,KAAA,CAACL,WAAW;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAD,KAAAF,EAAA;EAAAG,KAAAH,EAAA;CAAA;CAFhBvB,gBAAgByB,IAEbC,EAAa;CAAC,OACV;AAAI;AAEb,IAAaE,sCAAb,cAAyDd,iBAAiB;CACxE;CAGA,4BAAoB,IAAIkB,IAA0C;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OAAO,oBAAA,YAAA,EAAGR,SAAS,CAAA;CACrB;CAEA,6BAGK5D,MAAM,EAAEqC,UAAUgD,UAAUC,eAAe;EAC9C,MAAMpE,UAAUf,cACR,IAAIY,sBAAsB,KAAKkB,MAAM,CAAC,CAACsD,YAAYlD,QAAQ,GACjE,CAACA,QAAQ,CACX;EAEA,MAAMjB,cAAcvB,OAAO,KAAK;EAChCC,gBAAgB;GACd,IAAI0F,QAAQC,IAAIC,aAAa,gBAAgBJ,aAAalF,UAAU;IAClE,MAAMuF,KAAKC,iBAAiB;KAC1B,IAAI,CAACxE,YAAYM,SACfmE,QAAQC,KACN,2QAGF;IAEJ,GAAG,GAAG;IACN,aAAaC,aAAaJ,EAAE;GAC9B;EAEF,GAAG,CAACL,QAAQ,CAAC;EAEb,OACE,oBAAC,+BAAD;GAAwCpE;GACtC,UAAA,oBAAC,UAAD,EAAA,UACE,oBAAC,KAAK,gBAAN;IAA+BmB;IAC7B,UAAA,oBAAC,wBAAD,EAAqCjB,YAAY,CAAA;GAC9B,CAAA,EACb,CAAA;EACmB,CAAA;CAEnC,CAAC;CAED,mCAEM,EAAEiE,eAAe;EACrB,KAAKrD,2BAA2B;EAEhC,OAAOiE,MAAMC,KAAK,KAAKpE,UAAUqE,KAAK,CAAC,CAAC,CAACC,KAAK/D,aAC5C,oBAAC,KAAK,4BAAN;GAEYA;GACAgD;EAAS,GAFdhD,QAEc,CAEtB;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useCallback","useRef","useEffect","useEffectEvent","useLayoutEffect","memo","PropsWithChildren","ComponentType","useMemo","Fragment","UseBoundStore","StoreApi","create","useAui","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadListRuntimeCore","AssistantRuntime","BaseSubscribable","ThreadRuntimeImpl","ThreadListRuntimeImpl","RemoteThreadListHook","RemoteThreadListHookInstance","runtime","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","useRuntimeHook","useRuntime","instances","Map","useAliveThreadsKeysChanged","parent","constructor","runtimeHook","startThreadRuntime","threadId","has","set","setState","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","getThreadRuntimeCore","undefined","stopThreadRuntime","delete","_notifySubscribers","setRuntimeHook","newRuntimeHook","prevRuntimeHook","getState","_RuntimeBinder","children","threadBinding","thread","__internal_threadBinding","updateRuntime","aliveThread","isMounted","outerSubscribe","aui","initPromiseRef","hasInitializedRef","runtimeCore","setGetInitializePromise","Record","__internal_setGetInitializePromise","call","handleInitialize","state","threadListItem","status","initialize","unstable_on","generateTitle","threads","main","_OuterActiveThreadProvider","provider","Provider","getItemById","process","env","NODE_ENV","id","setTimeout","console","warn","clearTimeout","__internal_RenderThreadRuntimes","Array","from","keys","map"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useCallback,\n useRef,\n useEffect,\n useEffectEvent,\n useLayoutEffect,\n memo,\n type PropsWithChildren,\n type ComponentType,\n useMemo,\n Fragment,\n} from \"react\";\nimport { type UseBoundStore, type StoreApi, create } from \"zustand\";\nimport { useAui } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport type { ThreadListRuntimeCore } from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeImpl } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\n\ntype RemoteThreadListHook = () => AssistantRuntime;\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private useRuntimeHook: UseBoundStore<\n StoreApi<{ useRuntime: RemoteThreadListHook }>\n >;\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private useAliveThreadsKeysChanged = create(() => ({}));\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.useRuntimeHook = create(() => ({ useRuntime: runtimeHook }));\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n this.instances.set(threadId, {});\n this.useAliveThreadsKeysChanged.setState({}, true);\n }\n\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (!instance.runtime) {\n return; // misc update\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public stopThreadRuntime(threadId: string) {\n this.instances.delete(threadId);\n this.useAliveThreadsKeysChanged.setState({}, true);\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n const prevRuntimeHook = this.useRuntimeHook.getState().useRuntime;\n if (prevRuntimeHook !== newRuntimeHook) {\n this.useRuntimeHook.setState({ useRuntime: newRuntimeHook }, true);\n }\n }\n\n // Rendered as a child of the user's Provider so the runtime hook can\n // read context the Provider injects (e.g. RuntimeAdapterProvider).\n private _RuntimeBinder: FC<PropsWithChildren<{ threadId: string }>> = ({\n threadId,\n children,\n }) => {\n const { useRuntime } = this.useRuntimeHook();\n const runtime = useRuntime();\n\n const threadBinding = (runtime.thread as ThreadRuntimeImpl)\n .__internal_threadBinding;\n\n const updateRuntime = useCallback(() => {\n const aliveThread = this.instances.get(threadId);\n if (!aliveThread)\n throw new Error(\n `Thread \"${threadId}\" runtime binding not found. This is a bug in assistant-ui.`,\n );\n\n aliveThread.runtime = threadBinding.getState();\n this._notifySubscribers();\n }, [threadId, threadBinding]);\n\n const isMounted = useRef(false);\n if (!isMounted.current) {\n updateRuntime();\n }\n\n useEffect(() => {\n isMounted.current = true;\n updateRuntime();\n return threadBinding.outerSubscribe(updateRuntime);\n }, [threadBinding, updateRuntime]);\n\n const aui = useAui();\n const initPromiseRef = useRef<Promise<unknown> | undefined>(undefined);\n const hasInitializedRef = useRef(false);\n\n useEffect(() => {\n const runtimeCore = threadBinding.getState();\n const setGetInitializePromise = (runtimeCore as Record<string, unknown>)\n .__internal_setGetInitializePromise;\n if (typeof setGetInitializePromise === \"function\") {\n setGetInitializePromise.call(runtimeCore, () => initPromiseRef.current);\n }\n }, [threadBinding]);\n\n const handleInitialize = useEffectEvent(() => {\n if (hasInitializedRef.current) return;\n\n const state = aui.threadListItem.getState();\n if (state.status !== \"new\") return;\n hasInitializedRef.current = true;\n\n initPromiseRef.current = aui.threadListItem.initialize();\n\n const dispose = runtime.thread.unstable_on(\"runEnd\", () => {\n dispose();\n aui.threadListItem.generateTitle();\n });\n });\n\n useEffect(() => {\n hasInitializedRef.current = false;\n return runtime.threads.main.unstable_on(\"initialize\", handleInitialize);\n }, [runtime]);\n\n return <>{children}</>;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime binder and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._RuntimeBinder threadId={threadId}>\n <ProviderRenderDetector detectorRef={detectorRef} />\n </this._RuntimeBinder>\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n this.useAliveThreadsKeysChanged(); // trigger re-render on alive threads change\n\n return Array.from(this.instances.keys()).map((threadId) => (\n <this._OuterActiveThreadProvider\n key={threadId}\n threadId={threadId}\n provider={provider}\n />\n ));\n };\n}\n"],"mappings":";;;;;;;;;AA8BA,MAAM0B,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI,WAAA;GACdJ,YAAWM,UAAW;EAAH;EAClBD,KAAA,CAACL,WAAW;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAD,KAAAF,EAAA;EAAAG,KAAAH,EAAA;CAAA;CAFhBvB,gBAAgByB,IAEbC,EAAa;CAAC,OACV;AAAI;AAEb,IAAaE,sCAAb,cAAyDd,iBAAiB;CACxE;CAGA,4BAAoB,IAAIkB,IAA0C;CAClE,6BAAqCxB,cAAc,CAAC,EAAE;CACtD;CAEA2B,YACEC,aACAF,QACA;EACA,MAAM;EACN,KAAKA,SAASA;EACd,KAAKL,iBAAiBrB,cAAc,EAAEsB,YAAYM,YAAY,EAAE;CAClE;CAEA,mBAA0BE,UAAkB;EAC1C,IAAI,CAAC,KAAKP,UAAUQ,IAAID,QAAQ,GAAG;GACjC,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X;EAEA,MAAMjB,cAAcxB,OAAO,KAAK;EAChCC,gBAAgB;GACd,IAAI4F,QAAQC,IAAIC,aAAa,gBAAgBJ,aAAanF,UAAU;IAClE,MAAMwF,KAAKC,iBAAiB;KAC1B,IAAI,CAACzE,YAAYM,SACfoE,QAAQC,KACN,2QAGF;IAEJ,GAAG,GAAG;IACN,aAAaC,aAAaJ,EAAE;GAC9B;EAEF,GAAG,CAACL,QAAQ,CAAC;EAEb,OACE,oBAAC,+BAAD;GAAwCrE;GACtC,UAAA,oBAAC,UAAD,EAAA,UACE,oBAAC,KAAK,gBAAN;IAA+BmB;IAC7B,UAAA,oBAAC,wBAAD,EAAqCjB,YAAY,CAAA;GAC9B,CAAA,EACb,CAAA;EACmB,CAAA;CAEnC,CAAC;CAED,mCAEM,EAAEkE,eAAe;EACrB,KAAKtD,2BAA2B;EAEhC,OAAOkE,MAAMC,KAAK,KAAKrE,UAAUsE,KAAK,CAAC,CAAC,CAACC,KAAKhE,aAC5C,oBAAC,KAAK,4BAAN;GAEYA;GACAiD;EAAS,GAFdjD,QAEc,CAEtB;CACH;AACF"}
|
|
@@ -151,8 +151,11 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
151
151
|
switchToThread(threadIdOrRemoteId: string, options?: {
|
|
152
152
|
unarchive?: boolean;
|
|
153
153
|
}): Promise<void>;
|
|
154
|
+
private _startSwitchToThread;
|
|
154
155
|
private _switchToThread;
|
|
155
156
|
switchToNewThread(): Promise<void>;
|
|
157
|
+
private _switchToThreadFromProp;
|
|
158
|
+
private _startSwitchToNewThread;
|
|
156
159
|
private _switchToNewThread;
|
|
157
160
|
initialize: (threadId: string) => Promise<{
|
|
158
161
|
remoteId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;cAoCa,8CACH,4BACG;UAEH;mBACS;UAET;UACA;UACA;UACA;UACA;UAEA;mBACS;MAWN,eAAW,SAAA,OAzBX,mBAyBW;EAIf,yBAAqB;EAsDrB,YAAY;mBAmDF;EAGf,YAAA,SAAS,yBACT,iBAAiB;UAoBX;UACA;EAED,sBAAsB,SAAS;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;cAoCa,8CACH,4BACG;UAEH;mBACS;UAET;UACA;UACA;UACA;UACA;UAEA;mBACS;MAWN,eAAW,SAAA,OAzBX,mBAyBW;EAIf,yBAAqB;EAsDrB,YAAY;mBAmDF;EAGf,YAAA,SAAS,yBACT,iBAAiB;UAoBX;UACA;EAED,sBAAsB,SAAS;EAkC/B;EAgBA,UAAM;MAWF;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;cAMC;UAKJ;UAEA;EASD,4BAAwB;;;eAzDlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DN,qBAAqB,6BAA0B;;;eANvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBxB,YAAY,6BAA0B;EAItC,eACL,4BACA;IAAY;MACX;UAIK;UAgBM;EAuGP,qBAAqB;UAIpB;UAMA;UAOM;EA6CP,aAAoB,qBAAgB;;;;EAwDpC,gBAAuB,qBAAgB;EAmCvC,OAAO,4BAA4B,mBAAmB;EA6BtD,aACL,4BACA,QAAQ,sCACP;UAiDW;EAsBD,QAAQ,6BAA0B;EAmBxC,UAAU,6BAA6B;EAsBjC,OAAO,6BAA0B;EAoBjC,OAAO,6BAA6B;UAUzC;EAED,4BAA4B"}
|
|
@@ -139,6 +139,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
139
139
|
__internal_setOptions(options) {
|
|
140
140
|
if (this._options === options) return;
|
|
141
141
|
const adapterChanged = this._options !== void 0 && this._options.adapter !== options.adapter;
|
|
142
|
+
const controlledThreadIdChanged = this._initialThreadLoaded && this._options !== void 0 && this._options.threadId !== options.threadId;
|
|
142
143
|
this._options = options;
|
|
143
144
|
const Provider = options.adapter.unstable_Provider ?? Fragment;
|
|
144
145
|
if (Provider !== this.useProvider.getState().Provider) this.useProvider.setState({ Provider }, true);
|
|
@@ -152,14 +153,14 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
152
153
|
cursor: void 0
|
|
153
154
|
});
|
|
154
155
|
}
|
|
156
|
+
if (controlledThreadIdChanged) this._switchToThreadFromProp(options.threadId).catch(() => {});
|
|
155
157
|
}
|
|
156
158
|
__internal_load() {
|
|
157
159
|
this.getLoadThreadsPromise();
|
|
160
|
+
if (this._initialThreadLoaded) return;
|
|
161
|
+
this._initialThreadLoaded = true;
|
|
158
162
|
const startThreadId = this._options.threadId ?? this._options.initialThreadId;
|
|
159
|
-
if (
|
|
160
|
-
this._initialThreadLoaded = true;
|
|
161
|
-
this.switchToThread(startThreadId).catch(() => {});
|
|
162
|
-
}
|
|
163
|
+
if (startThreadId !== void 0) (this._options.threadId !== void 0 ? this._switchToThreadFromProp(startThreadId) : this.switchToThread(startThreadId)).catch(() => {});
|
|
163
164
|
}
|
|
164
165
|
reload() {
|
|
165
166
|
this._loadGeneration++;
|
|
@@ -197,11 +198,11 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
197
198
|
return getThreadData(this._state.value, this._mainThreadId)?.remoteId;
|
|
198
199
|
}
|
|
199
200
|
_lastNotifiedThreadId = void 0;
|
|
200
|
-
_notifyThreadIdChange() {
|
|
201
|
+
_notifyThreadIdChange(emit = true) {
|
|
201
202
|
const threadId = this._mainThreadRemoteId;
|
|
202
203
|
if (this._lastNotifiedThreadId === threadId) return;
|
|
203
204
|
this._lastNotifiedThreadId = threadId;
|
|
204
|
-
this._options.onThreadIdChange?.(threadId);
|
|
205
|
+
if (emit) this._options.onThreadIdChange?.(threadId);
|
|
205
206
|
}
|
|
206
207
|
getMainThreadRuntimeCore() {
|
|
207
208
|
const result = this._hookManager.getThreadRuntimeCore(this._mainThreadId);
|
|
@@ -219,12 +220,15 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
219
220
|
return getThreadData(this._state.value, threadIdOrRemoteId);
|
|
220
221
|
}
|
|
221
222
|
switchToThread(threadIdOrRemoteId, options) {
|
|
223
|
+
return this._startSwitchToThread(threadIdOrRemoteId, options, true);
|
|
224
|
+
}
|
|
225
|
+
_startSwitchToThread(threadIdOrRemoteId, options, emitThreadIdChange) {
|
|
222
226
|
const generation = ++this._switchGeneration;
|
|
223
|
-
const task = this._switchToThread(threadIdOrRemoteId, options, generation);
|
|
227
|
+
const task = this._switchToThread(threadIdOrRemoteId, options, generation, emitThreadIdChange);
|
|
224
228
|
this._switchTask = task;
|
|
225
229
|
return task;
|
|
226
230
|
}
|
|
227
|
-
async _switchToThread(threadIdOrRemoteId, options, generation) {
|
|
231
|
+
async _switchToThread(threadIdOrRemoteId, options, generation, emitThreadIdChange) {
|
|
228
232
|
let data = this.getItemById(threadIdOrRemoteId);
|
|
229
233
|
if (!data) {
|
|
230
234
|
const remoteMetadata = await this._options.adapter.fetch(threadIdOrRemoteId);
|
|
@@ -278,15 +282,21 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
278
282
|
}
|
|
279
283
|
this._mainThreadId = data.id;
|
|
280
284
|
this._notifySubscribers();
|
|
281
|
-
this._notifyThreadIdChange();
|
|
285
|
+
this._notifyThreadIdChange(emitThreadIdChange);
|
|
282
286
|
}
|
|
283
287
|
switchToNewThread() {
|
|
288
|
+
return this._startSwitchToNewThread(true);
|
|
289
|
+
}
|
|
290
|
+
_switchToThreadFromProp(threadId) {
|
|
291
|
+
return threadId !== void 0 ? this._startSwitchToThread(threadId, void 0, false) : this._startSwitchToNewThread(false);
|
|
292
|
+
}
|
|
293
|
+
_startSwitchToNewThread(emitThreadIdChange) {
|
|
284
294
|
const generation = ++this._switchGeneration;
|
|
285
|
-
const task = this._switchToNewThread(generation);
|
|
295
|
+
const task = this._switchToNewThread(generation, emitThreadIdChange);
|
|
286
296
|
this._switchTask = task;
|
|
287
297
|
return task;
|
|
288
298
|
}
|
|
289
|
-
async _switchToNewThread(generation) {
|
|
299
|
+
async _switchToNewThread(generation, emitThreadIdChange) {
|
|
290
300
|
while (this._state.baseValue.newThreadId !== void 0 && this._state.value.newThreadId === void 0) {
|
|
291
301
|
await this._state.waitForUpdate();
|
|
292
302
|
if (generation !== this._switchGeneration) return;
|
|
@@ -318,7 +328,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
318
328
|
}
|
|
319
329
|
});
|
|
320
330
|
}
|
|
321
|
-
return this._switchToThread(id, void 0, generation);
|
|
331
|
+
return this._switchToThread(id, void 0, generation, emitThreadIdChange);
|
|
322
332
|
}
|
|
323
333
|
initialize = async (threadId) => {
|
|
324
334
|
if (this._state.value.newThreadId !== threadId) {
|