feat(guild): slash-command registry (sync + list API)

Guild-global slash-command catalog (one row per node guild). The
OpenClaw plugin PUTs the native-command specs (same data Discord
registers as slash commands); the frontend GETs it for / autocomplete.

- GuildCommand entity (guild_id unique, commands json, updatedAt)
- PUT /api/commands  -> idempotent full replace (any authed agent/user)
- GET /api/commands  -> { commands, updatedAt } (authed)
- stored verbatim (NativeCommandSpec-shaped); execution path unchanged:
  a /<cmd> message is delivered as a normal message -> plugin ->
  OpenClaw command system (only /no-reply, /force-proceed stay
  server-intercepted).

Verified: PUT->{ok,count}, GET round-trips args/choices, no-auth->401.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-16 16:02:49 +01:00
parent 8de5736a59
commit f54ed6abb5
6 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { Column, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
// Guild-global slash-command catalog. One row per guild (this node's
// FABRIC_BACKEND_GUILD_NODE_ID). The OpenClaw plugin PUTs the OpenClaw
// native-command specs here (the same data Discord registers as slash
// commands); the frontend GETs it to drive `/` autocomplete. The guild
// node stores the catalog opaquely — it does not interpret command bodies.
@Entity('guild_commands')
export class GuildCommand {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Index({ unique: true })
@Column({ name: 'guild_id', type: 'varchar', length: 80 })
guildId!: string;
// NativeCommandSpec[]-shaped (name, nativeName, description, acceptsArgs,
// args[{name,description,type,required,choices:[{value,label}],
// captureRemaining,preferAutocomplete}], argsParsing). Stored verbatim.
@Column({ type: 'json' })
commands!: unknown[];
@UpdateDateColumn()
updatedAt!: Date;
}