mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
fix(web): support multi-tab workspace access
This commit is contained in:
1 parent
d0a9a03f7c
commit
ce603bdc52
26 files changed
+834
-269
No files matched your search
@@ -11,7 +11,7 @@
|
||||
"done": "Done",
|
||||
"retry": "Retry",
|
||||
"initFailed": "App initialization failed",
|
||||
"webWasmWorkspaceBusy": "Web WASM is already open in another tab. Close the other ChatLab Web WASM tab and retry.",
|
||||
"webWasmWorkspaceBusy": "The local workspace is temporarily in use by another tab. Wait a moment and retry.",
|
||||
"loading": "Loading...",
|
||||
"initializing": "Initializing...",
|
||||
"noResults": "No results found",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"done": "完了",
|
||||
"retry": "リトライ",
|
||||
"initFailed": "アプリの初期化に失敗しました",
|
||||
"webWasmWorkspaceBusy": "Web WASM は別のタブで開かれています。もう一方の ChatLab Web WASM タブを閉じてから再試行してください。",
|
||||
"webWasmWorkspaceBusy": "ローカルワークスペースは一時的に別のタブで使用されています。しばらく待ってから再試行してください。",
|
||||
"loading": "読み込み中...",
|
||||
"initializing": "初期化中...",
|
||||
"noResults": "結果が見つかりません",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"done": "完成",
|
||||
"retry": "重试",
|
||||
"initFailed": "应用初始化失败",
|
||||
"webWasmWorkspaceBusy": "Web WASM 已在另一个标签页中打开。请关闭另一个 ChatLab Web WASM 标签页后重试。",
|
||||
"webWasmWorkspaceBusy": "本地工作区暂时正由另一个标签页使用。请稍候后重试。",
|
||||
"loading": "加载中...",
|
||||
"initializing": "初始化中...",
|
||||
"noResults": "无匹配结果",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"done": "完成",
|
||||
"retry": "重試",
|
||||
"initFailed": "應用程式初始化失敗",
|
||||
"webWasmWorkspaceBusy": "Web WASM 已在另一個分頁中開啟。請關閉另一個 ChatLab Web WASM 分頁後重試。",
|
||||
"webWasmWorkspaceBusy": "本機工作區暫時正由另一個分頁使用。請稍候後重試。",
|
||||
"loading": "載入中...",
|
||||
"initializing": "初始化中...",
|
||||
"noResults": "無匹配結果",
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('registerWebWasmAdapters', () => {
|
||||
it('registers the browser runtime adapter and forwards Worker logs', () => {
|
||||
const registrations = new Map<string, unknown>()
|
||||
const logs: RuntimeLogEvent[] = []
|
||||
const workspaceChanges: string[] = []
|
||||
let clientOptions: WebRuntimeRpcClientOptions | undefined
|
||||
const client = {
|
||||
request: () => Promise.reject(new Error('not used')),
|
||||
@@ -24,6 +25,7 @@ describe('registerWebWasmAdapters', () => {
|
||||
return client
|
||||
},
|
||||
reportLog: (event) => logs.push(event),
|
||||
onWorkspaceChanged: (event) => workspaceChanges.push(`${event.type}:${event.sessionId}`),
|
||||
})
|
||||
|
||||
assert.deepEqual([...registrations.keys()], ['browser-runtime', 'import', 'data', 'platform', 'preferences'])
|
||||
@@ -38,6 +40,8 @@ describe('registerWebWasmAdapters', () => {
|
||||
message: 'Worker initialized',
|
||||
}
|
||||
clientOptions?.onLog?.(event)
|
||||
clientOptions?.onWorkspaceChanged?.({ type: 'rename', sessionId: 'session-one' })
|
||||
assert.deepEqual(logs, [event])
|
||||
assert.deepEqual(workspaceChanges, ['rename:session-one'])
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,9 @@
|
||||
import { createWebRuntimeClient, type RuntimeLogEvent, type WebRuntimeRpcClientOptions } from '@openchatlab/web-runtime'
|
||||
import {
|
||||
createWebRuntimeClient,
|
||||
type RuntimeLogEvent,
|
||||
type WebRuntimeRpcClientOptions,
|
||||
type WebRuntimeWorkspaceChangeEvent,
|
||||
} from '@openchatlab/web-runtime'
|
||||
import { reportRuntimeLog } from '@/services/log-report'
|
||||
import { BrowserRuntimeAdapter } from './browser'
|
||||
import type { BrowserRuntimeRpcPort } from './types'
|
||||
@@ -11,12 +16,13 @@ export interface RegisterWebWasmAdaptersOptions {
|
||||
register(key: string, adapter: unknown): void
|
||||
createClient?: (options: WebRuntimeRpcClientOptions) => BrowserRuntimeRpcPort
|
||||
reportLog?: (event: RuntimeLogEvent) => void
|
||||
onWorkspaceChanged?: (event: WebRuntimeWorkspaceChangeEvent) => void
|
||||
}
|
||||
|
||||
export function registerWebWasmAdapters(options: RegisterWebWasmAdaptersOptions): void {
|
||||
const reportLog = options.reportLog ?? reportRuntimeLog
|
||||
const createClient = options.createClient ?? createWebRuntimeClient
|
||||
const client = createClient({ onLog: reportLog })
|
||||
const client = createClient({ onLog: reportLog, onWorkspaceChanged: options.onWorkspaceChanged })
|
||||
|
||||
options.register('browser-runtime', new BrowserRuntimeAdapter(client))
|
||||
options.register('import', new BrowserImportAdapter(client))
|
||||
|
||||
Reference in new issue
Block a user