mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-02 18:20:04 +00:00
fix(register): stub env.AI so semantle init doesn't break registration
`npm run register` imports buildRegistry to derive the public command list but ran outside the Worker runtime, so `env.AI` was undefined — semantle (and previously doantu) tripped `createClient` type-checks. Add a no-op AI stub alongside stubKv and wire it through the buildRegistry env.
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
import { buildRegistry, resetRegistry } from "../src/modules/registry.js";
|
||||
import { stubKv } from "./stub-kv.js";
|
||||
import { stubAi, stubKv } from "./stub-kv.js";
|
||||
|
||||
const TELEGRAM_API = "https://api.telegram.org";
|
||||
|
||||
@@ -72,7 +72,7 @@ async function main() {
|
||||
// Build the registry against the same code the Worker uses. Stub KV
|
||||
// satisfies the binding so createStore() does not throw.
|
||||
resetRegistry();
|
||||
const reg = await buildRegistry({ MODULES: modules, KV: stubKv });
|
||||
const reg = await buildRegistry({ MODULES: modules, KV: stubKv, AI: stubAi });
|
||||
|
||||
const commands = [...reg.publicCommands.values()].map(({ cmd }) => ({
|
||||
command: cmd.name,
|
||||
|
||||
+16
-5
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* @file stub-kv — minimal no-op KVNamespace stub used by scripts/register.js.
|
||||
* @file stub-kv — no-op binding stubs used by scripts/register.js.
|
||||
*
|
||||
* The register script imports buildRegistry() to derive the public command
|
||||
* list at deploy time. buildRegistry calls createStore() → CFKVStore → needs
|
||||
* a KV binding. This stub satisfies the shape without doing any real IO,
|
||||
* since module init hooks in this codebase read-only (or tolerate missing
|
||||
* state). If a future module writes inside init(), update the stub to
|
||||
* list at deploy time. Module init hooks in this codebase dereference
|
||||
* runtime bindings like `env.KV` (via createStore) and `env.AI` (semantle).
|
||||
* These stubs satisfy the shape without doing any real IO. All init hooks
|
||||
* are assumed read-only (or tolerant of missing state) at registration time.
|
||||
* If a future module writes inside init(), update the matching stub to
|
||||
* swallow writes or gate the write on a `process.env.REGISTER_DRYRUN` flag.
|
||||
*/
|
||||
|
||||
@@ -33,3 +34,13 @@ export const stubKv = {
|
||||
return { value: null, metadata: null };
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Workers AI binding stub. Semantle's init() wires `createClient(env.AI)`
|
||||
* which only type-checks `.run` — no inference ever fires during register.
|
||||
*/
|
||||
export const stubAi = {
|
||||
async run() {
|
||||
return { data: [] };
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user