@zhin.js/plugin-lottery 1.0.8 → 1.1.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.
- package/AGENTS.md +8 -0
- package/commands/lottery/{[game:string=].js → [[game]]/index.js} +8 -7
- package/commands/lottery/{[game:string=].ts → [[game]]/index.ts} +8 -8
- package/commands/lottery-backtest/{[game:string=].js → [[game]]/index.js} +9 -10
- package/commands/lottery-backtest/{[game:string=].ts → [[game]]/index.ts} +9 -10
- package/commands/lottery-history/{[game:string].js → [game]/index.js} +7 -9
- package/commands/lottery-history/{[game:string].ts → [game]/index.ts} +8 -8
- package/commands/lottery-stats/{[game:string].js → [game]/index.js} +11 -12
- package/commands/lottery-stats/{[game:string].ts → [game]/index.ts} +11 -12
- package/commands/lottery-today/index.js +14 -0
- package/commands/lottery-today/index.ts +14 -0
- package/commands/lottery-train/{[game:string=].js → [[game]]/index.js} +9 -10
- package/commands/lottery-train/{[game:string=].ts → [[game]]/index.ts} +9 -10
- package/lib/agent/prompts.js +1 -1
- package/lib/agent/prompts.js.map +1 -1
- package/lib/agent/read-skills.js +3 -3
- package/lib/agent/read-skills.js.map +1 -1
- package/lib/command-helpers.d.ts +2 -3
- package/lib/command-helpers.d.ts.map +1 -1
- package/lib/command-helpers.js +4 -4
- package/lib/command-helpers.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -1
- package/lib/config.js.map +1 -1
- package/lib/db.d.ts +2 -2
- package/lib/db.d.ts.map +1 -1
- package/lib/db.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/lottery-tool-handlers.d.ts +6 -16
- package/lib/lottery-tool-handlers.d.ts.map +1 -1
- package/lib/lottery-tool-handlers.js +20 -102
- package/lib/lottery-tool-handlers.js.map +1 -1
- package/lib/memory-db.d.ts +1 -1
- package/lib/memory-db.js +1 -1
- package/lib/pipeline.d.ts +2 -1
- package/lib/pipeline.d.ts.map +1 -1
- package/lib/pipeline.js +3 -13
- package/lib/pipeline.js.map +1 -1
- package/lib/runtime-state.d.ts +6 -7
- package/lib/runtime-state.d.ts.map +1 -1
- package/lib/runtime-state.js +2 -12
- package/lib/runtime-state.js.map +1 -1
- package/package.json +22 -10
- package/plugin.js +22 -35
- package/{agent/skills/lottery.md → skills/lottery/SKILL.md} +9 -9
- package/skills/lottery/tools/compute-recommend/index.js +12 -0
- package/skills/lottery/tools/compute-recommend/index.ts +12 -0
- package/skills/lottery/tools/get-model-state/index.js +12 -0
- package/skills/lottery/tools/get-model-state/index.ts +12 -0
- package/skills/lottery/tools/history/index.js +18 -0
- package/skills/lottery/tools/history/index.ts +17 -0
- package/skills/lottery/tools/list-pending/index.js +12 -0
- package/skills/lottery/tools/list-pending/index.ts +12 -0
- package/skills/lottery/tools/save-prediction/index.js +12 -0
- package/skills/lottery/tools/save-prediction/index.ts +12 -0
- package/skills/lottery/tools/stats-snapshot/index.js +12 -0
- package/skills/lottery/tools/stats-snapshot/index.ts +12 -0
- package/skills/lottery/tools/sync/index.js +16 -0
- package/skills/lottery/tools/sync/index.ts +21 -0
- package/src/agent/prompts.ts +1 -1
- package/src/agent/read-skills.ts +3 -3
- package/src/command-helpers.ts +4 -4
- package/src/config.ts +2 -2
- package/src/db.ts +3 -2
- package/src/index.ts +1 -8
- package/src/lottery-tool-handlers.ts +21 -106
- package/src/memory-db.ts +1 -1
- package/src/pipeline.ts +5 -14
- package/src/runtime-state.ts +7 -14
- package/agent/agent.ts +0 -6
- package/agent/instructions.md +0 -2
- package/agent/runtime-tools.ts +0 -57
- package/agent/tools/compute_recommend.ts +0 -11
- package/agent/tools/get_model_state.ts +0 -11
- package/agent/tools/history.ts +0 -22
- package/agent/tools/list_pending.ts +0 -11
- package/agent/tools/save_prediction.ts +0 -14
- package/agent/tools/stats_snapshot.ts +0 -11
- package/agent/tools/sync.ts +0 -18
- package/commands/lottery-today.js +0 -17
- package/commands/lottery-today.ts +0 -15
- package/lib/db-store.d.ts +0 -10
- package/lib/db-store.d.ts.map +0 -1
- package/lib/db-store.js +0 -30
- package/lib/db-store.js.map +0 -1
- package/lib/lottery-agent-deps.d.ts +0 -29
- package/lib/lottery-agent-deps.d.ts.map +0 -1
- package/lib/lottery-agent-deps.js +0 -25
- package/lib/lottery-agent-deps.js.map +0 -1
- package/lib/push.d.ts +0 -14
- package/lib/push.d.ts.map +0 -1
- package/lib/push.js +0 -24
- package/lib/push.js.map +0 -1
- package/src/db-store.ts +0 -34
- package/src/lottery-agent-deps.ts +0 -40
- package/src/push.ts +0 -35
- /package/evals/{pipeline_smoke.eval.ts → $pipeline_smoke.eval.ts} +0 -0
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import { DISCLAIMER } from './types.js';
|
|
2
1
|
import { parseGameId } from './games/registry.js';
|
|
3
2
|
import { loadDraws } from './db.js';
|
|
4
3
|
import { recommendGame } from './recommend/game-pick.js';
|
|
5
|
-
import { loadGameWeights,
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { getLotteryAgentDeps } from './lottery-agent-deps.js';
|
|
10
|
-
export async function handleGetModelState(game) {
|
|
11
|
-
const deps = getLotteryAgentDeps();
|
|
12
|
-
const db = deps.getDb();
|
|
13
|
-
if (!db)
|
|
14
|
-
return 'db not ready';
|
|
4
|
+
import { loadGameWeights, loadAccuracySnapshot, savePrediction, listPendingPredictions, } from './evaluate/tracker.js';
|
|
5
|
+
import { lotteryKl8 } from './config.js';
|
|
6
|
+
export async function handleGetModelState(runtime, game) {
|
|
7
|
+
const { db } = runtime;
|
|
15
8
|
const gid = parseGameId(game ?? '');
|
|
16
|
-
const ids = gid ? [gid] :
|
|
9
|
+
const ids = gid ? [gid] : runtime.enabledGames;
|
|
17
10
|
const out = [];
|
|
18
11
|
for (const id of ids) {
|
|
19
12
|
const w = await loadGameWeights(db, id);
|
|
@@ -22,35 +15,29 @@ export async function handleGetModelState(game) {
|
|
|
22
15
|
}
|
|
23
16
|
return JSON.stringify(out);
|
|
24
17
|
}
|
|
25
|
-
export async function handleComputeRecommend(game) {
|
|
26
|
-
const deps = getLotteryAgentDeps();
|
|
18
|
+
export async function handleComputeRecommend(runtime, game) {
|
|
27
19
|
const gid = parseGameId(game);
|
|
28
20
|
if (!gid)
|
|
29
21
|
return 'invalid game';
|
|
30
|
-
const db =
|
|
31
|
-
|
|
32
|
-
return 'db not ready';
|
|
33
|
-
const cfg = deps.getConfig();
|
|
22
|
+
const { db, config: cfg } = runtime;
|
|
23
|
+
const kl8 = lotteryKl8(cfg);
|
|
34
24
|
const draws = await loadDraws(db, gid, cfg.historyLimit);
|
|
35
25
|
if (!draws.length)
|
|
36
|
-
return 'no data
|
|
26
|
+
return 'no data; run the lottery draw synchronization tool first';
|
|
37
27
|
const pick = recommendGame(gid, draws, {
|
|
38
|
-
pickCount: gid === 'kl8' ?
|
|
28
|
+
pickCount: gid === 'kl8' ? kl8.pickCount : cfg.pickCount,
|
|
39
29
|
tieSeed: new Date().toISOString().slice(0, 10),
|
|
40
30
|
weights: await loadGameWeights(db, gid),
|
|
41
31
|
accuracy: await loadAccuracySnapshot(db, gid),
|
|
42
|
-
kl8: gid === 'kl8' ?
|
|
32
|
+
kl8: gid === 'kl8' ? kl8 : undefined,
|
|
43
33
|
});
|
|
44
34
|
return JSON.stringify(pick);
|
|
45
35
|
}
|
|
46
|
-
export async function handleSavePrediction(game, numbersJson) {
|
|
47
|
-
const deps = getLotteryAgentDeps();
|
|
36
|
+
export async function handleSavePrediction(runtime, game, numbersJson) {
|
|
48
37
|
const gid = parseGameId(game);
|
|
49
38
|
if (!gid)
|
|
50
39
|
return 'invalid game';
|
|
51
|
-
const db =
|
|
52
|
-
if (!db)
|
|
53
|
-
return 'db not ready';
|
|
40
|
+
const { db } = runtime;
|
|
54
41
|
const numbers = JSON.parse(numbersJson);
|
|
55
42
|
const weights = await loadGameWeights(db, gid);
|
|
56
43
|
await savePrediction(db, {
|
|
@@ -62,93 +49,24 @@ export async function handleSavePrediction(game, numbersJson) {
|
|
|
62
49
|
});
|
|
63
50
|
return JSON.stringify({ ok: true, gameId: gid });
|
|
64
51
|
}
|
|
65
|
-
export async function handleListPending(game) {
|
|
66
|
-
const
|
|
67
|
-
const db = deps.getDb();
|
|
68
|
-
if (!db)
|
|
69
|
-
return 'db not ready';
|
|
52
|
+
export async function handleListPending(runtime, game) {
|
|
53
|
+
const { db } = runtime;
|
|
70
54
|
const gid = parseGameId(game ?? '');
|
|
71
55
|
return JSON.stringify(await listPendingPredictions(db, gid ?? undefined));
|
|
72
56
|
}
|
|
73
|
-
export async function
|
|
74
|
-
const deps = getLotteryAgentDeps();
|
|
75
|
-
const gid = parseGameId(input.game);
|
|
76
|
-
if (!gid)
|
|
77
|
-
return 'invalid game';
|
|
78
|
-
const db = deps.getDb();
|
|
79
|
-
if (!db)
|
|
80
|
-
return 'db not ready';
|
|
81
|
-
const hit = await submitAgentReview(db, {
|
|
82
|
-
gameId: gid,
|
|
83
|
-
predictAt: input.predict_at,
|
|
84
|
-
actualIssue: input.actual_issue,
|
|
85
|
-
actualNumbers: JSON.parse(input.actual_numbers_json),
|
|
86
|
-
analysis: input.analysis ?? '',
|
|
87
|
-
}, deps.getConfig().historyLimit);
|
|
88
|
-
return hit ? JSON.stringify(hit) : 'pending not found';
|
|
89
|
-
}
|
|
90
|
-
export async function handleSetWeights(game, freq, omit, trend) {
|
|
91
|
-
const deps = getLotteryAgentDeps();
|
|
92
|
-
const gid = parseGameId(game);
|
|
93
|
-
if (!gid)
|
|
94
|
-
return 'invalid game';
|
|
95
|
-
const db = deps.getDb();
|
|
96
|
-
if (!db)
|
|
97
|
-
return 'db not ready';
|
|
98
|
-
const w = normalizeWeights({ freq, omit, trend });
|
|
99
|
-
const snap = await loadAccuracySnapshot(db, gid);
|
|
100
|
-
await saveGameWeights(db, gid, w, snap?.evalCount ?? 0, snap?.avgHitRate ?? 0);
|
|
101
|
-
return JSON.stringify({ ok: true, weights: w });
|
|
102
|
-
}
|
|
103
|
-
export async function handleSaveMemory(content, memoryType, game) {
|
|
104
|
-
const deps = getLotteryAgentDeps();
|
|
105
|
-
const db = deps.getDb();
|
|
106
|
-
if (!db)
|
|
107
|
-
return 'db not ready';
|
|
108
|
-
const gid = parseGameId(game ?? '');
|
|
109
|
-
await saveAgentMemory(db, content, memoryType || 'insight', gid ?? '');
|
|
110
|
-
return JSON.stringify({ ok: true });
|
|
111
|
-
}
|
|
112
|
-
export async function handleGetMemory(game, limit) {
|
|
113
|
-
const deps = getLotteryAgentDeps();
|
|
114
|
-
const db = deps.getDb();
|
|
115
|
-
if (!db)
|
|
116
|
-
return 'db not ready';
|
|
117
|
-
const gid = parseGameId(game ?? '');
|
|
118
|
-
const lim = Math.min(50, limit || 20);
|
|
119
|
-
return JSON.stringify(await loadAgentMemory(db, gid ?? undefined, lim));
|
|
120
|
-
}
|
|
121
|
-
export async function handlePublishReport(content, push) {
|
|
122
|
-
const deps = getLotteryAgentDeps();
|
|
123
|
-
const db = deps.getDb();
|
|
124
|
-
if (!db)
|
|
125
|
-
return 'db not ready';
|
|
126
|
-
const text = content.trim();
|
|
127
|
-
if (!text.includes(DISCLAIMER))
|
|
128
|
-
return 'content must include disclaimer';
|
|
129
|
-
const date = new Date().toISOString().slice(0, 10);
|
|
130
|
-
await saveDailyReport(db, { date, picks: [], disclaimer: DISCLAIMER, body: text }, text);
|
|
131
|
-
const doPush = push === true && Boolean(getLotteryOutboundPush());
|
|
132
|
-
if (doPush)
|
|
133
|
-
await pushLotteryReport(text);
|
|
134
|
-
return JSON.stringify({ ok: true, date, pushed: doPush });
|
|
135
|
-
}
|
|
136
|
-
export async function handleStatsSnapshot(game) {
|
|
137
|
-
const deps = getLotteryAgentDeps();
|
|
57
|
+
export async function handleStatsSnapshot(runtime, game) {
|
|
138
58
|
const gid = parseGameId(game);
|
|
139
59
|
if (!gid)
|
|
140
60
|
return 'invalid game';
|
|
141
|
-
const db =
|
|
142
|
-
|
|
143
|
-
return 'db not ready';
|
|
144
|
-
const cfg = deps.getConfig();
|
|
61
|
+
const { db, config: cfg } = runtime;
|
|
62
|
+
const kl8 = lotteryKl8(cfg);
|
|
145
63
|
const draws = await loadDraws(db, gid, Math.min(30, cfg.historyLimit));
|
|
146
64
|
const pick = recommendGame(gid, draws, {
|
|
147
|
-
pickCount: gid === 'kl8' ?
|
|
65
|
+
pickCount: gid === 'kl8' ? kl8.pickCount : cfg.pickCount,
|
|
148
66
|
tieSeed: 'snapshot',
|
|
149
67
|
weights: await loadGameWeights(db, gid),
|
|
150
68
|
accuracy: await loadAccuracySnapshot(db, gid),
|
|
151
|
-
kl8: gid === 'kl8' ?
|
|
69
|
+
kl8: gid === 'kl8' ? kl8 : undefined,
|
|
152
70
|
});
|
|
153
71
|
return JSON.stringify({ sample: draws.length, pick, recentDraws: draws.slice(0, 5) });
|
|
154
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lottery-tool-handlers.js","sourceRoot":"","sources":["../src/lottery-tool-handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lottery-tool-handlers.js","sourceRoot":"","sources":["../src/lottery-tool-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAuB,EAAE,IAAa;IAC9E,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IACvB,MAAM,GAAG,GAAG,WAAW,CAAC,IA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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LotteryDb } from './db.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* In-memory fallback for runtimes without a DatabaseHost.
|
|
4
4
|
* Enough for smoke: today/history/stats/train/backtest/pipeline no longer return「数据库未就绪」.
|
|
5
5
|
*/
|
|
6
6
|
export declare function createInMemoryLotteryDb(): LotteryDb;
|
package/lib/memory-db.js
CHANGED
|
@@ -32,7 +32,7 @@ const TABLE_NAMES = [
|
|
|
32
32
|
MEMORY_TABLE,
|
|
33
33
|
];
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* In-memory fallback for runtimes without a DatabaseHost.
|
|
36
36
|
* Enough for smoke: today/history/stats/train/backtest/pipeline no longer return「数据库未就绪」.
|
|
37
37
|
*/
|
|
38
38
|
export function createInMemoryLotteryDb() {
|
package/lib/pipeline.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { GameId } from './types.js';
|
|
|
2
2
|
import { type LotteryDb } from './db.js';
|
|
3
3
|
import type { Kl8Config } from './games/kl8-groups.js';
|
|
4
4
|
export interface PipelineDeps {
|
|
5
|
-
|
|
5
|
+
db: LotteryDb;
|
|
6
6
|
enabledGames: () => GameId[];
|
|
7
7
|
historyLimit: number;
|
|
8
8
|
pickCount: number;
|
|
@@ -16,6 +16,7 @@ export interface PipelineDeps {
|
|
|
16
16
|
};
|
|
17
17
|
weightPersist: boolean;
|
|
18
18
|
weightHoldoutFallback: boolean;
|
|
19
|
+
outbound: ((text: string) => Promise<void>) | null;
|
|
19
20
|
}
|
|
20
21
|
export interface PipelineOptions {
|
|
21
22
|
gameId?: GameId;
|
package/lib/pipeline.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAY,KAA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BAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAGtE"}
|
package/lib/pipeline.js
CHANGED
|
@@ -4,7 +4,6 @@ import { evaluatePendingPredictions, gamesNeedingPrediction } from './evaluate/r
|
|
|
4
4
|
import { formatBacktestSection, refreshWeightsForGames, runBacktestForGames } from './evaluate/backtest.js';
|
|
5
5
|
import { planRecommendWeights, gamesToPredict, runHoldoutBacktest, } from './evaluate/weight-guard.js';
|
|
6
6
|
import { cancelTodayPendingPredictions } from './evaluate/tracker.js';
|
|
7
|
-
import { pushLotteryReport, getLotteryOutboundPush } from './push.js';
|
|
8
7
|
function backtestOpts(deps) {
|
|
9
8
|
return {
|
|
10
9
|
pickCount: deps.pickCount,
|
|
@@ -24,16 +23,7 @@ async function attachBacktestOverview(db, gameIds, deps, holdoutSummaries = [])
|
|
|
24
23
|
return formatBacktestSection(summaries);
|
|
25
24
|
}
|
|
26
25
|
export async function runLotteryPipeline(deps, options = {}) {
|
|
27
|
-
const db = deps
|
|
28
|
-
if (!db) {
|
|
29
|
-
return {
|
|
30
|
-
sync: 'db not ready',
|
|
31
|
-
review: 'skipped',
|
|
32
|
-
recommend: 'skipped',
|
|
33
|
-
pushed: false,
|
|
34
|
-
reportText: '数据库未就绪',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
26
|
+
const { db } = deps;
|
|
37
27
|
const gameIds = options.gameId ? [options.gameId] : deps.enabledGames();
|
|
38
28
|
const syncParts = [];
|
|
39
29
|
const insertedAll = [];
|
|
@@ -107,8 +97,8 @@ export async function runLotteryPipeline(deps, options = {}) {
|
|
|
107
97
|
: `saved ${needPredict.join(', ')}`;
|
|
108
98
|
}
|
|
109
99
|
let pushed = false;
|
|
110
|
-
if (options.push && reportText &&
|
|
111
|
-
await
|
|
100
|
+
if (options.push && reportText && deps.outbound) {
|
|
101
|
+
await deps.outbound(reportText);
|
|
112
102
|
pushed = true;
|
|
113
103
|
}
|
|
114
104
|
return {
|
package/lib/pipeline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAEnD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAqBtE,SAAS,YAAY,CAAC,IAAkB;IACtC,OAAO;QACL,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;QAC5B,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;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C,QAAQ,CAAC,UAAU,CAAC,CAAC;QAChC,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM;QACpC,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,aAAa;QACxB,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAA0B;IAC5D,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC9D,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
|
package/lib/runtime-state.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import type { LotteryConfig } from './config.js';
|
|
1
2
|
import type { LotteryDb } from './db.js';
|
|
3
|
+
import type { GameId } from './types.js';
|
|
2
4
|
export interface LotteryRuntime {
|
|
3
5
|
readonly db: LotteryDb;
|
|
6
|
+
readonly config: Readonly<LotteryConfig>;
|
|
7
|
+
readonly enabledGames: readonly GameId[];
|
|
8
|
+
readonly outbound: ((text: string) => Promise<void>) | null;
|
|
4
9
|
}
|
|
5
|
-
export declare const lotteryRuntimeToken: import("
|
|
6
|
-
export declare function resolveLotteryRuntime(context: {
|
|
7
|
-
owner?: {
|
|
8
|
-
id?: unknown;
|
|
9
|
-
};
|
|
10
|
-
use<T>(token: typeof lotteryRuntimeToken): T;
|
|
11
|
-
}): LotteryRuntime | undefined;
|
|
10
|
+
export declare const lotteryRuntimeToken: import("zhin.js").Token<LotteryRuntime>;
|
|
12
11
|
//# sourceMappingURL=runtime-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-state.d.ts","sourceRoot":"","sources":["../src/runtime-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-state.d.ts","sourceRoot":"","sources":["../src/runtime-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;CAC7D;AAED,eAAO,MAAM,mBAAmB,yCAG/B,CAAC"}
|
package/lib/runtime-state.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import { createToken } from '
|
|
2
|
-
export const lotteryRuntimeToken = createToken('zhin.lottery.runtime', 'Owner-scoped Lottery
|
|
3
|
-
export function resolveLotteryRuntime(context) {
|
|
4
|
-
try {
|
|
5
|
-
return context.use(lotteryRuntimeToken);
|
|
6
|
-
}
|
|
7
|
-
catch (error) {
|
|
8
|
-
if (context.owner?.id)
|
|
9
|
-
throw error;
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import { createToken } from 'zhin.js';
|
|
2
|
+
export const lotteryRuntimeToken = createToken('zhin.lottery.runtime', 'Owner-scoped Lottery runtime');
|
|
13
3
|
//# sourceMappingURL=runtime-state.js.map
|
package/lib/runtime-state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-state.js","sourceRoot":"","sources":["../src/runtime-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"runtime-state.js","sourceRoot":"","sources":["../src/runtime-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAYtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAC5C,sBAAsB,EACtB,8BAA8B,CAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-lottery",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Multi-game lottery analysis for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"commands",
|
|
20
20
|
"src",
|
|
21
21
|
"lib",
|
|
22
|
-
"
|
|
22
|
+
"AGENTS.md",
|
|
23
|
+
"tools",
|
|
24
|
+
"skills",
|
|
23
25
|
"evals",
|
|
24
26
|
"README.md"
|
|
25
27
|
],
|
|
@@ -41,24 +43,26 @@
|
|
|
41
43
|
},
|
|
42
44
|
"license": "MIT",
|
|
43
45
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"@zhin.js/
|
|
46
|
+
"zod": "^4.4.3",
|
|
47
|
+
"@zhin.js/tool": "1.1.1",
|
|
48
|
+
"@zhin.js/skill": "1.1.1"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"typescript": "^6.0.3",
|
|
49
52
|
"vitest": "^4.1.10",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
53
|
+
"@zhin.js/agent": "1.1.26",
|
|
54
|
+
"zhin.js": "1.1.2"
|
|
52
55
|
},
|
|
53
56
|
"peerDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"@zhin.js/
|
|
57
|
+
"@zhin.js/agent": "^1.1.26",
|
|
58
|
+
"@zhin.js/command": "^1.1.1",
|
|
59
|
+
"zhin.js": "^1.1.2"
|
|
56
60
|
},
|
|
57
61
|
"peerDependenciesMeta": {
|
|
58
62
|
"@zhin.js/agent": {
|
|
59
63
|
"optional": true
|
|
60
64
|
},
|
|
61
|
-
"
|
|
65
|
+
"@zhin.js/command": {
|
|
62
66
|
"optional": true
|
|
63
67
|
}
|
|
64
68
|
},
|
|
@@ -84,12 +88,20 @@
|
|
|
84
88
|
{
|
|
85
89
|
"package": "@zhin.js/command",
|
|
86
90
|
"api": "^1.0.0"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"package": "@zhin.js/tool",
|
|
94
|
+
"api": "^1.0.0"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"package": "@zhin.js/skill",
|
|
98
|
+
"api": "^1.0.0"
|
|
87
99
|
}
|
|
88
100
|
],
|
|
89
101
|
"plugins": []
|
|
90
102
|
},
|
|
91
103
|
"scripts": {
|
|
92
|
-
"build": "tsc",
|
|
104
|
+
"build": "pnpm run clean && tsc",
|
|
93
105
|
"clean": "rimraf lib",
|
|
94
106
|
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/utils/lottery/tests"
|
|
95
107
|
}
|
package/plugin.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { definePlugin,
|
|
2
|
+
import { definePlugin, databaseHostToken, outboundHostToken, scheduleHostToken, } from 'zhin.js';
|
|
3
3
|
import { lotteryEnabledGames, lotteryKl8, resolveLotteryConfig, } from "./lib/config.js";
|
|
4
4
|
import { defineLotteryTables } from "./lib/db.js";
|
|
5
|
-
import { registerLotteryDb } from "./lib/db-store.js";
|
|
6
|
-
import { registerLotteryAgentDeps } from "./lib/lottery-agent-deps.js";
|
|
7
5
|
import { createInMemoryLotteryDb } from "./lib/memory-db.js";
|
|
8
6
|
import { lotteryRuntimeToken } from "./lib/runtime-state.js";
|
|
9
7
|
import { runLotteryPipeline } from "./lib/pipeline.js";
|
|
10
|
-
import { registerLotteryOutboundPush } from "./lib/push.js";
|
|
11
8
|
/**
|
|
12
9
|
* Plugin Runtime:
|
|
13
10
|
* - DB: prefer databaseHostToken; else memory.
|
|
@@ -21,14 +18,15 @@ export default definePlugin({
|
|
|
21
18
|
},
|
|
22
19
|
async setup(context) {
|
|
23
20
|
const config = resolveLotteryConfig(context.config.get());
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
// host 与 memory 模型表面结构兼容(where 均返回 PromiseLike),可直接互换。
|
|
22
|
+
const db = (() => {
|
|
23
|
+
if (context.resources.has(databaseHostToken)) {
|
|
24
|
+
const host = context.resources.use(databaseHostToken);
|
|
25
|
+
defineLotteryTables(host);
|
|
26
|
+
return host;
|
|
27
|
+
}
|
|
28
|
+
return createInMemoryLotteryDb();
|
|
29
|
+
})();
|
|
32
30
|
let outboundPush = null;
|
|
33
31
|
if (context.resources.has(outboundHostToken) && config.pushTargets.length > 0) {
|
|
34
32
|
const outbound = context.resources.use(outboundHostToken);
|
|
@@ -37,9 +35,11 @@ export default definePlugin({
|
|
|
37
35
|
try {
|
|
38
36
|
await outbound.send({
|
|
39
37
|
adapter: target.adapter,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
endpointKey: target.endpointKey || target.adapter,
|
|
39
|
+
conversation: {
|
|
40
|
+
kind: (target.channelType || 'private'),
|
|
41
|
+
id: target.channelId,
|
|
42
|
+
},
|
|
43
43
|
content: text,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -49,26 +49,12 @@ export default definePlugin({
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
context.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
historyLimit: config.historyLimit,
|
|
58
|
-
kl8: lotteryKl8(config),
|
|
59
|
-
}),
|
|
60
|
-
enabledGames: () => lotteryEnabledGames(config),
|
|
61
|
-
scheduleCron: () => config.scheduleCron,
|
|
62
|
-
scheduleEnabled: () => config.scheduleEnabled,
|
|
63
|
-
pipelinePush: config.pushTargets.length > 0,
|
|
52
|
+
context.resources.provide(lotteryRuntimeToken, Object.freeze({
|
|
53
|
+
db,
|
|
54
|
+
config: Object.freeze({ ...config }),
|
|
55
|
+
enabledGames: Object.freeze([...lotteryEnabledGames(config)]),
|
|
56
|
+
outbound: outboundPush,
|
|
64
57
|
}));
|
|
65
|
-
// Agent tools (agent/tools/*): register into the Runtime Agent Host when AI
|
|
66
|
-
// is installed. Lazy import keeps @zhin.js/agent out of IM-only installs.
|
|
67
|
-
if (context.resources.has(agentToolsHostToken)) {
|
|
68
|
-
const agentTools = context.resources.use(agentToolsHostToken);
|
|
69
|
-
const { registerLotteryAgentTools } = await import('./agent/runtime-tools.js');
|
|
70
|
-
context.lifecycle.add(registerLotteryAgentTools(agentTools));
|
|
71
|
-
}
|
|
72
58
|
if (!context.resources.has(scheduleHostToken) || !config.scheduleEnabled) {
|
|
73
59
|
return;
|
|
74
60
|
}
|
|
@@ -79,7 +65,7 @@ export default definePlugin({
|
|
|
79
65
|
description: 'Daily lottery pipeline',
|
|
80
66
|
async execute() {
|
|
81
67
|
await runLotteryPipeline({
|
|
82
|
-
|
|
68
|
+
db,
|
|
83
69
|
enabledGames: () => lotteryEnabledGames(config),
|
|
84
70
|
historyLimit: config.historyLimit,
|
|
85
71
|
pickCount: config.pickCount,
|
|
@@ -93,6 +79,7 @@ export default definePlugin({
|
|
|
93
79
|
},
|
|
94
80
|
weightPersist: config.weightPersistEnabled,
|
|
95
81
|
weightHoldoutFallback: config.weightHoldoutFallback,
|
|
82
|
+
outbound: outboundPush,
|
|
96
83
|
}, { push: config.pushTargets.length > 0 });
|
|
97
84
|
},
|
|
98
85
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Automated daily pipeline — sync, review, recommend, publish
|
|
3
3
|
tools:
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
4
|
+
- "compute-recommend"
|
|
5
|
+
- "get-model-state"
|
|
6
|
+
- "history"
|
|
7
|
+
- "list-pending"
|
|
8
|
+
- "save-prediction"
|
|
9
|
+
- "stats-snapshot"
|
|
10
|
+
- "sync"
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
# Lottery pipeline skill
|
|
@@ -18,14 +18,14 @@ The plugin runs one job (default 18:00):
|
|
|
18
18
|
|
|
19
19
|
1. **Sync** — pull official draws into `lottery_draws`
|
|
20
20
|
2. **Review** — match pending predictions to newly synced issues; tune F/O/T weights
|
|
21
|
-
3. **Recommend** —
|
|
21
|
+
3. **Recommend** — call the lottery recommendation tool for each enabled game
|
|
22
22
|
4. **Push** — send report to endpoint masters (cron only)
|
|
23
23
|
|
|
24
24
|
Manual trigger: `lottery [game]`
|
|
25
25
|
|
|
26
26
|
## Agent role
|
|
27
27
|
|
|
28
|
-
Interactive chat may use
|
|
28
|
+
Interactive chat may use the tools owned by this lottery plugin instance. Tool names are qualified from the runtime owner, so instructions must select them by description instead of assuming an instance key. Recommended numbers must come from the lottery recommendation tool.
|
|
29
29
|
|
|
30
30
|
## Game ids
|
|
31
31
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { handleComputeRecommend } from "../../../../lib/lottery-tool-handlers.js";
|
|
5
|
+
import { lotteryRuntimeToken } from "../../../../lib/runtime-state.js";
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: 'Compute lottery recommendation numbers via F/O/T stats engine',
|
|
8
|
+
inputSchema: z.object({ game: z.string().min(1) }),
|
|
9
|
+
async execute({ game }, context) {
|
|
10
|
+
return handleComputeRecommend(context.use(lotteryRuntimeToken), game);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { handleComputeRecommend } from '../../../../src/lottery-tool-handlers.js';
|
|
4
|
+
import { lotteryRuntimeToken } from '../../../../src/runtime-state.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ game: string }>({
|
|
7
|
+
description: 'Compute lottery recommendation numbers via F/O/T stats engine',
|
|
8
|
+
inputSchema: z.object({ game: z.string().min(1) }),
|
|
9
|
+
async execute({ game }, context) {
|
|
10
|
+
return handleComputeRecommend(context.use(lotteryRuntimeToken), game);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { handleGetModelState } from "../../../../lib/lottery-tool-handlers.js";
|
|
5
|
+
import { lotteryRuntimeToken } from "../../../../lib/runtime-state.js";
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: 'Query model weights and historical hit rate per game',
|
|
8
|
+
inputSchema: z.object({ game: z.string().min(1).optional() }),
|
|
9
|
+
async execute({ game }, context) {
|
|
10
|
+
return handleGetModelState(context.use(lotteryRuntimeToken), game);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { handleGetModelState } from '../../../../src/lottery-tool-handlers.js';
|
|
4
|
+
import { lotteryRuntimeToken } from '../../../../src/runtime-state.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ game?: string }>({
|
|
7
|
+
description: 'Query model weights and historical hit rate per game',
|
|
8
|
+
inputSchema: z.object({ game: z.string().min(1).optional() }),
|
|
9
|
+
async execute({ game }, context) {
|
|
10
|
+
return handleGetModelState(context.use(lotteryRuntimeToken), game);
|
|
11
|
+
},
|
|
12
|
+
});
|