@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.
Files changed (101) hide show
  1. package/AGENTS.md +8 -0
  2. package/commands/lottery/{[game:string=].js → [[game]]/index.js} +8 -7
  3. package/commands/lottery/{[game:string=].ts → [[game]]/index.ts} +8 -8
  4. package/commands/lottery-backtest/{[game:string=].js → [[game]]/index.js} +9 -10
  5. package/commands/lottery-backtest/{[game:string=].ts → [[game]]/index.ts} +9 -10
  6. package/commands/lottery-history/{[game:string].js → [game]/index.js} +7 -9
  7. package/commands/lottery-history/{[game:string].ts → [game]/index.ts} +8 -8
  8. package/commands/lottery-stats/{[game:string].js → [game]/index.js} +11 -12
  9. package/commands/lottery-stats/{[game:string].ts → [game]/index.ts} +11 -12
  10. package/commands/lottery-today/index.js +14 -0
  11. package/commands/lottery-today/index.ts +14 -0
  12. package/commands/lottery-train/{[game:string=].js → [[game]]/index.js} +9 -10
  13. package/commands/lottery-train/{[game:string=].ts → [[game]]/index.ts} +9 -10
  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/memory-db.d.ts +1 -1
  38. package/lib/memory-db.js +1 -1
  39. package/lib/pipeline.d.ts +2 -1
  40. package/lib/pipeline.d.ts.map +1 -1
  41. package/lib/pipeline.js +3 -13
  42. package/lib/pipeline.js.map +1 -1
  43. package/lib/runtime-state.d.ts +6 -7
  44. package/lib/runtime-state.d.ts.map +1 -1
  45. package/lib/runtime-state.js +2 -12
  46. package/lib/runtime-state.js.map +1 -1
  47. package/package.json +22 -10
  48. package/plugin.js +22 -35
  49. package/{agent/skills/lottery.md → skills/lottery/SKILL.md} +9 -9
  50. package/skills/lottery/tools/compute-recommend/index.js +12 -0
  51. package/skills/lottery/tools/compute-recommend/index.ts +12 -0
  52. package/skills/lottery/tools/get-model-state/index.js +12 -0
  53. package/skills/lottery/tools/get-model-state/index.ts +12 -0
  54. package/skills/lottery/tools/history/index.js +18 -0
  55. package/skills/lottery/tools/history/index.ts +17 -0
  56. package/skills/lottery/tools/list-pending/index.js +12 -0
  57. package/skills/lottery/tools/list-pending/index.ts +12 -0
  58. package/skills/lottery/tools/save-prediction/index.js +12 -0
  59. package/skills/lottery/tools/save-prediction/index.ts +12 -0
  60. package/skills/lottery/tools/stats-snapshot/index.js +12 -0
  61. package/skills/lottery/tools/stats-snapshot/index.ts +12 -0
  62. package/skills/lottery/tools/sync/index.js +16 -0
  63. package/skills/lottery/tools/sync/index.ts +21 -0
  64. package/src/agent/prompts.ts +1 -1
  65. package/src/agent/read-skills.ts +3 -3
  66. package/src/command-helpers.ts +4 -4
  67. package/src/config.ts +2 -2
  68. package/src/db.ts +3 -2
  69. package/src/index.ts +1 -8
  70. package/src/lottery-tool-handlers.ts +21 -106
  71. package/src/memory-db.ts +1 -1
  72. package/src/pipeline.ts +5 -14
  73. package/src/runtime-state.ts +7 -14
  74. package/agent/agent.ts +0 -6
  75. package/agent/instructions.md +0 -2
  76. package/agent/runtime-tools.ts +0 -57
  77. package/agent/tools/compute_recommend.ts +0 -11
  78. package/agent/tools/get_model_state.ts +0 -11
  79. package/agent/tools/history.ts +0 -22
  80. package/agent/tools/list_pending.ts +0 -11
  81. package/agent/tools/save_prediction.ts +0 -14
  82. package/agent/tools/stats_snapshot.ts +0 -11
  83. package/agent/tools/sync.ts +0 -18
  84. package/commands/lottery-today.js +0 -17
  85. package/commands/lottery-today.ts +0 -15
  86. package/lib/db-store.d.ts +0 -10
  87. package/lib/db-store.d.ts.map +0 -1
  88. package/lib/db-store.js +0 -30
  89. package/lib/db-store.js.map +0 -1
  90. package/lib/lottery-agent-deps.d.ts +0 -29
  91. package/lib/lottery-agent-deps.d.ts.map +0 -1
  92. package/lib/lottery-agent-deps.js +0 -25
  93. package/lib/lottery-agent-deps.js.map +0 -1
  94. package/lib/push.d.ts +0 -14
  95. package/lib/push.d.ts.map +0 -1
  96. package/lib/push.js +0 -24
  97. package/lib/push.js.map +0 -1
  98. package/src/db-store.ts +0 -34
  99. package/src/lottery-agent-deps.ts +0 -40
  100. package/src/push.ts +0 -35
  101. /package/evals/{pipeline_smoke.eval.ts → $pipeline_smoke.eval.ts} +0 -0
@@ -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
+ });
@@ -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
+ });
@@ -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
+ });
@@ -15,7 +15,7 @@ export function buildDailyPipelinePrompt(ctx: LotteryAgentContext): string {
15
15
  return [
16
16
  '[lottery daily_pipeline]',
17
17
  `games: ${games}`,
18
- 'Steps: lottery_sync → review pending (skip if empty) → lottery_compute_recommend → lottery_publish_report',
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
  }
@@ -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。数据通过 lottery_* 工具查库,算法流程见 skills。',
22
- '可用 web_search 检索公开分析资料;推荐号码只能来自 lottery_compute_recommend,不得臆造或篡改。',
23
- '每次任务结束应将洞察写入 lottery_save_memory,形成可累积的专业记忆。',
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');
@@ -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 | null = getLotteryDb(),
12
+ db: LotteryDb,
14
13
  ): PipelineDeps {
15
14
  const config = resolveLotteryConfig(raw);
16
15
  return {
17
- getDb: () => db,
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, getLotteryDb };
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 endpointId?: string;
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
- endpointId: typeof t.endpointId === 'string' ? t.endpointId : t.adapter,
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
- select: () => {
17
- where: (q: Record<string, unknown>) => Promise<unknown[]>;
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, resolveLotteryRuntime } from './runtime-state.js';
4
+ export { lotteryRuntimeToken } from './runtime-state.js';
12
5
  export type { LotteryRuntime } from './runtime-state.js';
13
6
  export { formatPipelineReply, runLotteryPipeline } from './pipeline.js';
@@ -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/memory-db.ts CHANGED
@@ -44,7 +44,7 @@ const TABLE_NAMES = [
44
44
  ] as const;
45
45
 
46
46
  /**
47
- * Slice-2 fallback while Plugin Runtime has no DatabaseFeature Resource path.
47
+ * In-memory fallback for runtimes without a DatabaseHost.
48
48
  * Enough for smoke: today/history/stats/train/backtest/pipeline no longer return「数据库未就绪」.
49
49
  */
50
50
  export function createInMemoryLotteryDb(): LotteryDb {
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
- import { createToken } from '@zhin.js/plugin-runtime';
1
+ import { createToken } from 'zhin.js';
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
- }
package/agent/agent.ts DELETED
@@ -1,6 +0,0 @@
1
- import { defineAgent } from '@zhin.js/agent';
2
-
3
- export default defineAgent({
4
- description: 'Multi-game lottery analysis pipeline: sync, review, recommend, publish.',
5
- keywords: ['lottery', 'caipiao', 'kl8', 'ssq'],
6
- });
@@ -1,2 +0,0 @@
1
- You are the lottery plugin agent. Use typed tools for sync, stats, recommendations, and reviews.
2
- Always include the standard disclaimer in published reports. Prefer exact numbers from tools over guessing.
@@ -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
- });