// commands.ts — define once
export const schema = defineSchema({
cartAdd: {
description: 'Add a product to the cart',
target: { id: 'number', name: 'string' },
payload: { qty: 'number' },
result: { count: 'number', total: 'number' },
},
cartCheckout: {
description: 'Charge the cart and place the order',
authorize: 'checkout', // → Gate::forUser($user)->authorize('checkout', ...)
target: { cartId: 'number' },
},
});
// → typed schema bus (validation + LLM tools included)
const bus = createSchemaCommandBus(schema);
// → typed SHARED bus for every useCommand()/getCommandBus() call site
declare module 'vapor-chamber' {
interface GlobalCommands extends CommandsOf<typeof schema> {}
}
setCommandBus(bus);
// → Laravel stubs + registry: node scripts/generate-laravel.mjs commands.mjs
// → agent tools: bus.toTools() / vapor-chamber/mcp
defineSchema — identity helper that PRESERVES field-type literals, so the schema keeps its inference power. Without it,
{ id: 'number' }widens toRecord<string, string>and every inferred type collapses toany.The complete one-source-of-truth wiring: