diff --git a/packages/core/src/bot.ts b/packages/core/src/bot.ts index b463cbd9be..49adedee1e 100644 --- a/packages/core/src/bot.ts +++ b/packages/core/src/bot.ts @@ -1,4 +1,4 @@ -import { Logger, sleep } from '@koishijs/utils' +import { Logger, Random, sleep } from '@koishijs/utils' import { Adapter } from './adapter' import { App } from './app' import { Session } from './session' @@ -14,6 +14,7 @@ export abstract class Bot { public internal?: any public selfId?: string public logger: Logger + public id = Random.id() private _status: Bot.Status diff --git a/plugins/frontend/console/client/client.ts b/plugins/frontend/console/client/client.ts index 8ce1d1ec71..7875cabdd6 100644 --- a/plugins/frontend/console/client/client.ts +++ b/plugins/frontend/console/client/client.ts @@ -146,8 +146,7 @@ const initTask = new Promise((resolve) => { delete extensions[path] } - const { redirect } = router.currentRoute.value.query - const tasks = newValue.map(async (path) => { + async function loadExtension(path: string) { if (extensions[path]) return extensions[path] = new Context() @@ -170,9 +169,13 @@ const initTask = new Promise((resolve) => { router.replace(location) } } - }) + } + + const { redirect } = router.currentRoute.value.query + await Promise.all(newValue.map((path) => { + return loadExtension(path).catch(console.error) + })) - await Promise.allSettled(tasks) if (!oldValue) resolve() }, { deep: true }) }) diff --git a/plugins/frontend/console/client/components/form/index.ts b/plugins/frontend/console/client/components/form/index.ts index 58bfe4cf49..ece81d0b30 100644 --- a/plugins/frontend/console/client/components/form/index.ts +++ b/plugins/frontend/console/client/components/form/index.ts @@ -4,7 +4,7 @@ import Input from './input.vue' import TabItem from './tab-item.vue' import TabGroup from './tab-group.vue' import Radio from './radio.vue' -import Schema from './schema.vue' +import Schema from './schema/index.vue' import { App } from 'vue' export default function (app: App) { diff --git a/plugins/frontend/console/client/components/form/schema-group.vue b/plugins/frontend/console/client/components/form/schema-group.vue deleted file mode 100644 index ec1bf8863f..0000000000 --- a/plugins/frontend/console/client/components/form/schema-group.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - - - diff --git a/plugins/frontend/console/client/components/form/schema-union.vue b/plugins/frontend/console/client/components/form/schema-union.vue deleted file mode 100644 index f96bb50b95..0000000000 --- a/plugins/frontend/console/client/components/form/schema-union.vue +++ /dev/null @@ -1,33 +0,0 @@ - - - diff --git a/plugins/frontend/console/client/components/form/schema.vue b/plugins/frontend/console/client/components/form/schema/index.vue similarity index 69% rename from plugins/frontend/console/client/components/form/schema.vue rename to plugins/frontend/console/client/components/form/schema/index.vue index 64b051de8b..1e78166a1d 100644 --- a/plugins/frontend/console/client/components/form/schema.vue +++ b/plugins/frontend/console/client/components/form/schema/index.vue @@ -1,30 +1,9 @@ - +
+ +
diff --git a/plugins/frontend/manager/src/bots.ts b/plugins/frontend/manager/src/bots.ts index eaef1dd309..0930d53972 100644 --- a/plugins/frontend/manager/src/bots.ts +++ b/plugins/frontend/manager/src/bots.ts @@ -1,4 +1,4 @@ -import { Adapter, Bot, Context, pick, Time } from 'koishi' +import { Bot, Context, Dict, pick, Time } from 'koishi' import { DataService } from '@koishijs/plugin-console' declare module 'koishi' { @@ -31,7 +31,7 @@ class TickCounter { } } -class BotProvider extends DataService { +class BotProvider extends DataService> { constructor(ctx: Context) { super(ctx, 'bots') @@ -57,13 +57,13 @@ class BotProvider extends DataService { } async get() { - return this.ctx.bots.map((bot) => ({ + return Object.fromEntries(this.ctx.bots.map((bot) => [bot.id, { ...pick(bot, ['platform', 'protocol', 'selfId', 'avatar', 'username', 'status', 'config']), error: bot.error?.message, adapter: bot.adapter.platform, messageSent: bot._messageSent.get(), messageReceived: bot._messageReceived.get(), - })) + }] as const)) } } diff --git a/plugins/frontend/manager/src/index.ts b/plugins/frontend/manager/src/index.ts index ae39b6cfc3..7e30259760 100644 --- a/plugins/frontend/manager/src/index.ts +++ b/plugins/frontend/manager/src/index.ts @@ -23,12 +23,6 @@ export { } declare module '@koishijs/plugin-console' { - interface Events { - 'plugin/load'(name: string, config: any): void - 'plugin/unload'(name: string, config: any): void - 'bot/create'(platform: string, config: any): void - } - namespace Console { interface Services { bots: BotProvider diff --git a/plugins/frontend/manager/src/writer.ts b/plugins/frontend/manager/src/writer.ts index e7d074df18..25fa122417 100644 --- a/plugins/frontend/manager/src/writer.ts +++ b/plugins/frontend/manager/src/writer.ts @@ -1,6 +1,15 @@ import { Context } from 'koishi' import { Loader } from '@koishijs/cli' +declare module '@koishijs/plugin-console' { + interface Events { + 'plugin/load'(name: string, config: any): void + 'plugin/unload'(name: string, config: any): void + 'bot/login'(id: string, adapter: string, config: any): void + 'bot/logout'(id: string, adapter: string, config: any): void + } +} + export default class ConfigWriter { private loader: Loader private plugins: {}