iobroker.javascript 10.2.1 → 10.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +1 -1
  2. package/admin/assets/{AiChatPanel-CsDFom-L.js → AiChatPanel-DsQB1Hb5.js} +8 -8
  3. package/admin/assets/{AiChatService-k72w0sOt.js → AiChatService-Bsp_rhVx.js} +1 -1
  4. package/admin/assets/AiDiffView-Cri2QFh1.js +1 -0
  5. package/admin/assets/{AiInlineProvider-C5EJApDe.js → AiInlineProvider-BxOW88xU.js} +1 -1
  6. package/admin/assets/{Debugger-B6_1wqlh.js → Debugger-CcDNCkmw.js} +7 -7
  7. package/admin/assets/Error-Ch2nx5uC.js +1 -0
  8. package/admin/assets/Import-XKVP-nRT.js +1 -0
  9. package/admin/assets/RulesEditor-B6YQNZfq.js +1 -0
  10. package/admin/assets/RulesEditor-BwQ6Bo1V.css +1 -0
  11. package/admin/assets/{ScriptEditor-BxwJbR3_.js → ScriptEditor-BkuL2lZ1.js} +2 -2
  12. package/admin/assets/{ScriptEditorVanillaMonaco-C3AgkXsv.js → ScriptEditorVanillaMonaco-DYNr4-5w.js} +3 -3
  13. package/admin/assets/{_virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-CQpJXcpz.js → _virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-BMAFQFoH.js} +1 -1
  14. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js +1217 -0
  15. package/admin/assets/{_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-B8K8J9cp.js → _virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-CDctpiPx.js} +1 -1
  16. package/admin/assets/aiPromptBuilder-db3Z4xhV.js +1 -0
  17. package/admin/assets/blockly-fcfyKYzp.js +1053 -0
  18. package/admin/assets/{blocks_action-CPgrbjAf.js → blocks_action-EYzXGRHi.js} +1 -1
  19. package/admin/assets/{blocks_convert-2eEzarQy.js → blocks_convert-BewF036e.js} +1 -1
  20. package/admin/assets/{blocks_logic-DMEjFKWc.js → blocks_logic-BEcVdiZ4.js} +1 -1
  21. package/admin/assets/{blocks_number-Bsx0zQT_.js → blocks_number-Cp7J-juL.js} +1 -1
  22. package/admin/assets/{blocks_object-Q1nKLN6t.js → blocks_object-CCe0acSu.js} +1 -1
  23. package/admin/assets/{blocks_procedures-CHMjZQbf.js → blocks_procedures-BzFeWYcX.js} +1 -1
  24. package/admin/assets/{blocks_sendto-DsDq_Gu7.js → blocks_sendto-EBwcaHpm.js} +1 -1
  25. package/admin/assets/{blocks_switch-Yog8S2MC.js → blocks_switch-CjohzLLS.js} +1 -1
  26. package/admin/assets/{blocks_system-2D8iX32Y.js → blocks_system-D9V3f3Vv.js} +1 -1
  27. package/admin/assets/{blocks_text-C5-csrVL.js → blocks_text-CnEbzx6V.js} +1 -1
  28. package/admin/assets/{blocks_time-LB5i9yMW.js → blocks_time-B5OcgKMo.js} +1 -1
  29. package/admin/assets/{blocks_timeout-CHGW670q.js → blocks_timeout-ONu3mIX3.js} +1 -1
  30. package/admin/assets/{blocks_trigger-D-2z_OfF.js → blocks_trigger-3DujkROX.js} +1 -1
  31. package/admin/assets/{cronHoverProvider-DYMf8M44.js → cronHoverProvider-BZMOFHO_.js} +1 -1
  32. package/admin/assets/{field_cron-B-SF-uZM.js → field_cron-CxKi__cX.js} +1 -1
  33. package/admin/assets/{field_oid-fYE12Bhj.js → field_oid-CJIYiGxY.js} +1 -1
  34. package/admin/assets/{field_script-aZs3j-vG.js → field_script-CehplM7L.js} +1 -1
  35. package/admin/assets/{helpers-CalO_DDQ.js → helpers-BiP5KGR8.js} +1 -1
  36. package/admin/assets/{hostInit-CzvCZFy5.js → hostInit-Bs-bStPF.js} +1 -1
  37. package/admin/assets/{index-CqFiN-25.js → index-CRX4LAhD.js} +67 -67
  38. package/admin/assets/index-CXaeqPRy.css +1 -0
  39. package/admin/assets/{inlineChatWidget-n7ufGLov.js → inlineChatWidget-NIvdRGmU.js} +2 -2
  40. package/admin/assets/{inlineDiffController-5u3tIcIH.js → inlineDiffController-Qh402KhK.js} +2 -2
  41. package/admin/assets/{mf-entry-bootstrap-0-db6d825d.js → mf-entry-bootstrap-0-4b82aeb4.js} +3 -3
  42. package/admin/assets/pendingShares-B3t6ewri.js +1 -0
  43. package/admin/assets/{stateHoverProvider-C0OUV2Nh.js → stateHoverProvider-BkW15VMN.js} +1 -1
  44. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-CiidVc0O.js +1 -0
  45. package/admin/custom/assets/Components-SGnA-3W_.js +1 -0
  46. package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-Bx3X6TLB.js +1 -0
  47. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-CdvEvX5z.js +1 -0
  48. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-o8Mkax3s.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D5NaoeJi.js} +1 -1
  49. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-Cbgw_a3f.js +1 -0
  50. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare___mf_0_mui_mf_1_x_mf_2_date_mf_2_pickers__loadShare__.js-CMr75K5w.js +1 -0
  51. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare__date_mf_2_fns__loadShare__.js-DKIvPDPX.js +1 -0
  52. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-D50aYKgD.js +1 -0
  53. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__prebuild___mf_0_iobroker_mf_1_json_mf_2_config__prebuild__-bDecxMAs.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__prebuild___mf_0_iobroker_mf_1_json_mf_2_config__prebuild__-CEzQFX7o.js} +7 -9
  54. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__prebuild__leaflet__prebuild__-BUDmnAcx.js +1 -0
  55. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__prebuild__react_mf_2_dom_mf_1_client__prebuild__-Thbi9Vo9.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__prebuild__react_mf_2_dom_mf_1_client__prebuild__-D_1oh1WH.js} +1 -1
  56. package/admin/custom/assets/{hostInit-B0Qa8jfJ.js → hostInit-IJMNq3h7.js} +1 -1
  57. package/admin/custom/assets/index-7r4VklMp.js +1 -0
  58. package/admin/custom/assets/{lib-BDVPOOMD.js → lib-DDU2Oe48.js} +1 -1
  59. package/admin/custom/assets/{mf-entry-bootstrap-0-b41e47ad.js → mf-entry-bootstrap-0-f149bc46.js} +3 -3
  60. package/admin/custom/assets/pendingShares-DarGQhyO.js +1 -0
  61. package/admin/custom/assets/virtualExposes-C0IqMANQ.js +1 -0
  62. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-CqKvh5Xu.js +1 -0
  63. package/admin/custom/assets/{virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-C0XlV8T_.js → virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-DrBN_S5o.js} +2 -2
  64. package/admin/custom/customComponents.js +2 -2
  65. package/admin/mf-manifest.json +1 -1
  66. package/admin/mf-stats.json +1 -1
  67. package/admin/remoteEntry.js +2 -2
  68. package/admin/tab.html +6 -6
  69. package/io-package.json +27 -27
  70. package/package.json +2 -2
  71. package/admin/assets/AiDiffView-DAleMXcP.js +0 -1
  72. package/admin/assets/Error-DBiAAbCC.js +0 -1
  73. package/admin/assets/Import-Dm-2zYlI.js +0 -1
  74. package/admin/assets/RulesEditor-BML5AwgM.js +0 -1
  75. package/admin/assets/RulesEditor-CybrKL-9.css +0 -1
  76. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-Drq9CkPs.js +0 -1217
  77. package/admin/assets/aiPromptBuilder-CuCGSQIi.js +0 -1
  78. package/admin/assets/blockly-Fp-1_Ye3.js +0 -1047
  79. package/admin/assets/index-Z8Hkv58g.css +0 -1
  80. package/admin/assets/pendingShares-C6DqQuMX.js +0 -1
  81. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-BvxK85AS.js +0 -1
  82. package/admin/custom/assets/Components-qR8oYG5T.js +0 -1
  83. package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-CB5V_0nT.js +0 -1
  84. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-CFSZkPFK.js +0 -1
  85. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-DLa2mE8b.js +0 -1
  86. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare___mf_0_mui_mf_1_x_mf_2_date_mf_2_pickers__loadShare__.js-CZc6K9E9.js +0 -1
  87. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare__date_mf_2_fns__loadShare__.js-Bx5h7ISf.js +0 -1
  88. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Ca3AhTHn.js +0 -1
  89. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__prebuild__leaflet__prebuild__-CAKlcuIS.js +0 -1
  90. package/admin/custom/assets/index-DADYLUN0.js +0 -1
  91. package/admin/custom/assets/pendingShares-Gn0OX49v.js +0 -1
  92. package/admin/custom/assets/virtualExposes-DjwWqUOb.js +0 -1
  93. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-CHOLf9xJ.js +0 -1
  94. /package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-Cc7MmJgr.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-Cc7MmJgr.js} +0 -0
  95. /package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__loadShare__leaflet__loadShare__.js-im3edKNs.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__loadShare__leaflet__loadShare__.js-im3edKNs.js} +0 -0
  96. /package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__32150414352696__prebuild__react_mf_1_jsx_mf_2_runtime__prebuild__-Byvr2uOb.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__136440932828998__prebuild__react_mf_1_jsx_mf_2_runtime__prebuild__-Byvr2uOb.js} +0 -0
package/README.md CHANGED
@@ -27,7 +27,7 @@ Executes JavaScript, TypeScript Scripts.
27
27
  -->
28
28
 
29
29
  ## Changelog
30
- ### 10.2.1 (2026-09-11)
30
+ ### 10.2.3 (2026-09-13)
31
31
  * (@GermanBluefox) Rules: selection of state fixed
32
32
 
33
33
  ### 10.2.0 (2026-09-11)
@@ -1,5 +1,5 @@
1
- import{t as e}from"./vite-preload-helper-CaC3yEL3.js";import{An as t,Bt as n,Cr as r,Dn as i,Ht as a,Kn as o,On as s,Or as c,Qt as l,Rt as u,Sn as d,Un as f,Ut as p,Vt as m,Wt as h,Zt as g,bn as _,bt as v,dt as y,gr as b,hn as x,jn as S,mn as C,nr as w,p as T,rr as E,wn as ee,wr as D,xr as O,xt as k,yr as A,yt as j}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-Drq9CkPs.js";import{S as M,g as te,h as N,m as P,s as F}from"./index-CqFiN-25.js";import{a as I,c as L,d as R,f as z,h as B,i as V,l as H,m as U,n as W,o as G,p as K,r as ne,s as q,t as J,u as Y}from"./AiChatService-k72w0sOt.js";var X=f(w(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m5 11h-4v4h-2v-4H7v-2h4V7h2v4h4z`}),`AddCircleOutlined`),re=f(w(`path`,{d:`M21.99 4c0-1.1-.89-2-1.99-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4zM17 11h-4v4h-2v-4H7V9h4V5h2v4h4z`}),`AddComment`),ie=f(w(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10h5v-2h-5c-4.34 0-8-3.66-8-8s3.66-8 8-8 8 3.66 8 8v1.43c0 .79-.71 1.57-1.5 1.57s-1.5-.78-1.5-1.57V12c0-2.76-2.24-5-5-5s-5 2.24-5 5 2.24 5 5 5c1.38 0 2.64-.56 3.54-1.47.65.89 1.77 1.47 2.96 1.47 1.97 0 3.5-1.6 3.5-3.57V12c0-5.52-4.48-10-10-10m0 13c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3`}),`AlternateEmail`),ae=f(w(`path`,{d:`M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z`}),`CompareArrows`),oe=f(w(`path`,{d:`M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4m0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4`}),`Person`),se=f(w(`path`,{d:`M3 10h11v2H3zm0-4h11v2H3zm0 8h7v2H3zm17.59-2.07-4.25 4.24-2.12-2.12-1.41 1.41L16.34 19 22 13.34z`}),`PlaylistAddCheck`),ce=f(w(`path`,{d:`M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3M7.5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S9.83 13 9 13s-1.5-.67-1.5-1.5M16 17H8v-2h8zm-1-4c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13`}),`SmartToy`);c();var le=[{type:`function`,function:{name:`search_datapoints`,description:`Search ALL ioBroker objects by ID, name, or role — includes states, channels, devices, folders, enums (rooms/functions), adapters, instances, scripts, meta, etc. Returns matching IDs with object type, name, role, unit, and a hasChildren hint for containers. IMPORTANT: Aliases and physical device groupings are usually CHANNELS containing multiple state children (e.g. a motion sensor is often a channel alias.0.Floor.Room.MotionSensor with states ACTUAL, BATTERY, STATE under it). If a channel/device/folder matches your query, call get_object_info on its ID to list its state children. Role-based queries work too: "sensor.motion", "switch.light", "value.temperature".`,parameters:{type:`object`,properties:{query:{type:`string`,description:`Search pattern (case-insensitive substring) - matches against object ID, name, and role. Examples: "bewegungsmelder", "temperature", "sensor.motion", "alias.0", "küche", "zigbee2mqtt.0.lamp".`},max_results:{type:`number`,description:`Maximum number of results to return (default: 20).`},object_type:{type:`string`,description:`Optional filter by object type: "state", "channel", "device", "folder", "enum", "adapter", "instance", "script", "meta", etc. Omit to search every type.`}},required:[`query`]}}},{type:`function`,function:{name:`get_state_value`,description:`Get the current value of an ioBroker state/datapoint. Returns value, timestamp, and acknowledgment flag.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The full state ID, e.g. "zigbee2mqtt.0.sensor.temperature"`}},required:[`id`]}}},{type:`function`,function:{name:`get_object_info`,description:`Get detailed info about ANY ioBroker object + its full parent hierarchy + direct children. Works for every object type: state, channel, device, folder, adapter, instance, enum, meta, script. Returns: the object itself, parent chain (all non-state ancestors up to the adapter), and — if the object is a container (channel/device/folder/enum/instance/adapter/meta) — the list of direct children with their types, names, roles and units. Use this to navigate the object tree: start from a channel found by search_datapoints, read its children to see the actual state IDs underneath.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The full object ID, e.g. "zigbee2mqtt.0.0x1234.state", "alias.0.Room.MotionSensor", or "enum.rooms.kitchen".`}},required:[`id`]}}},{type:`function`,function:{name:`search_scripts`,description:`Search through all ioBroker JavaScript/Blockly/Rules scripts. Can search by script name/path OR by content (e.g. find all scripts that use a specific datapoint ID). Returns matching script names, paths, and matching lines.`,parameters:{type:`object`,properties:{query:{type:`string`,description:`Search term - matches against script name, path, AND source code content. Examples: "carport", "zigbee2mqtt.0.lamp.state", "telegram"`},max_results:{type:`number`,description:`Maximum number of scripts to return (default: 10)`}},required:[`query`]}}},{type:`function`,function:{name:`read_script`,description:`Read the full source code of a specific ioBroker script by its ID or path. Use search_scripts first to find the script ID, then read_script to see its complete code.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The script ID (e.g. "script.js.common.Licht.Carport") or path (e.g. "common/Licht/Carport")`}},required:[`id`]}}},{type:`function`,function:{name:`list_scripts`,description:`List ALL available ioBroker scripts with their names, paths, types (JavaScript/Blockly/TypeScript), and enabled status. Use this to get an overview of all scripts before searching or reading specific ones.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`run_script`,description:"Execute a JavaScript or TypeScript snippet in the live ioBroker javascript engine and get back everything it logged. The code runs with the full script API (log, console.*, setState, getState, on, schedule, $, exec, httpGet, …) in VERBOSE mode, so internal operations (setState/getState/subscribe/…) are logged too — ideal for diagnosing behaviour or inspecting values. The snippet runs for a short window and is then automatically STOPPED and fully cleaned up (timers, subscriptions, schedules removed); it does NOT create a persistent script. Use `log(...)` or `console.log(...)` in the code to surface the values you want to inspect. WARNING: side effects are real (e.g. setState changes actual devices) — prefer read-only diagnostics unless the user explicitly asked to change something.",parameters:{type:`object`,properties:{source:{type:`string`,description:`The JavaScript (or TypeScript) source to execute. Log the values you want to inspect via log(...) / console.log(...). Top-level await is supported.`},engineType:{type:`string`,description:`Optional. "TypeScript/ts" to run the code as TypeScript. Defaults to JavaScript.`},timeout:{type:`number`,description:`Optional. Milliseconds to keep the script alive to collect asynchronous logs before it is stopped (default 5000, max 60000). Increase when waiting for timers, subscriptions or HTTP responses.`},logLevel:{type:`string`,description:`Optional minimum severity to return: silly, debug, info, warn, error. Default silly (everything).`}},required:[`source`]}}},{type:`function`,function:{name:`get_editor_selection`,description:`Read what the user has currently selected in the script editor. Returns the selected text and its line/column range, or a message if nothing is selected. Use this when the user refers to "this", "das hier", "the selection", or asks about a specific piece of code they highlighted.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_editor_content`,description:`Read the full current content of the script editor (may differ from the initial script version if the user has made edits). Use this when you need the live editor state rather than the saved script.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_cursor_position`,description:`Read the current cursor position (line and column, 1-based) in the script editor.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`highlight_text_in_editor`,description:`Search for a literal text in the script editor and select + scroll to it. Returns how many occurrences were found. Use this to draw the user's attention to a specific snippet you are discussing.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Exact substring to search for (case-sensitive).`}},required:[`text`]}}},{type:`function`,function:{name:`highlight_line_range`,description:`Select and scroll to a range of lines in the editor. Both line numbers are 1-based and inclusive. Use this to show the user which block of code you are referring to.`,parameters:{type:`object`,properties:{start_line:{type:`number`,description:`First line (1-based, inclusive).`},end_line:{type:`number`,description:`Last line (1-based, inclusive).`}},required:[`start_line`,`end_line`]}}},{type:`function`,function:{name:`go_to_line`,description:`Move the cursor to a specific line (and optional column) and scroll that line into view. Use this to navigate the user to a relevant spot.`,parameters:{type:`object`,properties:{line:{type:`number`,description:`1-based line number.`},column:{type:`number`,description:`1-based column (optional, default 1).`}},required:[`line`]}}},{type:`function`,function:{name:`insert_text_at_cursor`,description:`Insert text at the current cursor position in the editor (or replace the current selection if one exists). Use sparingly — prefer returning code in a fenced markdown block so the user can review and smart-apply it. Only use direct insertion when the user explicitly asked you to write something into the editor.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Text to insert.`}},required:[`text`]}}},{type:`function`,function:{name:`replace_selection`,description:`Replace the currently selected text in the editor with new text. Fails if nothing is selected. Use this to refactor or rewrite a specific highlighted snippet.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Replacement text.`}},required:[`text`]}}},{type:`function`,function:{name:`get_diagnostics`,description:`Read all active Monaco diagnostics (errors, warnings, info, hints) from the current editor model — this is what shows up as red/yellow squiggles. Use this to find syntax errors, unused variables, missing types, or other editor-reported issues the user might be asking about.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_document_symbols`,description:`Get the document outline of the current script: all top-level functions, classes, constants, and variables with their line numbers. Use this to understand the structure of a long script or to find where a specific function is defined.`,parameters:{type:`object`,properties:{}}}}];function Z(e){return e&&typeof e==`object`?e.en||e.de||``:e||``}function ue(e,t,n){let r=(n||``).toLowerCase();if(!r)return!1;if(e.toLowerCase().includes(r))return!0;let i=t==null?void 0:t.common;if(!i)return!1;let a=Z(i.name).toLowerCase();if(a&&a.includes(r))return!0;let o=(i.role||``).toLowerCase();return!!(o&&o.includes(r))}async function de(e,t,n=20,r){let i=await I(e),a=r==null?void 0:r.toLowerCase(),o=[],s=Object.keys(i),c=new Set;for(let e of s){let t=e.lastIndexOf(`.`);t>0&&c.add(e.substring(0,t))}for(let e of s){let r=i[e],s=r==null?void 0:r.type;if(!s||a&&s!==a||!ue(e,r,t))continue;let l=r.common,u={id:e,type:s,name:Z(l==null?void 0:l.name)};if(l!=null&&l.role&&(u.role=l.role),s===`state`?(u.stateType=(l==null?void 0:l.type)||``,l!=null&&l.unit&&(u.unit=l.unit)):c.has(e)&&(u.hasChildren=!0),o.push(u),o.length>=n)break}return o.length===0?JSON.stringify({message:`No objects found matching "${t}". Hint: try a role like "sensor.motion" or a partial path.`}):JSON.stringify(o)}async function fe(e,t){try{let n=await e.getState(t);return JSON.stringify(n?{val:n.val,ts:n.ts?new Date(n.ts).toISOString():null,ack:n.ack,from:n.from}:{error:`State '${t}' not found`})}catch{return JSON.stringify({error:`Failed to read state '${t}'`})}}var pe=new Set([`channel`,`device`,`folder`,`adapter`,`instance`,`enum`,`meta`]),me=50;async function he(e,t){try{let r=await e.getObject(t);if(!r)return JSON.stringify({error:`Object '${t}' not found`});let i={id:r._id,type:r.type,common:r.common},a=t.split(`.`),o=[];for(let t=a.length-1;t>=2;t--){let r=a.slice(0,t).join(`.`);try{let t=await e.getObject(r);if(t&&t.type!==`state`){var n;o.push({id:t._id,type:t.type,name:Z((n=t.common)==null?void 0:n.name),common:t.common})}}catch{}}if(o.length>0&&(i.parents=o),pe.has(r.type)){let n=await I(e),r=[],a=`${t}.`,o=!1;for(let e of Object.keys(n))if(e.startsWith(a)&&!e.substring(a.length).includes(`.`)){let t=n[e],i=t==null?void 0:t.common,a={id:e,name:Z(i==null?void 0:i.name),type:(t==null?void 0:t.type)||``};if(i!=null&&i.role&&(a.role=i.role),(t==null?void 0:t.type)===`state`&&i!=null&&i.unit&&(a.unit=i.unit),r.push(a),r.length>=me){o=!0;break}}r.length>0&&(i.children=r,o&&(i.childrenTruncated=!0,i.childrenHint=`Only the first ${me} children are shown. Use search_datapoints with a more specific query or the object_type filter to narrow down.`))}return JSON.stringify(i)}catch{return JSON.stringify({error:`Failed to read object '${t}'`})}}function ge(e){return N(e)||e}function _e(e,t,n=10){let r=t.toLowerCase(),i=[];for(let t of e){let e=t.id.toLowerCase(),a=t.name.toLowerCase(),o=t.id.replace(/^script\.js\./,``).replace(/\./g,`/`),s=t.engineType===`Blockly`||t.engineType===`Rules`,c=e.includes(r)||a.includes(r),l=s?ge(t.source):t.source,u=l.toLowerCase().includes(r);if(c||u){let e={id:t.id,path:o,name:t.name,type:s?`Blockly`:t.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:t.enabled};if(u){let t=l.split(`
2
- `),n=[];for(let e=0;e<t.length&&!(t[e].toLowerCase().includes(r)&&(n.push({line:e+1,text:t[e].trim()}),n.length>=5));e++);n.length>0&&(e.matchingLines=n)}if(i.push(e),i.length>=n)break}}return i.length===0?JSON.stringify({message:`No scripts found matching "${t}"`}):JSON.stringify(i)}function ve(e,t){let n=t.replace(/\//g,`.`).toLowerCase(),r=e.find(e=>{let t=e.id.toLowerCase();return t===n||t===`script.js.${n}`||t.endsWith(`.${n}`)});if(!r)return JSON.stringify({error:`Script '${t}' not found. Use search_scripts to find available scripts.`});let i=r.engineType===`Blockly`||r.engineType===`Rules`,a=i?ge(r.source):r.source,o=r.id.replace(/^script\.js\./,``).replace(/\./g,`/`);return JSON.stringify({id:r.id,path:o,name:r.name,type:i?`Blockly`:r.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:r.enabled,source:a})}function ye(e){let t=e.map(e=>({id:e.id,path:e.id.replace(/^script\.js\./,``).replace(/\./g,`/`),name:e.name,type:e.engineType===`Blockly`||e.engineType===`Rules`?`Blockly`:e.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:e.enabled}));return JSON.stringify(t)}function Q(){return JSON.stringify({error:`Editor is not available. This tool requires the script editor to be open.`})}async function be(e,t,n){if(!t)return JSON.stringify({error:`No running javascript instance found to execute the script.`});let r=n.source;if(!r||typeof r!=`string`)return JSON.stringify({error:`No source code provided.`});try{var i;let a=await e.sendTo(t,`execute`,{source:r,engineType:n.engineType,timeout:n.timeout,logLevel:n.logLevel});return!a||a.ok===!1?JSON.stringify({error:(a==null?void 0:a.error)||`Execution failed`,logs:(a==null?void 0:a.logs)||[]}):JSON.stringify({engineType:a.engineType,runtime:a.runtime,truncated:a.truncated||!1,logCount:((i=a.logs)==null?void 0:i.length)||0,logs:a.logs||[],output:a.output||``})}catch(e){return JSON.stringify({error:`Failed to execute script: ${e instanceof Error?e.message:String(e)}`})}}async function xe(e,t,n,r,i){let a;try{a=JSON.parse(t.function.arguments)}catch{return JSON.stringify({error:`Invalid arguments: ${t.function.arguments}`})}switch(t.function.name){case`search_datapoints`:return de(e,a.query,a.max_results||20,a.object_type);case`get_state_value`:return fe(e,a.id);case`get_object_info`:return he(e,a.id);case`search_scripts`:return _e(n||[],a.query,a.max_results||10);case`read_script`:return ve(n||[],a.id);case`list_scripts`:return ye(n||[]);case`run_script`:return be(e,i,a);case`get_editor_selection`:{if(!(r!=null&&r.getSelection))return Q();let e=r.getSelection();return JSON.stringify(e||{message:`No text is currently selected in the editor.`})}case`get_editor_content`:return r!=null&&r.getContent?JSON.stringify({content:r.getContent()}):Q();case`get_cursor_position`:{if(!(r!=null&&r.getCursorPosition))return Q();let e=r.getCursorPosition();return JSON.stringify(e||{message:`Editor has no cursor position (not focused).`})}case`highlight_text_in_editor`:{if(!(r!=null&&r.highlightText))return Q();let e=r.highlightText(a.text);return JSON.stringify({matches:e,message:e===0?`Text "${a.text}" was not found in the editor.`:`Highlighted ${e} occurrence(s) of "${a.text}".`})}case`highlight_line_range`:{if(!(r!=null&&r.highlightLineRange))return Q();let e=r.highlightLineRange(a.start_line,a.end_line);return JSON.stringify({success:e,message:e?`Selected lines ${a.start_line}-${a.end_line}.`:`Could not select the requested line range.`})}case`go_to_line`:{if(!(r!=null&&r.goToLine))return Q();let e=r.goToLine(a.line,a.column);return JSON.stringify({success:e,message:e?`Cursor moved to line ${a.line}.`:`Could not move the cursor.`})}case`insert_text_at_cursor`:{if(!(r!=null&&r.insertTextAtCursor))return Q();let e=r.insertTextAtCursor(a.text);return JSON.stringify({success:e,message:e?`Text inserted at cursor.`:`Editor rejected the insertion.`})}case`replace_selection`:{if(!(r!=null&&r.replaceSelection))return Q();let e=r.replaceSelection(a.text);return JSON.stringify({success:e,message:e?`Selection replaced.`:`No text was selected to replace.`})}case`get_diagnostics`:{if(!(r!=null&&r.getDiagnostics))return Q();let e=r.getDiagnostics();return JSON.stringify({count:e.length,diagnostics:e})}case`get_document_symbols`:{if(!(r!=null&&r.getSymbols))return Q();let e=await r.getSymbols();return JSON.stringify({count:e.length,symbols:e})}default:return JSON.stringify({error:`Unknown tool: ${t.function.name}`})}}var Se=0;function Ce(){return`msg_${Date.now()}_${++Se}`}function we(t){let{socket:n,runningInstances:i,currentCode:a,currentLanguage:o,allScripts:s,editorApi:c,currentScriptId:l}=t,u=b((e,t,n)=>e===`none`||!n?null:{range:t,scriptId:l||``,scriptVersion:(a||``).length,kind:e,originalText:n},[l,a]),[d,f]=D(()=>{try{let e=window.localStorage.getItem(`Editor.aiChatMessages`);return e?JSON.parse(e):[]}catch{return[]}}),p=b(e=>{f(t=>{let n=typeof e==`function`?e(t):e,r=n.length>100?n.slice(-100):n;try{window.localStorage.setItem(`Editor.aiChatMessages`,JSON.stringify(r))}catch{try{let e=r.slice(-20);window.localStorage.setItem(`Editor.aiChatMessages`,JSON.stringify(e))}catch{}}return r})},[]),[m,h]=D(!1),[g,_]=D(null),[v,y]=D(window.localStorage.getItem(`Editor.aiChatMode`)||`agent`),x=b(e=>{y(e),window.localStorage.setItem(`Editor.aiChatMode`,e)},[]),[S,C]=D(null),[w,E]=D(window.localStorage.getItem(`openai-model`)||``),[ee,O]=D([]),[k,j]=D({}),[M,N]=D(!0),[F,I]=D(null),W=r(null),J=r(null),X=r(null),re=r(null),ie=b(e=>{E(e),K(e,k[e])},[k]),ae=b(async()=>{N(!0),I(null);try{let e=await R(n,i);if(O(e.models),j(e.providerMap),e.models.length>0){let t=z().model,n=t&&e.models.includes(t)?t:e.models[0];E(n),K(n,e.providerMap[n])}e.errors.length>0&&I(e.errors.join(`; `))}catch(e){I(String(e))}N(!1)},[n,i]);A(()=>{ae()},[ae]);let oe=b(e=>{let t=!1,n=!1,r=[],i=!1,a=/@([\w/äöüÄÖÜß-]+)/g,o;for(;(o=a.exec(e))!==null;){let e=o[1].toLowerCase();if(e===`alle`||e===`all`)t=!0;else if(e===`geräte`||e===`devices`||e===`geraete`)n=!0;else if(i=!0,s&&s.length>0){let e=o[1].replace(/\//g,`.`).toLowerCase(),t=e.split(`.`),n=s.find(n=>{let r=n.id.toLowerCase(),i=r.replace(/^script\.js\./,``);if(i===e||i.endsWith(`.${e}`)||r===`script.js.${e}`)return!0;let a=0;for(let e of t){let t=i.indexOf(e,a);if(t===-1)return!1;a=t+e.length}return!0});if(n)r.push(n.id);else for(let e of t){if(e.length<3)continue;let t=s.filter(t=>t.id.toLowerCase().includes(`.${e}`)||t.name.toLowerCase().includes(e));for(let e of t)r.includes(e.id)||r.push(e.id)}}}return i&&r.length===0&&(t=!0),{cleanMessage:e.replace(/@[\w/äöüÄÖÜß]+\s*/g,``).trim(),mentionedScriptIds:r,includeAll:t,includeDevices:n}},[s]),se=b(async(e,t,r)=>{re.current||=await H(),W.current||=await G(n,i);let c=Y(),l=o===`blockly`,u=e||r.length>0,d=`You are an AI assistant for ioBroker JavaScript adapter scripting. Help the user write, debug, and understand ioBroker scripts. Write comments in ${c}. Use the ioBroker JavaScript API correctly.
1
+ import{t as e}from"./vite-preload-helper-CaC3yEL3.js";import{$n as t,An as n,Bn as r,Bt as i,Cn as a,Dn as o,En as s,Ht as c,Lt as l,Qn as u,Un as d,Ut as f,Vt as p,Xt as m,Zt as h,_r as g,br as _,bt as v,fr as y,hr as b,kn as x,mn as S,p as C,pn as w,ut as T,vt as E,wr as D,xn as ee,yn as O,yr as k,yt as A,zt as j}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";import{S as M,g as te,h as N,m as P,s as F}from"./index-CRX4LAhD.js";import{a as I,c as L,d as R,f as z,h as B,i as V,l as H,m as U,n as W,o as G,p as K,r as ne,s as q,t as J,u as Y}from"./AiChatService-Bsp_rhVx.js";var X=r(u(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m5 11h-4v4h-2v-4H7v-2h4V7h2v4h4z`}),`AddCircleOutlined`),re=r(u(`path`,{d:`M21.99 4c0-1.1-.89-2-1.99-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4zM17 11h-4v4h-2v-4H7V9h4V5h2v4h4z`}),`AddComment`),ie=r(u(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10h5v-2h-5c-4.34 0-8-3.66-8-8s3.66-8 8-8 8 3.66 8 8v1.43c0 .79-.71 1.57-1.5 1.57s-1.5-.78-1.5-1.57V12c0-2.76-2.24-5-5-5s-5 2.24-5 5 2.24 5 5 5c1.38 0 2.64-.56 3.54-1.47.65.89 1.77 1.47 2.96 1.47 1.97 0 3.5-1.6 3.5-3.57V12c0-5.52-4.48-10-10-10m0 13c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3`}),`AlternateEmail`),ae=r(u(`path`,{d:`M9.01 14H2v2h7.01v3L13 15l-3.99-4zm5.98-1v-3H22V8h-7.01V5L11 9z`}),`CompareArrows`),oe=r(u(`path`,{d:`M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4m0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4`}),`Person`),se=r(u(`path`,{d:`M3 10h11v2H3zm0-4h11v2H3zm0 8h7v2H3zm17.59-2.07-4.25 4.24-2.12-2.12-1.41 1.41L16.34 19 22 13.34z`}),`PlaylistAddCheck`),ce=r(u(`path`,{d:`M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3M7.5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S9.83 13 9 13s-1.5-.67-1.5-1.5M16 17H8v-2h8zm-1-4c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13`}),`SmartToy`);D();var le=[{type:`function`,function:{name:`search_datapoints`,description:`Search ALL ioBroker objects by ID, name, or role — includes states, channels, devices, folders, enums (rooms/functions), adapters, instances, scripts, meta, etc. Returns matching IDs with object type, name, role, unit, and a hasChildren hint for containers. IMPORTANT: Aliases and physical device groupings are usually CHANNELS containing multiple state children (e.g. a motion sensor is often a channel alias.0.Floor.Room.MotionSensor with states ACTUAL, BATTERY, STATE under it). If a channel/device/folder matches your query, call get_object_info on its ID to list its state children. Role-based queries work too: "sensor.motion", "switch.light", "value.temperature".`,parameters:{type:`object`,properties:{query:{type:`string`,description:`Search pattern (case-insensitive substring) - matches against object ID, name, and role. Examples: "bewegungsmelder", "temperature", "sensor.motion", "alias.0", "küche", "zigbee2mqtt.0.lamp".`},max_results:{type:`number`,description:`Maximum number of results to return (default: 20).`},object_type:{type:`string`,description:`Optional filter by object type: "state", "channel", "device", "folder", "enum", "adapter", "instance", "script", "meta", etc. Omit to search every type.`}},required:[`query`]}}},{type:`function`,function:{name:`get_state_value`,description:`Get the current value of an ioBroker state/datapoint. Returns value, timestamp, and acknowledgment flag.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The full state ID, e.g. "zigbee2mqtt.0.sensor.temperature"`}},required:[`id`]}}},{type:`function`,function:{name:`get_object_info`,description:`Get detailed info about ANY ioBroker object + its full parent hierarchy + direct children. Works for every object type: state, channel, device, folder, adapter, instance, enum, meta, script. Returns: the object itself, parent chain (all non-state ancestors up to the adapter), and — if the object is a container (channel/device/folder/enum/instance/adapter/meta) — the list of direct children with their types, names, roles and units. Use this to navigate the object tree: start from a channel found by search_datapoints, read its children to see the actual state IDs underneath.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The full object ID, e.g. "zigbee2mqtt.0.0x1234.state", "alias.0.Room.MotionSensor", or "enum.rooms.kitchen".`}},required:[`id`]}}},{type:`function`,function:{name:`search_scripts`,description:`Search through all ioBroker JavaScript/Blockly/Rules scripts. Can search by script name/path OR by content (e.g. find all scripts that use a specific datapoint ID). Returns matching script names, paths, and matching lines.`,parameters:{type:`object`,properties:{query:{type:`string`,description:`Search term - matches against script name, path, AND source code content. Examples: "carport", "zigbee2mqtt.0.lamp.state", "telegram"`},max_results:{type:`number`,description:`Maximum number of scripts to return (default: 10)`}},required:[`query`]}}},{type:`function`,function:{name:`read_script`,description:`Read the full source code of a specific ioBroker script by its ID or path. Use search_scripts first to find the script ID, then read_script to see its complete code.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`The script ID (e.g. "script.js.common.Licht.Carport") or path (e.g. "common/Licht/Carport")`}},required:[`id`]}}},{type:`function`,function:{name:`list_scripts`,description:`List ALL available ioBroker scripts with their names, paths, types (JavaScript/Blockly/TypeScript), and enabled status. Use this to get an overview of all scripts before searching or reading specific ones.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`run_script`,description:"Execute a JavaScript or TypeScript snippet in the live ioBroker javascript engine and get back everything it logged. The code runs with the full script API (log, console.*, setState, getState, on, schedule, $, exec, httpGet, …) in VERBOSE mode, so internal operations (setState/getState/subscribe/…) are logged too — ideal for diagnosing behaviour or inspecting values. The snippet runs for a short window and is then automatically STOPPED and fully cleaned up (timers, subscriptions, schedules removed); it does NOT create a persistent script. Use `log(...)` or `console.log(...)` in the code to surface the values you want to inspect. WARNING: side effects are real (e.g. setState changes actual devices) — prefer read-only diagnostics unless the user explicitly asked to change something.",parameters:{type:`object`,properties:{source:{type:`string`,description:`The JavaScript (or TypeScript) source to execute. Log the values you want to inspect via log(...) / console.log(...). Top-level await is supported.`},engineType:{type:`string`,description:`Optional. "TypeScript/ts" to run the code as TypeScript. Defaults to JavaScript.`},timeout:{type:`number`,description:`Optional. Milliseconds to keep the script alive to collect asynchronous logs before it is stopped (default 5000, max 60000). Increase when waiting for timers, subscriptions or HTTP responses.`},logLevel:{type:`string`,description:`Optional minimum severity to return: silly, debug, info, warn, error. Default silly (everything).`}},required:[`source`]}}},{type:`function`,function:{name:`get_editor_selection`,description:`Read what the user has currently selected in the script editor. Returns the selected text and its line/column range, or a message if nothing is selected. Use this when the user refers to "this", "das hier", "the selection", or asks about a specific piece of code they highlighted.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_editor_content`,description:`Read the full current content of the script editor (may differ from the initial script version if the user has made edits). Use this when you need the live editor state rather than the saved script.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_cursor_position`,description:`Read the current cursor position (line and column, 1-based) in the script editor.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`highlight_text_in_editor`,description:`Search for a literal text in the script editor and select + scroll to it. Returns how many occurrences were found. Use this to draw the user's attention to a specific snippet you are discussing.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Exact substring to search for (case-sensitive).`}},required:[`text`]}}},{type:`function`,function:{name:`highlight_line_range`,description:`Select and scroll to a range of lines in the editor. Both line numbers are 1-based and inclusive. Use this to show the user which block of code you are referring to.`,parameters:{type:`object`,properties:{start_line:{type:`number`,description:`First line (1-based, inclusive).`},end_line:{type:`number`,description:`Last line (1-based, inclusive).`}},required:[`start_line`,`end_line`]}}},{type:`function`,function:{name:`go_to_line`,description:`Move the cursor to a specific line (and optional column) and scroll that line into view. Use this to navigate the user to a relevant spot.`,parameters:{type:`object`,properties:{line:{type:`number`,description:`1-based line number.`},column:{type:`number`,description:`1-based column (optional, default 1).`}},required:[`line`]}}},{type:`function`,function:{name:`insert_text_at_cursor`,description:`Insert text at the current cursor position in the editor (or replace the current selection if one exists). Use sparingly — prefer returning code in a fenced markdown block so the user can review and smart-apply it. Only use direct insertion when the user explicitly asked you to write something into the editor.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Text to insert.`}},required:[`text`]}}},{type:`function`,function:{name:`replace_selection`,description:`Replace the currently selected text in the editor with new text. Fails if nothing is selected. Use this to refactor or rewrite a specific highlighted snippet.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Replacement text.`}},required:[`text`]}}},{type:`function`,function:{name:`get_diagnostics`,description:`Read all active Monaco diagnostics (errors, warnings, info, hints) from the current editor model — this is what shows up as red/yellow squiggles. Use this to find syntax errors, unused variables, missing types, or other editor-reported issues the user might be asking about.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`get_document_symbols`,description:`Get the document outline of the current script: all top-level functions, classes, constants, and variables with their line numbers. Use this to understand the structure of a long script or to find where a specific function is defined.`,parameters:{type:`object`,properties:{}}}}];function Z(e){return e&&typeof e==`object`?e.en||e.de||``:e||``}function ue(e,t,n){let r=(n||``).toLowerCase();if(!r)return!1;if(e.toLowerCase().includes(r))return!0;let i=t==null?void 0:t.common;if(!i)return!1;let a=Z(i.name).toLowerCase();if(a&&a.includes(r))return!0;let o=(i.role||``).toLowerCase();return!!(o&&o.includes(r))}async function de(e,t,n=20,r){let i=await I(e),a=r==null?void 0:r.toLowerCase(),o=[],s=Object.keys(i),c=new Set;for(let e of s){let t=e.lastIndexOf(`.`);t>0&&c.add(e.substring(0,t))}for(let e of s){let r=i[e],s=r==null?void 0:r.type;if(!s||a&&s!==a||!ue(e,r,t))continue;let l=r.common,u={id:e,type:s,name:Z(l==null?void 0:l.name)};if(l!=null&&l.role&&(u.role=l.role),s===`state`?(u.stateType=(l==null?void 0:l.type)||``,l!=null&&l.unit&&(u.unit=l.unit)):c.has(e)&&(u.hasChildren=!0),o.push(u),o.length>=n)break}return o.length===0?JSON.stringify({message:`No objects found matching "${t}". Hint: try a role like "sensor.motion" or a partial path.`}):JSON.stringify(o)}async function fe(e,t){try{let n=await e.getState(t);return JSON.stringify(n?{val:n.val,ts:n.ts?new Date(n.ts).toISOString():null,ack:n.ack,from:n.from}:{error:`State '${t}' not found`})}catch{return JSON.stringify({error:`Failed to read state '${t}'`})}}var pe=new Set([`channel`,`device`,`folder`,`adapter`,`instance`,`enum`,`meta`]),me=50;async function he(e,t){try{let r=await e.getObject(t);if(!r)return JSON.stringify({error:`Object '${t}' not found`});let i={id:r._id,type:r.type,common:r.common},a=t.split(`.`),o=[];for(let t=a.length-1;t>=2;t--){let r=a.slice(0,t).join(`.`);try{let t=await e.getObject(r);if(t&&t.type!==`state`){var n;o.push({id:t._id,type:t.type,name:Z((n=t.common)==null?void 0:n.name),common:t.common})}}catch{}}if(o.length>0&&(i.parents=o),pe.has(r.type)){let n=await I(e),r=[],a=`${t}.`,o=!1;for(let e of Object.keys(n))if(e.startsWith(a)&&!e.substring(a.length).includes(`.`)){let t=n[e],i=t==null?void 0:t.common,a={id:e,name:Z(i==null?void 0:i.name),type:(t==null?void 0:t.type)||``};if(i!=null&&i.role&&(a.role=i.role),(t==null?void 0:t.type)===`state`&&i!=null&&i.unit&&(a.unit=i.unit),r.push(a),r.length>=me){o=!0;break}}r.length>0&&(i.children=r,o&&(i.childrenTruncated=!0,i.childrenHint=`Only the first ${me} children are shown. Use search_datapoints with a more specific query or the object_type filter to narrow down.`))}return JSON.stringify(i)}catch{return JSON.stringify({error:`Failed to read object '${t}'`})}}function ge(e){return N(e)||e}function _e(e,t,n=10){let r=t.toLowerCase(),i=[];for(let t of e){let e=t.id.toLowerCase(),a=t.name.toLowerCase(),o=t.id.replace(/^script\.js\./,``).replace(/\./g,`/`),s=t.engineType===`Blockly`||t.engineType===`Rules`,c=e.includes(r)||a.includes(r),l=s?ge(t.source):t.source,u=l.toLowerCase().includes(r);if(c||u){let e={id:t.id,path:o,name:t.name,type:s?`Blockly`:t.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:t.enabled};if(u){let t=l.split(`
2
+ `),n=[];for(let e=0;e<t.length&&!(t[e].toLowerCase().includes(r)&&(n.push({line:e+1,text:t[e].trim()}),n.length>=5));e++);n.length>0&&(e.matchingLines=n)}if(i.push(e),i.length>=n)break}}return i.length===0?JSON.stringify({message:`No scripts found matching "${t}"`}):JSON.stringify(i)}function ve(e,t){let n=t.replace(/\//g,`.`).toLowerCase(),r=e.find(e=>{let t=e.id.toLowerCase();return t===n||t===`script.js.${n}`||t.endsWith(`.${n}`)});if(!r)return JSON.stringify({error:`Script '${t}' not found. Use search_scripts to find available scripts.`});let i=r.engineType===`Blockly`||r.engineType===`Rules`,a=i?ge(r.source):r.source,o=r.id.replace(/^script\.js\./,``).replace(/\./g,`/`);return JSON.stringify({id:r.id,path:o,name:r.name,type:i?`Blockly`:r.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:r.enabled,source:a})}function ye(e){let t=e.map(e=>({id:e.id,path:e.id.replace(/^script\.js\./,``).replace(/\./g,`/`),name:e.name,type:e.engineType===`Blockly`||e.engineType===`Rules`?`Blockly`:e.engineType.includes(`TypeScript`)?`TypeScript`:`JavaScript`,enabled:e.enabled}));return JSON.stringify(t)}function Q(){return JSON.stringify({error:`Editor is not available. This tool requires the script editor to be open.`})}async function be(e,t,n){if(!t)return JSON.stringify({error:`No running javascript instance found to execute the script.`});let r=n.source;if(!r||typeof r!=`string`)return JSON.stringify({error:`No source code provided.`});try{var i;let a=await e.sendTo(t,`execute`,{source:r,engineType:n.engineType,timeout:n.timeout,logLevel:n.logLevel});return!a||a.ok===!1?JSON.stringify({error:(a==null?void 0:a.error)||`Execution failed`,logs:(a==null?void 0:a.logs)||[]}):JSON.stringify({engineType:a.engineType,runtime:a.runtime,truncated:a.truncated||!1,logCount:((i=a.logs)==null?void 0:i.length)||0,logs:a.logs||[],output:a.output||``})}catch(e){return JSON.stringify({error:`Failed to execute script: ${e instanceof Error?e.message:String(e)}`})}}async function xe(e,t,n,r,i){let a;try{a=JSON.parse(t.function.arguments)}catch{return JSON.stringify({error:`Invalid arguments: ${t.function.arguments}`})}switch(t.function.name){case`search_datapoints`:return de(e,a.query,a.max_results||20,a.object_type);case`get_state_value`:return fe(e,a.id);case`get_object_info`:return he(e,a.id);case`search_scripts`:return _e(n||[],a.query,a.max_results||10);case`read_script`:return ve(n||[],a.id);case`list_scripts`:return ye(n||[]);case`run_script`:return be(e,i,a);case`get_editor_selection`:{if(!(r!=null&&r.getSelection))return Q();let e=r.getSelection();return JSON.stringify(e||{message:`No text is currently selected in the editor.`})}case`get_editor_content`:return r!=null&&r.getContent?JSON.stringify({content:r.getContent()}):Q();case`get_cursor_position`:{if(!(r!=null&&r.getCursorPosition))return Q();let e=r.getCursorPosition();return JSON.stringify(e||{message:`Editor has no cursor position (not focused).`})}case`highlight_text_in_editor`:{if(!(r!=null&&r.highlightText))return Q();let e=r.highlightText(a.text);return JSON.stringify({matches:e,message:e===0?`Text "${a.text}" was not found in the editor.`:`Highlighted ${e} occurrence(s) of "${a.text}".`})}case`highlight_line_range`:{if(!(r!=null&&r.highlightLineRange))return Q();let e=r.highlightLineRange(a.start_line,a.end_line);return JSON.stringify({success:e,message:e?`Selected lines ${a.start_line}-${a.end_line}.`:`Could not select the requested line range.`})}case`go_to_line`:{if(!(r!=null&&r.goToLine))return Q();let e=r.goToLine(a.line,a.column);return JSON.stringify({success:e,message:e?`Cursor moved to line ${a.line}.`:`Could not move the cursor.`})}case`insert_text_at_cursor`:{if(!(r!=null&&r.insertTextAtCursor))return Q();let e=r.insertTextAtCursor(a.text);return JSON.stringify({success:e,message:e?`Text inserted at cursor.`:`Editor rejected the insertion.`})}case`replace_selection`:{if(!(r!=null&&r.replaceSelection))return Q();let e=r.replaceSelection(a.text);return JSON.stringify({success:e,message:e?`Selection replaced.`:`No text was selected to replace.`})}case`get_diagnostics`:{if(!(r!=null&&r.getDiagnostics))return Q();let e=r.getDiagnostics();return JSON.stringify({count:e.length,diagnostics:e})}case`get_document_symbols`:{if(!(r!=null&&r.getSymbols))return Q();let e=await r.getSymbols();return JSON.stringify({count:e.length,symbols:e})}default:return JSON.stringify({error:`Unknown tool: ${t.function.name}`})}}var Se=0;function Ce(){return`msg_${Date.now()}_${++Se}`}function we(t){let{socket:n,runningInstances:r,currentCode:i,currentLanguage:a,allScripts:o,editorApi:s,currentScriptId:c}=t,l=y((e,t,n)=>e===`none`||!n?null:{range:t,scriptId:c||``,scriptVersion:(i||``).length,kind:e,originalText:n},[c,i]),[u,d]=_(()=>{try{let e=window.localStorage.getItem(`Editor.aiChatMessages`);return e?JSON.parse(e):[]}catch{return[]}}),f=y(e=>{d(t=>{let n=typeof e==`function`?e(t):e,r=n.length>100?n.slice(-100):n;try{window.localStorage.setItem(`Editor.aiChatMessages`,JSON.stringify(r))}catch{try{let e=r.slice(-20);window.localStorage.setItem(`Editor.aiChatMessages`,JSON.stringify(e))}catch{}}return r})},[]),[p,m]=_(!1),[h,g]=_(null),[v,x]=_(window.localStorage.getItem(`Editor.aiChatMode`)||`agent`),S=y(e=>{x(e),window.localStorage.setItem(`Editor.aiChatMode`,e)},[]),[w,T]=_(null),[E,D]=_(window.localStorage.getItem(`openai-model`)||``),[ee,O]=_([]),[A,j]=_({}),[M,N]=_(!0),[F,I]=_(null),W=k(null),J=k(null),X=k(null),re=k(null),ie=y(e=>{D(e),K(e,A[e])},[A]),ae=y(async()=>{N(!0),I(null);try{let e=await R(n,r);if(O(e.models),j(e.providerMap),e.models.length>0){let t=z().model,n=t&&e.models.includes(t)?t:e.models[0];D(n),K(n,e.providerMap[n])}e.errors.length>0&&I(e.errors.join(`; `))}catch(e){I(String(e))}N(!1)},[n,r]);b(()=>{ae()},[ae]);let oe=y(e=>{let t=!1,n=!1,r=[],i=!1,a=/@([\w/äöüÄÖÜß-]+)/g,s;for(;(s=a.exec(e))!==null;){let e=s[1].toLowerCase();if(e===`alle`||e===`all`)t=!0;else if(e===`geräte`||e===`devices`||e===`geraete`)n=!0;else if(i=!0,o&&o.length>0){let e=s[1].replace(/\//g,`.`).toLowerCase(),t=e.split(`.`),n=o.find(n=>{let r=n.id.toLowerCase(),i=r.replace(/^script\.js\./,``);if(i===e||i.endsWith(`.${e}`)||r===`script.js.${e}`)return!0;let a=0;for(let e of t){let t=i.indexOf(e,a);if(t===-1)return!1;a=t+e.length}return!0});if(n)r.push(n.id);else for(let e of t){if(e.length<3)continue;let t=o.filter(t=>t.id.toLowerCase().includes(`.${e}`)||t.name.toLowerCase().includes(e));for(let e of t)r.includes(e.id)||r.push(e.id)}}}return i&&r.length===0&&(t=!0),{cleanMessage:e.replace(/@[\w/äöüÄÖÜß]+\s*/g,``).trim(),mentionedScriptIds:r,includeAll:t,includeDevices:n}},[o]),se=y(async(e,t,s)=>{re.current||=await H(),W.current||=await G(n,r);let c=Y(),l=a===`blockly`,u=e||s.length>0,d=`You are an AI assistant for ioBroker JavaScript adapter scripting. Help the user write, debug, and understand ioBroker scripts. Write comments in ${c}. Use the ioBroker JavaScript API correctly.
3
3
 
4
4
  ioBroker object hierarchy: adapter.instance.device.channel.state
5
5
  - A "state" is a single datapoint (e.g. zigbee2mqtt.0.0x1234.temperature)
@@ -11,17 +11,17 @@ When looking up info about a datapoint, ALWAYS also check its parent channel/dev
11
11
  To verify code or diagnose runtime behaviour, you can use the run_script tool: it executes a JavaScript/TypeScript snippet in the live engine (verbose mode) and returns everything it logged, then auto-stops it. Log the values you want to inspect via log(...) / console.log(...). It runs against the live system, so prefer read-only diagnostics (getState, $, getObject) and only call setState when the user explicitly asked to change something.
12
12
 
13
13
  Available API and syntax rules:
14
- ${re.current}`;if(l&&(d+="\n\nThe user is working in the Blockly visual editor. When asked to create or modify code, respond with Blockly XML in a ```xml code block instead of JavaScript."),(t||e)&&(X.current||=await V(n),d+=`\n\nAvailable smart home devices:\n${JSON.stringify(X.current,null,0)}`),!u&&a){if(l){let e=a.indexOf(`%%BLOCKLY_XML%%`),t=e===-1?a:a.substring(0,e).trim(),n=e===-1?``:a.substring(e+15).trim();d+=`\n\nThe user is working on this Blockly script (currently open in the editor).\n\nGenerated JavaScript (shows the logic):\n\`\`\`javascript\n${t}\n\`\`\``,n&&(d+=`\n\nBlockly XML (use for modifications):\n\`\`\`xml\n${n}\n\`\`\``)}else d+=`\n\nThe user's question is about this script (currently open in the editor, ${o||`javascript`}):\n\`\`\`${o||`javascript`}\n${a}\n\`\`\``}if(e&&s&&s.length>0)d+=`\n\nThe user requested ALL scripts. Search through all of them to answer the question. Always identify WHICH script you describe by its full ID. Scripts may reference datapoint IDs via variables.\n\n${P(s,!0)}`;else if(r.length>0&&s){let e=s.filter(e=>r.includes(e.id));e.length>0&&(d+=`\n\nIMPORTANT: The user is asking about the following script(s). Answer ONLY about these scripts, NOT about the currently open editor tab. Analyze the source code below carefully:\n\n${P(e,!0)}`)}return l&&(d+=`\n\n${q(c)}`),[{role:`system`,content:d}]},[n,i,a,o,s]),ce=b(async e=>{if(!e.trim()||m)return;let t=k[w];if(!t){C(T.t(`Please select a valid model`));return}let r=W.current||await G(n,i);if(W.current=r,!r){C(T.t(`No API keys configured`));return}let a=Object.keys(i)[0];if(!a){C(T.t(`No running javascript instance found`));return}let s=t===`custom`&&r.gptBaseUrl||``,c={id:Ce(),role:`user`,content:e,timestamp:Date.now()},l={id:Ce(),role:`assistant`,content:`⏳ ${T.t(`Generating plan...`)}`,timestamp:Date.now()};p(e=>[...e,c,l]),h(!0),C(null);try{let r=Y();X.current||=await V(n);let i=X.current||[],c=`Devices in my smart home:\n${JSON.stringify(i)}\n\nI need a plan for this task: ${e}\n\nAnswer with max 6 lines. Use FULL device IDs from the list above (e.g. zigbee2mqtt.0.0xa4c1383f5ef5fb07.state). No explanation. No reasoning.\n1. IDs: <full IDs from the device list. If a device is not in the list, use TODO_DEVICE_ID as placeholder>\n2. Trigger: <on(id) for state changes OR schedule('min hour * * *') for time-based tasks>\n3. Condition: <when to act>\n4. Actions: <what to set, with full IDs and values. For Telegram use sendTo('telegram.0', 'send', {text: msg})>\n5. Else: <alternative actions or nothing>\n6. Extra: <logging, formatting, etc.>\nValues are boolean (true/false) or numbers, not strings. Use .state not .state_toggle.`,l=await U(n,a,{messages:[{role:`user`,content:c}],model:w,provider:t,baseUrl:s});if(l.error){C(l.error),p(e=>e.slice(0,-2)),h(!1);return}let u=B(l.content||``);p(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:`📋 **${T.t(`Plan`)}:**\n${u}`}),t});let d={id:Ce(),role:`assistant`,content:`⏳ ${T.t(`Generating code...`)}`,timestamp:Date.now()};p(e=>[...e,d]);let f=o===`blockly`,m=f?`TASK: ${e}\n\nPLAN:\n${u}\n\nGenerate Blockly XML blocks for this ioBroker automation. Use the exact state IDs from the plan. If the plan contains TODO_DEVICE_ID, keep it as a placeholder. Write comments in ${r}. Put the blocks in a \`\`\`xml code block. You may add a short explanation before or after the XML.`:`TASK: ${e}\n\nPLAN:\n${u}\n\nWrite the ioBroker script. Use the exact state IDs from the plan. If the plan contains TODO_DEVICE_ID, keep it as a placeholder with a comment so the user can fill in the correct ID. Write comments in ${r}. Put the code in a \`\`\`javascript code block. You may add a short explanation before or after the code.`,g=f?q(r):L(r),v=await U(n,a,{messages:[{role:`system`,content:g},{role:`user`,content:m}],model:w,provider:t,baseUrl:s});if(v.error){C(v.error),p(e=>e.slice(0,-1)),h(!1);return}let y=B(v.content||``);p(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:y}),t}),_(`${T.t(`devices`)}: ${i.length}`)}catch(e){C(String(e)),p(e=>e.slice(0,-1))}h(!1)},[w,k,m,n,i,o,p]),Z=b(async e=>{if(v===`code`)return ce(e);if(!e.trim()||m)return;let t=k[w];if(!t){C(T.t(`Please select a valid model`));return}let r=W.current||await G(n,i);if(W.current=r,!r){C(T.t(`No API keys configured`));return}let a=Object.keys(i)[0];if(!a){C(T.t(`No running javascript instance found`));return}let o=J.current;if(J.current=null,!o)try{var l;let e=c==null||(l=c.getSelection)==null?void 0:l.call(c);e&&e.text&&(o=u(`selection`,e.range,e.text))}catch{}let f={id:Ce(),role:`user`,content:e,timestamp:Date.now(),sourceRange:o},g={id:Ce(),role:`assistant`,content:``,timestamp:Date.now(),sourceRange:o};p(e=>[...e,f,g]),h(!0),C(null);let{cleanMessage:y,mentionedScriptIds:b,includeAll:x,includeDevices:S}=oe(e),E=[];if(x)E.push(`${T.t(`all scripts`)} (${(s==null?void 0:s.length)||0})`);else if(b.length>0){let e=b.map(e=>e.replace(/^script\.js\./,``));E.push(e.join(`, `))}else E.push(T.t(`current script`));S&&E.push(T.t(`devices`)),_(`${T.t(`Context`)}: ${E.join(` + `)}`);let ee=await se(x,S,b),D=t===`custom`&&r.gptBaseUrl||``,O=y||e;if(s&&s.length>0){let e=O.match(/\b[\w-]+\.\d+\.[\w.-]+/g);if(e){let t=[];for(let n of new Set(e)){let e=te(s,n);e.length>0&&t.push(`Datapoint "${n}" is used in:\n${e.map(e=>` - ${e.scriptName} (${e.scriptId}) line ${e.lineNumber}: ${e.usageType} → ${e.line}`).join(`
14
+ ${re.current}`;if(l&&(d+="\n\nThe user is working in the Blockly visual editor. When asked to create or modify code, respond with Blockly XML in a ```xml code block instead of JavaScript."),(t||e)&&(X.current||=await V(n),d+=`\n\nAvailable smart home devices:\n${JSON.stringify(X.current,null,0)}`),!u&&i){if(l){let e=i.indexOf(`%%BLOCKLY_XML%%`),t=e===-1?i:i.substring(0,e).trim(),n=e===-1?``:i.substring(e+15).trim();d+=`\n\nThe user is working on this Blockly script (currently open in the editor).\n\nGenerated JavaScript (shows the logic):\n\`\`\`javascript\n${t}\n\`\`\``,n&&(d+=`\n\nBlockly XML (use for modifications):\n\`\`\`xml\n${n}\n\`\`\``)}else d+=`\n\nThe user's question is about this script (currently open in the editor, ${a||`javascript`}):\n\`\`\`${a||`javascript`}\n${i}\n\`\`\``}if(e&&o&&o.length>0)d+=`\n\nThe user requested ALL scripts. Search through all of them to answer the question. Always identify WHICH script you describe by its full ID. Scripts may reference datapoint IDs via variables.\n\n${P(o,!0)}`;else if(s.length>0&&o){let e=o.filter(e=>s.includes(e.id));e.length>0&&(d+=`\n\nIMPORTANT: The user is asking about the following script(s). Answer ONLY about these scripts, NOT about the currently open editor tab. Analyze the source code below carefully:\n\n${P(e,!0)}`)}return l&&(d+=`\n\n${q(c)}`),[{role:`system`,content:d}]},[n,r,i,a,o]),ce=y(async e=>{if(!e.trim()||p)return;let t=A[E];if(!t){T(C.t(`Please select a valid model`));return}let i=W.current||await G(n,r);if(W.current=i,!i){T(C.t(`No API keys configured`));return}let o=Object.keys(r)[0];if(!o){T(C.t(`No running javascript instance found`));return}let s=t===`custom`&&i.gptBaseUrl||``,c={id:Ce(),role:`user`,content:e,timestamp:Date.now()},l={id:Ce(),role:`assistant`,content:`⏳ ${C.t(`Generating plan...`)}`,timestamp:Date.now()};f(e=>[...e,c,l]),m(!0),T(null);try{let r=Y();X.current||=await V(n);let i=X.current||[],c=`Devices in my smart home:\n${JSON.stringify(i)}\n\nI need a plan for this task: ${e}\n\nAnswer with max 6 lines. Use FULL device IDs from the list above (e.g. zigbee2mqtt.0.0xa4c1383f5ef5fb07.state). No explanation. No reasoning.\n1. IDs: <full IDs from the device list. If a device is not in the list, use TODO_DEVICE_ID as placeholder>\n2. Trigger: <on(id) for state changes OR schedule('min hour * * *') for time-based tasks>\n3. Condition: <when to act>\n4. Actions: <what to set, with full IDs and values. For Telegram use sendTo('telegram.0', 'send', {text: msg})>\n5. Else: <alternative actions or nothing>\n6. Extra: <logging, formatting, etc.>\nValues are boolean (true/false) or numbers, not strings. Use .state not .state_toggle.`,l=await U(n,o,{messages:[{role:`user`,content:c}],model:E,provider:t,baseUrl:s});if(l.error){T(l.error),f(e=>e.slice(0,-2)),m(!1);return}let u=B(l.content||``);f(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:`📋 **${C.t(`Plan`)}:**\n${u}`}),t});let d={id:Ce(),role:`assistant`,content:`⏳ ${C.t(`Generating code...`)}`,timestamp:Date.now()};f(e=>[...e,d]);let p=a===`blockly`,h=p?`TASK: ${e}\n\nPLAN:\n${u}\n\nGenerate Blockly XML blocks for this ioBroker automation. Use the exact state IDs from the plan. If the plan contains TODO_DEVICE_ID, keep it as a placeholder. Write comments in ${r}. Put the blocks in a \`\`\`xml code block. You may add a short explanation before or after the XML.`:`TASK: ${e}\n\nPLAN:\n${u}\n\nWrite the ioBroker script. Use the exact state IDs from the plan. If the plan contains TODO_DEVICE_ID, keep it as a placeholder with a comment so the user can fill in the correct ID. Write comments in ${r}. Put the code in a \`\`\`javascript code block. You may add a short explanation before or after the code.`,_=p?q(r):L(r),v=await U(n,o,{messages:[{role:`system`,content:_},{role:`user`,content:h}],model:E,provider:t,baseUrl:s});if(v.error){T(v.error),f(e=>e.slice(0,-1)),m(!1);return}let y=B(v.content||``);f(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:y}),t}),g(`${C.t(`devices`)}: ${i.length}`)}catch(e){T(String(e)),f(e=>e.slice(0,-1))}m(!1)},[E,A,p,n,r,a,f]),Z=y(async e=>{if(v===`code`)return ce(e);if(!e.trim()||p)return;let t=A[E];if(!t){T(C.t(`Please select a valid model`));return}let i=W.current||await G(n,r);if(W.current=i,!i){T(C.t(`No API keys configured`));return}let a=Object.keys(r)[0];if(!a){T(C.t(`No running javascript instance found`));return}let c=J.current;if(J.current=null,!c)try{var d;let e=s==null||(d=s.getSelection)==null?void 0:d.call(s);e&&e.text&&(c=l(`selection`,e.range,e.text))}catch{}let h={id:Ce(),role:`user`,content:e,timestamp:Date.now(),sourceRange:c},_={id:Ce(),role:`assistant`,content:``,timestamp:Date.now(),sourceRange:c};f(e=>[...e,h,_]),m(!0),T(null);let{cleanMessage:y,mentionedScriptIds:b,includeAll:x,includeDevices:S}=oe(e),w=[];if(x)w.push(`${C.t(`all scripts`)} (${(o==null?void 0:o.length)||0})`);else if(b.length>0){let e=b.map(e=>e.replace(/^script\.js\./,``));w.push(e.join(`, `))}else w.push(C.t(`current script`));S&&w.push(C.t(`devices`)),g(`${C.t(`Context`)}: ${w.join(` + `)}`);let D=await se(x,S,b),ee=t===`custom`&&i.gptBaseUrl||``,O=y||e;if(o&&o.length>0){let e=O.match(/\b[\w-]+\.\d+\.[\w.-]+/g);if(e){let t=[];for(let n of new Set(e)){let e=te(o,n);e.length>0&&t.push(`Datapoint "${n}" is used in:\n${e.map(e=>` - ${e.scriptName} (${e.scriptId}) line ${e.lineNumber}: ${e.usageType} → ${e.line}`).join(`
15
15
  `)}`)}t.length>0&&(O+=`\n\n[Automatic analysis results]\n${t.join(`
16
16
 
17
- `)}`)}}let A=[...ee,...d.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content})),{role:`user`,content:O}],j=v===`agent`;try{let e=[...A];for(let r=0;r<5;r++){let i=await U(n,a,{messages:e,model:w,provider:t,baseUrl:D,...j?{tools:le}:{}});if(i.error){if(j&&r===0&&i.error.toLowerCase().includes(`tool`)){let r=await U(n,a,{messages:e,model:w,provider:t,baseUrl:D});if(r.error)C(r.error),p(e=>e.slice(0,-1));else{let e=B(r.content||``);p(t=>{let n=[...t],r=n[n.length-1];return(r==null?void 0:r.role)===`assistant`&&(n[n.length-1]={...r,content:e}),n})}break}C(i.error),p(e=>e.slice(0,-1));break}let o=i.tool_calls;if((!o||o.length===0)&&j&&i.content){let e=i.content.trim();try{let t=JSON.parse(e);t.name&&t.arguments&&(o=[{id:`text_tool_${Date.now()}`,type:`function`,function:{name:t.name,arguments:JSON.stringify(t.arguments)}}])}catch{}}if(!o||o.length===0){let e=B(i.content||``);p(t=>{let n=[...t],r=n[n.length-1];return(r==null?void 0:r.role)===`assistant`&&(n[n.length-1]={...r,content:e}),n});break}i.tool_calls=o;let l=i.tool_calls.map(e=>{let t={};try{t=JSON.parse(e.function.arguments)}catch{}switch(e.function.name){case`search_datapoints`:return`🔍 ${T.t(`Searching datapoints`)}: "${String(t.query||``)}"`;case`get_state_value`:return`📊 ${T.t(`Reading value`)}: ${String(t.id||``)}`;case`get_object_info`:return`📋 ${T.t(`Loading object info`)}: ${String(t.id||``)}`;case`search_scripts`:return`🔍 ${T.t(`Searching scripts`)}: "${String(t.query||``)}"`;case`read_script`:return`📖 ${T.t(`Reading script`)}: ${String(t.id||``)}`;case`list_scripts`:return`📂 ${T.t(`Loading script list`)}`;default:return`⚙️ ${e.function.name}`}});p(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:l.join(`
18
- `)}),t}),e.push({role:`assistant`,content:i.content||``,tool_calls:i.tool_calls});for(let t of i.tool_calls){let r=await xe(n,t,s,c,a);e.push({role:`tool`,tool_call_id:t.id,content:r})}}}catch(e){C(String(e)),p(e=>e.slice(0,-1))}h(!1)},[w,k,d,m,n,i,se,oe,s,v,ce,p,u,c]),ue=b(()=>{p([]),C(null),h(!1),_(null),ne(),window.localStorage.removeItem(`Editor.aiChatHistory`)},[p]),de=b(async(e,t)=>{let r=k[w];if(!r)return`Error: ${T.t(`Please select a valid model`)}`;let a=W.current||await G(n,i);if(W.current=a,!a)return`Error: ${T.t(`No API keys configured`)}`;let s=Object.keys(i)[0];if(!s)return`Error: ${T.t(`No running javascript instance found`)}`;let c=r===`custom`&&a.gptBaseUrl||``,l=o||`javascript`,u=`You are an assistant for writing ioBroker ${l} scripts. The user will ask a question about a snippet of their code. Match your answer to the question: \n- If they ask for an explanation, description, or "what does this do?", reply with clear prose (a few sentences). Do NOT repeat the code unchanged. \n- If they explicitly ask for a change, refactor, fix, or rewrite, reply with a single fenced \`\`\`${l===`blockly`?`xml`:l}\`\`\` code block containing the full replacement for the selection. You may add one short sentence before or after the block. \n- If they ask something ambiguous or meta (e.g. "is this correct?"), reply in prose first and only include code if proposing a change. \nioBroker globals available in scripts: on, setState, getState, schedule, sendTo, log, createState, setStateDelayed, existsState, httpGet, httpPost.`,d=t?`Code from my editor:\n\n\`\`\`${l===`blockly`?`xml`:l}\n${t}\n\`\`\`\n\n${e}`:e;try{let e=await U(n,s,{messages:[{role:`system`,content:u},{role:`user`,content:d}],model:w,provider:r,baseUrl:c});return e.error?`Error: ${e.error}`:e.content||``}catch(e){return`Error: ${e.message||String(e)}`}},[w,k,i,n,o]);return{messages:d,isLoading:m,error:S,model:w,availableModels:ee,modelProviderMap:k,modelsLoading:M,modelsError:F,lastContextInfo:g,mode:v,setMode:x,setModel:ie,sendMessage:Z,triggerAiAction:b(t=>{t.range&&t.code?J.current=u(t.kind||`codelens`,t.range,t.code):J.current=null,e(async()=>{let{buildActionPrompt:e}=await import(`./aiPromptBuilder-CuCGSQIi.js`);return{buildActionPrompt:e}},[],import.meta.url).then(({buildActionPrompt:e})=>{let n=e({action:t.action,code:t.code,language:o||`javascript`,diagnostic:t.diagnostic,question:t.question,rangeLabel:t.rangeLabel});n?Z(n):J.current=null}).catch(()=>{J.current=null,C(T.t(`Failed to build AI action prompt`))})},[Z,o,u]),askInline:de,clearChat:ue,retryLoadModels:ae}}c();var Te=({code:e,language:t,themeType:i,onInsertCode:o,onShowDiff:s,sourceRange:c})=>{let l=r(null);A(()=>{var n;let r=window.monaco;if(!l.current||!(r!=null&&(n=r.editor)!=null&&n.colorize))return;let a=t===`ts`||t===`typescript`?`typescript`:t||`javascript`;r.editor.colorize(e,a,{theme:i===`dark`?`vs-dark`:`vs`}).then(e=>{l.current&&(l.current.innerHTML=e)})},[e,t,i]);let u=b(()=>{navigator.clipboard.writeText(e)},[e]);return E(a,{sx:{position:`relative`,my:1,borderRadius:1,overflow:`hidden`,border:`1px solid`,borderColor:`divider`},children:[E(a,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,px:1,py:.5,bgcolor:`action.hover`,borderBottom:`1px solid`,borderColor:`divider`},children:[w(a,{sx:{fontSize:`0.75rem`,color:`text.secondary`,textTransform:`uppercase`},children:t||`javascript`}),E(a,{children:[w(n,{title:T.t(`Copy`),children:w(x,{size:`small`,onClick:u,children:w(j,{sx:{fontSize:16}})})}),o&&w(n,{title:T.t(`Insert into editor`),children:w(x,{size:`small`,onClick:()=>o(e),children:w(X,{sx:{fontSize:16}})})}),s&&w(n,{title:T.t(`Show as diff`),children:w(x,{size:`small`,onClick:()=>s(e,c),children:w(ae,{sx:{fontSize:16}})})})]})]}),w(`pre`,{ref:l,style:{margin:0,padding:`8px 12px`,overflow:`auto`,maxHeight:400,fontSize:`13px`,fontFamily:`'Cascadia Code', 'Fira Code', 'Consolas', monospace`,backgroundColor:i===`dark`?`#1e1e1e`:`#f8f8f8`,color:i===`dark`?`#d4d4d4`:`#333`},children:e})]})};c();var Ee=({xml:e})=>{let t=o(),n=r(null),i=r(null),[s,c]=D(60),l=r(!1);return A(()=>{l.current&&(l.current=!1,requestAnimationFrame(()=>{let e=window.Blockly,t=i.current;e&&t&&(e.svgResize(t),t.scrollCenter())}))},[s]),A(()=>{let r=window.Blockly;if(r&&n.current){i.current&&=(i.current.dispose(),null);try{let a=r.inject(n.current,{readOnly:!0,toolbox:null,trashcan:!1,zoom:{controls:!1,wheel:!1,startScale:1},move:{scrollbars:!1,drag:!1,wheel:!1},sounds:!1,renderer:`thrasos`,theme:F(t),media:`google-blockly/media/`});i.current=a;let o=e.trim();o.startsWith(`<xml`)||(o=`<xml xmlns="https://developers.google.com/blockly/xml">${o}</xml>`);let s=r.utils.xml.textToDom(o),u=10,d=Array.from(s.querySelectorAll(`:scope > block`));for(let e of d)e.setAttribute(`x`,`10`),e.setAttribute(`y`,String(u)),u+=200;r.Xml.domToWorkspace(s,a);let f=a.getTopBlocks(!1);if(f.length>1){let e=10;for(let t of f){let n=t.getRelativeToSurfaceXY();t.moveBy(10-n.x,e-n.y),e+=t.getHeightWidth().height+20}}let p=a.getBlocksBoundingBox();if(p){let e=p.bottom-p.top+20,t=Math.max(60,Math.ceil(e));l.current=!0,c(t)}}catch{}return()=>{i.current&&=(i.current.dispose(),null)}}},[e,t]),w(a,{ref:n,sx:{width:`100%`,height:s,minHeight:60,borderRadius:1,overflow:`hidden`,border:`1px solid`,borderColor:`divider`}})};c();function De(e){let t=[],n=/```(\w*)\n?([\s\S]*?)```/g,r=0,i;for(;(i=n.exec(e))!==null;){if(i.index>r){let n=e.substring(r,i.index).trim();n&&t.push({type:`text`,content:n})}t.push({type:`code`,content:i[2].trim(),language:i[1]||`javascript`}),r=i.index+i[0].length}if(r<e.length){let n=e.substring(r).trim();n&&t.push({type:`text`,content:n})}return t.length===0&&t.push({type:`text`,content:e}),t}function $(e){let t=[],n=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g,r=0,i,a=0;for(;(i=n.exec(e))!==null;)i.index>r&&t.push(e.substring(r,i.index)),i[2]?t.push(w(`strong`,{children:i[2]},a++)):i[3]?t.push(w(`em`,{children:i[3]},a++)):i[4]&&t.push(w(`code`,{className:`ai-chat-inline-code`,style:{padding:`2px 6px`,borderRadius:4,fontSize:`0.85em`,fontFamily:`'Cascadia Code', 'Fira Code', 'Consolas', monospace`},children:i[4]},a++)),r=i.index+i[0].length;return r<e.length&&t.push(e.substring(r)),t}function Oe(e){return e.trim().startsWith(`|`)&&e.trim().endsWith(`|`)}function ke(e){return/^\|[\s:]*-+[\s:|-]*\|$/.test(e.trim())}function Ae(e,t,n){let r=t.palette.mode===`dark`,i=e=>e.trim().replace(/^\||\|$/g,``).split(`|`).map(e=>e.trim()),o=i(e[0]),s=e.slice(2).map(i);return w(a,{sx:{overflowX:`auto`,my:1},children:E(`table`,{style:{borderCollapse:`collapse`,width:`100%`,fontSize:`0.8rem`,color:t.palette.text.primary},children:[w(`thead`,{children:w(`tr`,{children:o.map((e,n)=>w(`th`,{style:{border:`1px solid ${t.palette.divider}`,padding:`6px 10px`,backgroundColor:r?t.palette.grey[800]:t.palette.grey[100],color:t.palette.text.primary,fontWeight:600,textAlign:`left`},children:$(e)},n))})}),w(`tbody`,{children:s.map((e,n)=>w(`tr`,{style:{backgroundColor:n%2==1?r?t.palette.grey[900]:t.palette.grey[50]:void 0},children:e.map((e,n)=>w(`td`,{style:{border:`1px solid ${t.palette.divider}`,padding:`6px 10px`,color:t.palette.text.primary},children:$(e)},n))},n))})]})},n)}function je(e,t){let n=e.split(`
19
- `),r=[],i=0,a=0;for(;a<n.length;){let e=n[a].trim();if(e===``){a++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(e)){r.push(w(`hr`,{style:{border:`none`,borderTop:`1px solid ${t.palette.divider}`,margin:`8px 0`}},i++)),a++;continue}let o=e.match(/^(#{1,4})\s+(.+)$/);if(o){let e=o[1].length;r.push(w(`div`,{style:{fontWeight:600,fontSize:[`1.2em`,`1.1em`,`1em`,`0.95em`][e-1],margin:`8px 0 4px`},children:$(o[2])},i++)),a++;continue}if(Oe(e)&&a+1<n.length&&ke(n[a+1].trim())&&a+2<n.length){let e=[n[a],n[a+1]],o=a+2;for(;o<n.length&&Oe(n[o]);)e.push(n[o]),o++;r.push(Ae(e,t,i++)),a=o;continue}if(/^[-*+]\s/.test(e)){let e=[];for(;a<n.length&&/^\s*[-*+]\s/.test(n[a]);)e.push(n[a].replace(/^\s*[-*+]\s/,``).trim()),a++;r.push(w(`ul`,{style:{margin:`4px 0`,paddingLeft:20},children:e.map((e,t)=>w(`li`,{children:$(e)},t))},i++));continue}if(/^\d+[.)]\s/.test(e)){let e=[];for(;a<n.length&&/^\s*\d+[.)]\s/.test(n[a]);)e.push(n[a].replace(/^\s*\d+[.)]\s/,``).trim()),a++;r.push(w(`ol`,{style:{margin:`4px 0`,paddingLeft:20},children:e.map((e,t)=>w(`li`,{children:$(e)},t))},i++));continue}r.push(w(`div`,{children:$(e)},i++)),a++}return r}var Me=({message:e,themeType:t,currentLanguage:n,onInsertCode:r,onShowDiff:i,onApplyCode:o})=>{let s=e.role===`user`,c=p(),l=s?t===`dark`?c.palette.primary.dark:c.palette.primary.main:t===`dark`?c.palette.secondary.dark:c.palette.secondary.main,u=c.palette.getContrastText(l),d=O(()=>De(e.content),[e.content]),f=(e,t)=>!!(e===`xml`||e===`blockly`||n===`blockly`&&t&&/<block\s+type=/.test(t));return E(a,{sx:{display:`flex`,gap:1,px:1.5,py:1,mx:.75,my:.5,bgcolor:s?t===`dark`?`rgba(144, 202, 249, 0.10)`:`rgba(25, 118, 210, 0.07)`:t===`dark`?`rgba(206, 147, 216, 0.10)`:`rgba(156, 39, 176, 0.06)`,borderRadius:1.5,borderLeft:`3px solid`,borderLeftColor:l,transition:`background-color 120ms`,"&:hover":{bgcolor:s?t===`dark`?`rgba(144, 202, 249, 0.16)`:`rgba(25, 118, 210, 0.12)`:t===`dark`?`rgba(206, 147, 216, 0.16)`:`rgba(156, 39, 176, 0.10)`}},children:[w(S,{sx:{width:28,height:28,bgcolor:l,color:u,flexShrink:0,mt:.5},children:w(s?oe:ce,{sx:{fontSize:18}})}),w(a,{sx:{flex:1,minWidth:0,fontSize:`0.875rem`,lineHeight:1.6},children:d.map((n,s)=>n.type===`code`?f(n.language,n.content)?E(a,{sx:{my:1},children:[w(Ee,{xml:n.content}),E(a,{sx:{display:`flex`,gap:.5,mt:.5},children:[o&&w(h,{size:`small`,variant:`contained`,color:`primary`,startIcon:w(se,{sx:{fontSize:14}}),onClick:()=>o(n.content),sx:{textTransform:`none`,fontSize:`0.75rem`},children:T.t(`Apply blocks`)}),r&&w(h,{size:`small`,variant:`outlined`,startIcon:w(X,{sx:{fontSize:14}}),onClick:()=>r(n.content),sx:{textTransform:`none`,fontSize:`0.75rem`},children:T.t(`Insert blocks`)})]})]},s):w(Te,{code:n.content,language:n.language||`javascript`,themeType:t,onInsertCode:r,onShowDiff:i,sourceRange:e.sourceRange||null},s):w(a,{sx:{wordBreak:`break-word`,color:c.palette.text.primary},children:je(n.content,c)},s))})]})};function Ne(e){let t=(e||``).toLowerCase();return t.includes(`blockly`)||t.includes(`rules`)?`blockly`:t.includes(`typescript`)?`typescript`:`javascript`}function Pe(e,t){return`\`\`\`${t===`blockly`?`xml`:t}\n${e}\n\`\`\``}function Fe(e){let t=(e.code||``).trim(),n=Ne(e.language),r=e.rangeLabel?` (${e.rangeLabel})`:``;switch(e.action){case`explain`:return t?[`Please explain what this ioBroker ${n} code does${r}.`,`Focus on: which datapoints it reads/writes, which triggers fire it, and any side-effects.`,``,Pe(t,n)].join(`
17
+ `)}`)}}let k=[...D,...u.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content})),{role:`user`,content:O}],j=v===`agent`;try{let e=[...k];for(let r=0;r<5;r++){let i=await U(n,a,{messages:e,model:E,provider:t,baseUrl:ee,...j?{tools:le}:{}});if(i.error){if(j&&r===0&&i.error.toLowerCase().includes(`tool`)){let r=await U(n,a,{messages:e,model:E,provider:t,baseUrl:ee});if(r.error)T(r.error),f(e=>e.slice(0,-1));else{let e=B(r.content||``);f(t=>{let n=[...t],r=n[n.length-1];return(r==null?void 0:r.role)===`assistant`&&(n[n.length-1]={...r,content:e}),n})}break}T(i.error),f(e=>e.slice(0,-1));break}let c=i.tool_calls;if((!c||c.length===0)&&j&&i.content){let e=i.content.trim();try{let t=JSON.parse(e);t.name&&t.arguments&&(c=[{id:`text_tool_${Date.now()}`,type:`function`,function:{name:t.name,arguments:JSON.stringify(t.arguments)}}])}catch{}}if(!c||c.length===0){let e=B(i.content||``);f(t=>{let n=[...t],r=n[n.length-1];return(r==null?void 0:r.role)===`assistant`&&(n[n.length-1]={...r,content:e}),n});break}i.tool_calls=c;let l=i.tool_calls.map(e=>{let t={};try{t=JSON.parse(e.function.arguments)}catch{}switch(e.function.name){case`search_datapoints`:return`🔍 ${C.t(`Searching datapoints`)}: "${String(t.query||``)}"`;case`get_state_value`:return`📊 ${C.t(`Reading value`)}: ${String(t.id||``)}`;case`get_object_info`:return`📋 ${C.t(`Loading object info`)}: ${String(t.id||``)}`;case`search_scripts`:return`🔍 ${C.t(`Searching scripts`)}: "${String(t.query||``)}"`;case`read_script`:return`📖 ${C.t(`Reading script`)}: ${String(t.id||``)}`;case`list_scripts`:return`📂 ${C.t(`Loading script list`)}`;default:return`⚙️ ${e.function.name}`}});f(e=>{let t=[...e],n=t[t.length-1];return(n==null?void 0:n.role)===`assistant`&&(t[t.length-1]={...n,content:l.join(`
18
+ `)}),t}),e.push({role:`assistant`,content:i.content||``,tool_calls:i.tool_calls});for(let t of i.tool_calls){let r=await xe(n,t,o,s,a);e.push({role:`tool`,tool_call_id:t.id,content:r})}}}catch(e){T(String(e)),f(e=>e.slice(0,-1))}m(!1)},[E,A,u,p,n,r,se,oe,o,v,ce,f,l,s]),ue=y(()=>{f([]),T(null),m(!1),g(null),ne(),window.localStorage.removeItem(`Editor.aiChatHistory`)},[f]),de=y(async(e,t)=>{let i=A[E];if(!i)return`Error: ${C.t(`Please select a valid model`)}`;let o=W.current||await G(n,r);if(W.current=o,!o)return`Error: ${C.t(`No API keys configured`)}`;let s=Object.keys(r)[0];if(!s)return`Error: ${C.t(`No running javascript instance found`)}`;let c=i===`custom`&&o.gptBaseUrl||``,l=a||`javascript`,u=`You are an assistant for writing ioBroker ${l} scripts. The user will ask a question about a snippet of their code. Match your answer to the question: \n- If they ask for an explanation, description, or "what does this do?", reply with clear prose (a few sentences). Do NOT repeat the code unchanged. \n- If they explicitly ask for a change, refactor, fix, or rewrite, reply with a single fenced \`\`\`${l===`blockly`?`xml`:l}\`\`\` code block containing the full replacement for the selection. You may add one short sentence before or after the block. \n- If they ask something ambiguous or meta (e.g. "is this correct?"), reply in prose first and only include code if proposing a change. \nioBroker globals available in scripts: on, setState, getState, schedule, sendTo, log, createState, setStateDelayed, existsState, httpGet, httpPost.`,d=t?`Code from my editor:\n\n\`\`\`${l===`blockly`?`xml`:l}\n${t}\n\`\`\`\n\n${e}`:e;try{let e=await U(n,s,{messages:[{role:`system`,content:u},{role:`user`,content:d}],model:E,provider:i,baseUrl:c});return e.error?`Error: ${e.error}`:e.content||``}catch(e){return`Error: ${e.message||String(e)}`}},[E,A,r,n,a]);return{messages:u,isLoading:p,error:w,model:E,availableModels:ee,modelProviderMap:A,modelsLoading:M,modelsError:F,lastContextInfo:h,mode:v,setMode:S,setModel:ie,sendMessage:Z,triggerAiAction:y(t=>{t.range&&t.code?J.current=l(t.kind||`codelens`,t.range,t.code):J.current=null,e(async()=>{let{buildActionPrompt:e}=await import(`./aiPromptBuilder-db3Z4xhV.js`);return{buildActionPrompt:e}},[],import.meta.url).then(({buildActionPrompt:e})=>{let n=e({action:t.action,code:t.code,language:a||`javascript`,diagnostic:t.diagnostic,question:t.question,rangeLabel:t.rangeLabel});n?Z(n):J.current=null}).catch(()=>{J.current=null,T(C.t(`Failed to build AI action prompt`))})},[Z,a,l]),askInline:de,clearChat:ue,retryLoadModels:ae}}D();var Te=({code:e,language:n,themeType:r,onInsertCode:i,onShowDiff:a,sourceRange:o})=>{let s=k(null);b(()=>{var t;let i=window.monaco;if(!s.current||!(i!=null&&(t=i.editor)!=null&&t.colorize))return;let a=n===`ts`||n===`typescript`?`typescript`:n||`javascript`;i.editor.colorize(e,a,{theme:r===`dark`?`vs-dark`:`vs`}).then(e=>{s.current&&(s.current.innerHTML=e)})},[e,n,r]);let c=y(()=>{navigator.clipboard.writeText(e)},[e]);return t(p,{sx:{position:`relative`,my:1,borderRadius:1,overflow:`hidden`,border:`1px solid`,borderColor:`divider`},children:[t(p,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,px:1,py:.5,bgcolor:`action.hover`,borderBottom:`1px solid`,borderColor:`divider`},children:[u(p,{sx:{fontSize:`0.75rem`,color:`text.secondary`,textTransform:`uppercase`},children:n||`javascript`}),t(p,{children:[u(j,{title:C.t(`Copy`),children:u(S,{size:`small`,onClick:c,children:u(E,{sx:{fontSize:16}})})}),i&&u(j,{title:C.t(`Insert into editor`),children:u(S,{size:`small`,onClick:()=>i(e),children:u(X,{sx:{fontSize:16}})})}),a&&u(j,{title:C.t(`Show as diff`),children:u(S,{size:`small`,onClick:()=>a(e,o),children:u(ae,{sx:{fontSize:16}})})})]})]}),u(`pre`,{ref:s,style:{margin:0,padding:`8px 12px`,overflow:`auto`,maxHeight:400,fontSize:`13px`,fontFamily:`'Cascadia Code', 'Fira Code', 'Consolas', monospace`,backgroundColor:r===`dark`?`#1e1e1e`:`#f8f8f8`,color:r===`dark`?`#d4d4d4`:`#333`},children:e})]})};D();var Ee=({xml:e})=>{let t=d(),n=k(null),r=k(null),[i,a]=_(60),o=k(!1);return b(()=>{o.current&&(o.current=!1,requestAnimationFrame(()=>{let e=window.Blockly,t=r.current;e&&t&&(e.svgResize(t),t.scrollCenter())}))},[i]),b(()=>{let i=window.Blockly;if(i&&n.current){r.current&&=(r.current.dispose(),null);try{let s=i.inject(n.current,{readOnly:!0,toolbox:null,trashcan:!1,zoom:{controls:!1,wheel:!1,startScale:1},move:{scrollbars:!1,drag:!1,wheel:!1},sounds:!1,renderer:`thrasos`,theme:F(t),media:`google-blockly/media/`});r.current=s;let c=e.trim();c.startsWith(`<xml`)||(c=`<xml xmlns="https://developers.google.com/blockly/xml">${c}</xml>`);let l=i.utils.xml.textToDom(c),u=10,d=Array.from(l.querySelectorAll(`:scope > block`));for(let e of d)e.setAttribute(`x`,`10`),e.setAttribute(`y`,String(u)),u+=200;i.Xml.domToWorkspace(l,s);let f=s.getTopBlocks(!1);if(f.length>1){let e=10;for(let t of f){let n=t.getRelativeToSurfaceXY();t.moveBy(10-n.x,e-n.y),e+=t.getHeightWidth().height+20}}let p=s.getBlocksBoundingBox();if(p){let e=p.bottom-p.top+20,t=Math.max(60,Math.ceil(e));o.current=!0,a(t)}}catch{}return()=>{r.current&&=(r.current.dispose(),null)}}},[e,t]),u(p,{ref:n,sx:{width:`100%`,height:i,minHeight:60,borderRadius:1,overflow:`hidden`,border:`1px solid`,borderColor:`divider`}})};D();function De(e){let t=[],n=/```(\w*)\n?([\s\S]*?)```/g,r=0,i;for(;(i=n.exec(e))!==null;){if(i.index>r){let n=e.substring(r,i.index).trim();n&&t.push({type:`text`,content:n})}t.push({type:`code`,content:i[2].trim(),language:i[1]||`javascript`}),r=i.index+i[0].length}if(r<e.length){let n=e.substring(r).trim();n&&t.push({type:`text`,content:n})}return t.length===0&&t.push({type:`text`,content:e}),t}function $(e){let t=[],n=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g,r=0,i,a=0;for(;(i=n.exec(e))!==null;)i.index>r&&t.push(e.substring(r,i.index)),i[2]?t.push(u(`strong`,{children:i[2]},a++)):i[3]?t.push(u(`em`,{children:i[3]},a++)):i[4]&&t.push(u(`code`,{className:`ai-chat-inline-code`,style:{padding:`2px 6px`,borderRadius:4,fontSize:`0.85em`,fontFamily:`'Cascadia Code', 'Fira Code', 'Consolas', monospace`},children:i[4]},a++)),r=i.index+i[0].length;return r<e.length&&t.push(e.substring(r)),t}function Oe(e){return e.trim().startsWith(`|`)&&e.trim().endsWith(`|`)}function ke(e){return/^\|[\s:]*-+[\s:|-]*\|$/.test(e.trim())}function Ae(e,n,r){let i=n.palette.mode===`dark`,a=e=>e.trim().replace(/^\||\|$/g,``).split(`|`).map(e=>e.trim()),o=a(e[0]),s=e.slice(2).map(a);return u(p,{sx:{overflowX:`auto`,my:1},children:t(`table`,{style:{borderCollapse:`collapse`,width:`100%`,fontSize:`0.8rem`,color:n.palette.text.primary},children:[u(`thead`,{children:u(`tr`,{children:o.map((e,t)=>u(`th`,{style:{border:`1px solid ${n.palette.divider}`,padding:`6px 10px`,backgroundColor:i?n.palette.grey[800]:n.palette.grey[100],color:n.palette.text.primary,fontWeight:600,textAlign:`left`},children:$(e)},t))})}),u(`tbody`,{children:s.map((e,t)=>u(`tr`,{style:{backgroundColor:t%2==1?i?n.palette.grey[900]:n.palette.grey[50]:void 0},children:e.map((e,t)=>u(`td`,{style:{border:`1px solid ${n.palette.divider}`,padding:`6px 10px`,color:n.palette.text.primary},children:$(e)},t))},t))})]})},r)}function je(e,t){let n=e.split(`
19
+ `),r=[],i=0,a=0;for(;a<n.length;){let e=n[a].trim();if(e===``){a++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(e)){r.push(u(`hr`,{style:{border:`none`,borderTop:`1px solid ${t.palette.divider}`,margin:`8px 0`}},i++)),a++;continue}let o=e.match(/^(#{1,4})\s+(.+)$/);if(o){let e=o[1].length;r.push(u(`div`,{style:{fontWeight:600,fontSize:[`1.2em`,`1.1em`,`1em`,`0.95em`][e-1],margin:`8px 0 4px`},children:$(o[2])},i++)),a++;continue}if(Oe(e)&&a+1<n.length&&ke(n[a+1].trim())&&a+2<n.length){let e=[n[a],n[a+1]],o=a+2;for(;o<n.length&&Oe(n[o]);)e.push(n[o]),o++;r.push(Ae(e,t,i++)),a=o;continue}if(/^[-*+]\s/.test(e)){let e=[];for(;a<n.length&&/^\s*[-*+]\s/.test(n[a]);)e.push(n[a].replace(/^\s*[-*+]\s/,``).trim()),a++;r.push(u(`ul`,{style:{margin:`4px 0`,paddingLeft:20},children:e.map((e,t)=>u(`li`,{children:$(e)},t))},i++));continue}if(/^\d+[.)]\s/.test(e)){let e=[];for(;a<n.length&&/^\s*\d+[.)]\s/.test(n[a]);)e.push(n[a].replace(/^\s*\d+[.)]\s/,``).trim()),a++;r.push(u(`ol`,{style:{margin:`4px 0`,paddingLeft:20},children:e.map((e,t)=>u(`li`,{children:$(e)},t))},i++));continue}r.push(u(`div`,{children:$(e)},i++)),a++}return r}var Me=({message:e,themeType:r,currentLanguage:i,onInsertCode:a,onShowDiff:o,onApplyCode:s})=>{let l=e.role===`user`,d=c(),m=l?r===`dark`?d.palette.primary.dark:d.palette.primary.main:r===`dark`?d.palette.secondary.dark:d.palette.secondary.main,h=d.palette.getContrastText(m),_=g(()=>De(e.content),[e.content]),v=(e,t)=>!!(e===`xml`||e===`blockly`||i===`blockly`&&t&&/<block\s+type=/.test(t));return t(p,{sx:{display:`flex`,gap:1,px:1.5,py:1,mx:.75,my:.5,bgcolor:l?r===`dark`?`rgba(144, 202, 249, 0.10)`:`rgba(25, 118, 210, 0.07)`:r===`dark`?`rgba(206, 147, 216, 0.10)`:`rgba(156, 39, 176, 0.06)`,borderRadius:1.5,borderLeft:`3px solid`,borderLeftColor:m,transition:`background-color 120ms`,"&:hover":{bgcolor:l?r===`dark`?`rgba(144, 202, 249, 0.16)`:`rgba(25, 118, 210, 0.12)`:r===`dark`?`rgba(206, 147, 216, 0.16)`:`rgba(156, 39, 176, 0.10)`}},children:[u(n,{sx:{width:28,height:28,bgcolor:m,color:h,flexShrink:0,mt:.5},children:u(l?oe:ce,{sx:{fontSize:18}})}),u(p,{sx:{flex:1,minWidth:0,fontSize:`0.875rem`,lineHeight:1.6},children:_.map((n,i)=>n.type===`code`?v(n.language,n.content)?t(p,{sx:{my:1},children:[u(Ee,{xml:n.content}),t(p,{sx:{display:`flex`,gap:.5,mt:.5},children:[s&&u(f,{size:`small`,variant:`contained`,color:`primary`,startIcon:u(se,{sx:{fontSize:14}}),onClick:()=>s(n.content),sx:{textTransform:`none`,fontSize:`0.75rem`},children:C.t(`Apply blocks`)}),a&&u(f,{size:`small`,variant:`outlined`,startIcon:u(X,{sx:{fontSize:14}}),onClick:()=>a(n.content),sx:{textTransform:`none`,fontSize:`0.75rem`},children:C.t(`Insert blocks`)})]})]},i):u(Te,{code:n.content,language:n.language||`javascript`,themeType:r,onInsertCode:a,onShowDiff:o,sourceRange:e.sourceRange||null},i):u(p,{sx:{wordBreak:`break-word`,color:d.palette.text.primary},children:je(n.content,d)},i))})]})};function Ne(e){let t=(e||``).toLowerCase();return t.includes(`blockly`)||t.includes(`rules`)?`blockly`:t.includes(`typescript`)?`typescript`:`javascript`}function Pe(e,t){return`\`\`\`${t===`blockly`?`xml`:t}\n${e}\n\`\`\``}function Fe(e){let t=(e.code||``).trim(),n=Ne(e.language),r=e.rangeLabel?` (${e.rangeLabel})`:``;switch(e.action){case`explain`:return t?[`Please explain what this ioBroker ${n} code does${r}.`,`Focus on: which datapoints it reads/writes, which triggers fire it, and any side-effects.`,``,Pe(t,n)].join(`
20
20
  `):null;case`refactor`:return t?[`Refactor this ioBroker ${n} code${r} 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 \`\`\`${n===`blockly`?`xml`:n}\`\`\` code block so it can be smart-applied.`,``,Pe(t,n)].join(`
21
21
  `):null;case`comment`:return t?[`Add clear, concise inline comments to this ioBroker ${n} code${r}.`,`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.`,``,Pe(t,n)].join(`
22
22
  `):null;case`fix`:{if(!t)return null;let i=(e.diagnostic||``).trim();return[`This ioBroker ${n} code has an issue${r}. Please fix it and return the corrected code.${i?`\nReported problem: ${i}`:``}`,`Keep the fix minimal — do not rewrite unrelated parts.`,``,Pe(t,n)].join(`
23
23
  `)}case`tests`:return t?[`Suggest how to test this ioBroker ${n} script manually inside the ioBroker admin UI${r}.`,``,"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.`,``,Pe(t,n)].join(`
24
24
  `):null;case`ask`:{let i=(e.question||``).trim();return i?t?[`Regarding this ioBroker ${n} code${r}:`,``,Pe(t,n),``,i].join(`
25
- `):i:null}default:return null}}function Ie(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}c();function Le(){return[{id:`@all`,label:T.t(`mention @all`),descriptionKey:`All scripts`},{id:`@devices`,label:T.t(`mention @devices`),descriptionKey:`Smart home devices`}]}function Re({provider:e,isDark:t}){return W[e]?w(`img`,{src:`./img/${e}.svg`,alt:e,style:{...J,...t?{filter:`invert(0.85)`}:{}},onError:e=>{e.target.style.display=`none`}}):null}function ze(){try{let e=window.localStorage.getItem(`Editor.aiChatHistory`);return e?JSON.parse(e):[]}catch{return[]}}var Be=({onSend:e,disabled:o,themeType:c,hasSelection:l,selectionText:f,allScripts:p,model:h,availableModels:y,modelProviderMap:S,modelsLoading:C,onModelChange:k,mode:j,onModeChange:te,currentLanguage:N})=>{let[P,F]=D(``),[I,L]=D(!1),[R,z]=D(``),[B,V]=D(0),H=r(null),U=r(-1),W=r(ze()),G=r(-1),K=r(``),ne=O(()=>{let e=Le().map(e=>({...e,description:T.t(e.descriptionKey)}));if(p)for(let t of p){let n=t.id.replace(/^script\.js\./,``).replace(/\./g,`/`);e.push({id:`@${n}`,label:`@${n}`,description:`${t.name} [${t.enabled?`active`:`inactive`}]`})}return e},[p]),q=O(()=>{if(!R)return ne;let e=R.toLowerCase();return ne.filter(t=>t.id.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[ne,R]);A(()=>{V(0)},[R]);let J=b(()=>{let t=P.trim();if(!t||o)return;let n=t,r=Ie(t);if(r){let e=l&&f?f:``,t=Fe({action:r.action,code:e,language:N||`javascript`,question:r.action===`ask`?r.rest:void 0,diagnostic:r.action===`fix`&&r.rest||void 0});t&&(n=t)}else l&&f&&(n=`[Selected code in editor]\n\`\`\`\n${f}\n\`\`\`\n\n${t}`);W.current.push(t),G.current=-1,K.current=``;try{let e=W.current.slice(-50);window.localStorage.setItem(`Editor.aiChatHistory`,JSON.stringify(e))}catch{}e(n),F(``),L(!1),requestAnimationFrame(()=>{var e;return(e=H.current)==null?void 0:e.focus()})},[P,o,e,l,f,N]),Y=b(e=>{let t=U.current,n=H.current;if(t<0){let t=P?`${P}${e} `:`${e} `;F(t),L(!1),z(``),setTimeout(()=>{n&&(n.focus(),n.setSelectionRange(t.length,t.length))},0);return}let r=P.substring(0,t),i=(n==null?void 0:n.selectionStart)??P.length,a=`${r}${e} ${P.substring(i)}`;F(a),L(!1),z(``),U.current=-1,setTimeout(()=>{if(n){let t=r.length+e.length+1;n.focus(),n.setSelectionRange(t,t)}},0)},[P]),X=b(()=>{U.current=-1,z(``),L(e=>!e)},[]),re=b(e=>{let t=e.target.value;F(t);let n=e.target.selectionStart??t.length,r=t.substring(0,n).match(/@([\w/äöüÄÖÜß]*)$/);r?(U.current=n-r[0].length,z(r[1]),L(!0)):(L(!1),z(``))},[]),ae=b(e=>{if(I&&q.length>0){if(e.key===`ArrowDown`){e.preventDefault(),V(e=>(e+1)%q.length);return}if(e.key===`ArrowUp`){e.preventDefault(),V(e=>(e-1+q.length)%q.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),Y(q[B].id);return}if(e.key===`Escape`){e.preventDefault(),L(!1);return}}if(e.key===`ArrowUp`&&!I&&W.current.length>0){let t=H.current,n=!t||t.selectionStart===0,r=!P.includes(`
25
+ `):i:null}default:return null}}function Ie(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}D();function Le(){return[{id:`@all`,label:C.t(`mention @all`),descriptionKey:`All scripts`},{id:`@devices`,label:C.t(`mention @devices`),descriptionKey:`Smart home devices`}]}function Re({provider:e,isDark:t}){return W[e]?u(`img`,{src:`./img/${e}.svg`,alt:e,style:{...J,...t?{filter:`invert(0.85)`}:{}},onError:e=>{e.target.style.display=`none`}}):null}function ze(){try{let e=window.localStorage.getItem(`Editor.aiChatHistory`);return e?JSON.parse(e):[]}catch{return[]}}var Be=({onSend:e,disabled:n,themeType:r,hasSelection:c,selectionText:d,allScripts:f,model:h,availableModels:v,modelProviderMap:w,modelsLoading:T,onModelChange:E,mode:D,onModeChange:te,currentLanguage:N})=>{let[P,F]=_(``),[I,L]=_(!1),[R,z]=_(``),[B,V]=_(0),H=k(null),U=k(-1),W=k(ze()),G=k(-1),K=k(``),ne=g(()=>{let e=Le().map(e=>({...e,description:C.t(e.descriptionKey)}));if(f)for(let t of f){let n=t.id.replace(/^script\.js\./,``).replace(/\./g,`/`);e.push({id:`@${n}`,label:`@${n}`,description:`${t.name} [${t.enabled?`active`:`inactive`}]`})}return e},[f]),q=g(()=>{if(!R)return ne;let e=R.toLowerCase();return ne.filter(t=>t.id.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[ne,R]);b(()=>{V(0)},[R]);let J=y(()=>{let t=P.trim();if(!t||n)return;let r=t,i=Ie(t);if(i){let e=c&&d?d:``,t=Fe({action:i.action,code:e,language:N||`javascript`,question:i.action===`ask`?i.rest:void 0,diagnostic:i.action===`fix`&&i.rest||void 0});t&&(r=t)}else c&&d&&(r=`[Selected code in editor]\n\`\`\`\n${d}\n\`\`\`\n\n${t}`);W.current.push(t),G.current=-1,K.current=``;try{let e=W.current.slice(-50);window.localStorage.setItem(`Editor.aiChatHistory`,JSON.stringify(e))}catch{}e(r),F(``),L(!1),requestAnimationFrame(()=>{var e;return(e=H.current)==null?void 0:e.focus()})},[P,n,e,c,d,N]),Y=y(e=>{let t=U.current,n=H.current;if(t<0){let t=P?`${P}${e} `:`${e} `;F(t),L(!1),z(``),setTimeout(()=>{n&&(n.focus(),n.setSelectionRange(t.length,t.length))},0);return}let r=P.substring(0,t),i=(n==null?void 0:n.selectionStart)??P.length,a=`${r}${e} ${P.substring(i)}`;F(a),L(!1),z(``),U.current=-1,setTimeout(()=>{if(n){let t=r.length+e.length+1;n.focus(),n.setSelectionRange(t,t)}},0)},[P]),X=y(()=>{U.current=-1,z(``),L(e=>!e)},[]),re=y(e=>{let t=e.target.value;F(t);let n=e.target.selectionStart??t.length,r=t.substring(0,n).match(/@([\w/äöüÄÖÜß]*)$/);r?(U.current=n-r[0].length,z(r[1]),L(!0)):(L(!1),z(``))},[]),ae=y(e=>{if(I&&q.length>0){if(e.key===`ArrowDown`){e.preventDefault(),V(e=>(e+1)%q.length);return}if(e.key===`ArrowUp`){e.preventDefault(),V(e=>(e-1+q.length)%q.length);return}if(e.key===`Enter`||e.key===`Tab`){e.preventDefault(),Y(q[B].id);return}if(e.key===`Escape`){e.preventDefault(),L(!1);return}}if(e.key===`ArrowUp`&&!I&&W.current.length>0){let t=H.current,n=!t||t.selectionStart===0,r=!P.includes(`
26
26
  `);if(n&&r){e.preventDefault(),G.current===-1?(K.current=P,G.current=W.current.length-1):G.current>0&&G.current--,F(W.current[G.current]);return}}if(e.key===`ArrowDown`&&!I&&G.current>=0){let t=H.current,n=!t||t.selectionStart===P.length,r=!P.includes(`
27
- `);if(n&&r){e.preventDefault(),G.current<W.current.length-1?(G.current++,F(W.current[G.current])):(G.current=-1,F(K.current));return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),J())},[J,I,q,B,Y,P]);return E(a,{sx:{borderTop:`1px solid`,borderColor:`divider`,position:`relative`},children:[I&&q.length>0&&w(s,{elevation:4,sx:{position:`absolute`,bottom:`100%`,left:8,right:8,maxHeight:200,overflow:`auto`,zIndex:10,mb:.5},children:w(_,{dense:!0,disablePadding:!0,children:q.slice(0,15).map((e,t)=>w(d,{selected:t===B,onClick:()=>Y(e.id),sx:{py:.25,minHeight:32},children:w(ee,{primary:e.label,secondary:e.description,slotProps:{primary:{sx:{fontSize:`0.8rem`,fontWeight:500}},secondary:{sx:{fontSize:`0.7rem`}}}})},e.id))})}),j===`code`&&w(g,{label:`${T.t(`mention @devices`)} — ${T.t(`Smart home devices`)}`,size:`small`,variant:`outlined`,sx:{mx:1,mt:.5,maxWidth:`calc(100% - 16px)`}}),l&&f&&w(g,{icon:w(v,{sx:{fontSize:14}}),label:T.t(`Selected code as context`),size:`small`,variant:`outlined`,sx:{mx:1,mt:.5,maxWidth:`calc(100% - 16px)`}}),E(a,{sx:{mx:1,mt:.5,mb:.5,border:`1px solid`,borderColor:`divider`,borderRadius:1.5,overflow:`hidden`,"&:focus-within":{borderColor:`primary.main`}},children:[w(u,{inputRef:H,fullWidth:!0,multiline:!0,maxRows:6,placeholder:T.t(`Ask about your script...`),value:P,onChange:re,onKeyDown:ae,disabled:o,onBlur:()=>{setTimeout(()=>L(!1),200)},variant:`standard`,slotProps:{input:{disableUnderline:!0}},sx:{px:1.5,pt:1,pb:.5,"& .MuiInputBase-root":{fontSize:`0.875rem`}}}),E(a,{sx:{display:`flex`,alignItems:`center`,gap:.75,px:1,pb:.5},children:[w(n,{title:E(a,{sx:{fontSize:`0.8rem`,lineHeight:1.5,maxWidth:360},children:[w(a,{sx:{fontWeight:600,mb:.75},children:T.t(`AI chat mode`)}),E(a,{sx:{mb:.75},children:[E(`strong`,{children:[`💬 `,T.t(`Chat`)]}),` —`,` `,T.t(`Plain conversation. Use for questions, explanations, syntax help. Does not read or modify your scripts.`)]}),E(a,{sx:{mb:.75},children:[E(`strong`,{children:[`🤖 `,T.t(`Agent`)]}),` —`,` `,T.t(`For larger models with tool support. The AI can read, create, and edit scripts, look up datapoints, and browse the object tree — useful for "create a script that...", "which scripts use this state?" or "analyze my light script".`)]}),E(a,{children:[E(`strong`,{children:[`💻 `,T.t(`Code`)]}),` —`,` `,T.t(`For smaller models without tool support. Two-step script generator (plan then code) — useful for "create a script that..." or "write a Blockly rule for...". Output goes into the editor for smart-apply.`)]})]}),enterDelay:400,placement:`left`,children:E(t,{value:j,onChange:e=>te(e.target.value),size:`small`,variant:`standard`,disableUnderline:!0,sx:{fontSize:`0.7rem`,color:`text.secondary`,border:`1px solid`,borderColor:`text.secondary`,borderRadius:3,bgcolor:`action.hover`,px:.75,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`},"& .MuiSelect-select":{py:`2px`,pr:`18px !important`,display:`flex`,alignItems:`center`,gap:.5}},children:[w(i,{value:`chat`,sx:{fontSize:`0.75rem`},title:T.t(`Plain conversation. Best for: general questions, syntax help, concept explanations.`),children:`💬 Chat`}),w(i,{value:`agent`,sx:{fontSize:`0.75rem`},title:T.t(`For larger models with tool support. Best for: creating, editing, or analyzing scripts; finding datapoint usages; inspecting the object tree.`),children:`🤖 Agent`}),w(i,{value:`code`,sx:{fontSize:`0.75rem`},title:T.t(`For smaller models without tool support. Best for: creating new JavaScript/TypeScript or Blockly scripts from a description.`),children:`💻 Code`})]})}),w(t,{value:h,onChange:e=>k(e.target.value),size:`small`,disabled:C||y.length===0,variant:`standard`,disableUnderline:!0,sx:{fontSize:`0.7rem`,color:`text.secondary`,border:`1px solid`,borderColor:`text.secondary`,borderRadius:3,bgcolor:`action.hover`,px:.75,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`},"& .MuiSelect-select":{py:`2px`,pr:`18px !important`,display:`flex`,alignItems:`center`,gap:.5}},children:y.map(e=>E(i,{value:e,sx:{fontSize:`0.75rem`,display:`flex`,gap:.5},children:[w(Re,{provider:S[e],isDark:c===`dark`}),e]},e))}),w(n,{title:T.t(`Mention scripts as context for the AI. Use @all for all scripts or @scriptName for a specific one.`),enterDelay:500,children:w(x,{size:`small`,onClick:X,sx:{p:`3px`,color:I?`primary.main`:`text.secondary`,border:`1px solid`,borderColor:I?`primary.main`:`text.secondary`,bgcolor:I?void 0:`action.hover`,borderRadius:3,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`}},children:w(ie,{sx:{fontSize:16}})})}),w(a,{sx:{flex:1}}),E(m,{variant:`caption`,sx:{color:`text.disabled`,fontSize:`0.65rem`,mr:.5,whiteSpace:`nowrap`},children:[`Enter `,T.t(`to send`)]}),w(n,{title:`${T.t(`Send`)} (Enter)`,children:w(`span`,{children:w(x,{color:`primary`,onClick:J,disabled:o||!P.trim(),size:`small`,sx:{p:.25},children:w(M,{sx:{fontSize:18}})})})})]})]})]})};c();var Ve=({socket:e,runningInstances:t,themeType:i,currentCode:o,currentLanguage:s,selectedCode:c,allScripts:u,editorApi:d,aiActionRequest:f,onAiActionConsumed:p,onRegisterInlineAsk:h,onInsertCode:g,onShowDiff:_,onApplyCode:v,currentScriptId:S,onClose:ee})=>{var D;let j=r(null),{messages:M,isLoading:te,error:N,model:P,availableModels:F,modelProviderMap:I,modelsLoading:L,modelsError:R,lastContextInfo:z,mode:B,setMode:V,setModel:H,sendMessage:U,triggerAiAction:W,askInline:G,clearChat:K,retryLoadModels:ne}=we(O(()=>({socket:e,runningInstances:t,currentCode:o,currentLanguage:s,allScripts:u,editorApi:d,currentScriptId:S}),[e,t,o,s,u,d,S]));A(()=>(h==null||h(G),()=>h==null?void 0:h(null)),[G,h]);let q=r(null);A(()=>{f&&q.current!==f&&(q.current=f,W(f),p==null||p())},[f,W,p]),A(()=>{var e;(e=j.current)==null||e.scrollIntoView({behavior:`smooth`})},[M]);let J=b(e=>{g==null||g(e)},[g]),Y=b((e,t)=>{_==null||_(e,t)},[_]),X=b(e=>{v==null||v(e)},[v]);return E(a,{sx:{display:`flex`,flexDirection:`column`,height:`100%`,bgcolor:`background.default`,"& .ai-chat-inline-code":{backgroundColor:`action.selected`,color:`text.primary`,border:`1px solid`,borderColor:`divider`}},children:[E(a,{sx:{display:`flex`,alignItems:`center`,gap:1,px:1,py:.5,borderBottom:`1px solid`,borderColor:`divider`,bgcolor:i===`dark`?`grey.900`:`grey.100`,flexShrink:0},children:[w(m,{variant:`subtitle2`,sx:{fontWeight:600,flex:1,color:`text.primary`},children:T.t(`AI Chat`)}),L&&w(l,{size:16}),w(n,{title:T.t(`New chat`),children:w(x,{size:`small`,onClick:K,children:w(re,{sx:{fontSize:18}})})}),w(n,{title:T.t(`Close`),children:w(x,{size:`small`,onClick:ee,children:w(k,{sx:{fontSize:18}})})})]}),(N||R)&&w(C,{severity:`error`,sx:{m:1,py:0},action:R?w(x,{size:`small`,onClick:ne,children:w(y,{sx:{fontSize:16}})}):void 0,children:N||R}),z&&w(m,{variant:`caption`,sx:{px:1.5,py:.25,color:`text.secondary`,fontSize:`0.7rem`,bgcolor:`action.hover`,borderBottom:`1px solid`,borderColor:`divider`,flexShrink:0},children:z}),E(a,{sx:{flex:1,overflow:`auto`,py:1},children:[M.length===0&&!te&&E(a,{sx:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,height:`100%`,color:`text.secondary`,px:3,textAlign:`center`},children:[w(m,{variant:`body2`,sx:{mb:1},children:T.t(`Ask questions about your script, request changes, or generate new code.`)}),E(m,{variant:`caption`,color:`text.disabled`,children:[`Enter `,T.t(`to send`),`, Shift+Enter `,T.t(`for new line`)]})]}),M.filter(e=>e.role!==`system`).map(e=>w(Me,{message:e,themeType:i,currentLanguage:s,onInsertCode:J,onShowDiff:Y,onApplyCode:X},e.id)),te&&((D=M[M.length-1])==null?void 0:D.content)===``&&E(a,{sx:{display:`flex`,alignItems:`center`,gap:1,px:2,py:1},children:[w(l,{size:16}),w(m,{variant:`caption`,color:`text.secondary`,children:T.t(`Thinking...`)})]}),w(`div`,{ref:j})]}),w(Be,{onSend:U,disabled:te||F.length===0,themeType:i,hasSelection:!!c,selectionText:c,allScripts:u,model:P,availableModels:F,modelProviderMap:I,modelsLoading:L,onModelChange:H,mode:B,onModeChange:V,currentLanguage:s})]})};export{Ve as default,Ie as n,Fe as t};
27
+ `);if(n&&r){e.preventDefault(),G.current<W.current.length-1?(G.current++,F(W.current[G.current])):(G.current=-1,F(K.current));return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),J())},[J,I,q,B,Y,P]);return t(p,{sx:{borderTop:`1px solid`,borderColor:`divider`,position:`relative`},children:[I&&q.length>0&&u(o,{elevation:4,sx:{position:`absolute`,bottom:`100%`,left:8,right:8,maxHeight:200,overflow:`auto`,zIndex:10,mb:.5},children:u(O,{dense:!0,disablePadding:!0,children:q.slice(0,15).map((e,t)=>u(ee,{selected:t===B,onClick:()=>Y(e.id),sx:{py:.25,minHeight:32},children:u(a,{primary:e.label,secondary:e.description,slotProps:{primary:{sx:{fontSize:`0.8rem`,fontWeight:500}},secondary:{sx:{fontSize:`0.7rem`}}}})},e.id))})}),D===`code`&&u(m,{label:`${C.t(`mention @devices`)} — ${C.t(`Smart home devices`)}`,size:`small`,variant:`outlined`,sx:{mx:1,mt:.5,maxWidth:`calc(100% - 16px)`}}),c&&d&&u(m,{icon:u(A,{sx:{fontSize:14}}),label:C.t(`Selected code as context`),size:`small`,variant:`outlined`,sx:{mx:1,mt:.5,maxWidth:`calc(100% - 16px)`}}),t(p,{sx:{mx:1,mt:.5,mb:.5,border:`1px solid`,borderColor:`divider`,borderRadius:1.5,overflow:`hidden`,"&:focus-within":{borderColor:`primary.main`}},children:[u(l,{inputRef:H,fullWidth:!0,multiline:!0,maxRows:6,placeholder:C.t(`Ask about your script...`),value:P,onChange:re,onKeyDown:ae,disabled:n,onBlur:()=>{setTimeout(()=>L(!1),200)},variant:`standard`,slotProps:{input:{disableUnderline:!0}},sx:{px:1.5,pt:1,pb:.5,"& .MuiInputBase-root":{fontSize:`0.875rem`}}}),t(p,{sx:{display:`flex`,alignItems:`center`,gap:.75,px:1,pb:.5},children:[u(j,{title:t(p,{sx:{fontSize:`0.8rem`,lineHeight:1.5,maxWidth:360},children:[u(p,{sx:{fontWeight:600,mb:.75},children:C.t(`AI chat mode`)}),t(p,{sx:{mb:.75},children:[t(`strong`,{children:[`💬 `,C.t(`Chat`)]}),` —`,` `,C.t(`Plain conversation. Use for questions, explanations, syntax help. Does not read or modify your scripts.`)]}),t(p,{sx:{mb:.75},children:[t(`strong`,{children:[`🤖 `,C.t(`Agent`)]}),` —`,` `,C.t(`For larger models with tool support. The AI can read, create, and edit scripts, look up datapoints, and browse the object tree — useful for "create a script that...", "which scripts use this state?" or "analyze my light script".`)]}),t(p,{children:[t(`strong`,{children:[`💻 `,C.t(`Code`)]}),` —`,` `,C.t(`For smaller models without tool support. Two-step script generator (plan then code) — useful for "create a script that..." or "write a Blockly rule for...". Output goes into the editor for smart-apply.`)]})]}),enterDelay:400,placement:`left`,children:t(x,{value:D,onChange:e=>te(e.target.value),size:`small`,variant:`standard`,disableUnderline:!0,sx:{fontSize:`0.7rem`,color:`text.secondary`,border:`1px solid`,borderColor:`text.secondary`,borderRadius:3,bgcolor:`action.hover`,px:.75,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`},"& .MuiSelect-select":{py:`2px`,pr:`18px !important`,display:`flex`,alignItems:`center`,gap:.5}},children:[u(s,{value:`chat`,sx:{fontSize:`0.75rem`},title:C.t(`Plain conversation. Best for: general questions, syntax help, concept explanations.`),children:`💬 Chat`}),u(s,{value:`agent`,sx:{fontSize:`0.75rem`},title:C.t(`For larger models with tool support. Best for: creating, editing, or analyzing scripts; finding datapoint usages; inspecting the object tree.`),children:`🤖 Agent`}),u(s,{value:`code`,sx:{fontSize:`0.75rem`},title:C.t(`For smaller models without tool support. Best for: creating new JavaScript/TypeScript or Blockly scripts from a description.`),children:`💻 Code`})]})}),u(x,{value:h,onChange:e=>E(e.target.value),size:`small`,disabled:T||v.length===0,variant:`standard`,disableUnderline:!0,sx:{fontSize:`0.7rem`,color:`text.secondary`,border:`1px solid`,borderColor:`text.secondary`,borderRadius:3,bgcolor:`action.hover`,px:.75,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`},"& .MuiSelect-select":{py:`2px`,pr:`18px !important`,display:`flex`,alignItems:`center`,gap:.5}},children:v.map(e=>t(s,{value:e,sx:{fontSize:`0.75rem`,display:`flex`,gap:.5},children:[u(Re,{provider:w[e],isDark:r===`dark`}),e]},e))}),u(j,{title:C.t(`Mention scripts as context for the AI. Use @all for all scripts or @scriptName for a specific one.`),enterDelay:500,children:u(S,{size:`small`,onClick:X,sx:{p:`3px`,color:I?`primary.main`:`text.secondary`,border:`1px solid`,borderColor:I?`primary.main`:`text.secondary`,bgcolor:I?void 0:`action.hover`,borderRadius:3,"&:hover":{borderColor:`text.disabled`,bgcolor:`action.hover`}},children:u(ie,{sx:{fontSize:16}})})}),u(p,{sx:{flex:1}}),t(i,{variant:`caption`,sx:{color:`text.disabled`,fontSize:`0.65rem`,mr:.5,whiteSpace:`nowrap`},children:[`Enter `,C.t(`to send`)]}),u(j,{title:`${C.t(`Send`)} (Enter)`,children:u(`span`,{children:u(S,{color:`primary`,onClick:J,disabled:n||!P.trim(),size:`small`,sx:{p:.25},children:u(M,{sx:{fontSize:18}})})})})]})]})]})};D();var Ve=({socket:e,runningInstances:n,themeType:r,currentCode:a,currentLanguage:o,selectedCode:s,allScripts:c,editorApi:l,aiActionRequest:d,onAiActionConsumed:f,onRegisterInlineAsk:m,onInsertCode:_,onShowDiff:x,onApplyCode:E,currentScriptId:D,onClose:ee})=>{var O;let A=k(null),{messages:M,isLoading:te,error:N,model:P,availableModels:F,modelProviderMap:I,modelsLoading:L,modelsError:R,lastContextInfo:z,mode:B,setMode:V,setModel:H,sendMessage:U,triggerAiAction:W,askInline:G,clearChat:K,retryLoadModels:ne}=we(g(()=>({socket:e,runningInstances:n,currentCode:a,currentLanguage:o,allScripts:c,editorApi:l,currentScriptId:D}),[e,n,a,o,c,l,D]));b(()=>(m==null||m(G),()=>m==null?void 0:m(null)),[G,m]);let q=k(null);b(()=>{d&&q.current!==d&&(q.current=d,W(d),f==null||f())},[d,W,f]),b(()=>{var e;(e=A.current)==null||e.scrollIntoView({behavior:`smooth`})},[M]);let J=y(e=>{_==null||_(e)},[_]),Y=y((e,t)=>{x==null||x(e,t)},[x]),X=y(e=>{E==null||E(e)},[E]);return t(p,{sx:{display:`flex`,flexDirection:`column`,height:`100%`,bgcolor:`background.default`,"& .ai-chat-inline-code":{backgroundColor:`action.selected`,color:`text.primary`,border:`1px solid`,borderColor:`divider`}},children:[t(p,{sx:{display:`flex`,alignItems:`center`,gap:1,px:1,py:.5,borderBottom:`1px solid`,borderColor:`divider`,bgcolor:r===`dark`?`grey.900`:`grey.100`,flexShrink:0},children:[u(i,{variant:`subtitle2`,sx:{fontWeight:600,flex:1,color:`text.primary`},children:C.t(`AI Chat`)}),L&&u(h,{size:16}),u(j,{title:C.t(`New chat`),children:u(S,{size:`small`,onClick:K,children:u(re,{sx:{fontSize:18}})})}),u(j,{title:C.t(`Close`),children:u(S,{size:`small`,onClick:ee,children:u(v,{sx:{fontSize:18}})})})]}),(N||R)&&u(w,{severity:`error`,sx:{m:1,py:0},action:R?u(S,{size:`small`,onClick:ne,children:u(T,{sx:{fontSize:16}})}):void 0,children:N||R}),z&&u(i,{variant:`caption`,sx:{px:1.5,py:.25,color:`text.secondary`,fontSize:`0.7rem`,bgcolor:`action.hover`,borderBottom:`1px solid`,borderColor:`divider`,flexShrink:0},children:z}),t(p,{sx:{flex:1,overflow:`auto`,py:1},children:[M.length===0&&!te&&t(p,{sx:{display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,height:`100%`,color:`text.secondary`,px:3,textAlign:`center`},children:[u(i,{variant:`body2`,sx:{mb:1},children:C.t(`Ask questions about your script, request changes, or generate new code.`)}),t(i,{variant:`caption`,color:`text.disabled`,children:[`Enter `,C.t(`to send`),`, Shift+Enter `,C.t(`for new line`)]})]}),M.filter(e=>e.role!==`system`).map(e=>u(Me,{message:e,themeType:r,currentLanguage:o,onInsertCode:J,onShowDiff:Y,onApplyCode:X},e.id)),te&&((O=M[M.length-1])==null?void 0:O.content)===``&&t(p,{sx:{display:`flex`,alignItems:`center`,gap:1,px:2,py:1},children:[u(h,{size:16}),u(i,{variant:`caption`,color:`text.secondary`,children:C.t(`Thinking...`)})]}),u(`div`,{ref:A})]}),u(Be,{onSend:U,disabled:te||F.length===0,themeType:r,hasSelection:!!s,selectionText:s,allScripts:c,model:P,availableModels:F,modelProviderMap:I,modelsLoading:L,onModelChange:H,mode:B,onModeChange:V,currentLanguage:o})]})};export{Ve as default,Ie as n,Fe as t};
@@ -1,4 +1,4 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./vite-preload-helper-CaC3yEL3.js";import{ct as n,p as r}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-Drq9CkPs.js";var i=e(n(),1),a=t(()=>import(`./docs-compact-D7rpMc7r.js`),[],import.meta.url),o={openai:`img/openai.svg`,anthropic:`img/anthropic.svg`,gemini:`img/gemini.svg`,deepseek:`img/deepseek.svg`,custom:`img/custom.svg`},s={width:16,height:16,flexShrink:0,opacity:.7},c={ru:`Russian`,en:`English`,de:`German`,es:`Spanish`,fr:`French`,it:`Italian`,pl:`Polish`,nl:`Dutch`,pt:`Portuguese`,uk:`Ukrainian`,"zh-cn":`Chinese`},l=null,u=null,d=null,f=null;function p(){l=null,u=null,d=null,f=null}async function m(e,t){if(l)return l;let n=Object.keys(t)[0];if(!n)return null;let r=await e.sendTo(n,`getAvailableAiProviders`,{}),i=((r==null?void 0:r.providers)||[]).map(e=>e.provider),a=((r==null?void 0:r.providers)||[]).find(e=>e.provider===`custom`);return i.length?(l={providers:i,gptBaseUrl:a==null?void 0:a.baseUrl},l):null}var h=`embedding.text-embedding.textembedding.embeddinggemma.embed-.-embed.bge-.mxbai-embed.nomic-embed.arctic-embed.snowflake-arctic-embed.all-minilm.multilingual-e5.jina-embed.voyage-.gecko.paraphrase-multilingual.dall-e.gpt-image.image-edit.-image-preview.-image-latest.flash-image.nano-banana.stable-diffusion.sdxl.midjourney.flux-.imagen.sora.veo-.cogvideo.runway-.lumiere.lyria.whisper.tts-.-tts.speech-.audio-preview.mini-tts.mini-transcribe.-transcribe.native-audio.flash-live.gpt-audio.realtime.bark-.xtts.voicebox.moderation.omni-moderation.llama-guard.shieldgemma.prompt-guard.-guardian.safeguard.rerank.reranker.babbage-.davinci-.curie-.text-ada-.text-davinci.text-curie.text-babbage.instructgpt.code-davinci.code-cushman.-turbo-instruct.-search-preview.-search-api.code-search.text-search.similarity-.computer-use-preview.deep-research.robotics.aqa.reader-lm.-nsql.minicheck`.split(`.`);function g(e){let t=e.toLowerCase();return!(h.some(e=>t.includes(e))||t.startsWith(`claude-1`)||t.startsWith(`claude-instant`))}var _=`openai-model`,v=`openai-model-provider`;function y(e,t){window.localStorage.setItem(_,e),t?window.localStorage.setItem(v,t):window.localStorage.removeItem(v)}function b(){return{model:window.localStorage.getItem(_)||``,provider:window.localStorage.getItem(v)||``}}async function x(e,t){let n=await m(e,t);if(!n)return{models:[],providerMap:{},errors:[`No API keys configured`]};let i=Object.keys(t)[0];if(!i)return{models:[],providerMap:{},errors:[r.t(`No running javascript instance found`)]};let a=[],o={},s=[],c={},l=[],u=(t,n)=>{l.push(e.sendTo(i,`testApiConnection`,{provider:t}).then(e=>{e.models?c[t]=e.models:e.error&&s.push(`${n||t}: ${e.error}`)}).catch(e=>{s.push(`${n||t}: ${String(e)}`)}))},d={openai:`OpenAI`,anthropic:`Anthropic`,gemini:`Gemini`,deepseek:`DeepSeek`,custom:`Custom`};for(let e of n.providers)u(e,d[e]);await Promise.all(l);for(let e of n.providers)for(let t of c[e]||[])g(t)&&!o[t]&&(a.push(t),o[t]=e);return a.sort(),{models:a,providerMap:o,errors:s}}async function S(e,t,n){var r;return await e.sendTo(t,`chatCompletion`,{timeout:n.timeout||6e5,model:n.model,provider:n.provider,messages:n.messages,...n.baseUrl?{baseUrl:n.baseUrl}:{},...(r=n.tools)!=null&&r.length?{tools:n.tools}:{}})}async function C(e){if(f)return f;let t=await e.getObjectViewSystem(`state`,``,`香`),n=await e.getObjectViewSystem(`channel`,``,`香`),r=await e.getObjectViewSystem(`device`,``,`香`),i=await e.getObjectViewSystem(`folder`,``,`香`),a=await e.getObjectViewSystem(`enum`,``,`香`);return f=Object.assign(t,n,r,i,a),f}async function w(e){return C(e)}function T(e,t){return e&&typeof e==`object`?e[t]||e.en:e||``}async function E(e){if(u)return u;let t=r.getLanguage(),n=await C(e),a=Object.keys(n).sort(),o=new i.default,s=[],c=[`UNREACH_STICKY`],l=[i.Types.info],d=[],f=[],p=[],m=[];a.forEach(e=>{var t,r;((t=n[e])==null?void 0:t.type)===`enum`?d.push(e):(r=n[e])!=null&&(r=r.common)!=null&&r.smartName&&m.push(e)}),d.forEach(e=>{e.startsWith(`enum.rooms.`)?f.push(e):e.startsWith(`enum.functions.`)&&p.push(e);let t=n[e].common.members;t!=null&&t.length&&t.forEach(e=>{n[e]&&!m.includes(e)&&m.push(e)})});let h={id:``,objects:n,_keysOptional:a,_usedIdsOptional:s,ignoreIndicators:c,excludedTypes:l},g=[];m.forEach(e=>{h.id=e;let r=o.detect(h);r&&r.forEach(e=>{var r;let i=(r=e.states.find(e=>e.id))==null?void 0:r.id;if(!i||g.find(e=>e.id===i))return;let a=n[i],o={id:i,name:T(a.common.name,t),type:a.type,deviceType:e.type,states:e.states.filter(e=>e.id).map(e=>({id:e.id,name:e.name,role:e.defaultRole,type:n[e.id].common.type,unit:n[e.id].common.unit,read:n[e.id].common.read??!0,write:n[e.id].common.write??!0}))},s=i.split(`.`),c,l;(a.type===`channel`||a.type===`state`)&&(s.pop(),c=s.join(`.`),n[c]&&(n[c].type===`channel`||n[c].type===`folder`)?(s.pop(),l=s.join(`.`),(!n[l]||n[l].type!==`device`&&n[c].type!==`folder`)&&(l=void 0)):c=void 0);let u=f.find(e=>{var t,r,a;return(t=n[e].common.members)!=null&&t.includes(i)||c&&(r=n[e].common.members)!=null&&r.includes(c)?!0:l&&((a=n[e].common.members)==null?void 0:a.includes(l))});u&&(o.room=T(n[u].common.name,t));let d=p.find(e=>{var t,r,a;return(t=n[e].common.members)!=null&&t.includes(i)||c&&(r=n[e].common.members)!=null&&r.includes(c)?!0:l&&((a=n[e].common.members)==null?void 0:a.includes(l))});d&&(o.function=T(n[d].common.name,t)),g.push(o)})});for(let e=0;e<g.length;e++){let r=g[e];if(r.type===`state`||r.type===`channel`){let e=r.id.split(`.`);e.pop();let i=n[e.join(`.`)];if(i&&(i.type===`channel`||i.type===`device`||i.type===`folder`)){var _,v;r.name=T(((_=i.common)==null?void 0:_.name)||r.name,t),e.pop();let a=n[e.join(`.`)];if((a==null?void 0:a.type)===`device`&&(v=a.common)!=null&&v.icon){var y;r.name=T(((y=a.common)==null?void 0:y.name)||r.name,t)}}else{var b;r.name=T((i==null||(b=i.common)==null?void 0:b.name)||r.name,t)}}}return u=g,g}async function D(){return d||(d=(await a).default,d)}function O(){return c[r.getLanguage()]||`English`}function k(e){return`You write ioBroker JavaScript adapter scripts.
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./vite-preload-helper-CaC3yEL3.js";import{p as n,st as r}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";var i=e(r(),1),a=t(()=>import(`./docs-compact-D7rpMc7r.js`),[],import.meta.url),o={openai:`img/openai.svg`,anthropic:`img/anthropic.svg`,gemini:`img/gemini.svg`,deepseek:`img/deepseek.svg`,custom:`img/custom.svg`},s={width:16,height:16,flexShrink:0,opacity:.7},c={ru:`Russian`,en:`English`,de:`German`,es:`Spanish`,fr:`French`,it:`Italian`,pl:`Polish`,nl:`Dutch`,pt:`Portuguese`,uk:`Ukrainian`,"zh-cn":`Chinese`},l=null,u=null,d=null,f=null;function p(){l=null,u=null,d=null,f=null}async function m(e,t){if(l)return l;let n=Object.keys(t)[0];if(!n)return null;let r=await e.sendTo(n,`getAvailableAiProviders`,{}),i=((r==null?void 0:r.providers)||[]).map(e=>e.provider),a=((r==null?void 0:r.providers)||[]).find(e=>e.provider===`custom`);return i.length?(l={providers:i,gptBaseUrl:a==null?void 0:a.baseUrl},l):null}var h=`embedding.text-embedding.textembedding.embeddinggemma.embed-.-embed.bge-.mxbai-embed.nomic-embed.arctic-embed.snowflake-arctic-embed.all-minilm.multilingual-e5.jina-embed.voyage-.gecko.paraphrase-multilingual.dall-e.gpt-image.image-edit.-image-preview.-image-latest.flash-image.nano-banana.stable-diffusion.sdxl.midjourney.flux-.imagen.sora.veo-.cogvideo.runway-.lumiere.lyria.whisper.tts-.-tts.speech-.audio-preview.mini-tts.mini-transcribe.-transcribe.native-audio.flash-live.gpt-audio.realtime.bark-.xtts.voicebox.moderation.omni-moderation.llama-guard.shieldgemma.prompt-guard.-guardian.safeguard.rerank.reranker.babbage-.davinci-.curie-.text-ada-.text-davinci.text-curie.text-babbage.instructgpt.code-davinci.code-cushman.-turbo-instruct.-search-preview.-search-api.code-search.text-search.similarity-.computer-use-preview.deep-research.robotics.aqa.reader-lm.-nsql.minicheck`.split(`.`);function g(e){let t=e.toLowerCase();return!(h.some(e=>t.includes(e))||t.startsWith(`claude-1`)||t.startsWith(`claude-instant`))}var _=`openai-model`,v=`openai-model-provider`;function y(e,t){window.localStorage.setItem(_,e),t?window.localStorage.setItem(v,t):window.localStorage.removeItem(v)}function b(){return{model:window.localStorage.getItem(_)||``,provider:window.localStorage.getItem(v)||``}}async function x(e,t){let r=await m(e,t);if(!r)return{models:[],providerMap:{},errors:[`No API keys configured`]};let i=Object.keys(t)[0];if(!i)return{models:[],providerMap:{},errors:[n.t(`No running javascript instance found`)]};let a=[],o={},s=[],c={},l=[],u=(t,n)=>{l.push(e.sendTo(i,`testApiConnection`,{provider:t}).then(e=>{e.models?c[t]=e.models:e.error&&s.push(`${n||t}: ${e.error}`)}).catch(e=>{s.push(`${n||t}: ${String(e)}`)}))},d={openai:`OpenAI`,anthropic:`Anthropic`,gemini:`Gemini`,deepseek:`DeepSeek`,custom:`Custom`};for(let e of r.providers)u(e,d[e]);await Promise.all(l);for(let e of r.providers)for(let t of c[e]||[])g(t)&&!o[t]&&(a.push(t),o[t]=e);return a.sort(),{models:a,providerMap:o,errors:s}}async function S(e,t,n){var r;return await e.sendTo(t,`chatCompletion`,{timeout:n.timeout||6e5,model:n.model,provider:n.provider,messages:n.messages,...n.baseUrl?{baseUrl:n.baseUrl}:{},...(r=n.tools)!=null&&r.length?{tools:n.tools}:{}})}async function C(e){if(f)return f;let t=await e.getObjectViewSystem(`state`,``,`香`),n=await e.getObjectViewSystem(`channel`,``,`香`),r=await e.getObjectViewSystem(`device`,``,`香`),i=await e.getObjectViewSystem(`folder`,``,`香`),a=await e.getObjectViewSystem(`enum`,``,`香`);return f=Object.assign(t,n,r,i,a),f}async function w(e){return C(e)}function T(e,t){return e&&typeof e==`object`?e[t]||e.en:e||``}async function E(e){if(u)return u;let t=n.getLanguage(),r=await C(e),a=Object.keys(r).sort(),o=new i.default,s=[],c=[`UNREACH_STICKY`],l=[i.Types.info],d=[],f=[],p=[],m=[];a.forEach(e=>{var t,n;((t=r[e])==null?void 0:t.type)===`enum`?d.push(e):(n=r[e])!=null&&(n=n.common)!=null&&n.smartName&&m.push(e)}),d.forEach(e=>{e.startsWith(`enum.rooms.`)?f.push(e):e.startsWith(`enum.functions.`)&&p.push(e);let t=r[e].common.members;t!=null&&t.length&&t.forEach(e=>{r[e]&&!m.includes(e)&&m.push(e)})});let h={id:``,objects:r,_keysOptional:a,_usedIdsOptional:s,ignoreIndicators:c,excludedTypes:l},g=[];m.forEach(e=>{h.id=e;let n=o.detect(h);n&&n.forEach(e=>{var n;let i=(n=e.states.find(e=>e.id))==null?void 0:n.id;if(!i||g.find(e=>e.id===i))return;let a=r[i],o={id:i,name:T(a.common.name,t),type:a.type,deviceType:e.type,states:e.states.filter(e=>e.id).map(e=>({id:e.id,name:e.name,role:e.defaultRole,type:r[e.id].common.type,unit:r[e.id].common.unit,read:r[e.id].common.read??!0,write:r[e.id].common.write??!0}))},s=i.split(`.`),c,l;(a.type===`channel`||a.type===`state`)&&(s.pop(),c=s.join(`.`),r[c]&&(r[c].type===`channel`||r[c].type===`folder`)?(s.pop(),l=s.join(`.`),(!r[l]||r[l].type!==`device`&&r[c].type!==`folder`)&&(l=void 0)):c=void 0);let u=f.find(e=>{var t,n,a;return(t=r[e].common.members)!=null&&t.includes(i)||c&&(n=r[e].common.members)!=null&&n.includes(c)?!0:l&&((a=r[e].common.members)==null?void 0:a.includes(l))});u&&(o.room=T(r[u].common.name,t));let d=p.find(e=>{var t,n,a;return(t=r[e].common.members)!=null&&t.includes(i)||c&&(n=r[e].common.members)!=null&&n.includes(c)?!0:l&&((a=r[e].common.members)==null?void 0:a.includes(l))});d&&(o.function=T(r[d].common.name,t)),g.push(o)})});for(let e=0;e<g.length;e++){let n=g[e];if(n.type===`state`||n.type===`channel`){let e=n.id.split(`.`);e.pop();let i=r[e.join(`.`)];if(i&&(i.type===`channel`||i.type===`device`||i.type===`folder`)){var _,v;n.name=T(((_=i.common)==null?void 0:_.name)||n.name,t),e.pop();let a=r[e.join(`.`)];if((a==null?void 0:a.type)===`device`&&(v=a.common)!=null&&v.icon){var y;n.name=T(((y=a.common)==null?void 0:y.name)||n.name,t)}}else{var b;n.name=T((i==null||(b=i.common)==null?void 0:b.name)||n.name,t)}}}return u=g,g}async function D(){return d||(d=(await a).default,d)}function O(){return c[n.getLanguage()]||`English`}function k(e){return`You write ioBroker JavaScript adapter scripts.
2
2
  Copy EXACTLY this syntax. Do NOT change the callback signature.
3
3
  IMPORTANT: Write all code at top level. NEVER use console.log (use log instead). NEVER define functions with the function keyword.
4
4
 
@@ -0,0 +1 @@
1
+ import{$n as e,Bt as t,Qn as n,Rt as r,St as i,Ut as a,Vt as o,bt as s,fr as c,hr as l,p as u,wr as d,yr as f}from"./_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__113183188387379__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-D-gi6Mty.js";d();var p=({originalCode:d,modifiedCode:p,language:m,themeType:h,onAccept:g,onReject:_})=>{let v=f(null),y=f(null),b=f(null);l(()=>{let e=window.monaco;if(!e||!v.current)return;let t=e.editor.createDiffEditor(v.current,{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,theme:h===`dark`?`vs-dark`:`vs`,scrollBeyondLastLine:!1,minimap:{enabled:!1}}),n=e.editor.createModel(d,m),r=e.editor.createModel(p,m);return b.current=r,t.setModel({original:n,modified:r}),y.current=t,()=>{t.dispose(),n.dispose(),r.dispose(),y.current=null,b.current=null}},[d,p,m,h]);let x=c(()=>{var e;g(((e=b.current)==null?void 0:e.getValue())||p)},[p,g]);return e(o,{sx:{display:`flex`,flexDirection:`column`,height:`100%`,width:`100%`},children:[e(r,{variant:`dense`,sx:{minHeight:36,bgcolor:`background.paper`,borderBottom:`1px solid`,borderColor:`divider`,gap:1,flexShrink:0},children:[n(t,{variant:`subtitle2`,sx:{flex:1},children:u.t(`AI suggested changes`)}),n(a,{variant:`contained`,color:`success`,size:`small`,startIcon:n(i,{}),onClick:x,children:u.t(`Accept`)}),n(a,{variant:`outlined`,color:`error`,size:`small`,startIcon:n(s,{}),onClick:_,children:u.t(`Reject`)})]}),n(o,{ref:v,sx:{flex:1,overflow:`hidden`}})]})};export{p as default};
@@ -1,4 +1,4 @@
1
- import{f as e}from"./AiChatService-k72w0sOt.js";var t=800,n=`You are a code completion engine for ioBroker JavaScript adapter scripts.
1
+ import{f as e}from"./AiChatService-Bsp_rhVx.js";var t=800,n=`You are a code completion engine for ioBroker JavaScript adapter scripts.
2
2
  Complete the code at the cursor position marked with <CURSOR>.
3
3
  Return ONLY the completion text, no explanation, no markdown fences, no comments about what you did.
4
4
  If you cannot complete, return an empty string.