@zhin.js/plugin-lottery 1.0.2 → 1.0.4
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.
- package/agent/runtime-tools.ts +57 -0
- package/lib/lottery-agent-deps.d.ts +7 -2
- package/lib/lottery-agent-deps.d.ts.map +1 -1
- package/lib/lottery-agent-deps.js +13 -10
- package/lib/lottery-agent-deps.js.map +1 -1
- package/package.json +5 -5
- package/plugin.ts +10 -1
- package/src/lottery-agent-deps.ts +11 -10
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge agent/tools/* authoring definitions into the Plugin Runtime Agent Host.
|
|
3
|
+
* Loaded lazily from plugin.ts only when agentToolsHostToken is present, so
|
|
4
|
+
* IM-only installs never pull @zhin.js/agent into the module graph.
|
|
5
|
+
* Lives outside src/ (like the other agent/ authoring files) and is therefore
|
|
6
|
+
* not part of the tsc build — the Plugin Runtime loads it from source.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentToolsHost } from '@zhin.js/plugin-runtime';
|
|
9
|
+
import syncTool from './tools/sync.js';
|
|
10
|
+
import computeRecommendTool from './tools/compute_recommend.js';
|
|
11
|
+
import historyTool from './tools/history.js';
|
|
12
|
+
import getModelStateTool from './tools/get_model_state.js';
|
|
13
|
+
import listPendingTool from './tools/list_pending.js';
|
|
14
|
+
import savePredictionTool from './tools/save_prediction.js';
|
|
15
|
+
import statsSnapshotTool from './tools/stats_snapshot.js';
|
|
16
|
+
|
|
17
|
+
interface AuthoringToolLike {
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly inputSchema?: unknown;
|
|
20
|
+
readonly keywords?: readonly string[];
|
|
21
|
+
readonly tags?: readonly string[];
|
|
22
|
+
readonly platforms?: readonly string[];
|
|
23
|
+
readonly scopes?: readonly ('private' | 'group' | 'channel')[];
|
|
24
|
+
readonly permissions?: readonly string[];
|
|
25
|
+
readonly hidden?: boolean;
|
|
26
|
+
execute(input: never, ctx?: unknown): unknown | Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const TOOLS: ReadonlyArray<readonly [string, AuthoringToolLike]> = [
|
|
30
|
+
['lottery_sync', syncTool as AuthoringToolLike],
|
|
31
|
+
['lottery_compute_recommend', computeRecommendTool as AuthoringToolLike],
|
|
32
|
+
['lottery_history', historyTool as AuthoringToolLike],
|
|
33
|
+
['lottery_get_model_state', getModelStateTool as AuthoringToolLike],
|
|
34
|
+
['lottery_list_pending', listPendingTool as AuthoringToolLike],
|
|
35
|
+
['lottery_save_prediction', savePredictionTool as AuthoringToolLike],
|
|
36
|
+
['lottery_stats_snapshot', statsSnapshotTool as AuthoringToolLike],
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/** Register every lottery agent tool for this generation; returns disposal. */
|
|
40
|
+
export function registerLotteryAgentTools(host: AgentToolsHost): () => void {
|
|
41
|
+
const disposers = TOOLS.map(([name, tool]) => host.register({
|
|
42
|
+
name,
|
|
43
|
+
description: tool.description,
|
|
44
|
+
inputSchema: tool.inputSchema,
|
|
45
|
+
source: 'lottery',
|
|
46
|
+
...(tool.keywords ? { keywords: tool.keywords } : {}),
|
|
47
|
+
...(tool.tags ? { tags: tool.tags } : {}),
|
|
48
|
+
...(tool.platforms ? { platforms: tool.platforms } : {}),
|
|
49
|
+
...(tool.scopes ? { scopes: tool.scopes } : {}),
|
|
50
|
+
...(tool.permissions ? { permissions: tool.permissions } : {}),
|
|
51
|
+
...(tool.hidden !== undefined ? { hidden: tool.hidden } : {}),
|
|
52
|
+
execute: (input) => tool.execute(input as never, { pluginName: 'lottery', runtimeName: name }),
|
|
53
|
+
}));
|
|
54
|
+
return () => {
|
|
55
|
+
for (const dispose of disposers.splice(0)) dispose();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
3
|
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
4
|
*/
|
|
5
|
+
import { type Dispose } from '@zhin.js/plugin-runtime';
|
|
5
6
|
import type { GameId } from './types.js';
|
|
6
7
|
import type { LotteryDb } from './db.js';
|
|
7
8
|
import type { Kl8Config } from './games/kl8-groups.js';
|
|
@@ -18,7 +19,11 @@ export interface LotteryAgentDeps {
|
|
|
18
19
|
pipelinePush: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare function setLotteryAgentDeps(deps: LotteryAgentDeps): void;
|
|
21
|
-
/**
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
24
|
+
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
25
|
+
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerLotteryAgentDeps(deps: LotteryAgentDeps): Dispose;
|
|
23
28
|
export declare function getLotteryAgentDeps(): LotteryAgentDeps;
|
|
24
29
|
//# sourceMappingURL=lottery-agent-deps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lottery-agent-deps.d.ts","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,SAAS,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,CAAC;IAC7E,YAAY,EAAE,MAAM,MAAM,EAAE,CAAC;IAC7B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,YAAY,EAAE,OAAO,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"lottery-agent-deps.d.ts","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAuC,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,SAAS,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,CAAC;IAC7E,YAAY,EAAE,MAAM,MAAM,EAAE,CAAC;IAC7B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,YAAY,EAAE,OAAO,CAAC;CACvB;AAMD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAExE;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAItD"}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
|
+
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
|
+
*/
|
|
5
|
+
import { createGenerationStore, DisposeStack } from '@zhin.js/plugin-runtime';
|
|
6
|
+
const agentDepsStore = createGenerationStore('lottery/agent-deps');
|
|
1
7
|
let _deps = null;
|
|
2
|
-
const registrations = [];
|
|
3
8
|
export function setLotteryAgentDeps(deps) {
|
|
4
9
|
_deps = deps;
|
|
5
10
|
}
|
|
6
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
13
|
+
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
14
|
+
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
15
|
+
*/
|
|
7
16
|
export function registerLotteryAgentDeps(deps) {
|
|
8
|
-
|
|
9
|
-
registrations.push(registration);
|
|
10
|
-
return () => {
|
|
11
|
-
const index = registrations.lastIndexOf(registration);
|
|
12
|
-
if (index >= 0)
|
|
13
|
-
registrations.splice(index, 1);
|
|
14
|
-
};
|
|
17
|
+
return agentDepsStore.provide({ lifecycle: new DisposeStack() }, deps);
|
|
15
18
|
}
|
|
16
19
|
export function getLotteryAgentDeps() {
|
|
17
|
-
const deps =
|
|
20
|
+
const deps = agentDepsStore.tryUse() ?? _deps;
|
|
18
21
|
if (!deps)
|
|
19
22
|
throw new Error('lottery agent deps not initialized');
|
|
20
23
|
return deps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lottery-agent-deps.js","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lottery-agent-deps.js","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAgB,MAAM,yBAAyB,CAAC;AAc5F,MAAM,cAAc,GAAG,qBAAqB,CAAmB,oBAAoB,CAAC,CAAC;AAErF,IAAI,KAAK,GAA4B,IAAI,CAAC;AAE1C,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,KAAK,GAAG,IAAI,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAsB;IAC7D,OAAO,cAAc,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,YAAY,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC;IAC9C,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-lottery",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Multi-game lottery analysis for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zhin.js/
|
|
45
|
-
"@zhin.js/
|
|
44
|
+
"@zhin.js/command": "1.0.3",
|
|
45
|
+
"@zhin.js/plugin-runtime": "1.1.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^6.0.3",
|
|
49
49
|
"vitest": "^4.1.10",
|
|
50
50
|
"zod": "^4.4.3",
|
|
51
|
-
"@zhin.js/agent": "1.0.
|
|
51
|
+
"@zhin.js/agent": "1.0.6"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"zod": "^4.0.0",
|
|
55
|
-
"@zhin.js/agent": "1.0.
|
|
55
|
+
"@zhin.js/agent": "1.0.6"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@zhin.js/agent": {
|
package/plugin.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
definePlugin,
|
|
3
|
+
agentToolsHostToken,
|
|
3
4
|
databaseHostToken,
|
|
4
5
|
outboundHostToken,
|
|
5
6
|
scheduleHostToken,
|
|
@@ -29,7 +30,7 @@ export default definePlugin<LotteryConfig>({
|
|
|
29
30
|
metadata: {
|
|
30
31
|
displayName: 'Lottery',
|
|
31
32
|
},
|
|
32
|
-
setup(context) {
|
|
33
|
+
async setup(context) {
|
|
33
34
|
const config = resolveLotteryConfig(context.config.get());
|
|
34
35
|
const db = context.resources.has(databaseHostToken)
|
|
35
36
|
? context.resources.use(databaseHostToken)
|
|
@@ -74,6 +75,14 @@ export default definePlugin<LotteryConfig>({
|
|
|
74
75
|
pipelinePush: config.pushTargets.length > 0,
|
|
75
76
|
}));
|
|
76
77
|
|
|
78
|
+
// Agent tools (agent/tools/*): register into the Runtime Agent Host when AI
|
|
79
|
+
// is installed. Lazy import keeps @zhin.js/agent out of IM-only installs.
|
|
80
|
+
if (context.resources.has(agentToolsHostToken)) {
|
|
81
|
+
const agentTools = context.resources.use(agentToolsHostToken);
|
|
82
|
+
const { registerLotteryAgentTools } = await import('./agent/runtime-tools.js');
|
|
83
|
+
context.lifecycle.add(registerLotteryAgentTools(agentTools));
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
if (!context.resources.has(scheduleHostToken) || !config.scheduleEnabled) {
|
|
78
87
|
return;
|
|
79
88
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
3
|
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
4
|
*/
|
|
5
|
+
import { createGenerationStore, DisposeStack, type Dispose } from '@zhin.js/plugin-runtime';
|
|
5
6
|
import type { GameId } from './types.js';
|
|
6
7
|
import type { LotteryDb } from './db.js';
|
|
7
8
|
import type { Kl8Config } from './games/kl8-groups.js';
|
|
@@ -15,25 +16,25 @@ export interface LotteryAgentDeps {
|
|
|
15
16
|
pipelinePush: boolean;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
const agentDepsStore = createGenerationStore<LotteryAgentDeps>('lottery/agent-deps');
|
|
20
|
+
|
|
18
21
|
let _deps: LotteryAgentDeps | null = null;
|
|
19
|
-
const registrations: Array<{ readonly value: LotteryAgentDeps }> = [];
|
|
20
22
|
|
|
21
23
|
export function setLotteryAgentDeps(deps: LotteryAgentDeps): void {
|
|
22
24
|
_deps = deps;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
27
|
+
/**
|
|
28
|
+
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
29
|
+
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
30
|
+
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
31
|
+
*/
|
|
32
|
+
export function registerLotteryAgentDeps(deps: LotteryAgentDeps): Dispose {
|
|
33
|
+
return agentDepsStore.provide({ lifecycle: new DisposeStack() }, deps);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export function getLotteryAgentDeps(): LotteryAgentDeps {
|
|
36
|
-
const deps =
|
|
37
|
+
const deps = agentDepsStore.tryUse() ?? _deps;
|
|
37
38
|
if (!deps) throw new Error('lottery agent deps not initialized');
|
|
38
39
|
return deps;
|
|
39
40
|
}
|