Skip to content

Commit

Permalink
Code sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdong262 committed Jan 13, 2025
1 parent 6054045 commit 90fe95c
Show file tree
Hide file tree
Showing 8 changed files with 2,567 additions and 261 deletions.
2,734 changes: 2,481 additions & 253 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electerm-web",
"version": "2.51.18",
"version": "2.60.6",
"description": "Running electerm in as web app",
"main": "src/app/app.js",
"type": "module",
Expand Down Expand Up @@ -47,7 +47,7 @@
"preferGlobal": true,
"devDependencies": {
"@ant-design/icons": "5.5.1",
"@electerm/electerm-react": "1.51.21",
"@electerm/electerm-react": "1.60.6",
"@electerm/electerm-resource": "1.3.7",
"@electerm/strip-ansi": "^1.0.0",
"@novnc/novnc": "^1.4.0",
Expand Down Expand Up @@ -77,6 +77,7 @@
"react-colorful": "^5.6.1",
"react-delta-hooks": "1.1.5",
"react-dom": "18.3.1",
"react-markdown": "9.0.1",
"replace-in-file": "6.3.5",
"shelljs": "0.8.5",
"standard": "^17.1.0",
Expand All @@ -88,10 +89,10 @@
"zmodem-ts": "^1.0.4"
},
"dependencies": {
"@electerm/electerm-locales": "2.0.23",
"@electerm/electerm-locales": "2.0.25",
"@electerm/electerm-themes": "^1.0.1",
"@electerm/rdpjs": "^1.0.0",
"@electerm/ssh2": "1.16.0",
"@electerm/ssh2": "1.16.1",
"@yetzt/nedb": "1.8.0",
"axios": "^1.7.7",
"dayjs": "^1.11.13",
Expand All @@ -116,9 +117,10 @@
"nanoid": "3.1.31",
"node-bash": "5.0.1",
"node-pty": "1.1.0-beta14",
"openai": "4.77.3",
"os-locale-s": "1.0.8",
"pug": "3.0.2",
"serialport": "10.4.0",
"serialport": "13.0.0",
"socks": "2.7.1",
"socks-proxy-agent": "8.0.1",
"socksv5": "^0.0.6",
Expand Down
15 changes: 14 additions & 1 deletion src/app/common/default-setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,18 @@ export default {
'name',
'size',
'modifyTime'
]
],
hideIP: false,
dataSyncSelected: 'all',
baseURLAI: 'https://api.deepseek.com',
modelAI: 'deepseek-chat',
roleAI: `You are a terminal command expert.
- Provide clear, safe, and efficient shell commands
- Always explain what each command does
- Warn about potentially dangerous operations
- Format command output with markdown code blocks
- If multiple steps are needed, number them
- Mention any prerequisites or dependencies
- Include common flags and options
- Specify which OS (Linux/Mac/Windows) the command is for`
}
50 changes: 50 additions & 0 deletions src/app/lib/ai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* AI integration with DeepSeek API
*/
import OpenAI from 'openai'
import log from '../common/log.js'
import defaultSettings from '../common/config-default.js'

// Initialize OpenAI with DeepSeek configuration
const initAIClient = async (config) => {
return new OpenAI(config)
}

export const AIchat = async (
prompt,
model = defaultSettings.modelAI,
role = defaultSettings.roleAI,
baseURL = defaultSettings.baseURLAI,
apiKey
) => {
try {
const client = await initAIClient({
baseURL,
apiKey
})
const completion = await client.chat.completions.create({
messages: [
{
role: 'system',
content: role
},
{
role: 'user',
content: prompt
}
],
model
})

return {
response: completion.choices[0].message.content
}
} catch (e) {
log.error('AI chat error')
log.error(e)
return {
error: e.message,
stack: e.stack
}
}
}
2 changes: 1 addition & 1 deletion src/app/lib/global-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GlobalState {
app: null,
rawArgs: null,
loadTime: null,
initTime: null,
initTime: Date.now(),
watchFilePath: '',
oldRectangle: null,
serverPort: null,
Expand Down
6 changes: 6 additions & 0 deletions src/app/lib/run-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import { watchFile, unwatchFile } from './watch-file.js'
import lookup from './lookup.js'
import { init } from './init.js'
import { showItemInFolder } from './show-item-in-folder.js'
import { AIchat } from './ai.js'
import globalState from './global-state.js'

const globs = {
AIchat,
encryptAsync,
decryptAsync,
showItemInFolder,
Expand All @@ -32,6 +35,9 @@ const globs = {
toCss,
init,
initCommandLine: () => Promise.resolve(0),
getInitTime: () => {
return globalState.get('initTime')
},
loadFontList,
saveUserConfig,
registerDeepLink: () => Promise.resolve(1),
Expand Down
7 changes: 7 additions & 0 deletions src/client/web-components/web-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ window.api = {
return false
} else if (func === 'getLoadTime' || func === 'setLoadTime') {
return 0
} else if (func === 'getInitTime') {
if (window.et.initTime !== undefined) {
return window.et.initTime
} else {
window.et.initTime = Date.now()
return window.et.initTime
}
}
return window.wsFetch({
action: 'runSync',
Expand Down
2 changes: 1 addition & 1 deletion src/client/web-components/web-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { manage } from 'manate'
import initState from '../electerm-react/store/init-state'
import { StateStore } from '../electerm-react/store/index.js'
import { StateStore } from '../electerm-react/store/store'
import loginExtend from './store-login'

class Store extends StateStore {
Expand Down

0 comments on commit 90fe95c

Please sign in to comment.