初始化web服务功能
This commit is contained in:
@@ -10,8 +10,7 @@ import {
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
|
||||
import { disposeTauriListener } from "@/lib/tauri-listener"
|
||||
import { subscribe } from "@/lib/platform"
|
||||
import { inferLiveToolName } from "@/lib/tool-call-normalization"
|
||||
import {
|
||||
acpConnect,
|
||||
@@ -22,7 +21,7 @@ import {
|
||||
acpCancel,
|
||||
acpRespondPermission,
|
||||
acpDisconnect,
|
||||
} from "@/lib/tauri"
|
||||
} from "@/lib/api"
|
||||
import type {
|
||||
AgentType,
|
||||
AcpAgentStatus,
|
||||
@@ -1609,25 +1608,24 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
||||
// Single global event listener
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
let unlisten: UnlistenFn | null = null
|
||||
let unlisten: (() => void) | null = null
|
||||
|
||||
listenerReadyRef.current = false
|
||||
|
||||
listen<AcpEvent>("acp://event", (event) => {
|
||||
const e = event.payload
|
||||
const contextKey = reverseMapRef.current.get(e.connection_id)
|
||||
subscribe<AcpEvent>("acp://event", (payload) => {
|
||||
const contextKey = reverseMapRef.current.get(payload.connection_id)
|
||||
if (!contextKey) {
|
||||
bufferUnmappedEvent(e)
|
||||
bufferUnmappedEvent(payload)
|
||||
return
|
||||
}
|
||||
|
||||
// Touch activity on every incoming event
|
||||
lastActivityRef.current.set(contextKey, Date.now())
|
||||
handleMappedEvent(contextKey, e)
|
||||
handleMappedEvent(contextKey, payload)
|
||||
})
|
||||
.then((fn) => {
|
||||
if (cancelled) {
|
||||
disposeTauriListener(fn, "AcpConnectionsProvider.globalEvent")
|
||||
fn()
|
||||
} else {
|
||||
unlisten = fn
|
||||
listenerReadyRef.current = true
|
||||
@@ -1647,7 +1645,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
||||
clearTimeout(flushTimerRef.current)
|
||||
flushTimerRef.current = null
|
||||
}
|
||||
disposeTauriListener(unlisten, "AcpConnectionsProvider.globalEvent")
|
||||
unlisten?.()
|
||||
}
|
||||
}, [bufferUnmappedEvent, handleMappedEvent, resolveListenerReadyWaiters])
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import type { LiveMessage } from "@/contexts/acp-connections-context"
|
||||
import { getFolderConversation } from "@/lib/tauri"
|
||||
import { getFolderConversation } from "@/lib/api"
|
||||
import type {
|
||||
DbConversationDetail,
|
||||
MessageTurn,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import { toErrorMessage } from "@/lib/app-error"
|
||||
import { getFolder, listFolderConversations } from "@/lib/tauri"
|
||||
import { getFolder, listFolderConversations } from "@/lib/api"
|
||||
import type {
|
||||
AgentType,
|
||||
AgentStats,
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
KeyRound,
|
||||
Loader2,
|
||||
} from "lucide-react"
|
||||
import { openUrl } from "@tauri-apps/plugin-opener"
|
||||
import { openUrl } from "@/lib/platform"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
getGitHubAccounts,
|
||||
updateGitHubAccounts,
|
||||
saveAccountToken,
|
||||
} from "@/lib/tauri"
|
||||
} from "@/lib/api"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Context
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { useTranslations } from "next-intl"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
import { useWorkspaceContext } from "@/contexts/workspace-context"
|
||||
import { saveFolderOpenedConversations } from "@/lib/tauri"
|
||||
import { saveFolderOpenedConversations } from "@/lib/api"
|
||||
import type {
|
||||
AgentType,
|
||||
ConversationStatus,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from "react"
|
||||
import { terminalSpawn, terminalKill } from "@/lib/tauri"
|
||||
import { terminalSpawn, terminalKill } from "@/lib/api"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
import { useShortcutSettings } from "@/hooks/use-shortcut-settings"
|
||||
import { matchShortcutEvent } from "@/lib/keyboard-shortcuts"
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
readFileForEdit,
|
||||
readFilePreview,
|
||||
saveFileContent,
|
||||
} from "@/lib/tauri"
|
||||
} from "@/lib/api"
|
||||
import { languageFromPath } from "@/lib/language-detect"
|
||||
import {
|
||||
loadPersistedWorkspaceMode,
|
||||
|
||||
Reference in New Issue
Block a user