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:
2026-04-23 11:38:27 +07:00
parent 4acc471f6f
commit 919fa038d5
2 changed files with 18 additions and 7 deletions
+2 -2
View File
@@ -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
View File
@@ -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: [] };
},
};