可能是初版,但短时间内是最终版本
这个提交包含在:
3
.gitignore
vendored
普通文件
3
.gitignore
vendored
普通文件
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
tsconfig.tsbuildinfo
|
||||
dist
|
||||
13
docs/Design.md
普通文件
13
docs/Design.md
普通文件
@ -0,0 +1,13 @@
|
||||
# OnlineAi-Core 设计文档
|
||||
|
||||
## 模块功能
|
||||
|
||||
在OnlineAi-Core中,大部分业务以`模块`的方式呈现,模块的业务范围如下:
|
||||
|
||||
- 注册程序互交接口
|
||||
- 监听事件钩子
|
||||
- 触发事件钩子
|
||||
|
||||
## 事件钩子
|
||||
|
||||
在OnlineAi-Core中,
|
||||
13
package.json
普通文件
13
package.json
普通文件
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "onlineai-core",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "^22.15.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build":"tsc --build",
|
||||
"prebuild":"node scripts/prebuild.js"
|
||||
}
|
||||
}
|
||||
42
scripts/CopyJSONs.js
普通文件
42
scripts/CopyJSONs.js
普通文件
@ -0,0 +1,42 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
console.log("复制文件脚本")
|
||||
|
||||
const from = path.join(__dirname,"..","src");
|
||||
const to = path.join(__dirname,"..","dist");
|
||||
|
||||
var CopyAbleReg = new RegExp(".json");
|
||||
|
||||
var CopyAble = ((filename)=>{
|
||||
return CopyAbleReg.test(filename)
|
||||
})
|
||||
|
||||
var Resolve = ((root)=>{
|
||||
fs.readdir(path.join(from,root),(err,files)=>{
|
||||
if(err){
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
files.forEach((filename)=>{
|
||||
if(fs.lstatSync(path.join(from,root,filename)).isDirectory()){
|
||||
fs.mkdir(path.join(to,root,filename),()=>{
|
||||
Resolve(path.join(root,filename))
|
||||
})
|
||||
}else{
|
||||
if(CopyAble(filename)){
|
||||
fs.copyFile(path.join(from,root,filename),path.join(to,root,filename),(err)=>{
|
||||
if(err){
|
||||
console.error(err);
|
||||
console.log("Copy",path.join(from,root,filename),"To",path.join(to,root,filename," Failed."))
|
||||
return;
|
||||
}
|
||||
console.log("Copy",path.join(from,root,filename),"To",path.join(to,root,filename," Success."))
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Resolve(".")
|
||||
2
scripts/prebuild.js
普通文件
2
scripts/prebuild.js
普通文件
@ -0,0 +1,2 @@
|
||||
const path = require("path");
|
||||
require(path.join(__dirname,"CopyJSONs"));
|
||||
5
src/LRCore/LRCore.ts
普通文件
5
src/LRCore/LRCore.ts
普通文件
@ -0,0 +1,5 @@
|
||||
// 新版本利刃引擎
|
||||
|
||||
export var LRCore = (()=>{
|
||||
|
||||
})
|
||||
3
src/LRCore/LRs/LR1.json
普通文件
3
src/LRCore/LRs/LR1.json
普通文件
@ -0,0 +1,3 @@
|
||||
{
|
||||
"你好":"你好"
|
||||
}
|
||||
11
src/LRCore/index.ts
普通文件
11
src/LRCore/index.ts
普通文件
@ -0,0 +1,11 @@
|
||||
// builtin是标准模块,只需要在程序中导出一个模块即可
|
||||
import * as CI from "../interface/Core"
|
||||
|
||||
export default (()=>{
|
||||
var LRCore:OACModule = {} as any;
|
||||
LRCore.Msg_HOOKS = new Map();
|
||||
LRCore.Msg_HOOKS.set("cn.jamaccao.oac.core.message",(Core,Data:CI.Core_Message)=>{
|
||||
Data.Message
|
||||
})
|
||||
return LRCore;
|
||||
})
|
||||
14
src/LRCore/meta.json
普通文件
14
src/LRCore/meta.json
普通文件
@ -0,0 +1,14 @@
|
||||
{
|
||||
"id":"cn.jamaccao.oac.lrcore",
|
||||
"version":[1,0,0,0],
|
||||
"info":{
|
||||
"Name":"利刃引擎",
|
||||
"Author":["OACTeam"]
|
||||
},
|
||||
"dependencies":[{
|
||||
"id":"cn.jamaccao.oac.builtin",
|
||||
"version":[1,0,0,0]
|
||||
}],
|
||||
"type": "standard",
|
||||
"startup":"index"
|
||||
}
|
||||
23
src/builtin/index.ts
普通文件
23
src/builtin/index.ts
普通文件
@ -0,0 +1,23 @@
|
||||
// builtin是标准模块,只需要在程序中导出一个模块即可
|
||||
import * as CI from "./../interface/Core"
|
||||
|
||||
export namespace BuildIn{
|
||||
export interface QueryUser extends OACData{
|
||||
UserID:number
|
||||
}
|
||||
}
|
||||
|
||||
export default (()=>{
|
||||
var Builtin:OACModule = {} as any;
|
||||
Builtin.Msg_HOOKS = new Map();
|
||||
Builtin.Msg_HOOKS.set("cn.jamaccao.oac.core.userinit",(Core,Data:CI.Core_UserInit)=>{
|
||||
// 用户初始化
|
||||
})
|
||||
Builtin.Msg_HOOKS.set("cn.jamaccao.oac.core.message",(Core,Data)=>{
|
||||
// 当受到消息时
|
||||
})
|
||||
Builtin.Msg_HOOKS.set("cn.jamaccao.oac.builtin.queryuser",(Core,Data:BuildIn.QueryUser)=>{
|
||||
|
||||
})
|
||||
return Builtin;
|
||||
})
|
||||
11
src/builtin/meta.json
普通文件
11
src/builtin/meta.json
普通文件
@ -0,0 +1,11 @@
|
||||
{
|
||||
"id":"cn.jamaccao.oac.builtin",
|
||||
"version":[1,0,0,0],
|
||||
"info":{
|
||||
"Name":"Built-In Modules",
|
||||
"Author":["OACTeam"]
|
||||
},
|
||||
"dependencies":[],
|
||||
"type": "standard",
|
||||
"startup":"index"
|
||||
}
|
||||
78
src/index.ts
普通文件
78
src/index.ts
普通文件
@ -0,0 +1,78 @@
|
||||
// 新版本OnlineAi-Core
|
||||
import oacConfig from "./oac.config";
|
||||
import path from "path";
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
var Modules = new Map<string,OACModule>()
|
||||
|
||||
var HOOKs = new Map<string,HOOK[]>();
|
||||
|
||||
var ModuleManager:ModuleManager = {
|
||||
GetModule(id) {
|
||||
return Modules.get(id);
|
||||
},
|
||||
RegModule(id, module) {
|
||||
Modules.set(id,module);
|
||||
module.Msg_HOOKS.forEach((value,name)=>{
|
||||
if(HOOKs.get(name) == undefined){
|
||||
HOOKs.set(name,[value]);;
|
||||
}else{
|
||||
HOOKs.get(name)?.push(value);
|
||||
}
|
||||
})
|
||||
return module;
|
||||
},
|
||||
}
|
||||
|
||||
oacConfig.Modules.forEach((moduleName,i)=>{
|
||||
fs.readFile(path.join(__dirname,moduleName,"meta.json"),(err,data)=>{
|
||||
if(err){
|
||||
console.error(err)
|
||||
return;
|
||||
}
|
||||
|
||||
var meta = JSON.parse(data.toString("utf-8")) as Meta;
|
||||
|
||||
var Available:boolean = true;
|
||||
meta.dependencies.forEach((v)=>{
|
||||
if(ModuleManager.GetModule(v.id) == undefined){
|
||||
Available = false;
|
||||
}
|
||||
})
|
||||
|
||||
if(! Available){
|
||||
return;
|
||||
}
|
||||
|
||||
var startup = path.join(__dirname,moduleName,meta.startup);
|
||||
|
||||
switch(meta.type){
|
||||
case "standard":
|
||||
ModuleManager.RegModule(meta.id,require(startup).default())
|
||||
break
|
||||
case "modifier":
|
||||
console.error("暂未实现");
|
||||
break
|
||||
case "plugin":
|
||||
require(startup)(ModuleManager);
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
oacConfig.Modules.map((v,i)=>{
|
||||
return new Promise(()=>{
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Modules.forEach((v,k)=>{
|
||||
console.log(k);
|
||||
console.log(v);
|
||||
})
|
||||
|
||||
HOOKs.forEach((v,k)=>{
|
||||
console.log(k);
|
||||
console.log(v);
|
||||
})
|
||||
13
src/interface/Core.d.ts
vendored
普通文件
13
src/interface/Core.d.ts
vendored
普通文件
@ -0,0 +1,13 @@
|
||||
interface User{
|
||||
UserID:number,
|
||||
Provider:{
|
||||
Name:string,
|
||||
Raw:string
|
||||
}
|
||||
}
|
||||
|
||||
export interface Core_UserInit extends OACData,User{}
|
||||
|
||||
export interface Core_Message extends OACData,User{
|
||||
Message:string
|
||||
}
|
||||
45
src/interface/OAC.d.ts
vendored
普通文件
45
src/interface/OAC.d.ts
vendored
普通文件
@ -0,0 +1,45 @@
|
||||
declare type HOOK = ((Core:any,Data:any)=>void);
|
||||
|
||||
interface Dictionary{
|
||||
[K:string]:DictionaryItem
|
||||
}
|
||||
|
||||
type DictionaryItem = string|number|boolean|Dictionary|Array<DictionaryItem>
|
||||
|
||||
declare interface OACData extends Dictionary{}
|
||||
|
||||
declare interface OACModule{
|
||||
Msg_HOOKS:Map<string,HOOK>
|
||||
}
|
||||
|
||||
declare interface ModuleManager{
|
||||
GetModule(id:string):OACModule|undefined,
|
||||
RegModule(id:string,module:OACModule):OACModule;
|
||||
}
|
||||
|
||||
declare interface HookManager{
|
||||
RegHook(id:string,HOOK:HOOK):Symbol;
|
||||
RemoveHook(id:string,HOOK:HOOK):boolean;
|
||||
RemoveHookBySymbol(id:string,Symbol:Symbol):boolean;
|
||||
ListHooks(id:string):HOOK[];
|
||||
}
|
||||
|
||||
declare interface Meta{
|
||||
id:string,
|
||||
version:Array<number>
|
||||
info:{
|
||||
Name:string
|
||||
Author:Array<String>
|
||||
},
|
||||
/**
|
||||
* @argument standard 标准模块,通过自动化流程注册到主线程中
|
||||
* @argument plugin 插件模块,程序通过RegModule注册到主线程中
|
||||
* @argument modifier 修改模块,程序可以重新注册模块注册器
|
||||
*/
|
||||
type:"standard"|"modifier"|"plugin"
|
||||
startup:string,
|
||||
dependencies:Array<{
|
||||
id:string,
|
||||
version:Array<number>
|
||||
}>
|
||||
}
|
||||
21
src/oac.config.ts
普通文件
21
src/oac.config.ts
普通文件
@ -0,0 +1,21 @@
|
||||
interface Config extends Dictionary{
|
||||
Basic:{
|
||||
Name:string
|
||||
},
|
||||
Listen:{
|
||||
Port:number
|
||||
},
|
||||
Modules:string[]
|
||||
}
|
||||
|
||||
export default (()=>{
|
||||
var Config = {} as Config;
|
||||
Config.Basic = {
|
||||
"Name":"OnlineAi Core Development"
|
||||
}
|
||||
Config.Listen = {
|
||||
"Port": 9997
|
||||
}
|
||||
Config.Modules = ["builtin","LRCore"]
|
||||
return Config;
|
||||
})()
|
||||
113
tsconfig.json
普通文件
113
tsconfig.json
普通文件
@ -0,0 +1,113 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "libReplacement": true, /* Enable lib replacement. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
"rootDir": "./src", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
||||
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
||||
15
yarn.lock
普通文件
15
yarn.lock
普通文件
@ -0,0 +1,15 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@^22.15.3":
|
||||
version "22.15.3"
|
||||
resolved "https://registry.npmmirror.com/@types/node/-/node-22.15.3.tgz#b7fb9396a8ec5b5dfb1345d8ac2502060e9af68b"
|
||||
integrity sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw==
|
||||
dependencies:
|
||||
undici-types "~6.21.0"
|
||||
|
||||
undici-types@~6.21.0:
|
||||
version "6.21.0"
|
||||
resolved "https://registry.npmmirror.com/undici-types/-/undici-types-6.21.0.tgz#691d00af3909be93a7faa13be61b3a5b50ef12cb"
|
||||
integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==
|
||||
在新工单中引用
屏蔽一个用户