UNPKG

iobroker.javascript

Version:
7 lines 3.23 kB
import{r as e}from"./rolldown-runtime-C0FnF6B9.js";var t=e({buildActionPrompt:()=>i,parseSlashCommand:()=>a});function n(e){let t=(e||``).toLowerCase();return t.includes(`blockly`)||t.includes(`rules`)?`blockly`:t.includes(`typescript`)?`typescript`:`javascript`}function r(e,t){return`\`\`\`${t===`blockly`?`xml`:t}\n${e}\n\`\`\``}function i(e){let t=(e.code||``).trim(),i=n(e.language),a=e.rangeLabel?` (${e.rangeLabel})`:``;switch(e.action){case`explain`:return t?[`Please explain what this ioBroker ${i} code does${a}.`,`Focus on: which datapoints it reads/writes, which triggers fire it, and any side-effects.`,``,r(t,i)].join(` `):null;case`refactor`:return t?[`Refactor this ioBroker ${i} code${a} to be cleaner and more idiomatic.`,`Preserve behavior exactly. Keep ioBroker APIs (on, setState, getState, schedule, sendTo, log).`,`Return the full refactored block inside a \`\`\`${i===`blockly`?`xml`:i}\`\`\` code block so it can be smart-applied.`,``,r(t,i)].join(` `):null;case`comment`:return t?[`Add clear, concise inline comments to this ioBroker ${i} code${a}.`,`Only add comments where they add real value (non-obvious logic, tricky edge cases, business rules).`,`Do not over-comment trivial lines. Return the commented version in a code block.`,``,r(t,i)].join(` `):null;case`fix`:{if(!t)return null;let n=(e.diagnostic||``).trim();return[`This ioBroker ${i} code has an issue${a}. Please fix it and return the corrected code.${n?`\nReported problem: ${n}`:``}`,`Keep the fix minimal — do not rewrite unrelated parts.`,``,r(t,i)].join(` `)}case`tests`:return t?[`Suggest how to test this ioBroker ${i} script manually inside the ioBroker admin UI${a}.`,``,"ioBroker scripts run inside the adapter sandbox and CANNOT be unit-tested with Jest, Mocha, or any external test framework. Do NOT propose Jest/Mocha tests, do NOT propose extracting the code into a separate Node.js project, do NOT write `describe` / `test` blocks.",``,`Instead, propose a short list of manual test cases. For each case describe:`,` • Setup — which ioBroker datapoints to prepare and to which values (via the objects tree "Values" tab)`,` • Action — what to trigger: set a state with setState, wait for a schedule, change a sensor value, etc.`,` • Expected — what should happen afterwards: which states should change, what should appear in the adapter log (javascript.0), which side effects are visible`,``,`Keep it concise: 3-6 cases covering the happy path, typical edge cases, and any guard conditions the script has.`,``,r(t,i)].join(` `):null;case`ask`:{let n=(e.question||``).trim();return n?t?[`Regarding this ioBroker ${i} code${a}:`,``,r(t,i),``,n].join(` `):n:null}default:return null}}function a(e){let t=(e||``).trimStart();if(!t.startsWith(`/`))return null;let n=t.match(/^\/(\w+)(?:\s+([\s\S]*))?$/);if(!n)return null;let r=n[1].toLowerCase(),i=(n[2]||``).trim(),a={explain:`explain`,erklaere:`explain`,erklaeren:`explain`,refactor:`refactor`,refaktor:`refactor`,refaktoriere:`refactor`,comment:`comment`,comments:`comment`,kommentar:`comment`,kommentiere:`comment`,fix:`fix`,fixme:`fix`,tests:`tests`,test:`tests`,ask:`ask`,frag:`ask`,frage:`ask`}[r];return a?{action:a,rest:i}:null}export{i as n,a as r,t};