@zhin.js/plugin-lottery 2.0.3 → 2.0.6
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]].js +5 -5
- package/commands/lottery/[[game]].ts +4 -5
- package/commands/lottery-backtest/[[game]].js +4 -6
- package/commands/lottery-backtest/[[game]].ts +3 -5
- package/commands/lottery-history/[game].js +3 -6
- package/commands/lottery-history/[game].ts +4 -5
- package/commands/lottery-stats/[game].js +4 -6
- package/commands/lottery-stats/[game].ts +3 -5
- package/commands/lottery-today.js +3 -6
- package/commands/lottery-today.ts +4 -5
- package/commands/lottery-train/[[game]].js +4 -6
- package/commands/lottery-train/[[game]].ts +3 -5
- 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 +5 -6
- package/lib/runtime-state.d.ts.map +1 -1
- package/lib/runtime-state.js +1 -11
- package/lib/runtime-state.js.map +1 -1
- package/package.json +13 -11
- package/plugin.js +18 -33
- 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 +6 -13
- 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
package/lib/db-store.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-store.d.ts","sourceRoot":"","sources":["../src/db-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMzC,iFAAiF;AACjF,wBAAgB,qBAAqB,IAAI,SAAS,CAGjD;AAED,wBAAgB,YAAY,IAAI,SAAS,GAAG,IAAI,CAE/C;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAEvD;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,IAAI,CAO3D;AAED,uCAAuC;AACvC,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
|
package/lib/db-store.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createInMemoryLotteryDb } from './memory-db.js';
|
|
2
|
-
let _db = null;
|
|
3
|
-
const registrations = [];
|
|
4
|
-
/** Ensure an in-memory store when Runtime database Resource is not wired yet. */
|
|
5
|
-
export function ensureLotteryMemoryDb() {
|
|
6
|
-
if (!_db)
|
|
7
|
-
_db = createInMemoryLotteryDb();
|
|
8
|
-
return _db;
|
|
9
|
-
}
|
|
10
|
-
export function getLotteryDb() {
|
|
11
|
-
return registrations[registrations.length - 1]?.value ?? ensureLotteryMemoryDb();
|
|
12
|
-
}
|
|
13
|
-
export function setLotteryDb(db) {
|
|
14
|
-
_db = db;
|
|
15
|
-
}
|
|
16
|
-
/** Generation-owned database binding used by Plugin Runtime setup(). */
|
|
17
|
-
export function registerLotteryDb(db) {
|
|
18
|
-
const registration = Object.freeze({ value: db });
|
|
19
|
-
registrations.push(registration);
|
|
20
|
-
return () => {
|
|
21
|
-
const index = registrations.lastIndexOf(registration);
|
|
22
|
-
if (index >= 0)
|
|
23
|
-
registrations.splice(index, 1);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/** Test helper: clear module store. */
|
|
27
|
-
export function resetLotteryDb() {
|
|
28
|
-
_db = null;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=db-store.js.map
|
package/lib/db-store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-store.js","sourceRoot":"","sources":["../src/db-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,IAAI,GAAG,GAAqB,IAAI,CAAC;AACjC,MAAM,aAAa,GAAyC,EAAE,CAAC;AAE/D,iFAAiF;AACjF,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,GAAG;QAAE,GAAG,GAAG,uBAAuB,EAAE,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,qBAAqB,EAAE,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAoB;IAC/C,GAAG,GAAG,EAAE,CAAC;AACX,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,iBAAiB,CAAC,EAAa;IAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IAClD,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,KAAK,IAAI,CAAC;YAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,cAAc;IAC5B,GAAG,GAAG,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
|
-
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
|
-
*/
|
|
5
|
-
import { type Dispose } from '@zhin.js/plugin-runtime';
|
|
6
|
-
import type { GameId } from './types.js';
|
|
7
|
-
import type { LotteryDb } from './db.js';
|
|
8
|
-
import type { Kl8Config } from './games/kl8-groups.js';
|
|
9
|
-
export interface LotteryAgentDeps {
|
|
10
|
-
getDb: () => LotteryDb | null;
|
|
11
|
-
getConfig: () => {
|
|
12
|
-
pickCount: number;
|
|
13
|
-
historyLimit: number;
|
|
14
|
-
kl8: Kl8Config;
|
|
15
|
-
};
|
|
16
|
-
enabledGames: () => GameId[];
|
|
17
|
-
scheduleCron: () => string;
|
|
18
|
-
scheduleEnabled: () => boolean;
|
|
19
|
-
pipelinePush: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function setLotteryAgentDeps(deps: LotteryAgentDeps): void;
|
|
22
|
-
/**
|
|
23
|
-
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
24
|
-
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
25
|
-
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
26
|
-
*/
|
|
27
|
-
export declare function registerLotteryAgentDeps(deps: LotteryAgentDeps): Dispose;
|
|
28
|
-
export declare function getLotteryAgentDeps(): LotteryAgentDeps;
|
|
29
|
-
//# sourceMappingURL=lottery-agent-deps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lottery-agent-deps.d.ts","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAuC,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,SAAS,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,SAAS,CAAA;KAAE,CAAC;IAC7E,YAAY,EAAE,MAAM,MAAM,EAAE,CAAC;IAC7B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,OAAO,CAAC;IAC/B,YAAY,EAAE,OAAO,CAAC;CACvB;AAMD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAExE;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAItD"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
|
-
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
|
-
*/
|
|
5
|
-
import { createGenerationStore, DisposeStack } from '@zhin.js/plugin-runtime';
|
|
6
|
-
const agentDepsStore = createGenerationStore('lottery/agent-deps');
|
|
7
|
-
let _deps = null;
|
|
8
|
-
export function setLotteryAgentDeps(deps) {
|
|
9
|
-
_deps = deps;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
13
|
-
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
14
|
-
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
15
|
-
*/
|
|
16
|
-
export function registerLotteryAgentDeps(deps) {
|
|
17
|
-
return agentDepsStore.provide({ lifecycle: new DisposeStack() }, deps);
|
|
18
|
-
}
|
|
19
|
-
export function getLotteryAgentDeps() {
|
|
20
|
-
const deps = agentDepsStore.tryUse() ?? _deps;
|
|
21
|
-
if (!deps)
|
|
22
|
-
throw new Error('lottery agent deps not initialized');
|
|
23
|
-
return deps;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=lottery-agent-deps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lottery-agent-deps.js","sourceRoot":"","sources":["../src/lottery-agent-deps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAgB,MAAM,yBAAyB,CAAC;AAc5F,MAAM,cAAc,GAAG,qBAAqB,CAAmB,oBAAoB,CAAC,CAAC;AAErF,IAAI,KAAK,GAA4B,IAAI,CAAC;AAE1C,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,KAAK,GAAG,IAAI,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAsB;IAC7D,OAAO,cAAc,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,YAAY,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC;IAC9C,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACjE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/push.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface LotteryPushTarget {
|
|
2
|
-
readonly adapter: string;
|
|
3
|
-
readonly endpointId: string;
|
|
4
|
-
readonly channelType?: string;
|
|
5
|
-
readonly channelId: string;
|
|
6
|
-
}
|
|
7
|
-
export type LotteryOutboundPush = (text: string) => Promise<void>;
|
|
8
|
-
export declare function setLotteryOutboundPush(push: LotteryOutboundPush | null): void;
|
|
9
|
-
/** Generation-safe registration used by Plugin Runtime setup(). */
|
|
10
|
-
export declare function registerLotteryOutboundPush(push: LotteryOutboundPush | null): () => void;
|
|
11
|
-
export declare function getLotteryOutboundPush(): LotteryOutboundPush | null;
|
|
12
|
-
/** Push through the generation-owned OutboundHost configured by plugin setup. */
|
|
13
|
-
export declare function pushLotteryReport(text: string): Promise<void>;
|
|
14
|
-
//# sourceMappingURL=push.d.ts.map
|
package/lib/push.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAKlE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAE7E;AAED,mEAAmE;AACnE,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,GAAG,MAAM,IAAI,CAOxF;AAED,wBAAgB,sBAAsB,IAAI,mBAAmB,GAAG,IAAI,CAGnE;AAED,iFAAiF;AACjF,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnE"}
|
package/lib/push.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
let _outboundPush = null;
|
|
2
|
-
const registrations = [];
|
|
3
|
-
export function setLotteryOutboundPush(push) {
|
|
4
|
-
_outboundPush = push;
|
|
5
|
-
}
|
|
6
|
-
/** Generation-safe registration used by Plugin Runtime setup(). */
|
|
7
|
-
export function registerLotteryOutboundPush(push) {
|
|
8
|
-
const registration = Object.freeze({ value: push });
|
|
9
|
-
registrations.push(registration);
|
|
10
|
-
return () => {
|
|
11
|
-
const index = registrations.lastIndexOf(registration);
|
|
12
|
-
if (index >= 0)
|
|
13
|
-
registrations.splice(index, 1);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export function getLotteryOutboundPush() {
|
|
17
|
-
const active = registrations[registrations.length - 1];
|
|
18
|
-
return active ? active.value : _outboundPush;
|
|
19
|
-
}
|
|
20
|
-
/** Push through the generation-owned OutboundHost configured by plugin setup. */
|
|
21
|
-
export async function pushLotteryReport(text) {
|
|
22
|
-
await getLotteryOutboundPush()?.(text);
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=push.js.map
|
package/lib/push.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AASA,IAAI,aAAa,GAA+B,IAAI,CAAC;AACrD,MAAM,aAAa,GAA0D,EAAE,CAAC;AAEhF,MAAM,UAAU,sBAAsB,CAAC,IAAgC;IACrE,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,2BAA2B,CAAC,IAAgC;IAC1E,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACtD,IAAI,KAAK,IAAI,CAAC;YAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;AAC/C,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAClD,MAAM,sBAAsB,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC"}
|
package/src/db-store.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { LotteryDb } from './db.js';
|
|
2
|
-
import { createInMemoryLotteryDb } from './memory-db.js';
|
|
3
|
-
|
|
4
|
-
let _db: LotteryDb | null = null;
|
|
5
|
-
const registrations: Array<{ readonly value: LotteryDb }> = [];
|
|
6
|
-
|
|
7
|
-
/** Ensure an in-memory store when Runtime database Resource is not wired yet. */
|
|
8
|
-
export function ensureLotteryMemoryDb(): LotteryDb {
|
|
9
|
-
if (!_db) _db = createInMemoryLotteryDb();
|
|
10
|
-
return _db;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getLotteryDb(): LotteryDb | null {
|
|
14
|
-
return registrations[registrations.length - 1]?.value ?? ensureLotteryMemoryDb();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function setLotteryDb(db: LotteryDb | null): void {
|
|
18
|
-
_db = db;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Generation-owned database binding used by Plugin Runtime setup(). */
|
|
22
|
-
export function registerLotteryDb(db: LotteryDb): () => void {
|
|
23
|
-
const registration = Object.freeze({ value: db });
|
|
24
|
-
registrations.push(registration);
|
|
25
|
-
return () => {
|
|
26
|
-
const index = registrations.lastIndexOf(registration);
|
|
27
|
-
if (index >= 0) registrations.splice(index, 1);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Test helper: clear module store. */
|
|
32
|
-
export function resetLotteryDb(): void {
|
|
33
|
-
_db = null;
|
|
34
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared runtime deps for lottery agent/ authoring tools.
|
|
3
|
-
* Set once from plugin index during init — never call getPlugin() from tool execute.
|
|
4
|
-
*/
|
|
5
|
-
import { createGenerationStore, DisposeStack, type Dispose } from '@zhin.js/plugin-runtime';
|
|
6
|
-
import type { GameId } from './types.js';
|
|
7
|
-
import type { LotteryDb } from './db.js';
|
|
8
|
-
import type { Kl8Config } from './games/kl8-groups.js';
|
|
9
|
-
|
|
10
|
-
export interface LotteryAgentDeps {
|
|
11
|
-
getDb: () => LotteryDb | null;
|
|
12
|
-
getConfig: () => { pickCount: number; historyLimit: number; kl8: Kl8Config };
|
|
13
|
-
enabledGames: () => GameId[];
|
|
14
|
-
scheduleCron: () => string;
|
|
15
|
-
scheduleEnabled: () => boolean;
|
|
16
|
-
pipelinePush: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const agentDepsStore = createGenerationStore<LotteryAgentDeps>('lottery/agent-deps');
|
|
20
|
-
|
|
21
|
-
let _deps: LotteryAgentDeps | null = null;
|
|
22
|
-
|
|
23
|
-
export function setLotteryAgentDeps(deps: LotteryAgentDeps): void {
|
|
24
|
-
_deps = deps;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Generation-owned Agent dependency binding used by Plugin Runtime setup().
|
|
29
|
-
* The fresh lifecycle is detached: callers own the returned dispose (setup()
|
|
30
|
-
* hooks it into context.lifecycle); provide() does not retain the context.
|
|
31
|
-
*/
|
|
32
|
-
export function registerLotteryAgentDeps(deps: LotteryAgentDeps): Dispose {
|
|
33
|
-
return agentDepsStore.provide({ lifecycle: new DisposeStack() }, deps);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function getLotteryAgentDeps(): LotteryAgentDeps {
|
|
37
|
-
const deps = agentDepsStore.tryUse() ?? _deps;
|
|
38
|
-
if (!deps) throw new Error('lottery agent deps not initialized');
|
|
39
|
-
return deps;
|
|
40
|
-
}
|
package/src/push.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export interface LotteryPushTarget {
|
|
2
|
-
readonly adapter: string;
|
|
3
|
-
readonly endpointId: string;
|
|
4
|
-
readonly channelType?: string;
|
|
5
|
-
readonly channelId: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type LotteryOutboundPush = (text: string) => Promise<void>;
|
|
9
|
-
|
|
10
|
-
let _outboundPush: LotteryOutboundPush | null = null;
|
|
11
|
-
const registrations: Array<{ readonly value: LotteryOutboundPush | null }> = [];
|
|
12
|
-
|
|
13
|
-
export function setLotteryOutboundPush(push: LotteryOutboundPush | null): void {
|
|
14
|
-
_outboundPush = push;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Generation-safe registration used by Plugin Runtime setup(). */
|
|
18
|
-
export function registerLotteryOutboundPush(push: LotteryOutboundPush | null): () => void {
|
|
19
|
-
const registration = Object.freeze({ value: push });
|
|
20
|
-
registrations.push(registration);
|
|
21
|
-
return () => {
|
|
22
|
-
const index = registrations.lastIndexOf(registration);
|
|
23
|
-
if (index >= 0) registrations.splice(index, 1);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getLotteryOutboundPush(): LotteryOutboundPush | null {
|
|
28
|
-
const active = registrations[registrations.length - 1];
|
|
29
|
-
return active ? active.value : _outboundPush;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Push through the generation-owned OutboundHost configured by plugin setup. */
|
|
33
|
-
export async function pushLotteryReport(text: string): Promise<void> {
|
|
34
|
-
await getLotteryOutboundPush()?.(text);
|
|
35
|
-
}
|