feat(用户): 实现用户信息获取及配置写入功能
添加获取用户信息的API接口和Pinia存储 在登录流程中增加用户信息获取和配置写入操作 新增opencode配置写入的IPC通信功能
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { app, BrowserWindow, shell, ipcMain, Menu } from 'electron';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import net from 'node:net';
|
||||
import { spawn } from 'node:child_process';
|
||||
import started from 'electron-squirrel-startup';
|
||||
@@ -225,6 +226,48 @@ function registerIpcHandlers() {
|
||||
// Bonjour
|
||||
ipcMain.handle('bonjour:get-services', () => getDiscoveredServices());
|
||||
|
||||
// opencode 配置写入
|
||||
ipcMain.handle('opencode:write-config', async (_e, { modelInfo, deviceHost, devicePort }) => {
|
||||
const configDir = path.join(os.homedir(), '.config', 'opencode');
|
||||
const configPath = path.join(configDir, 'opencode.json');
|
||||
|
||||
await fs.promises.mkdir(configDir, { recursive: true });
|
||||
|
||||
const config = {
|
||||
$schema: 'https://opencode.ai/config.json',
|
||||
provider: {
|
||||
zhiju: {
|
||||
name: 'Zhiju AI',
|
||||
env: ['ZHIJU_API_KEY'],
|
||||
options: {
|
||||
baseURL: `http://${deviceHost}:${modelInfo.port}/v1`,
|
||||
apiKey: `${modelInfo.apiKey}`,
|
||||
},
|
||||
models: {
|
||||
[modelInfo.model_name]: {
|
||||
name: modelInfo.model_name,
|
||||
family: 'openai',
|
||||
status: modelInfo.status || 'beta',
|
||||
capabilities: modelInfo.capabilities || {
|
||||
reasoning: false,
|
||||
attachment: true,
|
||||
toolcall: true,
|
||||
input: { text: true, audio: false, image: true, video: false, pdf: true },
|
||||
output: { text: true, audio: false, image: false, video: false, pdf: false },
|
||||
},
|
||||
limit: modelInfo.limit || { context: 128000, output: 4096 },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
model: `zhiju/${modelInfo.model_name}`,
|
||||
};
|
||||
|
||||
await fs.promises.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
console.log('[opencode] config written to:', configPath);
|
||||
return true;
|
||||
});
|
||||
|
||||
// 窗口控制
|
||||
ipcMain.on('window:minimize', (event) => {
|
||||
const win = BrowserWindow.fromWebContents(event.sender);
|
||||
|
||||
Reference in New Issue
Block a user