@rozenite/controls-plugin 2.1.0 → 2.3.0

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 (56) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/devtools/assets/panel-EMOeI6i6.css +1 -0
  3. package/dist/devtools/assets/panel-mjW0t-tQ.js +18 -0
  4. package/dist/devtools/panel.html +2 -2
  5. package/dist/react-native/cjs/package.json +3 -0
  6. package/dist/react-native/cjs/react-native.js +14 -0
  7. package/dist/react-native/cjs/src/react-native/controlsRegistry.js +70 -0
  8. package/dist/react-native/cjs/src/react-native/useControlsAgentTools.js +175 -0
  9. package/dist/react-native/cjs/src/react-native/useRozeniteControlsPlugin.js +177 -0
  10. package/dist/react-native/cjs/src/shared/agent-tools.js +51 -0
  11. package/dist/react-native/cjs/src/shared/messaging.js +2 -0
  12. package/dist/react-native/cjs/src/shared/serialization.js +102 -0
  13. package/dist/react-native/cjs/src/shared/types.js +5 -0
  14. package/dist/react-native/package.json +3 -0
  15. package/dist/react-native/react-native.d.ts +2 -0
  16. package/dist/react-native/react-native.js +11 -0
  17. package/dist/react-native/src/react-native/controlsRegistry.d.ts +23 -0
  18. package/dist/react-native/src/react-native/controlsRegistry.js +66 -0
  19. package/dist/react-native/src/react-native/useControlsAgentTools.d.ts +2 -0
  20. package/dist/react-native/src/react-native/useControlsAgentTools.js +171 -0
  21. package/dist/react-native/src/react-native/useRozeniteControlsPlugin.d.ts +3 -0
  22. package/dist/react-native/src/react-native/useRozeniteControlsPlugin.js +173 -0
  23. package/dist/react-native/src/shared/agent-tools.d.ts +48 -0
  24. package/dist/react-native/src/shared/agent-tools.js +48 -0
  25. package/dist/react-native/src/shared/messaging.d.ts +35 -0
  26. package/dist/react-native/src/shared/messaging.js +1 -0
  27. package/dist/react-native/src/shared/serialization.d.ts +22 -0
  28. package/dist/react-native/src/shared/serialization.js +96 -0
  29. package/dist/react-native/src/shared/types.d.ts +69 -0
  30. package/dist/react-native/src/shared/types.js +1 -0
  31. package/dist/rozenite.json +1 -1
  32. package/dist/sdk/package.json +3 -0
  33. package/dist/sdk/sdk.d.ts +10 -0
  34. package/dist/sdk/sdk.js +8 -0
  35. package/dist/sdk/src/shared/agent-tools.d.ts +48 -0
  36. package/dist/sdk/src/shared/agent-tools.js +51 -0
  37. package/dist/sdk/src/shared/messaging.d.ts +35 -0
  38. package/dist/sdk/src/shared/messaging.js +2 -0
  39. package/dist/sdk/src/shared/types.d.ts +69 -0
  40. package/dist/sdk/src/shared/types.js +5 -0
  41. package/package.json +17 -18
  42. package/react-native.ts +8 -1
  43. package/rozenite.config.ts +1 -0
  44. package/src/__tests__/release-bundle.test.ts +32 -0
  45. package/src/ui/panel.tsx +5 -3
  46. package/tsconfig.json +4 -5
  47. package/dist/devtools/assets/panel-BvIa5kqW.css +0 -1
  48. package/dist/devtools/assets/panel-H7O6Qof-.js +0 -18
  49. package/dist/react-native/chunks/useRozeniteControlsPlugin.require.cjs +0 -1
  50. package/dist/react-native/chunks/useRozeniteControlsPlugin.require.js +0 -466
  51. package/dist/react-native/index.cjs +0 -1
  52. package/dist/react-native/index.d.ts +0 -138
  53. package/dist/react-native/index.js +0 -8
  54. package/dist/sdk/index.cjs +0 -1
  55. package/dist/sdk/index.d.ts +0 -150
  56. package/dist/sdk/index.js +0 -55
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("@rozenite/plugin-bridge"),y=require("react"),v=require("@rozenite/agent-bridge"),w=require("@rozenite/agent-shared"),P=(e,n)=>e?e(n):{valid:!0},O=e=>e.type==="text"?e:e.type==="toggle"?{id:e.id,type:e.type,title:e.title,value:e.value,description:e.description,disabled:e.disabled}:e.type==="button"?{id:e.id,type:e.type,title:e.title,actionLabel:e.actionLabel,description:e.description,disabled:e.disabled}:e.type==="select"?{id:e.id,type:e.type,title:e.title,value:e.value,options:e.options,description:e.description,disabled:e.disabled}:{id:e.id,type:e.type,title:e.title,value:e.value,placeholder:e.placeholder,applyLabel:e.applyLabel,description:e.description,disabled:e.disabled},U=e=>e.map(n=>({id:n.id,title:n.title,description:n.description,items:n.items.map(O)})),A=e=>{const n=new Map;return e.forEach(r=>{r.items.forEach(o=>{const t=`${r.id}:${o.id}`;o.type==="toggle"&&n.set(t,{type:"toggle",validate:o.validate,onUpdate:o.onUpdate}),o.type==="button"&&n.set(t,{type:"button",onPress:o.onPress}),o.type==="select"&&n.set(t,{type:"select",validate:o.validate,onUpdate:o.onUpdate}),o.type==="input"&&n.set(t,{type:"input",validate:o.validate,onUpdate:o.onUpdate})})}),n},T=(e,n)=>`${e}:${n}`,$="@rozenite/controls-plugin",E={listSections:w.defineAgentToolContract({name:"list-sections",description:"List all controls sections with their item IDs, types, and titles. Does not include values — call get-item for that.",inputSchema:{type:"object",properties:{}}}),getItem:w.defineAgentToolContract({name:"get-item",description:"Get full details of a single controls item including its current value. For select items this includes available options.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."}},required:["sectionId","itemId"]}}),setValue:w.defineAgentToolContract({name:"set-value",description:"Update the value of a toggle, select, or input item. Runs the validate callback when present. Fails for text (read-only) and button items.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."},value:{description:"New value. Boolean for toggle items, string for select/input items."}},required:["sectionId","itemId","value"]}}),pressButton:w.defineAgentToolContract({name:"press-button",description:"Trigger a button item's action. Fails if the item is not a button or is disabled.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."}},required:["sectionId","itemId"]}})},R=(e,n,r)=>{const o=e.find(i=>i.id===n);if(!o){const i=e.map(s=>s.id).join(", ");throw new Error(`Section "${n}" not found. Available: ${i||"(none)"}`)}const t=o.items.find(i=>i.id===r);if(!t){const i=o.items.map(s=>s.id).join(", ");throw new Error(`Item "${r}" not found in section "${n}". Available: ${i||"(none)"}`)}return{section:o,item:t}},C=(e,n=!0)=>{v.useRozenitePluginAgentTool({pluginId:$,tool:E.listSections,enabled:n,handler:()=>({sections:e().map(r=>({id:r.id,title:r.title,description:r.description,items:r.items.map(o=>({id:o.id,type:o.type,title:o.title,disabled:"disabled"in o?o.disabled:void 0}))}))})}),v.useRozenitePluginAgentTool({pluginId:$,tool:E.getItem,enabled:n,handler:({sectionId:r,itemId:o})=>{const{item:t}=R(e(),r,o);return t.type==="text"?{sectionId:r,item:{id:t.id,type:t.type,title:t.title,value:t.value,description:t.description}}:t.type==="toggle"?{sectionId:r,item:{id:t.id,type:t.type,title:t.title,value:t.value,description:t.description,disabled:t.disabled}}:t.type==="button"?{sectionId:r,item:{id:t.id,type:t.type,title:t.title,actionLabel:t.actionLabel,description:t.description,disabled:t.disabled}}:t.type==="select"?{sectionId:r,item:{id:t.id,type:t.type,title:t.title,value:t.value,options:t.options,description:t.description,disabled:t.disabled}}:{sectionId:r,item:{id:t.id,type:t.type,title:t.title,value:t.value,placeholder:t.placeholder,applyLabel:t.applyLabel,description:t.description,disabled:t.disabled}}}}),v.useRozenitePluginAgentTool({pluginId:$,tool:E.setValue,enabled:n,handler:async({sectionId:r,itemId:o,value:t})=>{const{item:i}=R(e(),r,o);if(i.type==="text")throw new Error(`Item "${o}" is a read-only text item and cannot be updated.`);if(i.type==="button")throw new Error(`Item "${o}" is a button. Use press-button to trigger its action.`);if(i.disabled)throw new Error(`Item "${o}" is disabled.`);if(i.type==="toggle"){if(typeof t!="boolean")throw new Error(`Expected boolean value for toggle item "${o}".`);if(i.validate){const s=i.validate(t);if(!s.valid)throw new Error(s.message)}return await i.onUpdate(t),{applied:!0,sectionId:r,itemId:o}}if(typeof t!="string")throw new Error(`Expected string value for ${i.type} item "${o}".`);if(i.type==="select"){const s=i.options.map(p=>p.value);if(!s.includes(t))throw new Error(`Invalid option "${t}" for item "${o}". Valid options: ${s.join(", ")}`)}if(i.validate){const s=i.validate(t);if(!s.valid)throw new Error(s.message)}return await i.onUpdate(t),{applied:!0,sectionId:r,itemId:o}}}),v.useRozenitePluginAgentTool({pluginId:$,tool:E.pressButton,enabled:n,handler:async({sectionId:r,itemId:o})=>{const{item:t}=R(e(),r,o);if(t.type!=="button")throw new Error(`Item "${o}" is not a button (type: ${t.type}). Use set-value to update its value.`);if(t.disabled)throw new Error(`Button "${o}" is disabled.`);return await t.onPress(),{pressed:!0,sectionId:r,itemId:o}}})},x={sections:[]},D=(e,n)=>typeof n=="function"?n(e):{...e,...n,sections:[...e.sections,...n.sections]},L=()=>{const e=new Map,n=new Set;let r=0;const o=()=>e.keys().next().value,t=()=>{r+=1,n.forEach(s=>s())},i=s=>{const p=Array.from(e.entries());return s?p.findIndex(([a])=>a===s.id)===-1?[...p,[s.id,s.input]]:p.map(([a,l])=>a===s.id?[a,s.input]:[a,l]):p};return{set(s,p){const f=o();e.set(s,p),f!==o()&&t()},delete(s){e.delete(s),t()},getOptions(s){return i(s).map(([,p])=>p).reduce(D,x)},isOwner(s,p){return i(p)[0]?.[0]===s},getSnapshot(){return r},subscribe(s){return n.add(s),()=>{n.delete(s)}}}},u=L(),m=e=>{const n=z.useRozeniteDevToolsClient({pluginId:"@rozenite/controls-plugin"}),o=y.useRef(Symbol("rozenite-controls")).current,t=y.useSyncExternalStore(u.subscribe,u.getSnapshot,u.getSnapshot);y.useEffect(()=>()=>{u.delete(o)},[o]),y.useEffect(()=>{u.set(o,e)},[e,o]);const i=y.useMemo(()=>u.isOwner(o,{id:o,input:e}),[e,t,o]);return C(()=>u.getOptions().sections,i),y.useEffect(()=>{n&&n.send("snapshot",{type:"snapshot",sections:U(u.getOptions().sections)})},[n,e,t]),y.useEffect(()=>{if(!n||!i)return;const s=async({requestId:a,sectionId:l,itemId:d,value:g})=>{const b=T(l,d),c=A(u.getOptions().sections).get(b);if(!c||c.type==="button"){n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:"Update target not found."});return}try{if(c.type==="toggle"){if(typeof g!="boolean"){n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:"Invalid toggle value."});return}const S=P(c.validate,g);if(!S.valid){n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:S.message});return}await c.onUpdate(g),n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"ok"});return}if(typeof g!="string"){n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:`Invalid ${c.type} value.`});return}const h=P(c.validate,g);if(!h.valid){n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:h.message});return}await c.onUpdate(g),n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"ok"})}catch(h){console.warn(`[Rozenite] Controls Plugin: Update failed for ${l}/${d}.`,h),n.send("update-result",{type:"update-result",requestId:a,sectionId:l,itemId:d,status:"error",message:"Update failed on the device."})}},p=async({sectionId:a,itemId:l,action:d})=>{if(d!=="press"){console.warn(`[Rozenite] Controls Plugin: Unsupported action "${d}" for ${a}/${l}.`);return}const g=T(a,l),b=A(u.getOptions().sections).get(g);if(!b){console.warn(`[Rozenite] Controls Plugin: Action target not found for ${a}/${l}.`);return}try{if(b.type!=="button"){console.warn(`[Rozenite] Controls Plugin: Invalid press action payload for ${a}/${l}.`);return}await b.onPress()}catch(c){console.warn(`[Rozenite] Controls Plugin: Action failed for ${a}/${l}.`,c)}},f=[n.onMessage("get-snapshot",()=>{n.send("snapshot",{type:"snapshot",sections:U(u.getOptions().sections)})}),n.onMessage("update-request",a=>{s(a)}),n.onMessage("invoke-action",a=>{p(a)})];return()=>{f.forEach(a=>a.remove())}},[n,i]),n};exports.useRozeniteControlsPlugin=m;
@@ -1,466 +0,0 @@
1
- import { useRozeniteDevToolsClient as x } from "@rozenite/plugin-bridge";
2
- import { useRef as z, useSyncExternalStore as A, useEffect as h, useMemo as C } from "react";
3
- import { useRozenitePluginAgentTool as v } from "@rozenite/agent-bridge";
4
- import { defineAgentToolContract as w } from "@rozenite/agent-shared";
5
- const U = (t, n) => t ? t(n) : { valid: !0 }, D = (t) => t.type === "text" ? t : t.type === "toggle" ? {
6
- id: t.id,
7
- type: t.type,
8
- title: t.title,
9
- value: t.value,
10
- description: t.description,
11
- disabled: t.disabled
12
- } : t.type === "button" ? {
13
- id: t.id,
14
- type: t.type,
15
- title: t.title,
16
- actionLabel: t.actionLabel,
17
- description: t.description,
18
- disabled: t.disabled
19
- } : t.type === "select" ? {
20
- id: t.id,
21
- type: t.type,
22
- title: t.title,
23
- value: t.value,
24
- options: t.options,
25
- description: t.description,
26
- disabled: t.disabled
27
- } : {
28
- id: t.id,
29
- type: t.type,
30
- title: t.title,
31
- value: t.value,
32
- placeholder: t.placeholder,
33
- applyLabel: t.applyLabel,
34
- description: t.description,
35
- disabled: t.disabled
36
- }, m = (t) => t.map((n) => ({
37
- id: n.id,
38
- title: n.title,
39
- description: n.description,
40
- items: n.items.map(D)
41
- })), O = (t) => {
42
- const n = /* @__PURE__ */ new Map();
43
- return t.forEach((r) => {
44
- r.items.forEach((s) => {
45
- const e = `${r.id}:${s.id}`;
46
- s.type === "toggle" && n.set(e, {
47
- type: "toggle",
48
- validate: s.validate,
49
- onUpdate: s.onUpdate
50
- }), s.type === "button" && n.set(e, {
51
- type: "button",
52
- onPress: s.onPress
53
- }), s.type === "select" && n.set(e, {
54
- type: "select",
55
- validate: s.validate,
56
- onUpdate: s.onUpdate
57
- }), s.type === "input" && n.set(e, {
58
- type: "input",
59
- validate: s.validate,
60
- onUpdate: s.onUpdate
61
- });
62
- });
63
- }), n;
64
- }, P = (t, n) => `${t}:${n}`, $ = "@rozenite/controls-plugin", E = {
65
- listSections: w({
66
- name: "list-sections",
67
- description: "List all controls sections with their item IDs, types, and titles. Does not include values — call get-item for that.",
68
- inputSchema: { type: "object", properties: {} }
69
- }),
70
- getItem: w({
71
- name: "get-item",
72
- description: "Get full details of a single controls item including its current value. For select items this includes available options.",
73
- inputSchema: {
74
- type: "object",
75
- properties: {
76
- sectionId: { type: "string", description: "Section ID." },
77
- itemId: { type: "string", description: "Item ID." }
78
- },
79
- required: ["sectionId", "itemId"]
80
- }
81
- }),
82
- setValue: w({
83
- name: "set-value",
84
- description: "Update the value of a toggle, select, or input item. Runs the validate callback when present. Fails for text (read-only) and button items.",
85
- inputSchema: {
86
- type: "object",
87
- properties: {
88
- sectionId: { type: "string", description: "Section ID." },
89
- itemId: { type: "string", description: "Item ID." },
90
- value: {
91
- description: "New value. Boolean for toggle items, string for select/input items."
92
- }
93
- },
94
- required: ["sectionId", "itemId", "value"]
95
- }
96
- }),
97
- pressButton: w({
98
- name: "press-button",
99
- description: "Trigger a button item's action. Fails if the item is not a button or is disabled.",
100
- inputSchema: {
101
- type: "object",
102
- properties: {
103
- sectionId: { type: "string", description: "Section ID." },
104
- itemId: { type: "string", description: "Item ID." }
105
- },
106
- required: ["sectionId", "itemId"]
107
- }
108
- })
109
- }, R = (t, n, r) => {
110
- const s = t.find((i) => i.id === n);
111
- if (!s) {
112
- const i = t.map((o) => o.id).join(", ");
113
- throw new Error(`Section "${n}" not found. Available: ${i || "(none)"}`);
114
- }
115
- const e = s.items.find((i) => i.id === r);
116
- if (!e) {
117
- const i = s.items.map((o) => o.id).join(", ");
118
- throw new Error(
119
- `Item "${r}" not found in section "${n}". Available: ${i || "(none)"}`
120
- );
121
- }
122
- return { section: s, item: e };
123
- }, L = (t, n = !0) => {
124
- v({
125
- pluginId: $,
126
- tool: E.listSections,
127
- enabled: n,
128
- handler: () => ({
129
- sections: t().map((r) => ({
130
- id: r.id,
131
- title: r.title,
132
- description: r.description,
133
- items: r.items.map((s) => ({
134
- id: s.id,
135
- type: s.type,
136
- title: s.title,
137
- disabled: "disabled" in s ? s.disabled : void 0
138
- }))
139
- }))
140
- })
141
- }), v({
142
- pluginId: $,
143
- tool: E.getItem,
144
- enabled: n,
145
- handler: ({ sectionId: r, itemId: s }) => {
146
- const { item: e } = R(t(), r, s);
147
- return e.type === "text" ? {
148
- sectionId: r,
149
- item: {
150
- id: e.id,
151
- type: e.type,
152
- title: e.title,
153
- value: e.value,
154
- description: e.description
155
- }
156
- } : e.type === "toggle" ? {
157
- sectionId: r,
158
- item: {
159
- id: e.id,
160
- type: e.type,
161
- title: e.title,
162
- value: e.value,
163
- description: e.description,
164
- disabled: e.disabled
165
- }
166
- } : e.type === "button" ? {
167
- sectionId: r,
168
- item: {
169
- id: e.id,
170
- type: e.type,
171
- title: e.title,
172
- actionLabel: e.actionLabel,
173
- description: e.description,
174
- disabled: e.disabled
175
- }
176
- } : e.type === "select" ? {
177
- sectionId: r,
178
- item: {
179
- id: e.id,
180
- type: e.type,
181
- title: e.title,
182
- value: e.value,
183
- options: e.options,
184
- description: e.description,
185
- disabled: e.disabled
186
- }
187
- } : {
188
- sectionId: r,
189
- item: {
190
- id: e.id,
191
- type: e.type,
192
- title: e.title,
193
- value: e.value,
194
- placeholder: e.placeholder,
195
- applyLabel: e.applyLabel,
196
- description: e.description,
197
- disabled: e.disabled
198
- }
199
- };
200
- }
201
- }), v({
202
- pluginId: $,
203
- tool: E.setValue,
204
- enabled: n,
205
- handler: async ({ sectionId: r, itemId: s, value: e }) => {
206
- const { item: i } = R(t(), r, s);
207
- if (i.type === "text")
208
- throw new Error(`Item "${s}" is a read-only text item and cannot be updated.`);
209
- if (i.type === "button")
210
- throw new Error(`Item "${s}" is a button. Use press-button to trigger its action.`);
211
- if (i.disabled)
212
- throw new Error(`Item "${s}" is disabled.`);
213
- if (i.type === "toggle") {
214
- if (typeof e != "boolean")
215
- throw new Error(`Expected boolean value for toggle item "${s}".`);
216
- if (i.validate) {
217
- const o = i.validate(e);
218
- if (!o.valid)
219
- throw new Error(o.message);
220
- }
221
- return await i.onUpdate(e), { applied: !0, sectionId: r, itemId: s };
222
- }
223
- if (typeof e != "string")
224
- throw new Error(`Expected string value for ${i.type} item "${s}".`);
225
- if (i.type === "select") {
226
- const o = i.options.map((p) => p.value);
227
- if (!o.includes(e))
228
- throw new Error(
229
- `Invalid option "${e}" for item "${s}". Valid options: ${o.join(", ")}`
230
- );
231
- }
232
- if (i.validate) {
233
- const o = i.validate(e);
234
- if (!o.valid)
235
- throw new Error(o.message);
236
- }
237
- return await i.onUpdate(e), { applied: !0, sectionId: r, itemId: s };
238
- }
239
- }), v({
240
- pluginId: $,
241
- tool: E.pressButton,
242
- enabled: n,
243
- handler: async ({ sectionId: r, itemId: s }) => {
244
- const { item: e } = R(t(), r, s);
245
- if (e.type !== "button")
246
- throw new Error(
247
- `Item "${s}" is not a button (type: ${e.type}). Use set-value to update its value.`
248
- );
249
- if (e.disabled)
250
- throw new Error(`Button "${s}" is disabled.`);
251
- return await e.onPress(), { pressed: !0, sectionId: r, itemId: s };
252
- }
253
- });
254
- }, T = {
255
- sections: []
256
- }, k = (t, n) => typeof n == "function" ? n(t) : {
257
- ...t,
258
- ...n,
259
- sections: [...t.sections, ...n.sections]
260
- }, j = () => {
261
- const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
262
- let r = 0;
263
- const s = () => t.keys().next().value, e = () => {
264
- r += 1, n.forEach((o) => o());
265
- }, i = (o) => {
266
- const p = Array.from(t.entries());
267
- return o ? p.findIndex(([a]) => a === o.id) === -1 ? [...p, [o.id, o.input]] : p.map(
268
- ([a, l]) => a === o.id ? [a, o.input] : [a, l]
269
- ) : p;
270
- };
271
- return {
272
- set(o, p) {
273
- const g = s();
274
- t.set(o, p), g !== s() && e();
275
- },
276
- delete(o) {
277
- t.delete(o), e();
278
- },
279
- getOptions(o) {
280
- return i(o).map(([, p]) => p).reduce(k, T);
281
- },
282
- isOwner(o, p) {
283
- return i(p)[0]?.[0] === o;
284
- },
285
- getSnapshot() {
286
- return r;
287
- },
288
- subscribe(o) {
289
- return n.add(o), () => {
290
- n.delete(o);
291
- };
292
- }
293
- };
294
- }, u = j(), _ = (t) => {
295
- const n = x({
296
- pluginId: "@rozenite/controls-plugin"
297
- }), s = z(/* @__PURE__ */ Symbol("rozenite-controls")).current, e = A(
298
- u.subscribe,
299
- u.getSnapshot,
300
- u.getSnapshot
301
- );
302
- h(() => () => {
303
- u.delete(s);
304
- }, [s]), h(() => {
305
- u.set(s, t);
306
- }, [t, s]);
307
- const i = C(
308
- () => u.isOwner(s, {
309
- id: s,
310
- input: t
311
- }),
312
- [t, e, s]
313
- );
314
- return L(() => u.getOptions().sections, i), h(() => {
315
- n && n.send("snapshot", {
316
- type: "snapshot",
317
- sections: m(u.getOptions().sections)
318
- });
319
- }, [n, t, e]), h(() => {
320
- if (!n || !i)
321
- return;
322
- const o = async ({
323
- requestId: a,
324
- sectionId: l,
325
- itemId: d,
326
- value: y
327
- }) => {
328
- const f = P(l, d), c = O(u.getOptions().sections).get(f);
329
- if (!c || c.type === "button") {
330
- n.send("update-result", {
331
- type: "update-result",
332
- requestId: a,
333
- sectionId: l,
334
- itemId: d,
335
- status: "error",
336
- message: "Update target not found."
337
- });
338
- return;
339
- }
340
- try {
341
- if (c.type === "toggle") {
342
- if (typeof y != "boolean") {
343
- n.send("update-result", {
344
- type: "update-result",
345
- requestId: a,
346
- sectionId: l,
347
- itemId: d,
348
- status: "error",
349
- message: "Invalid toggle value."
350
- });
351
- return;
352
- }
353
- const S = U(c.validate, y);
354
- if (!S.valid) {
355
- n.send("update-result", {
356
- type: "update-result",
357
- requestId: a,
358
- sectionId: l,
359
- itemId: d,
360
- status: "error",
361
- message: S.message
362
- });
363
- return;
364
- }
365
- await c.onUpdate(y), n.send("update-result", {
366
- type: "update-result",
367
- requestId: a,
368
- sectionId: l,
369
- itemId: d,
370
- status: "ok"
371
- });
372
- return;
373
- }
374
- if (typeof y != "string") {
375
- n.send("update-result", {
376
- type: "update-result",
377
- requestId: a,
378
- sectionId: l,
379
- itemId: d,
380
- status: "error",
381
- message: `Invalid ${c.type} value.`
382
- });
383
- return;
384
- }
385
- const b = U(c.validate, y);
386
- if (!b.valid) {
387
- n.send("update-result", {
388
- type: "update-result",
389
- requestId: a,
390
- sectionId: l,
391
- itemId: d,
392
- status: "error",
393
- message: b.message
394
- });
395
- return;
396
- }
397
- await c.onUpdate(y), n.send("update-result", {
398
- type: "update-result",
399
- requestId: a,
400
- sectionId: l,
401
- itemId: d,
402
- status: "ok"
403
- });
404
- } catch (b) {
405
- console.warn(
406
- `[Rozenite] Controls Plugin: Update failed for ${l}/${d}.`,
407
- b
408
- ), n.send("update-result", {
409
- type: "update-result",
410
- requestId: a,
411
- sectionId: l,
412
- itemId: d,
413
- status: "error",
414
- message: "Update failed on the device."
415
- });
416
- }
417
- }, p = async ({ sectionId: a, itemId: l, action: d }) => {
418
- if (d !== "press") {
419
- console.warn(
420
- `[Rozenite] Controls Plugin: Unsupported action "${d}" for ${a}/${l}.`
421
- );
422
- return;
423
- }
424
- const y = P(a, l), f = O(u.getOptions().sections).get(y);
425
- if (!f) {
426
- console.warn(
427
- `[Rozenite] Controls Plugin: Action target not found for ${a}/${l}.`
428
- );
429
- return;
430
- }
431
- try {
432
- if (f.type !== "button") {
433
- console.warn(
434
- `[Rozenite] Controls Plugin: Invalid press action payload for ${a}/${l}.`
435
- );
436
- return;
437
- }
438
- await f.onPress();
439
- } catch (c) {
440
- console.warn(
441
- `[Rozenite] Controls Plugin: Action failed for ${a}/${l}.`,
442
- c
443
- );
444
- }
445
- }, g = [
446
- n.onMessage("get-snapshot", () => {
447
- n.send("snapshot", {
448
- type: "snapshot",
449
- sections: m(u.getOptions().sections)
450
- });
451
- }),
452
- n.onMessage("update-request", (a) => {
453
- o(a);
454
- }),
455
- n.onMessage("invoke-action", (a) => {
456
- p(a);
457
- })
458
- ];
459
- return () => {
460
- g.forEach((a) => a.remove());
461
- };
462
- }, [n, i]), n;
463
- };
464
- export {
465
- _ as useRozeniteControlsPlugin
466
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=e=>e;exports.useRozeniteControlsPlugin=void 0;const n=process.env.NODE_ENV!=="production",t=typeof window>"u";n&&!t?exports.useRozeniteControlsPlugin=require("./chunks/useRozeniteControlsPlugin.require.cjs").useRozeniteControlsPlugin:exports.useRozeniteControlsPlugin=()=>null;exports.createSection=o;
@@ -1,138 +0,0 @@
1
- import { RozeniteDevToolsRequestClient } from '@rozenite/plugin-bridge';
2
-
3
- export declare type ControlsButtonItem = {
4
- id: string;
5
- type: 'button';
6
- title: string;
7
- actionLabel?: string;
8
- description?: string;
9
- disabled?: boolean;
10
- onPress: () => void | Promise<void>;
11
- };
12
-
13
- declare type ControlsButtonItemSnapshot = Omit<ControlsButtonItem, 'onPress'>;
14
-
15
- declare type ControlsEvent = ControlsSnapshotEvent | ControlsGetSnapshotEvent | ControlsUpdateRequestEvent | ControlsUpdateResultEvent | ControlsInvokeActionEvent;
16
-
17
- declare type ControlsEventMap = {
18
- [K in ControlsEvent['type']]: Extract<ControlsEvent, {
19
- type: K;
20
- }>;
21
- };
22
-
23
- declare type ControlsGetSnapshotEvent = {
24
- type: 'get-snapshot';
25
- };
26
-
27
- export declare type ControlsInputItem = ControlsMutableItemBase<string> & {
28
- type: 'input';
29
- placeholder?: string;
30
- applyLabel?: string;
31
- };
32
-
33
- declare type ControlsInputItemSnapshot = Omit<ControlsInputItem, 'validate' | 'onUpdate'>;
34
-
35
- declare type ControlsInvokeActionEvent = {
36
- type: 'invoke-action';
37
- sectionId: string;
38
- itemId: string;
39
- action: 'press';
40
- };
41
-
42
- export declare type ControlsItem = ControlsTextItem | ControlsToggleItem | ControlsButtonItem | ControlsSelectItem | ControlsInputItem;
43
-
44
- declare type ControlsItemSnapshot = ControlsTextItemSnapshot | ControlsToggleItemSnapshot | ControlsButtonItemSnapshot | ControlsSelectItemSnapshot | ControlsInputItemSnapshot;
45
-
46
- declare type ControlsMutableItemBase<TValue> = {
47
- id: string;
48
- title: string;
49
- value: TValue;
50
- description?: string;
51
- disabled?: boolean;
52
- validate?: (nextValue: TValue) => ControlsValidationResult;
53
- onUpdate: (nextValue: TValue) => void | Promise<void>;
54
- };
55
-
56
- export declare type ControlsSection = {
57
- id: string;
58
- title: string;
59
- description?: string;
60
- items: ControlsItem[];
61
- };
62
-
63
- declare type ControlsSectionSnapshot = Omit<ControlsSection, 'items'> & {
64
- items: ControlsItemSnapshot[];
65
- };
66
-
67
- export declare type ControlsSelectItem = ControlsMutableItemBase<string> & {
68
- type: 'select';
69
- options: ControlsSelectOption[];
70
- };
71
-
72
- declare type ControlsSelectItemSnapshot = Omit<ControlsSelectItem, 'validate' | 'onUpdate'>;
73
-
74
- export declare type ControlsSelectOption = {
75
- label: string;
76
- value: string;
77
- };
78
-
79
- declare type ControlsSnapshotEvent = {
80
- type: 'snapshot';
81
- sections: ControlsSectionSnapshot[];
82
- };
83
-
84
- export declare type ControlsTextItem = {
85
- id: string;
86
- type: 'text';
87
- title: string;
88
- value: string;
89
- description?: string;
90
- };
91
-
92
- declare type ControlsTextItemSnapshot = Omit<ControlsTextItem, never>;
93
-
94
- export declare type ControlsToggleItem = ControlsMutableItemBase<boolean> & {
95
- type: 'toggle';
96
- };
97
-
98
- declare type ControlsToggleItemSnapshot = Omit<ControlsToggleItem, 'validate' | 'onUpdate'>;
99
-
100
- declare type ControlsUpdateRequestEvent = {
101
- type: 'update-request';
102
- requestId: string;
103
- sectionId: string;
104
- itemId: string;
105
- value: boolean | string;
106
- };
107
-
108
- declare type ControlsUpdateResultEvent = {
109
- type: 'update-result';
110
- requestId: string;
111
- sectionId: string;
112
- itemId: string;
113
- status: 'ok' | 'error';
114
- message?: string;
115
- };
116
-
117
- export declare type ControlsValidationResult = {
118
- valid: true;
119
- } | {
120
- valid: false;
121
- message: string;
122
- };
123
-
124
- export declare const createSection: <TSection extends ControlsSection>(section: TSection) => TSection;
125
-
126
- export declare type RozeniteControlsPluginOptions = {
127
- sections: ControlsSection[];
128
- };
129
-
130
- export declare type RozeniteControlsPluginOptionsInput = RozeniteControlsPluginOptions | RozeniteControlsPluginOptionsUpdater;
131
-
132
- export declare type RozeniteControlsPluginOptionsUpdater = (previousOptions: RozeniteControlsPluginOptions) => RozeniteControlsPluginOptions;
133
-
134
- export declare let useRozeniteControlsPlugin: typeof useRozeniteControlsPlugin_2;
135
-
136
- declare const useRozeniteControlsPlugin_2: (optionsInput: RozeniteControlsPluginOptionsInput) => RozeniteDevToolsRequestClient<ControlsEventMap> | null;
137
-
138
- export { }
@@ -1,8 +0,0 @@
1
- const i = (n) => n;
2
- let e;
3
- const o = process.env.NODE_ENV !== "production", t = typeof window > "u";
4
- o && !t ? e = require("./chunks/useRozeniteControlsPlugin.require.js").useRozeniteControlsPlugin : e = () => null;
5
- export {
6
- i as createSection,
7
- e as useRozeniteControlsPlugin
8
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@rozenite/agent-shared"),t="@rozenite/controls-plugin",i={listSections:e.defineAgentToolContract({name:"list-sections",description:"List all controls sections with their item IDs, types, and titles. Does not include values — call get-item for that.",inputSchema:{type:"object",properties:{}}}),getItem:e.defineAgentToolContract({name:"get-item",description:"Get full details of a single controls item including its current value. For select items this includes available options.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."}},required:["sectionId","itemId"]}}),setValue:e.defineAgentToolContract({name:"set-value",description:"Update the value of a toggle, select, or input item. Runs the validate callback when present. Fails for text (read-only) and button items.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."},value:{description:"New value. Boolean for toggle items, string for select/input items."}},required:["sectionId","itemId","value"]}}),pressButton:e.defineAgentToolContract({name:"press-button",description:"Trigger a button item's action. Fails if the item is not a button or is disabled.",inputSchema:{type:"object",properties:{sectionId:{type:"string",description:"Section ID."},itemId:{type:"string",description:"Item ID."}},required:["sectionId","itemId"]}})},o=e.defineAgentToolDescriptors(t,i);exports.CONTROLS_AGENT_PLUGIN_ID=t;exports.controlsToolDefinitions=i;exports.controlsTools=o;