@zhin.js/plugin-lottery 2.0.2 → 2.0.5

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.
Files changed (92) hide show
  1. package/agent/skills/lottery.md +2 -10
  2. package/commands/lottery/{[game:string=].js → [[game]].js} +6 -5
  3. package/commands/lottery/{[game:string=].ts → [[game]].ts} +5 -5
  4. package/commands/lottery-backtest/{[game:string=].js → [[game]].js} +5 -6
  5. package/commands/lottery-backtest/{[game:string=].ts → [[game]].ts} +4 -5
  6. package/commands/lottery-history/{[game:string].js → [game].js} +4 -6
  7. package/commands/lottery-history/{[game:string].ts → [game].ts} +5 -5
  8. package/commands/lottery-stats/{[game:string].js → [game].js} +5 -6
  9. package/commands/lottery-stats/{[game:string].ts → [game].ts} +4 -5
  10. package/commands/lottery-today.js +3 -6
  11. package/commands/lottery-today.ts +4 -5
  12. package/commands/lottery-train/{[game:string=].js → [[game]].js} +5 -6
  13. package/commands/lottery-train/{[game:string=].ts → [[game]].ts} +4 -5
  14. package/lib/agent/prompts.js +1 -1
  15. package/lib/agent/prompts.js.map +1 -1
  16. package/lib/agent/read-skills.js +3 -3
  17. package/lib/agent/read-skills.js.map +1 -1
  18. package/lib/command-helpers.d.ts +2 -3
  19. package/lib/command-helpers.d.ts.map +1 -1
  20. package/lib/command-helpers.js +4 -4
  21. package/lib/command-helpers.js.map +1 -1
  22. package/lib/config.d.ts +1 -1
  23. package/lib/config.d.ts.map +1 -1
  24. package/lib/config.js +1 -1
  25. package/lib/config.js.map +1 -1
  26. package/lib/db.d.ts +2 -2
  27. package/lib/db.d.ts.map +1 -1
  28. package/lib/db.js.map +1 -1
  29. package/lib/index.d.ts +1 -2
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +1 -2
  32. package/lib/index.js.map +1 -1
  33. package/lib/lottery-tool-handlers.d.ts +6 -16
  34. package/lib/lottery-tool-handlers.d.ts.map +1 -1
  35. package/lib/lottery-tool-handlers.js +20 -102
  36. package/lib/lottery-tool-handlers.js.map +1 -1
  37. package/lib/pipeline.d.ts +2 -1
  38. package/lib/pipeline.d.ts.map +1 -1
  39. package/lib/pipeline.js +3 -13
  40. package/lib/pipeline.js.map +1 -1
  41. package/lib/runtime-state.d.ts +5 -6
  42. package/lib/runtime-state.d.ts.map +1 -1
  43. package/lib/runtime-state.js +1 -11
  44. package/lib/runtime-state.js.map +1 -1
  45. package/package.json +13 -11
  46. package/plugin.js +22 -35
  47. package/src/agent/prompts.ts +1 -1
  48. package/src/agent/read-skills.ts +3 -3
  49. package/src/command-helpers.ts +4 -4
  50. package/src/config.ts +2 -2
  51. package/src/db.ts +3 -2
  52. package/src/index.ts +1 -8
  53. package/src/lottery-tool-handlers.ts +21 -106
  54. package/src/pipeline.ts +5 -14
  55. package/src/runtime-state.ts +6 -13
  56. package/tools/compute-recommend.js +12 -0
  57. package/tools/compute-recommend.ts +12 -0
  58. package/tools/get-model-state.js +12 -0
  59. package/tools/get-model-state.ts +12 -0
  60. package/tools/history.js +18 -0
  61. package/tools/history.ts +17 -0
  62. package/tools/list-pending.js +12 -0
  63. package/tools/list-pending.ts +12 -0
  64. package/tools/save-prediction.js +12 -0
  65. package/tools/save-prediction.ts +12 -0
  66. package/tools/stats-snapshot.js +12 -0
  67. package/tools/stats-snapshot.ts +12 -0
  68. package/tools/sync.js +16 -0
  69. package/tools/sync.ts +21 -0
  70. package/agent/runtime-tools.ts +0 -57
  71. package/agent/tools/compute_recommend.ts +0 -11
  72. package/agent/tools/get_model_state.ts +0 -11
  73. package/agent/tools/history.ts +0 -22
  74. package/agent/tools/list_pending.ts +0 -11
  75. package/agent/tools/save_prediction.ts +0 -14
  76. package/agent/tools/stats_snapshot.ts +0 -11
  77. package/agent/tools/sync.ts +0 -18
  78. package/lib/db-store.d.ts +0 -10
  79. package/lib/db-store.d.ts.map +0 -1
  80. package/lib/db-store.js +0 -30
  81. package/lib/db-store.js.map +0 -1
  82. package/lib/lottery-agent-deps.d.ts +0 -29
  83. package/lib/lottery-agent-deps.d.ts.map +0 -1
  84. package/lib/lottery-agent-deps.js +0 -25
  85. package/lib/lottery-agent-deps.js.map +0 -1
  86. package/lib/push.d.ts +0 -14
  87. package/lib/push.d.ts.map +0 -1
  88. package/lib/push.js +0 -24
  89. package/lib/push.js.map +0 -1
  90. package/src/db-store.ts +0 -34
  91. package/src/lottery-agent-deps.ts +0 -40
  92. package/src/push.ts +0 -35
@@ -1,29 +1,21 @@
1
- import { DISCLAIMER, type GameId } from './types.js';
1
+ import type { GameId } from './types.js';
2
2
 
3
3
  import { parseGameId } from './games/registry.js';
4
4
  import { loadDraws } from './db.js';
5
5
  import { recommendGame } from './recommend/game-pick.js';
6
6
  import {
7
7
  loadGameWeights,
8
- saveGameWeights,
9
8
  loadAccuracySnapshot,
10
9
  savePrediction,
11
10
  listPendingPredictions,
12
- submitAgentReview,
13
- saveAgentMemory,
14
- loadAgentMemory,
15
11
  } from './evaluate/tracker.js';
16
- import { saveDailyReport } from './recommend/report.js';
17
- import { pushLotteryReport, getLotteryOutboundPush } from './push.js';
18
- import { normalizeWeights } from './stats/weights.js';
19
- import { getLotteryAgentDeps } from './lottery-agent-deps.js';
12
+ import type { LotteryRuntime } from './runtime-state.js';
13
+ import { lotteryKl8 } from './config.js';
20
14
 
21
- export async function handleGetModelState(game?: string): Promise<string> {
22
- const deps = getLotteryAgentDeps();
23
- const db = deps.getDb();
24
- if (!db) return 'db not ready';
15
+ export async function handleGetModelState(runtime: LotteryRuntime, game?: string): Promise<string> {
16
+ const { db } = runtime;
25
17
  const gid = parseGameId(game ?? '');
26
- const ids: GameId[] = gid ? [gid] : deps.enabledGames();
18
+ const ids: readonly GameId[] = gid ? [gid] : runtime.enabledGames;
27
19
  const out = [];
28
20
  for (const id of ids) {
29
21
  const w = await loadGameWeights(db, id);
@@ -33,31 +25,27 @@ export async function handleGetModelState(game?: string): Promise<string> {
33
25
  return JSON.stringify(out);
34
26
  }
35
27
 
36
- export async function handleComputeRecommend(game: string): Promise<string> {
37
- const deps = getLotteryAgentDeps();
28
+ export async function handleComputeRecommend(runtime: LotteryRuntime, game: string): Promise<string> {
38
29
  const gid = parseGameId(game);
39
30
  if (!gid) return 'invalid game';
40
- const db = deps.getDb();
41
- if (!db) return 'db not ready';
42
- const cfg = deps.getConfig();
31
+ const { db, config: cfg } = runtime;
32
+ const kl8 = lotteryKl8(cfg);
43
33
  const draws = await loadDraws(db, gid, cfg.historyLimit);
44
- if (!draws.length) return 'no data, run lottery_sync first';
34
+ if (!draws.length) return 'no data; run the lottery draw synchronization tool first';
45
35
  const pick = recommendGame(gid, draws, {
46
- pickCount: gid === 'kl8' ? cfg.kl8.pickCount : cfg.pickCount,
36
+ pickCount: gid === 'kl8' ? kl8.pickCount : cfg.pickCount,
47
37
  tieSeed: new Date().toISOString().slice(0, 10),
48
38
  weights: await loadGameWeights(db, gid),
49
39
  accuracy: await loadAccuracySnapshot(db, gid),
50
- kl8: gid === 'kl8' ? cfg.kl8 : undefined,
40
+ kl8: gid === 'kl8' ? kl8 : undefined,
51
41
  });
52
42
  return JSON.stringify(pick);
53
43
  }
54
44
 
55
- export async function handleSavePrediction(game: string, numbersJson: string): Promise<string> {
56
- const deps = getLotteryAgentDeps();
45
+ export async function handleSavePrediction(runtime: LotteryRuntime, game: string, numbersJson: string): Promise<string> {
57
46
  const gid = parseGameId(game);
58
47
  if (!gid) return 'invalid game';
59
- const db = deps.getDb();
60
- if (!db) return 'db not ready';
48
+ const { db } = runtime;
61
49
  const numbers = JSON.parse(numbersJson);
62
50
  const weights = await loadGameWeights(db, gid);
63
51
  await savePrediction(db, {
@@ -70,97 +58,24 @@ export async function handleSavePrediction(game: string, numbersJson: string): P
70
58
  return JSON.stringify({ ok: true, gameId: gid });
71
59
  }
72
60
 
73
- export async function handleListPending(game?: string): Promise<string> {
74
- const deps = getLotteryAgentDeps();
75
- const db = deps.getDb();
76
- if (!db) return 'db not ready';
61
+ export async function handleListPending(runtime: LotteryRuntime, game?: string): Promise<string> {
62
+ const { db } = runtime;
77
63
  const gid = parseGameId(game ?? '');
78
64
  return JSON.stringify(await listPendingPredictions(db, gid ?? undefined));
79
65
  }
80
66
 
81
- export async function handleSubmitReview(input: {
82
- game: string;
83
- predict_at: string;
84
- actual_issue: string;
85
- actual_numbers_json: string;
86
- analysis: string;
87
- }): Promise<string> {
88
- const deps = getLotteryAgentDeps();
89
- const gid = parseGameId(input.game);
90
- if (!gid) return 'invalid game';
91
- const db = deps.getDb();
92
- if (!db) return 'db not ready';
93
- const hit = await submitAgentReview(
94
- db,
95
- {
96
- gameId: gid,
97
- predictAt: input.predict_at,
98
- actualIssue: input.actual_issue,
99
- actualNumbers: JSON.parse(input.actual_numbers_json),
100
- analysis: input.analysis ?? '',
101
- },
102
- deps.getConfig().historyLimit,
103
- );
104
- return hit ? JSON.stringify(hit) : 'pending not found';
105
- }
106
-
107
- export async function handleSetWeights(game: string, freq: number, omit: number, trend: number): Promise<string> {
108
- const deps = getLotteryAgentDeps();
109
- const gid = parseGameId(game);
110
- if (!gid) return 'invalid game';
111
- const db = deps.getDb();
112
- if (!db) return 'db not ready';
113
- const w = normalizeWeights({ freq, omit, trend });
114
- const snap = await loadAccuracySnapshot(db, gid);
115
- await saveGameWeights(db, gid, w, snap?.evalCount ?? 0, snap?.avgHitRate ?? 0);
116
- return JSON.stringify({ ok: true, weights: w });
117
- }
118
-
119
- export async function handleSaveMemory(content: string, memoryType?: string, game?: string): Promise<string> {
120
- const deps = getLotteryAgentDeps();
121
- const db = deps.getDb();
122
- if (!db) return 'db not ready';
123
- const gid = parseGameId(game ?? '');
124
- await saveAgentMemory(db, content, memoryType || 'insight', gid ?? '');
125
- return JSON.stringify({ ok: true });
126
- }
127
-
128
- export async function handleGetMemory(game?: string, limit?: number): Promise<string> {
129
- const deps = getLotteryAgentDeps();
130
- const db = deps.getDb();
131
- if (!db) return 'db not ready';
132
- const gid = parseGameId(game ?? '');
133
- const lim = Math.min(50, limit || 20);
134
- return JSON.stringify(await loadAgentMemory(db, gid ?? undefined, lim));
135
- }
136
-
137
- export async function handlePublishReport(content: string, push?: boolean): Promise<string> {
138
- const deps = getLotteryAgentDeps();
139
- const db = deps.getDb();
140
- if (!db) return 'db not ready';
141
- const text = content.trim();
142
- if (!text.includes(DISCLAIMER)) return 'content must include disclaimer';
143
- const date = new Date().toISOString().slice(0, 10);
144
- await saveDailyReport(db, { date, picks: [] as never[], disclaimer: DISCLAIMER, body: text }, text);
145
- const doPush = push === true && Boolean(getLotteryOutboundPush());
146
- if (doPush) await pushLotteryReport(text);
147
- return JSON.stringify({ ok: true, date, pushed: doPush });
148
- }
149
-
150
- export async function handleStatsSnapshot(game: string): Promise<string> {
151
- const deps = getLotteryAgentDeps();
67
+ export async function handleStatsSnapshot(runtime: LotteryRuntime, game: string): Promise<string> {
152
68
  const gid = parseGameId(game);
153
69
  if (!gid) return 'invalid game';
154
- const db = deps.getDb();
155
- if (!db) return 'db not ready';
156
- const cfg = deps.getConfig();
70
+ const { db, config: cfg } = runtime;
71
+ const kl8 = lotteryKl8(cfg);
157
72
  const draws = await loadDraws(db, gid, Math.min(30, cfg.historyLimit));
158
73
  const pick = recommendGame(gid, draws, {
159
- pickCount: gid === 'kl8' ? cfg.kl8.pickCount : cfg.pickCount,
74
+ pickCount: gid === 'kl8' ? kl8.pickCount : cfg.pickCount,
160
75
  tieSeed: 'snapshot',
161
76
  weights: await loadGameWeights(db, gid),
162
77
  accuracy: await loadAccuracySnapshot(db, gid),
163
- kl8: gid === 'kl8' ? cfg.kl8 : undefined,
78
+ kl8: gid === 'kl8' ? kl8 : undefined,
164
79
  });
165
80
  return JSON.stringify({ sample: draws.length, pick, recentDraws: draws.slice(0, 5) });
166
81
  }
package/src/pipeline.ts CHANGED
@@ -16,11 +16,10 @@ import {
16
16
  runHoldoutBacktest,
17
17
  } from './evaluate/weight-guard.js';
18
18
  import { cancelTodayPendingPredictions } from './evaluate/tracker.js';
19
- import { pushLotteryReport, getLotteryOutboundPush } from './push.js';
20
19
  import type { Kl8Config } from './games/kl8-groups.js';
21
20
 
22
21
  export interface PipelineDeps {
23
- getDb: () => LotteryDb | null;
22
+ db: LotteryDb;
24
23
  enabledGames: () => GameId[];
25
24
  historyLimit: number;
26
25
  pickCount: number;
@@ -34,6 +33,7 @@ export interface PipelineDeps {
34
33
  };
35
34
  weightPersist: boolean;
36
35
  weightHoldoutFallback: boolean;
36
+ outbound: ((text: string) => Promise<void>) | null;
37
37
  }
38
38
 
39
39
  function backtestOpts(deps: PipelineDeps) {
@@ -77,16 +77,7 @@ export async function runLotteryPipeline(
77
77
  deps: PipelineDeps,
78
78
  options: PipelineOptions = {},
79
79
  ): Promise<PipelineStepResult> {
80
- const db = deps.getDb();
81
- if (!db) {
82
- return {
83
- sync: 'db not ready',
84
- review: 'skipped',
85
- recommend: 'skipped',
86
- pushed: false,
87
- reportText: '数据库未就绪',
88
- };
89
- }
80
+ const { db } = deps;
90
81
 
91
82
  const gameIds = options.gameId ? [options.gameId] : deps.enabledGames();
92
83
  const syncParts: string[] = [];
@@ -179,8 +170,8 @@ export async function runLotteryPipeline(
179
170
  }
180
171
 
181
172
  let pushed = false;
182
- if (options.push && reportText && getLotteryOutboundPush()) {
183
- await pushLotteryReport(reportText);
173
+ if (options.push && reportText && deps.outbound) {
174
+ await deps.outbound(reportText);
184
175
  pushed = true;
185
176
  }
186
177
 
@@ -1,23 +1,16 @@
1
1
  import { createToken } from '@zhin.js/plugin-runtime';
2
+ import type { LotteryConfig } from './config.js';
2
3
  import type { LotteryDb } from './db.js';
4
+ import type { GameId } from './types.js';
3
5
 
4
6
  export interface LotteryRuntime {
5
7
  readonly db: LotteryDb;
8
+ readonly config: Readonly<LotteryConfig>;
9
+ readonly enabledGames: readonly GameId[];
10
+ readonly outbound: ((text: string) => Promise<void>) | null;
6
11
  }
7
12
 
8
13
  export const lotteryRuntimeToken = createToken<LotteryRuntime>(
9
14
  'zhin.lottery.runtime',
10
- 'Owner-scoped Lottery database',
15
+ 'Owner-scoped Lottery runtime',
11
16
  );
12
-
13
- export function resolveLotteryRuntime(context: {
14
- owner?: { id?: unknown };
15
- use<T>(token: typeof lotteryRuntimeToken): T;
16
- }): LotteryRuntime | undefined {
17
- try {
18
- return context.use(lotteryRuntimeToken) as LotteryRuntime;
19
- } catch (error) {
20
- if (context.owner?.id) throw error;
21
- return undefined;
22
- }
23
- }
@@ -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
+ });
@@ -0,0 +1,18 @@
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 { parseGameId } from "../lib/games/registry.js";
5
+ import { loadDraws } from "../lib/db.js";
6
+ import { lotteryRuntimeToken } from "../lib/runtime-state.js";
7
+ export default defineAgentTool({
8
+ description: 'Query historical lottery draws',
9
+ inputSchema: z.object({ game: z.string().min(1), count: z.number().int().positive().optional() }),
10
+ async execute({ game, count }, context) {
11
+ const runtime = context.use(lotteryRuntimeToken);
12
+ const gid = parseGameId(game);
13
+ if (!gid)
14
+ return 'invalid game';
15
+ const lim = Math.min(30, count || 10);
16
+ return JSON.stringify(await loadDraws(runtime.db, gid, lim));
17
+ },
18
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/tool';
2
+ import { z } from 'zod';
3
+ import { parseGameId } from '../src/games/registry.js';
4
+ import { loadDraws } from '../src/db.js';
5
+ import { lotteryRuntimeToken } from '../src/runtime-state.js';
6
+
7
+ export default defineAgentTool<{ game: string; count?: number }>({
8
+ description: 'Query historical lottery draws',
9
+ inputSchema: z.object({ game: z.string().min(1), count: z.number().int().positive().optional() }),
10
+ async execute({ game, count }, context) {
11
+ const runtime = context.use(lotteryRuntimeToken);
12
+ const gid = parseGameId(game);
13
+ if (!gid) return 'invalid game';
14
+ const lim = Math.min(30, count || 10);
15
+ return JSON.stringify(await loadDraws(runtime.db, gid, lim));
16
+ },
17
+ });
@@ -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 { handleListPending } from "../lib/lottery-tool-handlers.js";
5
+ import { lotteryRuntimeToken } from "../lib/runtime-state.js";
6
+ export default defineAgentTool({
7
+ description: 'List pending lottery predictions awaiting review',
8
+ inputSchema: z.object({ game: z.string().min(1).optional() }),
9
+ async execute({ game }, context) {
10
+ return handleListPending(context.use(lotteryRuntimeToken), game);
11
+ },
12
+ });
@@ -0,0 +1,12 @@
1
+ import { defineAgentTool } from '@zhin.js/tool';
2
+ import { z } from 'zod';
3
+ import { handleListPending } from '../src/lottery-tool-handlers.js';
4
+ import { lotteryRuntimeToken } from '../src/runtime-state.js';
5
+
6
+ export default defineAgentTool<{ game?: string }>({
7
+ description: 'List pending lottery predictions awaiting review',
8
+ inputSchema: z.object({ game: z.string().min(1).optional() }),
9
+ async execute({ game }, context) {
10
+ return handleListPending(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 { handleSavePrediction } from "../lib/lottery-tool-handlers.js";
5
+ import { lotteryRuntimeToken } from "../lib/runtime-state.js";
6
+ export default defineAgentTool({
7
+ description: 'Save a pending lottery prediction',
8
+ inputSchema: z.object({ game: z.string().min(1), numbers_json: z.string().min(1) }),
9
+ async execute({ game, numbers_json }, context) {
10
+ return handleSavePrediction(context.use(lotteryRuntimeToken), game, numbers_json);
11
+ },
12
+ });
@@ -0,0 +1,12 @@
1
+ import { defineAgentTool } from '@zhin.js/tool';
2
+ import { z } from 'zod';
3
+ import { handleSavePrediction } from '../src/lottery-tool-handlers.js';
4
+ import { lotteryRuntimeToken } from '../src/runtime-state.js';
5
+
6
+ export default defineAgentTool<{ game: string; numbers_json: string }>({
7
+ description: 'Save a pending lottery prediction',
8
+ inputSchema: z.object({ game: z.string().min(1), numbers_json: z.string().min(1) }),
9
+ async execute({ game, numbers_json }, context) {
10
+ return handleSavePrediction(context.use(lotteryRuntimeToken), game, numbers_json);
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 { handleStatsSnapshot } from "../lib/lottery-tool-handlers.js";
5
+ import { lotteryRuntimeToken } from "../lib/runtime-state.js";
6
+ export default defineAgentTool({
7
+ description: 'Get stats snapshot for a lottery game',
8
+ inputSchema: z.object({ game: z.string().min(1) }),
9
+ async execute({ game }, context) {
10
+ return handleStatsSnapshot(context.use(lotteryRuntimeToken), game);
11
+ },
12
+ });
@@ -0,0 +1,12 @@
1
+ import { defineAgentTool } from '@zhin.js/tool';
2
+ import { z } from 'zod';
3
+ import { handleStatsSnapshot } from '../src/lottery-tool-handlers.js';
4
+ import { lotteryRuntimeToken } from '../src/runtime-state.js';
5
+
6
+ export default defineAgentTool<{ game: string }>({
7
+ description: 'Get stats snapshot for a lottery game',
8
+ inputSchema: z.object({ game: z.string().min(1) }),
9
+ async execute({ game }, context) {
10
+ return handleStatsSnapshot(context.use(lotteryRuntimeToken), game);
11
+ },
12
+ });
package/tools/sync.js ADDED
@@ -0,0 +1,16 @@
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 { parseGameId } from "../lib/games/registry.js";
5
+ import { lotteryRuntimeToken } from "../lib/runtime-state.js";
6
+ import { runDataSync } from "../lib/sync/run-sync.js";
7
+ export default defineAgentTool({
8
+ description: 'Sync official lottery draws into DB',
9
+ inputSchema: z.object({ game: z.string().min(1).optional() }),
10
+ async execute({ game }, context) {
11
+ const runtime = context.use(lotteryRuntimeToken);
12
+ const gid = parseGameId(game ?? '');
13
+ const result = await runDataSync(() => runtime.db, () => [...runtime.enabledGames], runtime.config.historyLimit, gid ?? undefined);
14
+ return JSON.stringify({ result });
15
+ },
16
+ });
package/tools/sync.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { defineAgentTool } from '@zhin.js/tool';
2
+ import { z } from 'zod';
3
+ import { parseGameId } from '../src/games/registry.js';
4
+ import { lotteryRuntimeToken } from '../src/runtime-state.js';
5
+ import { runDataSync } from '../src/sync/run-sync.js';
6
+
7
+ export default defineAgentTool<{ game?: string }>({
8
+ description: 'Sync official lottery draws into DB',
9
+ inputSchema: z.object({ game: z.string().min(1).optional() }),
10
+ async execute({ game }, context) {
11
+ const runtime = context.use(lotteryRuntimeToken);
12
+ const gid = parseGameId(game ?? '');
13
+ const result = await runDataSync(
14
+ () => runtime.db,
15
+ () => [...runtime.enabledGames],
16
+ runtime.config.historyLimit,
17
+ gid ?? undefined,
18
+ );
19
+ return JSON.stringify({ result });
20
+ },
21
+ });
@@ -1,57 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { handleComputeRecommend } from '../../src/lottery-tool-handlers.js';
4
-
5
- export default defineAgentTool<{ game: string }>({
6
- description: 'Compute lottery recommendation numbers via F/O/T stats engine',
7
- inputSchema: z.object({ game: z.string().min(1) }),
8
- async execute({ game }) {
9
- return handleComputeRecommend(game);
10
- },
11
- });
@@ -1,11 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { handleGetModelState } from '../../src/lottery-tool-handlers.js';
4
-
5
- export default defineAgentTool<{ game?: string }>({
6
- description: 'Query model weights and historical hit rate per game',
7
- inputSchema: z.object({ game: z.string().optional() }),
8
- async execute({ game }) {
9
- return handleGetModelState(game);
10
- },
11
- });
@@ -1,22 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { parseGameId } from '../../src/games/registry.js';
4
- import { loadDraws } from '../../src/db.js';
5
- import { getLotteryAgentDeps } from '../../src/lottery-agent-deps.js';
6
-
7
- export default defineAgentTool<{ game: string; count?: number }>({
8
- description: 'Query historical lottery draws',
9
- inputSchema: z.object({
10
- game: z.string().min(1),
11
- count: z.number().optional(),
12
- }),
13
- async execute({ game, count }) {
14
- const deps = getLotteryAgentDeps();
15
- const gid = parseGameId(game);
16
- if (!gid) return 'invalid game';
17
- const db = deps.getDb();
18
- if (!db) return 'db not ready';
19
- const lim = Math.min(30, count || 10);
20
- return JSON.stringify(await loadDraws(db, gid, lim));
21
- },
22
- });
@@ -1,11 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { handleListPending } from '../../src/lottery-tool-handlers.js';
4
-
5
- export default defineAgentTool<{ game?: string }>({
6
- description: 'List pending lottery predictions awaiting review',
7
- inputSchema: z.object({ game: z.string().optional() }),
8
- async execute({ game }) {
9
- return handleListPending(game);
10
- },
11
- });
@@ -1,14 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { handleSavePrediction } from '../../src/lottery-tool-handlers.js';
4
-
5
- export default defineAgentTool<{ game: string; numbers_json: string }>({
6
- description: 'Save a pending lottery prediction',
7
- inputSchema: z.object({
8
- game: z.string().min(1),
9
- numbers_json: z.string().min(1),
10
- }),
11
- async execute({ game, numbers_json }) {
12
- return handleSavePrediction(game, numbers_json);
13
- },
14
- });
@@ -1,11 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { handleStatsSnapshot } from '../../src/lottery-tool-handlers.js';
4
-
5
- export default defineAgentTool<{ game: string }>({
6
- description: 'Get stats snapshot for a lottery game',
7
- inputSchema: z.object({ game: z.string().min(1) }),
8
- async execute({ game }) {
9
- return handleStatsSnapshot(game);
10
- },
11
- });
@@ -1,18 +0,0 @@
1
- import { defineAgentTool } from '@zhin.js/agent/tools';
2
- import { z } from 'zod';
3
- import { parseGameId } from '../../src/games/registry.js';
4
- import { getLotteryAgentDeps } from '../../src/lottery-agent-deps.js';
5
- import { runDataSync } from '../../src/sync/run-sync.js';
6
-
7
- export default defineAgentTool<{ game?: string }>({
8
- description: 'Sync official lottery draws into DB',
9
- inputSchema: z.object({ game: z.string().optional() }),
10
- async execute({ game }) {
11
- const deps = getLotteryAgentDeps();
12
- const db = deps.getDb();
13
- if (!db) return 'db not ready';
14
- const gid = parseGameId(game ?? '');
15
- const result = await runDataSync(deps.getDb, deps.enabledGames, deps.getConfig().historyLimit, gid ?? undefined);
16
- return JSON.stringify({ result });
17
- },
18
- });
package/lib/db-store.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { LotteryDb } from './db.js';
2
- /** Ensure an in-memory store when Runtime database Resource is not wired yet. */
3
- export declare function ensureLotteryMemoryDb(): LotteryDb;
4
- export declare function getLotteryDb(): LotteryDb | null;
5
- export declare function setLotteryDb(db: LotteryDb | null): void;
6
- /** Generation-owned database binding used by Plugin Runtime setup(). */
7
- export declare function registerLotteryDb(db: LotteryDb): () => void;
8
- /** Test helper: clear module store. */
9
- export declare function resetLotteryDb(): void;
10
- //# sourceMappingURL=db-store.d.ts.map