@nexface/chat 0.1.21-alpha.0 → 0.1.21-alpha.1
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/assistant-runtime.js +14 -4
- package/dist/default-chat.js +42 -13
- package/dist/react.d.ts +6 -0
- package/dist/react.js +490 -92
- package/dist/session-coordinator.d.ts +23 -0
- package/dist/session-coordinator.js +139 -0
- package/dist/session-history.d.ts +29 -0
- package/dist/session-history.js +282 -0
- package/dist/storage.d.ts +3 -6
- package/dist/storage.js +50 -44
- package/dist/styles.css +1 -1
- package/dist/ui/thread-list.aui.d.ts +2 -1
- package/dist/ui/thread-list.aui.js +2 -2
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useLayoutEffect, useReducer, useRef, useState } from "react";
|
|
3
3
|
import { AssistantRuntimeProvider, MessageNotSentError, useExternalStoreRuntime, } from "@assistant-ui/react";
|
|
4
4
|
import { AssistantAttachments, toAssistantAttachment } from "./assistant-attachments.js";
|
|
5
|
-
import { assertChatSendable } from "./react.js";
|
|
5
|
+
import { assertChatSendable, sessionCommandResult } from "./react.js";
|
|
6
6
|
import { useVoiceInput } from "./voice/use-voice.js";
|
|
7
7
|
function parseToolArgs(text) {
|
|
8
8
|
try {
|
|
@@ -155,10 +155,20 @@ export function SessionRuntime({ id, chat, options, dictation, open = true, bloc
|
|
|
155
155
|
})),
|
|
156
156
|
onSwitchToNewThread: () => {
|
|
157
157
|
latest.current.createSession();
|
|
158
|
+
return sessionCommandResult(latest.current);
|
|
159
|
+
},
|
|
160
|
+
onSwitchToThread: (next) => {
|
|
161
|
+
latest.current.switchSession(next);
|
|
162
|
+
return sessionCommandResult(latest.current);
|
|
163
|
+
},
|
|
164
|
+
onRename: (target, title) => {
|
|
165
|
+
latest.current.renameSession(target, title);
|
|
166
|
+
return sessionCommandResult(latest.current);
|
|
167
|
+
},
|
|
168
|
+
onDelete: (target) => {
|
|
169
|
+
latest.current.deleteSession(target);
|
|
170
|
+
return sessionCommandResult(latest.current);
|
|
158
171
|
},
|
|
159
|
-
onSwitchToThread: (next) => latest.current.switchSession(next),
|
|
160
|
-
onRename: (target, title) => latest.current.renameSession(target, title),
|
|
161
|
-
onDelete: (target) => latest.current.deleteSession(target),
|
|
162
172
|
},
|
|
163
173
|
},
|
|
164
174
|
});
|
package/dist/default-chat.js
CHANGED
|
@@ -28937,7 +28937,8 @@ function ThreadListSearch({
|
|
|
28937
28937
|
}
|
|
28938
28938
|
function ThreadListItem({
|
|
28939
28939
|
disabled,
|
|
28940
|
-
menu
|
|
28940
|
+
menu,
|
|
28941
|
+
title: reason
|
|
28941
28942
|
}) {
|
|
28942
28943
|
const isRunning = useAuiState((s) => s.threadListItem.isRunning);
|
|
28943
28944
|
const title = useAuiState((s) => s.threadListItem.title);
|
|
@@ -28954,8 +28955,10 @@ function ThreadListItem({
|
|
|
28954
28955
|
ThreadListItemPrimitiveRoot,
|
|
28955
28956
|
{
|
|
28956
28957
|
"data-slot": "aui_thread-list-item",
|
|
28958
|
+
title: reason,
|
|
28959
|
+
"data-disabled": disabled || void 0,
|
|
28957
28960
|
className: cn(
|
|
28958
|
-
"group data-active:bg-foreground/[0.06] hover:bg-foreground/[0.04] has-data-[state=open]:bg-foreground/[0.04] rounded-control relative flex h-8 shrink-0 items-center transition-colors"
|
|
28961
|
+
"data-[disabled=true]:opacity-50 group data-active:bg-foreground/[0.06] hover:bg-foreground/[0.04] has-data-[state=open]:bg-foreground/[0.04] rounded-control relative flex h-8 shrink-0 items-center transition-colors"
|
|
28959
28962
|
),
|
|
28960
28963
|
children: [
|
|
28961
28964
|
isRenaming ? /* @__PURE__ */ jsx68(
|
|
@@ -29913,7 +29916,7 @@ var AssistantAttachments = class {
|
|
|
29913
29916
|
};
|
|
29914
29917
|
|
|
29915
29918
|
// src/assistant-runtime.tsx
|
|
29916
|
-
import { assertChatSendable } from "./react.js";
|
|
29919
|
+
import { assertChatSendable, sessionCommandResult } from "./react.js";
|
|
29917
29920
|
|
|
29918
29921
|
// src/voice/use-voice.ts
|
|
29919
29922
|
import { useLayoutEffect as useLayoutEffect11, useMemo as useMemo10, useRef as useRef29, useState as useState28 } from "react";
|
|
@@ -30218,10 +30221,20 @@ function SessionRuntime({
|
|
|
30218
30221
|
})),
|
|
30219
30222
|
onSwitchToNewThread: () => {
|
|
30220
30223
|
latest.current.createSession();
|
|
30224
|
+
return sessionCommandResult(latest.current);
|
|
30221
30225
|
},
|
|
30222
|
-
onSwitchToThread: (next) =>
|
|
30223
|
-
|
|
30224
|
-
|
|
30226
|
+
onSwitchToThread: (next) => {
|
|
30227
|
+
latest.current.switchSession(next);
|
|
30228
|
+
return sessionCommandResult(latest.current);
|
|
30229
|
+
},
|
|
30230
|
+
onRename: (target, title) => {
|
|
30231
|
+
latest.current.renameSession(target, title);
|
|
30232
|
+
return sessionCommandResult(latest.current);
|
|
30233
|
+
},
|
|
30234
|
+
onDelete: (target) => {
|
|
30235
|
+
latest.current.deleteSession(target);
|
|
30236
|
+
return sessionCommandResult(latest.current);
|
|
30237
|
+
}
|
|
30225
30238
|
}
|
|
30226
30239
|
}
|
|
30227
30240
|
});
|
|
@@ -47028,7 +47041,16 @@ function AssistantParts({
|
|
|
47028
47041
|
}
|
|
47029
47042
|
|
|
47030
47043
|
// src/default-chat.tsx
|
|
47031
|
-
import {
|
|
47044
|
+
import {
|
|
47045
|
+
canEditChatSession,
|
|
47046
|
+
historyNotice,
|
|
47047
|
+
isChatHistoryReady,
|
|
47048
|
+
watchHistorySidebar,
|
|
47049
|
+
isSessionOccupied,
|
|
47050
|
+
isSessionOperationPending,
|
|
47051
|
+
isChatRecoveryUnavailable,
|
|
47052
|
+
useChat as useChat3
|
|
47053
|
+
} from "./react.js";
|
|
47032
47054
|
import { sendErrorNotice } from "./errors.js";
|
|
47033
47055
|
import { Fragment as Fragment18, jsx as jsx100, jsxs as jsxs32 } from "react/jsx-runtime";
|
|
47034
47056
|
var textOf = (message) => message.parts.flatMap((part) => part.type === "text" ? [part.text] : []).join("");
|
|
@@ -47143,7 +47165,7 @@ function Chat({
|
|
|
47143
47165
|
const chat = useChat3();
|
|
47144
47166
|
const nextMessage = useNextMessage(chat, suggestNextMessage, open);
|
|
47145
47167
|
const { activeSessionId: sessionId, messages, status, interrupt } = chat;
|
|
47146
|
-
const busy = status !== "idle" && status !== "error";
|
|
47168
|
+
const busy = isSessionOperationPending(chat) || status !== "idle" && status !== "error";
|
|
47147
47169
|
const sessionBusy = busy && status !== "waiting";
|
|
47148
47170
|
const [fullscreen, setFullscreen] = useState40(false);
|
|
47149
47171
|
const changeFullscreen = (next) => {
|
|
@@ -47160,6 +47182,10 @@ function Chat({
|
|
|
47160
47182
|
const sidebarEnabled = sessionSidebar !== false;
|
|
47161
47183
|
const sidebarLayout = layout === "inline" && !fullscreen && typeof sessionSidebar === "object" && sessionSidebar.layout === "outside" ? "outside" : "overlay";
|
|
47162
47184
|
const sidebarOpen = sidebarEnabled && sidebar;
|
|
47185
|
+
useEffect34(
|
|
47186
|
+
() => sidebarOpen ? watchHistorySidebar(chat) : void 0,
|
|
47187
|
+
[sidebarOpen, chat.sendMessage]
|
|
47188
|
+
);
|
|
47163
47189
|
useEffect34(() => {
|
|
47164
47190
|
if (!sidebarEnabled) setSidebar(false);
|
|
47165
47191
|
}, [sidebarEnabled]);
|
|
@@ -47340,12 +47366,13 @@ function Chat({
|
|
|
47340
47366
|
/* @__PURE__ */ jsx100(ThreadListRoot, { children: /* @__PURE__ */ jsx100(ThreadListPrimitiveItems, { children: ({ threadListItem: session2 }) => (session2.title ?? "\u65B0\u4F1A\u8BDD").toLocaleLowerCase().includes(threadSearch.trim().toLocaleLowerCase()) ? /* @__PURE__ */ jsx100(
|
|
47341
47367
|
ThreadListItem,
|
|
47342
47368
|
{
|
|
47343
|
-
disabled: sessionBusy || binding.sending,
|
|
47369
|
+
disabled: sessionBusy || binding.sending || isSessionOccupied(chat, session2.id),
|
|
47370
|
+
title: isSessionOccupied(chat, session2.id) ? "This conversation is already open in another tab." : void 0,
|
|
47344
47371
|
menu: (beginRename) => /* @__PURE__ */ jsxs32(Fragment18, { children: [
|
|
47345
47372
|
/* @__PURE__ */ jsx100(
|
|
47346
47373
|
DropdownMenuItem3,
|
|
47347
47374
|
{
|
|
47348
|
-
disabled: sessionBusy || binding.sending,
|
|
47375
|
+
disabled: sessionBusy || binding.sending || isSessionOccupied(chat, session2.id),
|
|
47349
47376
|
onSelect: beginRename,
|
|
47350
47377
|
children: "\u91CD\u547D\u540D"
|
|
47351
47378
|
}
|
|
@@ -47354,7 +47381,7 @@ function Chat({
|
|
|
47354
47381
|
DropdownMenuItem3,
|
|
47355
47382
|
{
|
|
47356
47383
|
variant: "destructive",
|
|
47357
|
-
disabled: busy || binding.sending,
|
|
47384
|
+
disabled: busy || binding.sending || isSessionOccupied(chat, session2.id),
|
|
47358
47385
|
onSelect: () => setDialog({
|
|
47359
47386
|
title: "\u6E05\u7A7A\u6D88\u606F\uFF1F",
|
|
47360
47387
|
description: "\u8BE5\u4F1A\u8BDD\u6D88\u606F\u5C06\u88AB\u6E05\u9664\uFF0C\u4E1A\u52A1\u64CD\u4F5C\u4E0D\u4F1A\u56DE\u6EDA\u3002",
|
|
@@ -47368,7 +47395,7 @@ function Chat({
|
|
|
47368
47395
|
DropdownMenuItem3,
|
|
47369
47396
|
{
|
|
47370
47397
|
variant: "destructive",
|
|
47371
|
-
disabled: busy || binding.sending,
|
|
47398
|
+
disabled: busy || binding.sending || isSessionOccupied(chat, session2.id),
|
|
47372
47399
|
onSelect: () => setDialog({
|
|
47373
47400
|
title: "\u5220\u9664\u4F1A\u8BDD\uFF1F",
|
|
47374
47401
|
description: "\u804A\u5929\u8BB0\u5F55\u5C06\u88AB\u5220\u9664\uFF0C\u6B64\u64CD\u4F5C\u65E0\u6CD5\u64A4\u9500\u3002",
|
|
@@ -47432,6 +47459,7 @@ function Chat({
|
|
|
47432
47459
|
"nexface-chat__panel relative flex h-full min-h-0 overflow-hidden rounded-[inherit]"
|
|
47433
47460
|
),
|
|
47434
47461
|
"aria-label": `${title} chat`,
|
|
47462
|
+
"aria-busy": !isChatHistoryReady(chat) || isSessionOperationPending(chat),
|
|
47435
47463
|
children: [
|
|
47436
47464
|
sidebarOpen && sidebarLayout === "overlay" ? /* @__PURE__ */ jsxs32(Fragment18, { children: [
|
|
47437
47465
|
/* @__PURE__ */ jsx100(
|
|
@@ -47552,6 +47580,7 @@ function Chat({
|
|
|
47552
47580
|
}
|
|
47553
47581
|
),
|
|
47554
47582
|
footer: /* @__PURE__ */ jsxs32(Fragment18, { children: [
|
|
47583
|
+
historyNotice(chat) ? /* @__PURE__ */ jsx100("div", { role: "status", className: cn("text-muted-foreground text-xs"), children: historyNotice(chat) }) : null,
|
|
47555
47584
|
notice ? /* @__PURE__ */ jsxs32("div", { role: "status", className: cn("text-muted-foreground text-xs"), children: [
|
|
47556
47585
|
notice,
|
|
47557
47586
|
/* @__PURE__ */ jsx100("button", { onClick: () => setNotice(""), children: "\xD7" })
|
|
@@ -47586,7 +47615,7 @@ function Chat({
|
|
|
47586
47615
|
options: attachments,
|
|
47587
47616
|
placeholder,
|
|
47588
47617
|
suggestion: nextMessage,
|
|
47589
|
-
busy:
|
|
47618
|
+
busy: status !== "idle" && status !== "error" || Boolean(interrupt),
|
|
47590
47619
|
cancelling: status === "cancelling",
|
|
47591
47620
|
recoveryUnavailable: isChatRecoveryUnavailable(chat),
|
|
47592
47621
|
cancel: chat.cancel
|
package/dist/react.d.ts
CHANGED
|
@@ -60,6 +60,12 @@ export type NexfaceProviderProps = {
|
|
|
60
60
|
}) => Promise<Response>;
|
|
61
61
|
agent?: never;
|
|
62
62
|
});
|
|
63
|
+
export declare function isChatHistoryReady(chat: UseChatResult): boolean;
|
|
64
|
+
export declare function isSessionOccupied(chat: UseChatResult, id: string): boolean;
|
|
65
|
+
export declare function isSessionOperationPending(chat: UseChatResult): boolean;
|
|
66
|
+
export declare function watchHistorySidebar(chat: UseChatResult): (() => void) | undefined;
|
|
67
|
+
export declare function historyNotice(chat: UseChatResult): string | undefined;
|
|
68
|
+
export declare function sessionCommandResult(chat: UseChatResult): Promise<void> | undefined;
|
|
63
69
|
export declare function isChatRecoveryUnavailable(chat: UseChatResult): boolean;
|
|
64
70
|
export declare function canEditChatSession(chat: UseChatResult, sessionId: string): boolean;
|
|
65
71
|
export declare function assertChatSendable(chat: UseChatResult, sessionId: string): void;
|