{"_id":"@dantheman181/a1111-lms-adapter","name":"@dantheman181/a1111-lms-adapter","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@dantheman181/a1111-lms-adapter","version":"0.1.0","description":"TypeScript adapter that wraps AUTOMATIC1111's Stable Diffusion Web UI HTTP API while routing prompts through LM Studio (or any OpenAI-compatible chat endpoint) for prompt enhancement first.","main":"dist/index.js","module":"dist-esm/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist-esm/index.js","require":"./dist/index.js"}},"scripts":{"build":"tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json && node -e \"require('fs').writeFileSync('dist-esm/package.json', JSON.stringify({type:'module'}, null, 2))\"","test":"node --experimental-strip-types --test test/adapter.test.ts","typecheck":"tsc --noEmit","example:txt2img":"node --experimental-strip-types examples/txt2img.ts","example:img2img":"node --experimental-strip-types examples/img2img.ts","prepublishOnly":"npm run typecheck && npm run build"},"keywords":["stable-diffusion","automatic1111","a1111","lm-studio","lmstudio","prompt-enhancement","openai-compatible","typescript","adapter"],"license":"MIT","engines":{"node":">=18.0.0"},"devDependencies":{"@types/node":"20.11.30","typescript":"5.5.3"},"publishConfig":{"access":"public"},"gitHead":"a57215dde17d0d4d6ae58e8728ca26cb97b1abb8","_id":"@dantheman181/a1111-lms-adapter@0.1.0","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-qMv8RHStgwUvX+G9kRUs1pW+Yldr45zDe71s0KP1wx7cN/3c3Kel7afEJWM8d6jJS1rGsm4aWO4u4XSCM5N3Kg==","shasum":"8ed54165810a8fec4f8cc42bf82545c0567163dc","tarball":"https://registry.npmjs.org/@dantheman181/a1111-lms-adapter/-/a1111-lms-adapter-0.1.0.tgz","fileCount":11,"unpackedSize":72615,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDn/YXkTzB0c+gXsrH7yZgw1/iMpkqVcVlKU61ZbY7/iAIhALjQvk3SvFsOTdBNv2B7A1EFv1EC6tBleDT3XX7xss7F"}]},"_npmUser":{"name":"dantheman181","email":"savaget2006@gmail.com"},"directories":{},"maintainers":[{"name":"dantheman181","email":"savaget2006@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/a1111-lms-adapter_0.1.0_1778995111004_0.3535554465289248"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-17T05:18:30.919Z","0.1.0":"2026-05-17T05:18:31.156Z","modified":"2026-05-17T05:18:31.340Z"},"maintainers":[{"name":"dantheman181","email":"savaget2006@gmail.com"}],"description":"TypeScript adapter that wraps AUTOMATIC1111's Stable Diffusion Web UI HTTP API while routing prompts through LM Studio (or any OpenAI-compatible chat endpoint) for prompt enhancement first.","keywords":["stable-diffusion","automatic1111","a1111","lm-studio","lmstudio","prompt-enhancement","openai-compatible","typescript","adapter"],"license":"MIT","readme":"# a1111-lms-adapter\r\n\r\nTypeScript adapter that wraps **AUTOMATIC1111's Stable Diffusion Web UI** HTTP API while routing prompts through **LM Studio** (or any OpenAI-compatible chat endpoint) for prompt enhancement first.\r\n\r\nA short, vague user prompt becomes a detailed Stable-Diffusion-friendly one, then gets sent to A1111. Drop-in compatible with the txt2img / img2img request shapes.\r\n\r\n```ts\r\nimport { A1111LMSAdapter } from \"@dantheman181/a1111-lms-adapter\";\r\n\r\nconst adapter = new A1111LMSAdapter({\r\n  a1111BaseUrl: \"http://127.0.0.1:7860\",\r\n  lmStudioBaseUrl: \"http://127.0.0.1:1234\",\r\n});\r\n\r\nconst result = await adapter.txt2img({\r\n  prompt: \"a cat\",                      // becomes \"a regal tabby cat sitting…\"\r\n  steps: 25,\r\n  width: 768,\r\n  height: 768,\r\n});\r\n\r\n// result.images[0] is a base64-encoded PNG\r\n```\r\n\r\n## Why\r\n\r\nA1111 produces dramatically better images when given detailed, specific prompts. Most humans type short, vague ones. LM Studio is already running on most ML rigs. This module sits between the two and uses the LLM you already have to upgrade the prompt.\r\n\r\nIt's intentionally small. No image processing, no model loading, no batching — just an HTTP shim that does one thing well.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @dantheman181/a1111-lms-adapter\r\n```\r\n\r\nRequires Node 18+ for the built-in `fetch`.\r\n\r\n## Quick start\r\n\r\nTwo services need to be running:\r\n\r\n1. **AUTOMATIC1111** with the `--api` flag (default `http://127.0.0.1:7860`)\r\n2. **LM Studio** server with a model loaded (default `http://127.0.0.1:1234`)\r\n\r\nThen:\r\n\r\n```ts\r\nimport { A1111LMSAdapter } from \"@dantheman181/a1111-lms-adapter\";\r\n\r\nconst adapter = new A1111LMSAdapter({\r\n  a1111BaseUrl: \"http://127.0.0.1:7860\",\r\n  lmStudioBaseUrl: \"http://127.0.0.1:1234\",\r\n});\r\n\r\n// Generate an image — prompt is enhanced via LM Studio before reaching A1111.\r\nconst txt = await adapter.txt2img({\r\n  prompt: \"a portrait of a fox\",\r\n  steps: 25,\r\n  width: 768,\r\n  height: 768,\r\n});\r\n\r\n// Restyle an existing image.\r\nconst img = await adapter.img2img({\r\n  prompt: \"in watercolour, soft brushstrokes\",\r\n  init_images: [base64InputImage],\r\n  denoising_strength: 0.55,\r\n});\r\n\r\n// Preview the enhancement without committing to a generation.\r\nconst enhanced = await adapter.enhancePrompt(\"a cat\");\r\n```\r\n\r\n## Configuration\r\n\r\n```ts\r\nnew A1111LMSAdapter({\r\n  // ── Required ──────────────────────────────────────────────────────────\r\n  a1111BaseUrl: \"http://127.0.0.1:7860\",\r\n  lmStudioBaseUrl: \"http://127.0.0.1:1234\",\r\n\r\n  // ── Optional ──────────────────────────────────────────────────────────\r\n\r\n  /** Force a specific model id. Most LM Studio installs auto-select. */\r\n  lmStudioModel: \"qwen2.5-coder-7b\",\r\n\r\n  /** Tuning knobs for the enhancement call. */\r\n  enhancementTemperature: 0.7,    // default 0.7\r\n  enhancementMaxTokens:    300,   // default 300\r\n\r\n  /** Override the system prompt used during enhancement. */\r\n  enhancementSystemPrompt: \"Rewrite the user's prompt as a detailed Stable Diffusion prompt.\",\r\n\r\n  /** Per-call timeouts. A1111 can take a while; LM Studio less so. */\r\n  lmStudioTimeoutMs: 60_000,      // default 60s\r\n  a1111TimeoutMs:    600_000,     // default 10m\r\n\r\n  /** Bearer token forwarded on every request. LM Studio doesn't need one;\r\n   *  OpenRouter / OpenAI do. */\r\n  authToken: process.env.OPENROUTER_API_KEY,\r\n\r\n  /** Retry policy. Retries fire on 5xx, 408, 429, network errors. */\r\n  retries: 2,                      // default 2\r\n  retryBaseMs: 500,                // default 500 (exponential backoff)\r\n\r\n  /** Hook into your observability stack. */\r\n  log: (event, fields) => myLogger.info(event, fields),\r\n});\r\n```\r\n\r\n## Bypassing enhancement\r\n\r\nWhen the user has crafted a prompt themselves and doesn't want LM Studio touching it, pass `{ bypass: true }`:\r\n\r\n```ts\r\nawait adapter.txt2img({ prompt: \"exact prompt I want\" }, { bypass: true });\r\n```\r\n\r\n## Errors\r\n\r\nAll HTTP failures throw subclasses of `AdapterError` so you can pattern-match:\r\n\r\n```ts\r\nimport { A1111Error, LMStudioError, TimeoutError } from \"a1111-lms-adapter\";\r\n\r\ntry {\r\n  await adapter.txt2img({ prompt: \"x\" });\r\n} catch (err) {\r\n  if (err instanceof TimeoutError) /* retry, reduce steps, etc. */;\r\n  if (err instanceof LMStudioError) /* check LM Studio is up */;\r\n  if (err instanceof A1111Error) /* check A1111 is up */;\r\n  throw err;\r\n}\r\n```\r\n\r\nEach error carries `.status` (HTTP status, or 0 for network errors) and `.body` (the response body when one was returned).\r\n\r\n## Pointing at OpenRouter / OpenAI / vLLM\r\n\r\nThe LM Studio side speaks the OpenAI Chat Completions wire format, so any OpenAI-compatible endpoint works:\r\n\r\n```ts\r\nnew A1111LMSAdapter({\r\n  a1111BaseUrl: \"http://127.0.0.1:7860\",\r\n  lmStudioBaseUrl: \"https://openrouter.ai/api\",\r\n  lmStudioModel: \"deepseek/deepseek-chat-v3.1:free\",\r\n  authToken: process.env.OPENROUTER_API_KEY,\r\n});\r\n```\r\n\r\n## Examples\r\n\r\nTwo example scripts live in `examples/`:\r\n\r\n```bash\r\n# Generate an image\r\nnpx tsx examples/txt2img.ts \"a moody portrait of a fox\"\r\n\r\n# Restyle an existing image\r\nnpx tsx examples/img2img.ts ./photo.png \"in the style of Studio Ghibli\"\r\n```\r\n\r\n## Testing\r\n\r\n```bash\r\nnpm install\r\nnpm test\r\n```\r\n\r\nThe test suite spins up two fake HTTP servers (one for A1111, one for LM Studio) and exercises every code path: enhancement, bypass, error mapping, retries, timeouts, auth header forwarding. No real models or GPUs needed.\r\n\r\n## License\r\n\r\nMIT.\r\n","readmeFilename":"README.md","_rev":"1-7da7f1f17b8df34e128769174df4d5aa"}