@allbluecn/web-app 0.27.21 → 0.27.23
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/package.json +1 -1
- package/src/components/ai/global-harness-sidebar/global-sidebar-connection.tsx +4 -1
- package/src/components/harness/session/__tests__/use-harness-session-putmedia.test.tsx +4 -2
- package/src/components/harness/session/use-harness-chat-adapter.ts +4 -2
- package/src/components/harness/session/use-harness-session.ts +62 -18
- package/src/components/harness/workbench/workbench-connection.tsx +9 -1
- package/src/lib/changelog/sdk-versions.ts +2 -2
package/package.json
CHANGED
|
@@ -106,7 +106,10 @@ function HarnessConnection({ children }: { children: React.ReactNode }) {
|
|
|
106
106
|
const { activeThreadId, sidebarChatRef } = useSidebarBody()
|
|
107
107
|
const fallbackThreadIdRef = useRef(crypto.randomUUID());
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
// 只用「真实会话 id」连接 harness(workbench-connection 同款):空态兜底 UUID
|
|
110
|
+
// 会让 harness client 对假 id 开真实连接 → 400/404 重连循环 → 假故障横幅。
|
|
111
|
+
// fallbackThreadIdRef 保留给 legacy 连接路径,harness 空态传 '' 不连接。
|
|
112
|
+
const session = useHarnessSession({ threadId: activeThreadId ?? '' })
|
|
110
113
|
const chat = useHarnessChatAdapter(session)
|
|
111
114
|
const workbenchChat = chat as unknown as WorkbenchChat
|
|
112
115
|
sidebarChatRef.current = workbenchChat
|
|
@@ -61,12 +61,14 @@ beforeEach(() => {
|
|
|
61
61
|
describe('useHarnessSession putMedia 接线(T2.11 ④)', () => {
|
|
62
62
|
it('暴露的 putMedia 转发到 client.putMedia,返回 MediaRecord', async () => {
|
|
63
63
|
const { result } = renderHook(() => useHarnessSession({ threadId: 't1' }))
|
|
64
|
-
|
|
64
|
+
const putMedia = result.current.putMedia
|
|
65
|
+
expect(typeof putMedia).toBe('function')
|
|
65
66
|
|
|
66
67
|
const file = { body: new Blob(['x']), mimeType: 'image/png', name: 'cat.png' }
|
|
67
68
|
let record: unknown
|
|
68
69
|
await act(async () => {
|
|
69
|
-
|
|
70
|
+
// putMedia 仅在有 threadId(client 存在)时定义;本用例 threadId='t1'
|
|
71
|
+
record = await putMedia?.(file)
|
|
70
72
|
})
|
|
71
73
|
|
|
72
74
|
expect(putMediaMock).toHaveBeenCalledWith(file)
|
|
@@ -233,8 +233,10 @@ export function useHarnessChatAdapter(session: HarnessSession): HarnessChatLike
|
|
|
233
233
|
|
|
234
234
|
const [error, setError] = useState<Error | null>(null)
|
|
235
235
|
|
|
236
|
-
// 订阅 view 错误事件(harness 无 error 状态字段,经 on('error')
|
|
236
|
+
// 订阅 view 错误事件(harness 无 error 状态字段,经 on('error') 捕获)。
|
|
237
|
+
// 空态 view=null(无连接,见 use-harness-session 空态注释):跳过订阅。
|
|
237
238
|
useEffect(() => {
|
|
239
|
+
if (!view) return
|
|
238
240
|
const off = view.on('error', (message: string) => {
|
|
239
241
|
setError(new Error(message))
|
|
240
242
|
})
|
|
@@ -299,7 +301,7 @@ export function useHarnessChatAdapter(session: HarnessSession): HarnessChatLike
|
|
|
299
301
|
// AppChat:harness 消息流渲染组件(吃原始 ViewMessage)。用 createElement 而非
|
|
300
302
|
// JSX,保持本文件为纯 TS 数据层(无 JSX 语法)。
|
|
301
303
|
const AppChat = useMemo<ComponentType<Record<string, never>>>(
|
|
302
|
-
() => () => createElement(HarnessSessionAppChat, { view }),
|
|
304
|
+
() => () => (view ? createElement(HarnessSessionAppChat, { view }) : null),
|
|
303
305
|
[view],
|
|
304
306
|
)
|
|
305
307
|
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
// client-tools-dispatcher、queue-bar 消费。
|
|
20
20
|
|
|
21
21
|
import { useCallback, useMemo } from 'react'
|
|
22
|
-
import { useStore } from '@tanstack/react-store'
|
|
22
|
+
import { createStore, useStore } from '@tanstack/react-store'
|
|
23
23
|
import { createHarnessClient } from '@tanstack/ai-harness/client'
|
|
24
24
|
import { createSessionView } from '@tanstack/ai-harness/view'
|
|
25
25
|
import type { AnyHarness } from '@tanstack/ai-harness'
|
|
26
26
|
import type { MediaRecord } from '@tanstack/ai-harness/client'
|
|
27
|
-
import type { ViewMessage } from '@tanstack/ai-harness/view'
|
|
27
|
+
import type { SessionViewState, ViewMessage } from '@tanstack/ai-harness/view'
|
|
28
28
|
|
|
29
29
|
/** harness 会话 hook 的参数。threadId 由侧栏/工作台以 ChatThread 单一真源提供。 */
|
|
30
30
|
export interface UseHarnessSessionOptions {
|
|
@@ -47,41 +47,85 @@ export function useHarnessSession({ threadId }: UseHarnessSessionOptions) {
|
|
|
47
47
|
// createSessionView 自身处理重连/gap/媒体 URL 刷新,无需在此重试。
|
|
48
48
|
// client 一并暴露:putMedia(附件上传,T2.11 ④)与 hostEvents(title 写回,
|
|
49
49
|
// T2.11 ②)都在 client 上,view 不转发这两个能力。
|
|
50
|
+
// client + view 稳定引用:threadId 变化才重建(view 持有 SSE 连接与 store)。
|
|
51
|
+
// createSessionView 自身处理重连/gap/媒体 URL 刷新,无需在此重试。
|
|
52
|
+
// client 一并暴露:putMedia(附件上传,T2.11 ④)与 hostEvents(title 写回,
|
|
53
|
+
// T2.11 ②)都在 client 上,view 不转发这两个能力。
|
|
54
|
+
//
|
|
55
|
+
// 空态(无 threadId)不建 client/view:官方 HarnessClientOptions.threadId 必填,
|
|
56
|
+
// 缺省时 client.events() 的请求会被服务端 400 拒(threadId is required),重连
|
|
57
|
+
// 退避耗尽 → 「连接已断开 + 重试次数已达上限」假故障(桌面真机 CDP 实测)。
|
|
58
|
+
// 首条发送走 Provider 建会话(createConversationFn)→ pendingSend 槽,threadId
|
|
59
|
+
// 就位后本 useMemo 以新 threadId 重建并连接——空态动作均 no-op(不会被调用)。
|
|
50
60
|
const { client, view } = useMemo(() => {
|
|
61
|
+
if (!threadId) return { client: null, view: null }
|
|
51
62
|
const client = createHarnessClient<AnyHarness>({ url: '/api/harness', threadId })
|
|
52
63
|
return { client, view: createSessionView(client) }
|
|
53
64
|
}, [threadId])
|
|
54
65
|
|
|
66
|
+
// 空态占位 store:与 view.store 同型(SessionViewState)的全空值(hooks 规则——
|
|
67
|
+
// useStore 必须无条件调用;类型对齐否则 useStore 泛型在 store 联合上坍缩)。
|
|
68
|
+
const EMPTY_STORE = useMemo(
|
|
69
|
+
() =>
|
|
70
|
+
createStore<SessionViewState>({
|
|
71
|
+
threadId: '',
|
|
72
|
+
status: 'idle',
|
|
73
|
+
connection: 'closed',
|
|
74
|
+
messages: [],
|
|
75
|
+
approvals: [],
|
|
76
|
+
clientTools: [],
|
|
77
|
+
interrupts: [],
|
|
78
|
+
questions: [],
|
|
79
|
+
signIns: [],
|
|
80
|
+
waits: [],
|
|
81
|
+
agents: [],
|
|
82
|
+
queuedTurns: 0,
|
|
83
|
+
waitingInputs: [],
|
|
84
|
+
commands: [],
|
|
85
|
+
config: [],
|
|
86
|
+
tools: [],
|
|
87
|
+
models: [],
|
|
88
|
+
plugins: {},
|
|
89
|
+
}),
|
|
90
|
+
[],
|
|
91
|
+
)
|
|
92
|
+
const store = view?.store ?? EMPTY_STORE
|
|
93
|
+
|
|
55
94
|
// live 状态切片:useStore 订阅 view.store(TanStack Store),按字段选择避免全量重渲染
|
|
56
|
-
const messages = useStore(
|
|
57
|
-
const status = useStore(
|
|
58
|
-
const connection = useStore(
|
|
59
|
-
const approvals = useStore(
|
|
60
|
-
const interrupts = useStore(
|
|
61
|
-
const questions = useStore(
|
|
62
|
-
const clientTools = useStore(
|
|
63
|
-
const queuedTurns = useStore(
|
|
64
|
-
const waitingInputs = useStore(
|
|
95
|
+
const messages = useStore(store, (s) => s.messages)
|
|
96
|
+
const status = useStore(store, (s) => s.status)
|
|
97
|
+
const connection = useStore(store, (s) => s.connection)
|
|
98
|
+
const approvals = useStore(store, (s) => s.approvals)
|
|
99
|
+
const interrupts = useStore(store, (s) => s.interrupts)
|
|
100
|
+
const questions = useStore(store, (s) => s.questions)
|
|
101
|
+
const clientTools = useStore(store, (s) => s.clientTools)
|
|
102
|
+
const queuedTurns = useStore(store, (s) => s.queuedTurns)
|
|
103
|
+
const waitingInputs = useStore(store, (s) => s.waitingInputs)
|
|
65
104
|
|
|
66
|
-
// 动作:view.send 返回 Promise<void>;approve/reject 是同步 fire(内部 resolve
|
|
105
|
+
// 动作:view.send 返回 Promise<void>;approve/reject 是同步 fire(内部 resolve)。
|
|
106
|
+
// 空态(view=null)no-op——首条发送由 Provider 建会话 + pendingSend 接管。
|
|
67
107
|
const send = useCallback(
|
|
68
|
-
(text: string, attachments?: ReadonlyArray<MediaRecord>) => view
|
|
108
|
+
(text: string, attachments?: ReadonlyArray<MediaRecord>) => view?.send(text, attachments),
|
|
69
109
|
[view],
|
|
70
110
|
)
|
|
71
111
|
const approve = useCallback((id: string, editedArgs?: unknown) => {
|
|
112
|
+
if (!view) return
|
|
72
113
|
view.approve(editedArgs === undefined ? { id } : { id, editedArgs })
|
|
73
114
|
}, [view])
|
|
74
115
|
const reject = useCallback((id: string) => {
|
|
75
|
-
view
|
|
116
|
+
view?.reject({ id })
|
|
76
117
|
}, [view])
|
|
77
|
-
const cancel = useCallback(() => view
|
|
118
|
+
const cancel = useCallback(() => view?.cancel(), [view])
|
|
78
119
|
|
|
79
120
|
// 附件上传器(T2.11 ④):harness client.putMedia 暴露给 composer 的 useAttachments。
|
|
80
121
|
// 用 client.putMedia(接受 Blob)而非 view.putMedia(MediaBody 仅 ArrayBuffer|Uint8Array,
|
|
81
122
|
// 见 view/index.d.ts:101),与 use-attachments 的 File/Blob 通道类型对齐。
|
|
82
|
-
//
|
|
83
|
-
const putMedia =
|
|
84
|
-
(
|
|
123
|
+
// 空态无 client → undefined(composer useAttachments 回落 blobRef 旧链路径)。
|
|
124
|
+
const putMedia = useMemo(
|
|
125
|
+
() =>
|
|
126
|
+
client
|
|
127
|
+
? (file: { body: Blob; mimeType: string; name: string }) => client.putMedia(file)
|
|
128
|
+
: undefined,
|
|
85
129
|
[client],
|
|
86
130
|
)
|
|
87
131
|
|
|
@@ -125,7 +125,15 @@ function LegacyConnection({ children }: { children: React.ReactNode }) {
|
|
|
125
125
|
function HarnessConnection({ children }: { children: React.ReactNode }) {
|
|
126
126
|
const { threadId, chatRef, pendingSend, setPendingSend, activeConversationId, setRetryDismissed, setConversations } = useWorkbenchBody()
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
// 只用「真实会话 id」连接 harness:body 的 threadId 在空态兜底为 mount 级稳定
|
|
129
|
+
// UUID(legacy 孤儿线程修复的载体),harness 对假 id 建 client 会开真实连接,
|
|
130
|
+
// events/快照全 400/404 → 重连退避耗尽 → 「连接已断开 + 重试上限」假故障
|
|
131
|
+
// (桌面真机 CDP 实测,#652 的无-threadId 短路因兜底 UUID 恒真而永不触发)。
|
|
132
|
+
// 空态传 ''(falsy)→ use-harness-session 不建 client/view;首条发送经 Provider
|
|
133
|
+
// 建会话 → setActiveConversationId 置真实 id → 本 hook 以新 id 重建并连接。
|
|
134
|
+
// legacy 连接保持用兜底 threadId(ChatClient hydrate 语义,行为不变)。
|
|
135
|
+
const harnessThreadId = activeConversationId ?? ''
|
|
136
|
+
const session = useHarnessSession({ threadId: harnessThreadId })
|
|
129
137
|
const chat = useHarnessChatAdapter(session)
|
|
130
138
|
const workbenchChat = toWorkbenchChat(chat)
|
|
131
139
|
chatRef.current = workbenchChat
|
|
@@ -112,8 +112,8 @@ export const SDK_GROUPS: SdkGroup[] = [
|
|
|
112
112
|
"items": [
|
|
113
113
|
{
|
|
114
114
|
"name": "@allbluecn/web-app",
|
|
115
|
-
"version": "v0.27.
|
|
116
|
-
"lastUpdate": "Nov
|
|
115
|
+
"version": "v0.27.23",
|
|
116
|
+
"lastUpdate": "Nov 10, 2026",
|
|
117
117
|
"source": "apps/web/package.json",
|
|
118
118
|
"docsUrl": "https://github.com/allbluecn/allblue"
|
|
119
119
|
},
|