Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jan 30, 2025
1 parent 518383c commit 4db83f8
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 35 deletions.
6 changes: 3 additions & 3 deletions path/fount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_package() {
apk add --update "$1"
else
echo "无法安装 $1"
return 1
exit 1
fi
}

Expand Down Expand Up @@ -125,7 +125,7 @@ EOF
fi
if ! command -v deno &> /dev/null; then
echo "Deno missing, you cant run fount without deno"
return 1
exit 1
else
echo "Deno installed"
fi
Expand All @@ -151,7 +151,7 @@ run() {
fi
}
if [[ $# -gt 0 && $1 = 'init' ]]; then
return 0
exit 0
elif [[ $# -gt 0 && $1 = 'keepalive' ]]; then
runargs=($@[1:])
run @runargs
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if [[ $RETURN_CODE -ne 0 ]] && [[ $RETURN_CODE -ne 255 ]]; then
read -n 1 -s -r -p "Press any key to continue..."
echo
fi
return $RETURN_CODE
exit $RETURN_CODE
12 changes: 6 additions & 6 deletions src/decl/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ export class UserAPI_t {
Uninstall: (reason: string, from: string) => void;

interfaces: {
config: {
config?: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
chat?: {
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetChatLog: (arg: chatReplyRequest_t) => Promise<chatLogEntry_t[]>
MessageEdit: (arg: {
GetChatLog?: (arg: chatReplyRequest_t) => Promise<chatLogEntry_t[]>
MessageEdit?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<chatReply_t>
MessageEditting: (arg: {
MessageEditting?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<void>
MessageDelete: (arg: {
MessageDelete?: (arg: {
index: number
chat_log: chatLogEntry_t[]
chat_entry: chatLogEntry_t
Expand Down
22 changes: 11 additions & 11 deletions src/decl/WorldAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ export class WorldAPI_t {
Uninstall: (reason: string, from: string) => void;

interfaces: {
config: {
config?: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetGroupGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetChatLogForCharname: (arg: chatReplyRequest_t, charname: string) => Promise<chatLogEntry_t[]>
AddChatLogEntry: (arg: chatReplyRequest_t, entry: chatLogEntry_t) => void
GetCharReply: (arg: chatReplyRequest_t, charname: string) => Promise<chatReply_t | null>
MessageEdit: (arg: {
chat?: {
GetGreeting?: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetGroupGreeting?: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetPrompt?: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetChatLogForCharname?: (arg: chatReplyRequest_t, charname: string) => Promise<chatLogEntry_t[]>
AddChatLogEntry?: (arg: chatReplyRequest_t, entry: chatLogEntry_t) => void
GetCharReply?: (arg: chatReplyRequest_t, charname: string) => Promise<chatReply_t | null>
MessageEdit?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<chatReply_t>
MessageEditting: (arg: {
MessageEditting?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<void>
MessageDelete: (arg: {
MessageDelete?: (arg: {
index: number
chat_log: chatLogEntry_t[]
chat_entry: chatLogEntry_t
Expand Down
36 changes: 28 additions & 8 deletions src/decl/charAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { locale_t, timeStamp_t } from './basedefs.ts';
import { locale_t, role_t, timeStamp_t } from './basedefs.ts';
import { chatLogEntry_t, prompt_struct_t, single_part_prompt_t } from './prompt_struct.ts';
import { chatReply_t, chatReplyRequest_t } from '../public/shells/chat/decl/chatLog.ts';

Expand Down Expand Up @@ -39,42 +39,62 @@ export class charAPI_t {

// interface with shell (maybe chat WebUI or cute Live2d or a kill machine, i don't care)
interfaces: {
config: {
config?: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
chat?: {
GetGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetGroupGreeting: (arg: chatReplyRequest_t, index: number) => Promise<chatReply_t | null>
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetPromptForOther: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
GetReply: (arg: chatReplyRequest_t) => Promise<chatReply_t | null>
GetReplyFequency: (arg: chatReplyRequest_t) => number
MessageEdit: (arg: {
GetReplyFequency?: (arg: chatReplyRequest_t) => number
MessageEdit?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<chatReply_t>
MessageEditting: (arg: {
MessageEditting?: (arg: {
index: number
original: chatLogEntry_t
edited: chatReply_t
chat_log: chatLogEntry_t[]
extension?: any
}) => Promise<void>
MessageDelete: (arg: {
MessageDelete?: (arg: {
index: number
chat_log: chatLogEntry_t[]
chat_entry: chatLogEntry_t
extension?: any
}) => Promise<void>
},
discord: {
discord?: {
Intents?: DiscordGatewayIntentBits[]
Partials?: DiscordPartials[]
OnceClientReady: (client: DiscordClient, config: any) => void
},
shellassist?: {
Assist: (data: {
shelltype: string
shellhistory: ({
command: string
output: string
error: string
time: timeStamp_t
}|{
role: role_t
content: string
})[]
command_now: string
command_error: string
rejected_commands: string[]
}) => Promise<{
fixed_command: string
talk: string
}>
}
};
}
8 changes: 4 additions & 4 deletions src/decl/pluginAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export class pluginAPI_t {
Uninstall: (reason: string, from: string) => void;

interfaces: {
config: {
config?: {
GetData: () => Promise<any>
SetData: (data: any) => Promise<void>
},
chat: {
GetPrompt: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
RepalyHandler: RepalyHandler_t
chat?: {
GetPrompt?: (arg: chatReplyRequest_t, prompt_struct: prompt_struct_t, detail_level: number) => Promise<single_part_prompt_t>;
RepalyHandler?: RepalyHandler_t
}
};
}
2 changes: 1 addition & 1 deletion src/public/shells/AIsourceManage/src/server/endpoints.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function setEndpoints(app) {
})
app.post('/api/shells/AIsourceManage/deletefile', authenticate, async (req, res) => {
const { username } = await getUserByToken(req.cookies.accessToken)
deleteAISourceFile(username, req.body.AISourceFile)
await deleteAISourceFile(username, req.body.AISourceFile)
res.status(200).json({ message: 'File deleted successfully' })
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/public/shells/AIsourceManage/src/server/manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export function addAISourceFile(username, fileName) {

export function deleteAISourceFile(username, fileName) {
const fname = getUserDictionary(username) + '/AIsources/' + fileName + '.json'
fs.unlink(fname)
return fs.promises.unlink(fname)
}
3 changes: 3 additions & 0 deletions src/public/shells/install/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { renderTemplate } from '../../scripts/template.mjs'
import { applyTheme } from '../../scripts/theme.mjs'

applyTheme()

const fileImportTab = document.getElementById('file-import-tab')
const textImportTab = document.getElementById('text-import-tab')
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions src/public/shells/shellassist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="zh-CN" data-theme="dark">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>终端辅助</title>
<link href="https://cdn.jsdelivr.net/npm/daisyui@latest/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="./index.css">
</head>

<body class="flex flex-col h-screen">
<div class="flex flex-col flex-grow items-center justify-center p-4">
<p class="text-lg text-center mb-6">
Fount 支持将你喜欢的角色部署到你的终端中辅助你编码!
</p>
<a href="#">点击这里了解更多信息</a>
</div>

<script type="module" src="./index.mjs"></script>
</body>

</html>
3 changes: 3 additions & 0 deletions src/public/shells/shellassist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { applyTheme } from '../../scripts/theme.mjs'

applyTheme()
25 changes: 25 additions & 0 deletions src/public/shells/shellassist/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LoadChar } from '../../../server/managers/char_manager.mjs'

export default {
info: {
'': {
name: 'install',
avatar: '',
description: 'default description',
description_markdown: 'default description',
version: '1.0.0',
author: 'steve02081504',
homepage: '',
tags: []
}
},
Load: (app) => { },
Unload: (app) => { },
IPCInvokeHandler: async (user, data) => {
const char = await LoadChar(user, data.charname)
if (char?.interfaces?.shellassist)
return char.interfaces.shellassist.Assist(data)
else
throw new Error(`Char ${data.char} does not support shellassist interface`)
}
}
9 changes: 9 additions & 0 deletions src/server/ipc_server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ export class IPCManager {
const result = await shell.ArgumentsHandler(username, args)
socket.write(JSON.stringify({ status: 'ok', result }) + '\n') // 添加换行符作为结束
}
else if (command.type === 'invokeshell') {
const { username, shellname, data } = command.data
console.log(`调用 shell ${shellname} 作为 ${username},参数:${JSON.stringify(data)}`)
const shell = await loadShell(username, shellname)
const result = await shell.IPCInvokeHandler(username, data)
socket.write(JSON.stringify({ status: 'ok', result }) + '\n')
}
else if (command.type === 'shutdown')
shutdown()
else if (command.type === 'ping')
socket.write(JSON.stringify({ status: 'ok', message: 'pong' }) + '\n')
else
socket.write(JSON.stringify({ status: 'error', message: '不支持的命令类型' }) + '\n')
} catch (err) {
Expand Down
4 changes: 4 additions & 0 deletions src/server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export async function init() {
console.log(e.error)
e.preventDefault()
})
globalThis.addEventListener('unhandledRejection', (e) => {
console.log(e.reason)
e.preventDefault()
})
if (!await new IPCManager().startServer()) return false

console.freshLine('server start', 'server starting')
Expand Down

0 comments on commit 4db83f8

Please sign in to comment.