Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d32ccc6eb5 | ||
|
|
7b3e94d568 | ||
|
|
5cfe479044 | ||
|
|
f04ffa5dc6 | ||
|
|
a2a73ce2dd | ||
|
|
66d02eeb6a |
No files matched your search
@@ -10,7 +10,7 @@ permissions: write-all
|
||||
|
||||
env:
|
||||
OPENROUTER_API_URL: https://91vip.futureppo.top/v1/chat/completions
|
||||
OPENROUTER_MODEL: "kimi-k2-0905-turbo"
|
||||
OPENROUTER_MODEL: "glm-4.6-turbo"
|
||||
RELEASE_NAME: "NapCat"
|
||||
|
||||
jobs:
|
||||
@@ -236,7 +236,8 @@ jobs:
|
||||
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$BODY")
|
||||
|
||||
echo "=== raw response ==="
|
||||
echo "$RESPONSE"
|
||||
echo "=== OpenRouter raw response ==="
|
||||
echo "$RESPONSE" | jq .
|
||||
|
||||
|
||||
Vendored
+7
@@ -1,2 +1,9 @@
|
||||
{
|
||||
"debug.node.sourceMapPathOverrides": {
|
||||
"../../napcat-onebot/*": "${workspaceFolder}/packages/napcat-onebot/*",
|
||||
"../../napcat-core/*": "${workspaceFolder}/packages/napcat-core/*",
|
||||
"../../napcat-common/*": "${workspaceFolder}/packages/napcat-common/*",
|
||||
"../../napcat-webui-backend/*": "${workspaceFolder}/packages/napcat-webui-backend/*",
|
||||
"../../napcat-pty/*": "${workspaceFolder}/packages/napcat-pty/*"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"build:shell": "pnpm --filter napcat-shell run build || exit 1",
|
||||
"build:shell:dev": "pnpm --filter napcat-shell run build:dev || exit 1",
|
||||
"build:framework": "pnpm --filter napcat-framework run build || exit 1",
|
||||
"build:webui": "pnpm --filter napcat-webui-frontend run build || exit 1",
|
||||
"dev:shell": "pnpm --filter napcat-develop run dev || exit 1",
|
||||
@@ -13,6 +14,8 @@
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@vitejs/plugin-react-swc": "^4.2.2",
|
||||
"inversify": "^7.10.4",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"typescript": "^5.3.0",
|
||||
"vite": "^6.4.1",
|
||||
"vite-plugin-cp": "^6.0.3"
|
||||
|
||||
@@ -25,18 +25,18 @@ export class NTEventWrapper {
|
||||
private readonly listenerManager: Map<string, ListenerClassBase> = new Map<string, ListenerClassBase>(); // ListenerName-Unique -> Listener实例
|
||||
private readonly EventTask = new Map<string, Map<string, Map<string, InternalMapKey>>>(); // tasks ListenerMainName -> ListenerSubName-> uuid -> {timeout,createtime,func}
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
wrapperSession: NodeIQQNTWrapperSession
|
||||
) {
|
||||
this.WrapperSession = wrapperSession;
|
||||
}
|
||||
|
||||
createProxyDispatch (ListenerMainName: string) {
|
||||
createProxyDispatch(ListenerMainName: string) {
|
||||
const dispatcherListenerFunc = this.dispatcherListener.bind(this);
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get (target: any, prop: any, receiver: any) {
|
||||
get(target: any, prop: any, receiver: any) {
|
||||
if (typeof target[prop] === 'undefined') {
|
||||
// 如果方法不存在,返回一个函数,这个函数调用existentMethod
|
||||
return (...args: any[]) => {
|
||||
@@ -54,7 +54,7 @@ export class NTEventWrapper {
|
||||
Service extends keyof ServiceNamingMapping,
|
||||
ServiceMethod extends FuncKeys<ServiceNamingMapping[Service]>,
|
||||
T extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>
|
||||
> (eventName: `${Service}/${ServiceMethod}`): T | undefined {
|
||||
>(eventName: `${Service}/${ServiceMethod}`): T | undefined {
|
||||
const eventNameArr = eventName.split('/');
|
||||
type eventType = {
|
||||
[key: string]: () => { [key: string]: (...params: Parameters<T>) => Promise<ReturnType<T>>; };
|
||||
@@ -78,18 +78,15 @@ export class NTEventWrapper {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
createListenerFunction<T, Listener extends keyof ListenerNamingMapping,
|
||||
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>> (listenerMainName: string, uniqueCode: string = ''): T {
|
||||
createListenerFunction<T> (listenerMainName: string, uniqueCode: string = ''): T {
|
||||
const existListener = this.listenerManager.get(listenerMainName + uniqueCode);
|
||||
if (!existListener) {
|
||||
const Listener = this.createProxyDispatch(listenerMainName);
|
||||
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
|
||||
const Service = `NodeIKernel${ServiceSubName}Service/addKernel${ServiceSubName}Listener` as `${Listener}/${ListenerMethod}`;
|
||||
this.createEventFunction<
|
||||
keyof ServiceNamingMapping,
|
||||
FuncKeys<ServiceNamingMapping[keyof ServiceNamingMapping]>,
|
||||
(...args: any[]) => any
|
||||
>(Service as `${keyof ServiceNamingMapping}/${FuncKeys<ServiceNamingMapping[keyof ServiceNamingMapping]>}`);
|
||||
const Service = `NodeIKernel${ServiceSubName}Service/addKernel${ServiceSubName}Listener`;
|
||||
|
||||
// @ts-ignore
|
||||
this.createEventFunction(Service)(Listener as T);
|
||||
this.listenerManager.set(listenerMainName + uniqueCode, Listener);
|
||||
return Listener as T;
|
||||
}
|
||||
@@ -97,7 +94,7 @@ export class NTEventWrapper {
|
||||
}
|
||||
|
||||
// 统一回调清理事件
|
||||
async dispatcherListener (ListenerMainName: string, ListenerSubName: string, ...args: any[]) {
|
||||
async dispatcherListener(ListenerMainName: string, ListenerSubName: string, ...args: any[]) {
|
||||
this.EventTask.get(ListenerMainName)
|
||||
?.get(ListenerSubName)
|
||||
?.forEach((task, uuid) => {
|
||||
@@ -115,7 +112,7 @@ export class NTEventWrapper {
|
||||
Service extends keyof ServiceNamingMapping,
|
||||
ServiceMethod extends FuncKeys<ServiceNamingMapping[Service]>,
|
||||
EventType extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>
|
||||
> (
|
||||
>(
|
||||
serviceAndMethod: `${Service}/${ServiceMethod}`,
|
||||
...args: Parameters<EventType>
|
||||
): Promise<Awaited<ReturnType<EventType>>> {
|
||||
@@ -126,7 +123,7 @@ export class NTEventWrapper {
|
||||
Listener extends keyof ListenerNamingMapping,
|
||||
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>,
|
||||
ListenerType extends (...args: any) => any = EnsureFunc<ListenerNamingMapping[Listener][ListenerMethod]>
|
||||
> (
|
||||
>(
|
||||
listenerAndMethod: `${Listener}/${ListenerMethod}`,
|
||||
checker: (...args: Parameters<ListenerType>) => boolean,
|
||||
waitTimes = 1,
|
||||
@@ -140,7 +137,7 @@ export class NTEventWrapper {
|
||||
let complete = 0;
|
||||
let retData: Parameters<ListenerType> | undefined;
|
||||
|
||||
function sendDataCallback () {
|
||||
function sendDataCallback() {
|
||||
if (complete === 0) {
|
||||
reject(new Error(' ListenerName:' + listenerAndMethod + ' timeout'));
|
||||
} else {
|
||||
@@ -180,7 +177,7 @@ export class NTEventWrapper {
|
||||
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>,
|
||||
EventType extends (...args: any) => any = EnsureFunc<ServiceNamingMapping[Service][ServiceMethod]>,
|
||||
ListenerType extends (...args: any) => any = EnsureFunc<ListenerNamingMapping[Listener][ListenerMethod]>
|
||||
> (
|
||||
>(
|
||||
serviceAndMethod: `${Service}/${ServiceMethod}`,
|
||||
listenerAndMethod: `${Listener}/${ListenerMethod}`,
|
||||
args: Parameters<EventType>,
|
||||
@@ -194,7 +191,7 @@ export class NTEventWrapper {
|
||||
let retData: Parameters<ListenerType> | undefined;
|
||||
let retEvent: any = {};
|
||||
|
||||
function sendDataCallback (resolve: any, reject: any) {
|
||||
function sendDataCallback(resolve: any, reject: any) {
|
||||
if (complete === 0) {
|
||||
reject(
|
||||
new Error(
|
||||
|
||||
@@ -31,6 +31,7 @@ import { NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/napcat-cor
|
||||
import { proxiedListenerOf } from 'napcat-common/src/proxy-handler';
|
||||
import { NTQQPacketApi } from './apis/packet';
|
||||
import { NativePacketHandler } from './packet/handler/client';
|
||||
import { container, ReceiverServiceRegistry } from './packet/handler/serviceRegister';
|
||||
export * from './wrapper';
|
||||
export * from './types/index';
|
||||
export * from './services/index';
|
||||
@@ -118,6 +119,15 @@ export class NapCatCore {
|
||||
UserApi: new NTQQUserApi(this.context, this),
|
||||
GroupApi: new NTQQGroupApi(this.context, this),
|
||||
};
|
||||
container.bind(NapCatCore).toConstantValue(this);
|
||||
ReceiverServiceRegistry.forEach((ServiceClass, serviceName) => {
|
||||
container.bind(ServiceClass).toSelf();
|
||||
console.log(`Registering service handler for: ${serviceName}`);
|
||||
this.context.packetHandler.onCmd(serviceName, ({ seq, hex_data }) => {
|
||||
const serviceInstance = container.get(ServiceClass);
|
||||
return serviceInstance.handler(seq, hex_data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async initCore () {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import "reflect-metadata";
|
||||
import { Container, injectable } from "inversify";
|
||||
import { NapCatCore } from "../..";
|
||||
|
||||
export const container = new Container();
|
||||
|
||||
export const ReceiverServiceRegistry = new Map<string, new (...args: any[]) => ServiceBase>();
|
||||
|
||||
export abstract class ServiceBase {
|
||||
get core(): NapCatCore {
|
||||
return container.get(NapCatCore);
|
||||
}
|
||||
|
||||
abstract handler(seq: number, hex_data: string): Promise<void> | void;
|
||||
}
|
||||
|
||||
export function ReceiveService(serviceName: string) {
|
||||
return function <T extends new (...args: any[]) => ServiceBase>(constructor: T) {
|
||||
injectable()(constructor);
|
||||
ReceiverServiceRegistry.set(serviceName, constructor);
|
||||
return constructor;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ReceiveService, ServiceBase } from "../packet/handler/serviceRegister";
|
||||
|
||||
// @ReceiveService('trpc.msg.olpush.OlPushService.MsgPush')
|
||||
// export class OlPushService extends ServiceBase {
|
||||
// async handler(seq: number, hex_data: string) {
|
||||
// console.log(`OlPushService handler called with seq: ${seq} and data: ${hex_data}`);
|
||||
// }
|
||||
// }
|
||||
@@ -5,4 +5,4 @@ $uninstall = $uninstall.Trim('"')
|
||||
$qqPath = Split-Path $uninstall -Parent
|
||||
|
||||
Write-Host "QQPath: $qqPath"
|
||||
node.exe "./loadNapCat.cjs" "$qqPath"
|
||||
node.exe --inspect "./loadNapCat.cjs" "$qqPath"
|
||||
@@ -16,6 +16,7 @@ const nodeModules = [...builtinModules, builtinModules.map((m) => `node:${m}`)].
|
||||
const FrameworkBaseConfigPlugin: PluginOption[] = [
|
||||
autoIncludeTSPlugin({
|
||||
entries: [
|
||||
{ entry: 'napcat.ts', dir: path.resolve(__dirname, '../napcat-core/protocol') },
|
||||
{ entry: 'napcat.ts', dir: path.resolve(__dirname, '../napcat-onebot/action/test') }
|
||||
]
|
||||
}),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"build:dev": "vite build --mode development",
|
||||
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -19,6 +19,7 @@ const ShellBaseConfigPlugin: PluginOption[] = [
|
||||
react({ tsDecorators: true }),
|
||||
autoIncludeTSPlugin({
|
||||
entries: [
|
||||
{ entry: 'napcat.ts', dir: path.resolve(__dirname, '../napcat-core/protocol') },
|
||||
{ entry: 'napcat.ts', dir: path.resolve(__dirname, '../napcat-onebot/action/test') }
|
||||
]
|
||||
}),
|
||||
@@ -34,7 +35,7 @@ const ShellBaseConfigPlugin: PluginOption[] = [
|
||||
nodeResolve(),
|
||||
napcatVersion(),
|
||||
];
|
||||
const ShellBaseConfig = () =>
|
||||
const ShellBaseConfig = (source_map: boolean = false) =>
|
||||
defineConfig({
|
||||
resolve: {
|
||||
conditions: ['node', 'default'],
|
||||
@@ -48,7 +49,7 @@ const ShellBaseConfig = () =>
|
||||
},
|
||||
},
|
||||
build: {
|
||||
sourcemap: false,
|
||||
sourcemap: source_map,
|
||||
target: 'esnext',
|
||||
minify: false,
|
||||
lib: {
|
||||
@@ -61,11 +62,17 @@ const ShellBaseConfig = () =>
|
||||
fileName: (_, entryName) => `${entryName}.mjs`,
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [...nodeModules, ...external],
|
||||
external: [...nodeModules, ...external]
|
||||
},
|
||||
},
|
||||
});
|
||||
export default defineConfig((): UserConfig => {
|
||||
export default defineConfig(({ mode }): UserConfig => {
|
||||
if (mode === 'development') {
|
||||
return {
|
||||
...ShellBaseConfig(true),
|
||||
plugins: [...ShellBaseConfigPlugin],
|
||||
};
|
||||
}
|
||||
return {
|
||||
...ShellBaseConfig(),
|
||||
plugins: [...ShellBaseConfigPlugin],
|
||||
|
||||
@@ -12,6 +12,9 @@ export function autoIncludeTSPlugin(options) {
|
||||
async buildStart() {
|
||||
tsFilesMap = {};
|
||||
for (const { entry, dir } of entries) {
|
||||
if (!tsFilesMap[entry]) {
|
||||
tsFilesMap[entry] = [];
|
||||
}
|
||||
const fullDir = path.resolve(dir);
|
||||
const allTsFiles = await findTSFiles(fullDir);
|
||||
|
||||
@@ -29,13 +32,12 @@ export function autoIncludeTSPlugin(options) {
|
||||
}
|
||||
});
|
||||
|
||||
tsFilesMap[entry] = validFiles;
|
||||
tsFilesMap[entry].push(...validFiles);
|
||||
}
|
||||
},
|
||||
|
||||
transform(code, id) {
|
||||
for (const [entry, tsFiles] of Object.entries(tsFilesMap)) {
|
||||
// 检查id是否匹配entry(支持完整路径或相对路径)
|
||||
const isMatch = id.endsWith(entry) || id.includes(entry);
|
||||
if (isMatch && tsFiles.length > 0) {
|
||||
const imports = tsFiles.map(filePath => {
|
||||
@@ -43,11 +45,18 @@ export function autoIncludeTSPlugin(options) {
|
||||
return `import './${relativePath}';`;
|
||||
}).join('\n');
|
||||
|
||||
return imports + '\n' + code;
|
||||
const transformedCode = imports + '\n' + code;
|
||||
|
||||
return {
|
||||
code: transformedCode,
|
||||
map: { mappings: '' } // 空映射即可,VSCode 可以在 TS 上断点
|
||||
};
|
||||
}
|
||||
}
|
||||
return code;
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user