Skip to content

DummyConnector: declarative scriptable rule engine #19

Description

@AimTune

DummyConnector currently has hard-coded demo paths (/genui-weather, /genui-form, etc.). Make those declarative so the sandbox — and any third party using DummyConnector for demos / e2e tests — can configure response behavior without forking the connector.

Motivation

  • Backend-less demos. "When the user says 'cancel', show this card with two buttons."
  • E2E test fixtures. Replay deterministic conversations without spinning up a real bot.
  • Customer presentations. Show a tailored flow before the real backend exists.
  • Pairs naturally with the sandbox's ChativaSettings JSON paste-load: rule sets travel as part of the same config blob.

Proposed shape (v1)

type DummyRule = {
  /** Predicate over the user's outgoing message. */
  when: {
    type?: string;                         // match by message type
    textMatches?: string;                  // regex string applied to data.text
  };
  /** Static response, OR a GenUI chunk script. */
  then:
    | IncomingMessage
    | { kind: "genui"; chunks: AIChunk[] };
  /** Optional delay before emitting `then`. Defaults to `replyDelay`. */
  delay?: number;
};

new DummyConnector({
  replyDelay: 500,
  rules: [
    {
      when: { textMatches: "^/(help|yardım)$" },
      then: { id: "x", type: "buttons", from: "bot", data: { buttons: [{ label: "Order status" }, { label: "Talk to a human" }] } },
    },
    {
      when: { textMatches: "(cancel|iptal)" },
      then: { kind: "genui", chunks: [/* text + form */] },
    },
  ],
});

Rules evaluated in order; first match wins. No match → fall through to the default echo.

Hard rules

  • No custom JS execution. Pattern matching only — textMatches is a regex string, not arbitrary code.
  • All rule output passes through the existing IncomingMessage / AIChunk types (no new schemas needed besides updating connector option schema).

Sandbox integration

A new "Rules" tab in apps/sandbox/src/sandbox/sections/:

  • Add / edit / remove rules in a list.
  • "Apply" rebuilds the DummyConnector instance via the existing Connector tab swap path.
  • Rules serialise into the Config tab's JSON output as a dummy.rules field of chativaSettings.connector.

Schema impact

Update schemas/connectors/dummy.schema.json to include the rules field. Add a drift test for it (also covered by #4 / schema-coverage).

Acceptance criteria

  • DummyConnector accepts rules in its constructor options.
  • Rules with textMatches regex match outgoing messages and emit the configured then.
  • GenUI rules emit chunks via genUIChunkHandler.
  • Existing demo helpers (triggerGenUI, injectMessage) keep working.
  • Sandbox UI to add / edit / remove rules.
  • connector-dummy tests for rule matching, ordering, and fall-through.
  • schemas/connectors/dummy.schema.json updated and drift-tested.

Spun out of todos.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions