@zhin.js/plugin-lottery 1.0.8 → 1.1.0
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/skills/lottery.md +2 -10
- package/commands/lottery/{[game:string=].js → [[game]].js} +7 -6
- package/commands/lottery/{[game:string=].ts → [[game]].ts} +6 -6
- package/commands/lottery-backtest/{[game:string=].js → [[game]].js} +6 -7
- package/commands/lottery-backtest/{[game:string=].ts → [[game]].ts} +5 -6
- package/commands/lottery-history/{[game:string].js → [game].js} +5 -7
- package/commands/lottery-history/{[game:string].ts → [game].ts} +6 -6
- package/commands/lottery-stats/{[game:string].js → [game].js} +6 -7
- package/commands/lottery-stats/{[game:string].ts → [game].ts} +5 -6
- package/commands/lottery-today.js +4 -7
- package/commands/lottery-today.ts +5 -6
- package/commands/lottery-train/{[game:string=].js → [[game]].js} +6 -7
- package/commands/lottery-train/{[game:string=].ts → [[game]].ts} +5 -6
- 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/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 +15 -9
- package/plugin.js +22 -35
- 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/pipeline.ts +5 -14
- package/src/runtime-state.ts +7 -14
- package/tools/compute-recommend.js +12 -0
- package/tools/compute-recommend.ts +12 -0
- package/tools/get-model-state.js +12 -0
- package/tools/get-model-state.ts +12 -0
- package/tools/history.js +18 -0
- package/tools/history.ts +17 -0
- package/tools/list-pending.js +12 -0
- package/tools/list-pending.ts +12 -0
- package/tools/save-prediction.js +12 -0
- package/tools/save-prediction.ts +12 -0
- package/tools/stats-snapshot.js +12 -0
- package/tools/stats-snapshot.ts +12 -0
- package/tools/sync.js +16 -0
- package/tools/sync.ts +21 -0
- 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/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
|
@@ -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,IAAI,IAAI,EAAE,CAAC,CAAC;IACpC,MAAM,GAAG,GAAsB,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAClE,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,MAAM,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/C,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,C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AAC,GAAG,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE;QACrC,SAAS,EAAE,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS;QACxD,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,MAAM,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC;QACvC,QAAQ,EAAE,MAAM,oBAAoB,CAAC,EAAE,EAAE,GAAG,CAAC;QAC7C,GAAG,EAAE,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;KACrC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AACxF,CAAC"}
|
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,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
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,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAiBnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,SAAS,CAAC;IACd,YAAY,EAAE,MAAM,MAAM,EAAE,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,SAAS,CAAC;IACf,QAAQ,EAAE;QACR,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IACF,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;CACpD;AA0BD,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,YAAY,EAClB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CA0G7B;AAED,wBAAgB,mBAAmB,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;AACp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2BAA2B;YAC5D,CAAC,CAAC,SAAS,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,OAAO,CAAC,IAAI,IAAI,UAAU,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChD,MAAM,IAAI,CAAC,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.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Multi-game lottery analysis for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"src",
|
|
21
21
|
"lib",
|
|
22
22
|
"agent",
|
|
23
|
+
"tools",
|
|
23
24
|
"evals",
|
|
24
25
|
"README.md"
|
|
25
26
|
],
|
|
@@ -41,24 +42,25 @@
|
|
|
41
42
|
},
|
|
42
43
|
"license": "MIT",
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"@zhin.js/
|
|
45
|
+
"zod": "^4.4.3",
|
|
46
|
+
"@zhin.js/tool": "1.1.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"typescript": "^6.0.3",
|
|
49
50
|
"vitest": "^4.1.10",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
51
|
+
"@zhin.js/agent": "1.1.23",
|
|
52
|
+
"zhin.js": "1.1.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"@zhin.js/
|
|
55
|
+
"@zhin.js/agent": "^1.1.23",
|
|
56
|
+
"@zhin.js/command": "^1.1.0",
|
|
57
|
+
"zhin.js": "^1.1.0"
|
|
56
58
|
},
|
|
57
59
|
"peerDependenciesMeta": {
|
|
58
60
|
"@zhin.js/agent": {
|
|
59
61
|
"optional": true
|
|
60
62
|
},
|
|
61
|
-
"
|
|
63
|
+
"@zhin.js/command": {
|
|
62
64
|
"optional": true
|
|
63
65
|
}
|
|
64
66
|
},
|
|
@@ -84,12 +86,16 @@
|
|
|
84
86
|
{
|
|
85
87
|
"package": "@zhin.js/command",
|
|
86
88
|
"api": "^1.0.0"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"package": "@zhin.js/tool",
|
|
92
|
+
"api": "^1.0.0"
|
|
87
93
|
}
|
|
88
94
|
],
|
|
89
95
|
"plugins": []
|
|
90
96
|
},
|
|
91
97
|
"scripts": {
|
|
92
|
-
"build": "tsc",
|
|
98
|
+
"build": "pnpm run clean && tsc",
|
|
93
99
|
"clean": "rimraf lib",
|
|
94
100
|
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/utils/lottery/tests"
|
|
95
101
|
}
|
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
|
});
|
package/src/agent/prompts.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function buildDailyPipelinePrompt(ctx: LotteryAgentContext): string {
|
|
|
15
15
|
return [
|
|
16
16
|
'[lottery daily_pipeline]',
|
|
17
17
|
`games: ${games}`,
|
|
18
|
-
'Steps:
|
|
18
|
+
'Steps: synchronize draws → list pending predictions → compute recommendations → save predictions',
|
|
19
19
|
ctx.push ? 'push: true' : 'push: false',
|
|
20
20
|
].join('\n');
|
|
21
21
|
}
|
package/src/agent/read-skills.ts
CHANGED
|
@@ -18,9 +18,9 @@ export function readSkillMarkdown(...parts: string[]): string {
|
|
|
18
18
|
export function buildLotteryAgentSystemPrompt(): string {
|
|
19
19
|
const skills = readSkillMarkdown('lottery');
|
|
20
20
|
return [
|
|
21
|
-
'你是 Zhin 彩票分析 Agent
|
|
22
|
-
'可用 web_search
|
|
23
|
-
'
|
|
21
|
+
'你是 Zhin 彩票分析 Agent。使用当前彩票插件提供的工具查库,算法流程见 skills。',
|
|
22
|
+
'可用 web_search 检索公开分析资料;推荐号码只能来自“Compute lottery recommendation”工具,不得臆造或篡改。',
|
|
23
|
+
'需要保存推荐时必须调用“Save a pending lottery prediction”工具,不得声称已保存但未调用。',
|
|
24
24
|
'',
|
|
25
25
|
skills || '(skills 未加载,请依赖工具返回的统计数据。)',
|
|
26
26
|
].join('\n');
|
package/src/command-helpers.ts
CHANGED
|
@@ -4,17 +4,16 @@ import {
|
|
|
4
4
|
resolveLotteryConfig,
|
|
5
5
|
type LotteryConfig,
|
|
6
6
|
} from './config.js';
|
|
7
|
-
import { getLotteryDb } from './db-store.js';
|
|
8
7
|
import type { LotteryDb } from './db.js';
|
|
9
8
|
import { formatPipelineReply, runLotteryPipeline, type PipelineDeps } from './pipeline.js';
|
|
10
9
|
|
|
11
10
|
export function buildPipelineDeps(
|
|
12
11
|
raw: Partial<LotteryConfig> | undefined,
|
|
13
|
-
db: LotteryDb
|
|
12
|
+
db: LotteryDb,
|
|
14
13
|
): PipelineDeps {
|
|
15
14
|
const config = resolveLotteryConfig(raw);
|
|
16
15
|
return {
|
|
17
|
-
|
|
16
|
+
db,
|
|
18
17
|
enabledGames: () => lotteryEnabledGames(config),
|
|
19
18
|
historyLimit: config.historyLimit,
|
|
20
19
|
pickCount: config.pickCount,
|
|
@@ -28,8 +27,9 @@ export function buildPipelineDeps(
|
|
|
28
27
|
},
|
|
29
28
|
weightPersist: config.weightPersistEnabled,
|
|
30
29
|
weightHoldoutFallback: config.weightHoldoutFallback,
|
|
30
|
+
outbound: null,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export { formatPipelineReply, runLotteryPipeline, resolveLotteryConfig
|
|
34
|
+
export { formatPipelineReply, runLotteryPipeline, resolveLotteryConfig };
|
|
35
35
|
export type { LotteryConfig };
|
package/src/config.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface LotteryConfig {
|
|
|
23
23
|
|
|
24
24
|
export interface LotteryPushTargetConfig {
|
|
25
25
|
readonly adapter: string;
|
|
26
|
-
readonly
|
|
26
|
+
readonly endpointKey?: string;
|
|
27
27
|
readonly channelType?: string;
|
|
28
28
|
readonly channelId: string;
|
|
29
29
|
}
|
|
@@ -60,7 +60,7 @@ export function resolveLotteryConfig(raw: Partial<LotteryConfig> | undefined): L
|
|
|
60
60
|
&& t.channelId.length > 0)
|
|
61
61
|
.map((t) => Object.freeze({
|
|
62
62
|
adapter: t.adapter,
|
|
63
|
-
|
|
63
|
+
endpointKey: typeof t.endpointKey === 'string' ? t.endpointKey : t.adapter,
|
|
64
64
|
channelType: typeof t.channelType === 'string' ? t.channelType : 'private',
|
|
65
65
|
channelId: t.channelId,
|
|
66
66
|
}))
|
package/src/db.ts
CHANGED
|
@@ -13,8 +13,9 @@ export interface LotteryDb {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface LotteryModel {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// where 返回 PromiseLike:host 侧是链式 Selection(thenable),memory 侧是 Promise。
|
|
17
|
+
select: (...fields: string[]) => {
|
|
18
|
+
where: (q: Record<string, unknown>) => PromiseLike<unknown[]>;
|
|
18
19
|
};
|
|
19
20
|
insert: (row: Record<string, unknown>) => Promise<unknown>;
|
|
20
21
|
delete: () => { where: (q: Record<string, unknown>) => Promise<unknown> };
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
export { resolveLotteryConfig, DEFAULT_LOTTERY_CONFIG } from './config.js';
|
|
2
2
|
export type { LotteryConfig } from './config.js';
|
|
3
|
-
export {
|
|
4
|
-
getLotteryDb,
|
|
5
|
-
registerLotteryDb,
|
|
6
|
-
setLotteryDb,
|
|
7
|
-
ensureLotteryMemoryDb,
|
|
8
|
-
resetLotteryDb,
|
|
9
|
-
} from './db-store.js';
|
|
10
3
|
export { createInMemoryLotteryDb } from './memory-db.js';
|
|
11
|
-
export { lotteryRuntimeToken
|
|
4
|
+
export { lotteryRuntimeToken } from './runtime-state.js';
|
|
12
5
|
export type { LotteryRuntime } from './runtime-state.js';
|
|
13
6
|
export { formatPipelineReply, runLotteryPipeline } from './pipeline.js';
|