module

MJ::BusService

Exposes mj's image engines as a single multi-tool provider on the Arcana bus. One address (mj), dispatch on the payload's tool field, {"tool":"help"} returns the manifest. Runs a Client-backed Arcana::Toolset over the WebSocket daemon (arcana-core >= 0.9).

Every tool takes a source image via input_path (a file path) or image_base64, and returns the result either written to output_path (returning {output_path}) or, if no output_path, inline as {image_base64, content_type}.

Constants

BASE_SCHEMA = JSON.parse("{\n \"type\":\"object\",\n \"required\":[\"prompt\"],\n \"description\":\"Stage 1 of the base/decorate flow: a rudimentary flat-colour template rendered into a plain, undecorated, structurally-faithful 'base' master (SD1.5 img2img). The master is the reference for later 'decorate' variations. Map the template's colour patches to features in the prompt (e.g. 'the dark-red patch is the doorway').\",\n \"properties\":{\n \"prompt\":{\"type\":\"string\",\"description\":\"what the structure is, plus a legend mapping template colour patches to features.\"},\n \"input_path\":{\"type\":\"string\",\"description\":\"rough flat-colour template image path (or template_base64).\"},\n \"template_base64\":{\"type\":\"string\",\"description\":\"template PNG as base64 (alternative to input_path).\"},\n \"strength\":{\"type\":\"number\",\"description\":\"img2img denoise 0-1: the plain-vs-rich structure knob. Default 0.7 (rich but undecorated). Lower hews closer to the flat template; higher invents more.\"},\n \"steps\":{\"type\":\"integer\",\"description\":\"diffusion steps, default 30.\"},\n \"cfg_scale\":{\"type\":\"number\",\"description\":\"prompt adherence, default 4.5.\"},\n \"negative_prompt\":{\"type\":\"string\",\"description\":\"what to suppress. A default already excludes decoration, trim, scenery, people and text so the base stays plain; override to replace it.\"},\n \"model\":{\"type\":\"string\",\"description\":\"Runware model id. Default civitai:4384@128713 (SD1.5; FLUX img2img underperforms on flat masks).\"},\n \"output_path\":{\"type\":\"string\",\"description\":\"write the base PNG here; omit to get image_base64 back\"}\n }\n }")
DECORATE_SCHEMA = JSON.parse("{\n \"type\":\"object\",\n \"required\":[\"prompt\"],\n \"description\":\"Stage 2 of the base/decorate flow: take a plain 'base' master (or any image) and redraw it decorated in a given style/theme (Nano Banana 2, via reference-image edit). Optionally pass a style-reference image to steer the look.\",\n \"properties\":{\n \"prompt\":{\"type\":\"string\",\"description\":\"the style / theme / details to apply (e.g. 'weathered Victorian circus tent, red and gold stripes, brass trim').\"},\n \"input_path\":{\"type\":\"string\",\"description\":\"the master image path (or image_base64) — the thing to redraw.\"},\n \"image_base64\":{\"type\":\"string\",\"description\":\"master image as base64 (alternative to input_path).\"},\n \"style_path\":{\"type\":\"string\",\"description\":\"optional style-reference image path (or style_base64), passed as a second reference to steer the look.\"},\n \"style_base64\":{\"type\":\"string\",\"description\":\"style-reference image as base64 (alternative to style_path).\"},\n \"keep_structure\":{\"type\":\"boolean\",\"description\":\"preserve the master's silhouette/layout. Default true; prepends a form-preserving lead so the decoration honours the master instead of wandering. Set false to let the model reinterpret shape.\"},\n \"model\":{\"type\":\"string\",\"description\":\"Runware model id. Default google:4@3 (Nano Banana 2).\"},\n \"width\":{\"type\":\"integer\",\"description\":\"output px, default 1024\"},\n \"height\":{\"type\":\"integer\",\"description\":\"output px, default 1024\"},\n \"output_path\":{\"type\":\"string\",\"description\":\"write the decorated PNG here; omit to get image_base64 back\"}\n }\n }")
PIXELIZE_SCHEMA = JSON.parse("{\n \"type\":\"object\",\n \"properties\":{\n \"input_path\":{\"type\":\"string\",\"description\":\"path to source image (or use image_base64)\"},\n \"image_base64\":{\"type\":\"string\"},\n \"style\":{\"type\":\"string\",\"enum\":[\"8bit\",\"16bit\"],\"description\":\"pixel-art era (default 16bit)\"},\n \"background\":{\"type\":\"string\",\"description\":\"transparent | keep | #RRGGBB (default transparent)\"},\n \"snap\":{\"type\":\"boolean\",\"description\":\"pixel-perfect quantize pass (needs ImageMagick)\"},\n \"grid\":{\"type\":\"integer\"},\"colors\":{\"type\":\"integer\"},\n \"model\":{\"type\":\"string\"},\"width\":{\"type\":\"integer\"},\"height\":{\"type\":\"integer\"},\n \"output_path\":{\"type\":\"string\",\"description\":\"write result here; omit for image_base64\"}\n }\n }")
PROP_SCHEMA = JSON.parse("{\n \"type\":\"object\",\n \"required\":[\"prompt\"],\n \"description\":\"Rough flat-colour template, then AI paints the subject on a solid background, then that background is keyed out, giving a transparent PNG prop. The template is a ROUGH size/placement guide, not a cutter; the prop is cut from the render. Name the chosen background colour in your prompt (e.g. 'on a solid flat magenta background').\",\n \"properties\":{\n \"prompt\":{\"type\":\"string\",\"description\":\"What to draw. Include the background colour and 'game prop / centred / nothing else'.\"},\n \"input_path\":{\"type\":\"string\",\"description\":\"rough template image path (or template_base64). Optional but strongly recommended for size/placement.\"},\n \"template_base64\":{\"type\":\"string\",\"description\":\"template PNG as base64 (alternative to input_path)\"},\n \"background\":{\"type\":\"array\",\"items\":{\"type\":\"integer\"},\"description\":\"[r,g,b] background to render on and key out. Default [0,0,0] (black) suits BRIGHT subjects. Use a chroma colour far from the subject for DARK subjects: magenta [255,0,255] or green [0,255,0]. Whatever you pick, say it in the prompt.\"},\n \"key_low\":{\"type\":\"integer\",\"description\":\"per-channel distance-from-bg (0-255) below which a pixel is fully transparent. Default 4.\"},\n \"key_high\":{\"type\":\"integer\",\"description\":\"distance above which a pixel is fully opaque; smooth ramp between. Default 28. RAISE it (100-160) for SEE-THROUGH subjects (rigging, foliage, fences) so background peeking through the gaps keys out; lower keeps faint thin detail.\"},\n \"edge_blur\":{\"type\":\"integer\",\"description\":\"px of box blur on the alpha edge only. Default 0; 1 softens a hard cut.\"},\n \"despill\":{\"type\":\"boolean\",\"description\":\"colour-unmatte edge pixels (recover true foreground F=(C-(1-a)B)/a) to strip bg tint / chroma fringe from anti-aliased edges. Default true; leave on unless you want raw edge colours.\"},\n \"defringe\":{\"type\":\"boolean\",\"description\":\"final pass to subtract residual bg-chroma cast (magenta/green halo) left on very thin detail. Self-limiting (greys the tint, spares warm/neutral subject colour). Default true.\"},\n \"defringe_band\":{\"type\":\"integer\",\"description\":\"restrict defringe to within N px of transparent (the edge shell). Default 0 = whole image (fine, the pass is self-limiting). Set 1-3 only when the SUBJECT legitimately contains the key hue, to spare its interior.\"},\n \"model\":{\"type\":\"string\",\"description\":\"Runware model id. Default google:4@3 (Nano Banana 2). Do NOT use google:4@1 (deprecated/weak).\"},\n \"width\":{\"type\":\"integer\",\"description\":\"output px, default 1024\"},\n \"height\":{\"type\":\"integer\",\"description\":\"output px, default 1024\"},\n \"output_path\":{\"type\":\"string\",\"description\":\"write the transparent PNG here; omit to get image_base64 back\"}\n }\n }")
SFX_SCHEMA = JSON.parse("{\n \"type\":\"object\",\n \"properties\":{\n \"input_path\":{\"type\":\"string\",\"description\":\"reference sound path (wav/mp3/...) — or use audio_base64\"},\n \"audio_base64\":{\"type\":\"string\",\"description\":\"base64 of a wav/mp3 reference sound\"},\n \"preview_path\":{\"type\":\"string\",\"description\":\"optional: render an approximation wav here\"}\n }\n }")

Class methods

bus_url
Source
client
Source
emit(bytes : Bytes, data : JSON::Any) : JSON::Any
Source
handle_base(rw : RunwareClient, data : JSON::Any) : JSON::Any
Source
handle_decorate(rw : RunwareClient, data : JSON::Any) : JSON::Any
Source
handle_pixelize(rw : RunwareClient, data : JSON::Any) : JSON::Any
Source
handle_prop(rw : RunwareClient, data : JSON::Any) : JSON::Any
Source
handle_sfx(data : JSON::Any) : JSON::Any
Source
run

Standalone (mj bus): build, register, and block on the receive loop.

Source
source_bytes(data : JSON::Any) : Bytes
Source
start_background

Non-blocking (for mj serve): join the bus in a background fiber. Degrades gracefully — a missing key or unreachable daemon logs and leaves the web server running.

Source
tts(text : String, voice : String | Nil = nil, instructions : String | Nil = nil, format : String = "wav", speed : Float64 | Nil = nil) : Tuple(Bytes, String)

Synthesize speech via the openai:tts service on the bus. Returns the raw audio bytes + content-type. Reuses the mj service client's connection; request() correlates the reply, and handle_incoming routes it to us before the tool dispatcher. Raises if the bus isn't connected or TTS errors/times out.

Source