mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-15 12:53:31 +08:00
Implement IM adapters allowing users to chat with Claude Code from Telegram and Feishu/Lark. Includes persistent session management (chatId→sessionId mapping), project selection via /projects command, and a web UI settings page for configuring bot tokens, allowed users, and default project directory. Key changes: - adapters/: Telegram and Feishu adapter scripts with shared common modules (WsBridge, MessageBuffer, SessionStore, HttpClient, config, formatting) - Backend: adapterService + REST API (GET/PUT /api/adapters) with secret masking - Frontend: AdapterSettings page in Settings tab with i18n support - DirectoryPicker: use React Portal for dropdown to fix overflow clipping Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
36 lines
985 B
TypeScript
36 lines
985 B
TypeScript
import { create } from 'zustand'
|
|
import { adaptersApi } from '../api/adapters'
|
|
import type { AdapterFileConfig } from '../types/adapter'
|
|
|
|
type AdapterStore = {
|
|
config: AdapterFileConfig
|
|
isLoading: boolean
|
|
error: string | null
|
|
|
|
fetchConfig: () => Promise<void>
|
|
updateConfig: (patch: Partial<AdapterFileConfig>) => Promise<void>
|
|
}
|
|
|
|
export const useAdapterStore = create<AdapterStore>((set) => ({
|
|
config: {},
|
|
isLoading: false,
|
|
error: null,
|
|
|
|
fetchConfig: async () => {
|
|
set({ isLoading: true, error: null })
|
|
try {
|
|
const config = await adaptersApi.getConfig()
|
|
set({ config, isLoading: false })
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : 'Failed to load config'
|
|
set({ isLoading: false, error: message })
|
|
}
|
|
},
|
|
|
|
updateConfig: async (patch) => {
|
|
// PUT returns the merged masked config — no need for a separate GET
|
|
const config = await adaptersApi.updateConfig(patch)
|
|
set({ config })
|
|
},
|
|
}))
|