@vnejs/plugins.ai 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.ai";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import "@vnejs/contracts.ai";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.ai";
4
+ import { AiEmit } from "./modules/ai.emit.js";
5
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [AiEmit]);
@@ -0,0 +1,8 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { AiEmitPayload } from "@vnejs/contracts.ai";
3
+ import type { AiPluginConstants, AiPluginEvents, AiPluginParams, AiPluginSettings } from "../types.js";
4
+ export declare class AiEmit extends ModuleCore<AiPluginEvents, AiPluginConstants, AiPluginSettings, AiPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onEmit: ({ type, args }?: AiEmitPayload) => Promise<unknown>;
8
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class AiEmit extends ModuleCore {
3
+ name = "ai.emit";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.AI.EMIT, this.onEmit);
6
+ };
7
+ onEmit = async ({ type = "", args = {} } = {}) => {
8
+ const fn = this.PARAMS.AI.ALGORITHMS[type];
9
+ if (!fn)
10
+ return null;
11
+ return fn(args, this);
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { AiEmit } from "../modules/ai.emit.js";
3
+ import { createAiTestModule, registerAiPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
4
+ describe("AiEmit", () => {
5
+ beforeEach(() => {
6
+ registerAiPluginVne();
7
+ });
8
+ it("calls registered algorithm with args and module", async () => {
9
+ const algorithm = vi.fn(async (args, { emitOne }) => {
10
+ expect(typeof emitOne).toBe("function");
11
+ return args.value ?? null;
12
+ });
13
+ registerAiPluginVne({ ALGORITHMS: { strong: algorithm } });
14
+ const { module } = createAiTestModule(AiEmit);
15
+ const result = await module.onEmit({ type: "strong", args: { value: 42 } });
16
+ expect(algorithm).toHaveBeenCalledOnce();
17
+ expect(algorithm.mock.calls[0]?.[0]).toEqual({ value: 42 });
18
+ expect(algorithm.mock.calls[0]?.[1]).toBe(module);
19
+ expect(result).toBe(42);
20
+ });
21
+ it("returns null for unknown type", async () => {
22
+ const { module } = createAiTestModule(AiEmit);
23
+ const result = await module.onEmit({
24
+ type: "missing",
25
+ args: { board: null, turn: "white" },
26
+ });
27
+ expect(result).toBeNull();
28
+ });
29
+ it("returns null when ALGORITHMS is empty", async () => {
30
+ const { observer } = createAiTestModule(AiEmit);
31
+ const result = await observer.emitOne(SUBSCRIBE_EVENTS.EMIT, {
32
+ type: "random",
33
+ args: { board: null, turn: "white" },
34
+ });
35
+ expect(result).toBeNull();
36
+ });
37
+ });
@@ -0,0 +1,4 @@
1
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.ai";
2
+ import { createTestModule } from "@vnejs/test-utils";
3
+ export declare const registerAiPluginVne: (params?: Partial<typeof PARAMS>) => void;
4
+ export { createTestModule as createAiTestModule, SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME };
@@ -0,0 +1,11 @@
1
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.ai";
2
+ import { createTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
3
+ export const registerAiPluginVne = (params = {}) => {
4
+ registerCoreVne();
5
+ registerVnePlugin(PLUGIN_NAME, {
6
+ constants: CONSTANTS,
7
+ events: SUBSCRIBE_EVENTS,
8
+ params: { ...PARAMS, ...params, ALGORITHMS: { ...PARAMS.ALGORITHMS, ...(params.ALGORITHMS ?? {}) } },
9
+ });
10
+ };
11
+ export { createTestModule as createAiTestModule, SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME };
@@ -0,0 +1,6 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.ai";
3
+ export type AiPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents>;
4
+ export type AiPluginConstants = ModuleCoreConstants;
5
+ export type AiPluginSettings = ModuleCoreSettings;
6
+ export type AiPluginParams = ModuleCoreParams & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@vnejs/plugins.ai",
3
+ "version": "0.2.1",
4
+ "description": "Generic AI algorithm dispatch via EVENTS.AI.EMIT",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "npx @vnejs/monorepo test",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/contracts.ai": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module.core": "~0.2.0",
37
+ "@vnejs/shared": "~0.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "@vnejs/configs.ts-common": "~0.2.0",
41
+ "@vnejs/configs.vitest": "~0.2.0",
42
+ "@vnejs/test-utils": "~0.2.0",
43
+ "@vnejs/contracts.ai": "~0.2.0",
44
+ "@vnejs/module.core": "~0.2.0",
45
+ "@vnejs/shared": "~0.2.0"
46
+ }
47
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import "@vnejs/contracts.ai";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.ai";
5
+
6
+ import { AiEmit } from "./modules/ai.emit.js";
7
+
8
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [AiEmit]);
@@ -0,0 +1,19 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { AiEmitPayload } from "@vnejs/contracts.ai";
3
+
4
+ import type { AiPluginConstants, AiPluginEvents, AiPluginParams, AiPluginSettings } from "../types.js";
5
+
6
+ export class AiEmit extends ModuleCore<AiPluginEvents, AiPluginConstants, AiPluginSettings, AiPluginParams> {
7
+ name = "ai.emit";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.AI.EMIT, this.onEmit);
11
+ };
12
+
13
+ onEmit = async ({ type = "", args = {} }: AiEmitPayload = {}) => {
14
+ const fn = this.PARAMS.AI.ALGORITHMS[type];
15
+ if (!fn) return null;
16
+
17
+ return fn(args, this);
18
+ };
19
+ }
@@ -0,0 +1,48 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { AiEmit } from "../modules/ai.emit.js";
4
+ import { createAiTestModule, registerAiPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
5
+
6
+ describe("AiEmit", () => {
7
+ beforeEach(() => {
8
+ registerAiPluginVne();
9
+ });
10
+
11
+ it("calls registered algorithm with args and module", async () => {
12
+ const algorithm = vi.fn(async (args, { emitOne }) => {
13
+ expect(typeof emitOne).toBe("function");
14
+ return args.value ?? null;
15
+ });
16
+ registerAiPluginVne({ ALGORITHMS: { strong: algorithm } });
17
+
18
+ const { module } = createAiTestModule(AiEmit);
19
+ const result = await (module as AiEmit).onEmit({ type: "strong", args: { value: 42 } });
20
+
21
+ expect(algorithm).toHaveBeenCalledOnce();
22
+ expect(algorithm.mock.calls[0]?.[0]).toEqual({ value: 42 });
23
+ expect(algorithm.mock.calls[0]?.[1]).toBe(module);
24
+ expect(result).toBe(42);
25
+ });
26
+
27
+ it("returns null for unknown type", async () => {
28
+ const { module } = createAiTestModule(AiEmit);
29
+
30
+ const result = await (module as AiEmit).onEmit({
31
+ type: "missing",
32
+ args: { board: null, turn: "white" },
33
+ });
34
+
35
+ expect(result).toBeNull();
36
+ });
37
+
38
+ it("returns null when ALGORITHMS is empty", async () => {
39
+ const { observer } = createAiTestModule(AiEmit);
40
+
41
+ const result = await observer.emitOne(SUBSCRIBE_EVENTS.EMIT, {
42
+ type: "random",
43
+ args: { board: null, turn: "white" },
44
+ });
45
+
46
+ expect(result).toBeNull();
47
+ });
48
+ });
@@ -0,0 +1,13 @@
1
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.ai";
2
+ import { createTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
3
+
4
+ export const registerAiPluginVne = (params: Partial<typeof PARAMS> = {}) => {
5
+ registerCoreVne();
6
+ registerVnePlugin(PLUGIN_NAME, {
7
+ constants: CONSTANTS,
8
+ events: SUBSCRIBE_EVENTS,
9
+ params: { ...PARAMS, ...params, ALGORITHMS: { ...PARAMS.ALGORITHMS, ...(params.ALGORITHMS ?? {}) } },
10
+ });
11
+ };
12
+
13
+ export { createTestModule as createAiTestModule, SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME };
package/src/types.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.ai";
3
+
4
+ export type AiPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents>;
5
+ export type AiPluginConstants = ModuleCoreConstants;
6
+ export type AiPluginSettings = ModuleCoreSettings;
7
+ export type AiPluginParams = ModuleCoreParams & Record<PluginName, Params>;
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }