@rozenite/controls-plugin 1.7.0-rc.2 → 1.8.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.
- package/CHANGELOG.md +29 -0
- package/dist/devtools/assets/{panel-Csphk_TK.js → panel-BoQwJa2M.js} +10 -10
- package/dist/devtools/panel.html +1 -1
- package/dist/react-native/chunks/useRozeniteControlsPlugin.require.cjs +1 -1
- package/dist/react-native/chunks/useRozeniteControlsPlugin.require.js +121 -115
- package/dist/react-native/index.d.ts +1 -1
- package/dist/rozenite.json +1 -1
- package/dist/sdk/index.cjs +1 -0
- package/dist/sdk/index.d.ts +150 -0
- package/dist/sdk/index.js +55 -0
- package/package.json +13 -6
- package/sdk.ts +40 -0
- package/src/react-native/useControlsAgentTools.ts +19 -78
- package/src/shared/agent-tools.ts +121 -0
- package/tsconfig.json +2 -1
- package/vite.config.ts +1 -0
package/dist/devtools/panel.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<script>
|
|
23
23
|
var __ROZENITE_PANEL__ = true;
|
|
24
24
|
</script>
|
|
25
|
-
<script type="module" crossorigin src="../devtools/assets/panel-
|
|
25
|
+
<script type="module" crossorigin src="../devtools/assets/panel-BoQwJa2M.js"></script>
|
|
26
26
|
<link rel="stylesheet" crossorigin href="../devtools/assets/panel-B5zz0XK3.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@rozenite/plugin-bridge"),c=require("react"),f=require("@rozenite/agent-bridge"),b=require("@rozenite/agent-shared"),E=(n,t)=>n?n(t):{valid:!0},P=n=>n.type==="text"?n:n.type==="toggle"?{id:n.id,type:n.type,title:n.title,value:n.value,description:n.description,disabled:n.disabled}:n.type==="button"?{id:n.id,type:n.type,title:n.title,actionLabel:n.actionLabel,description:n.description,disabled:n.disabled}:n.type==="select"?{id:n.id,type:n.type,title:n.title,value:n.value,options:n.options,description:n.description,disabled:n.disabled}:{id:n.id,type:n.type,title:n.title,value:n.value,placeholder:n.placeholder,applyLabel:n.applyLabel,description:n.description,disabled:n.disabled},S=n=>n.map(t=>({id:t.id,title:t.title,description:t.description,items:t.items.map(P)})),z=n=>{const t=new Map;return n.forEach(o=>{o.items.forEach(e=>{const i=`${o.id}:${e.id}`;e.type==="toggle"&&t.set(i,{type:"toggle",validate:e.validate,onUpdate:e.onUpdate}),e.type==="button"&&t.set(i,{type:"button",onPress:e.onPress}),e.type==="select"&&t.set(i,{type:"select",validate:e.validate,onUpdate:e.onUpdate}),e.type==="input"&&t.set(i,{type:"input",validate:e.validate,onUpdate:e.onUpdate})})}),t},R=(n,t)=>`${n}:${t}`,v="@rozenite/controls-plugin",h={listSections:b.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:b.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:b.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:b.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"]}})},w=(n,t,o)=>{const e=n.find(s=>s.id===t);if(!e){const s=n.map(u=>u.id).join(", ");throw new Error(`Section "${t}" not found. Available: ${s||"(none)"}`)}const i=e.items.find(s=>s.id===o);if(!i){const s=e.items.map(u=>u.id).join(", ");throw new Error(`Item "${o}" not found in section "${t}". Available: ${s||"(none)"}`)}return{section:e,item:i}},T=n=>{f.useRozenitePluginAgentTool({pluginId:v,tool:h.listSections,handler:()=>({sections:n.map(t=>({id:t.id,title:t.title,description:t.description,items:t.items.map(o=>({id:o.id,type:o.type,title:o.title,disabled:"disabled"in o?o.disabled:void 0}))}))})}),f.useRozenitePluginAgentTool({pluginId:v,tool:h.getItem,handler:({sectionId:t,itemId:o})=>{const{item:e}=w(n,t,o);return e.type==="text"?{sectionId:t,item:{id:e.id,type:e.type,title:e.title,value:e.value,description:e.description}}:e.type==="toggle"?{sectionId:t,item:{id:e.id,type:e.type,title:e.title,value:e.value,description:e.description,disabled:e.disabled}}:e.type==="button"?{sectionId:t,item:{id:e.id,type:e.type,title:e.title,actionLabel:e.actionLabel,description:e.description,disabled:e.disabled}}:e.type==="select"?{sectionId:t,item:{id:e.id,type:e.type,title:e.title,value:e.value,options:e.options,description:e.description,disabled:e.disabled}}:{sectionId:t,item:{id:e.id,type:e.type,title:e.title,value:e.value,placeholder:e.placeholder,applyLabel:e.applyLabel,description:e.description,disabled:e.disabled}}}}),f.useRozenitePluginAgentTool({pluginId:v,tool:h.setValue,handler:async({sectionId:t,itemId:o,value:e})=>{const{item:i}=w(n,t,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 e!="boolean")throw new Error(`Expected boolean value for toggle item "${o}".`);if(i.validate){const s=i.validate(e);if(!s.valid)throw new Error(s.message)}return await i.onUpdate(e),{applied:!0,sectionId:t,itemId:o}}if(typeof e!="string")throw new Error(`Expected string value for ${i.type} item "${o}".`);if(i.type==="select"){const s=i.options.map(u=>u.value);if(!s.includes(e))throw new Error(`Invalid option "${e}" for item "${o}". Valid options: ${s.join(", ")}`)}if(i.validate){const s=i.validate(e);if(!s.valid)throw new Error(s.message)}return await i.onUpdate(e),{applied:!0,sectionId:t,itemId:o}}}),f.useRozenitePluginAgentTool({pluginId:v,tool:h.pressButton,handler:async({sectionId:t,itemId:o})=>{const{item:e}=w(n,t,o);if(e.type!=="button")throw new Error(`Item "${o}" is not a button (type: ${e.type}). Use set-value to update its value.`);if(e.disabled)throw new Error(`Button "${o}" is disabled.`);return await e.onPress(),{pressed:!0,sectionId:t,itemId:o}}})},C=({sections:n})=>{const t=A.useRozeniteDevToolsClient({pluginId:"@rozenite/controls-plugin"});T(n);const o=c.useMemo(()=>S(n),[n]),e=c.useMemo(()=>z(n),[n]),i=c.useRef(e);return c.useEffect(()=>{i.current=e},[e]),c.useEffect(()=>{t&&t.send("snapshot",{type:"snapshot",sections:o})},[t,o]),c.useEffect(()=>{if(!t)return;const s=async({requestId:r,sectionId:a,itemId:l,value:d})=>{const y=R(a,l),p=i.current.get(y);if(!p||p.type==="button"){t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:"Update target not found."});return}try{if(p.type==="toggle"){if(typeof d!="boolean"){t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:"Invalid toggle value."});return}const $=E(p.validate,d);if(!$.valid){t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:$.message});return}await p.onUpdate(d),t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"ok"});return}if(typeof d!="string"){t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:`Invalid ${p.type} value.`});return}const g=E(p.validate,d);if(!g.valid){t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:g.message});return}await p.onUpdate(d),t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"ok"})}catch(g){console.warn(`[Rozenite] Controls Plugin: Update failed for ${a}/${l}.`,g),t.send("update-result",{type:"update-result",requestId:r,sectionId:a,itemId:l,status:"error",message:"Update failed on the device."})}},u=async({sectionId:r,itemId:a,action:l})=>{if(l!=="press"){console.warn(`[Rozenite] Controls Plugin: Unsupported action "${l}" for ${r}/${a}.`);return}const d=R(r,a),y=i.current.get(d);if(!y){console.warn(`[Rozenite] Controls Plugin: Action target not found for ${r}/${a}.`);return}try{if(y.type!=="button"){console.warn(`[Rozenite] Controls Plugin: Invalid press action payload for ${r}/${a}.`);return}await y.onPress()}catch(p){console.warn(`[Rozenite] Controls Plugin: Action failed for ${r}/${a}.`,p)}},U=[t.onMessage("get-snapshot",()=>{t.send("snapshot",{type:"snapshot",sections:o})}),t.onMessage("update-request",r=>{s(r)}),t.onMessage("invoke-action",r=>{u(r)})];return()=>{U.forEach(r=>r.remove())}},[t,o]),t};exports.useRozeniteControlsPlugin=C;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useRozeniteDevToolsClient as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { useRozeniteDevToolsClient as S } from "@rozenite/plugin-bridge";
|
|
2
|
+
import { useMemo as E, useRef as P, useEffect as h } from "react";
|
|
3
3
|
import { useRozenitePluginAgentTool as f } from "@rozenite/agent-bridge";
|
|
4
|
-
|
|
4
|
+
import { defineAgentToolContract as g } from "@rozenite/agent-shared";
|
|
5
|
+
const U = (o, e) => o ? o(e) : { valid: !0 }, z = (o) => o.type === "text" ? o : o.type === "toggle" ? {
|
|
5
6
|
id: o.id,
|
|
6
7
|
type: o.type,
|
|
7
8
|
title: o.title,
|
|
@@ -32,75 +33,80 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
32
33
|
applyLabel: o.applyLabel,
|
|
33
34
|
description: o.description,
|
|
34
35
|
disabled: o.disabled
|
|
35
|
-
},
|
|
36
|
+
}, A = (o) => o.map((e) => ({
|
|
36
37
|
id: e.id,
|
|
37
38
|
title: e.title,
|
|
38
39
|
description: e.description,
|
|
39
|
-
items: e.items.map(
|
|
40
|
-
})),
|
|
40
|
+
items: e.items.map(z)
|
|
41
|
+
})), D = (o) => {
|
|
41
42
|
const e = /* @__PURE__ */ new Map();
|
|
42
43
|
return o.forEach((n) => {
|
|
43
44
|
n.items.forEach((t) => {
|
|
44
|
-
const
|
|
45
|
-
t.type === "toggle" && e.set(
|
|
45
|
+
const i = `${n.id}:${t.id}`;
|
|
46
|
+
t.type === "toggle" && e.set(i, {
|
|
46
47
|
type: "toggle",
|
|
47
48
|
validate: t.validate,
|
|
48
49
|
onUpdate: t.onUpdate
|
|
49
|
-
}), t.type === "button" && e.set(
|
|
50
|
+
}), t.type === "button" && e.set(i, {
|
|
50
51
|
type: "button",
|
|
51
52
|
onPress: t.onPress
|
|
52
|
-
}), t.type === "select" && e.set(
|
|
53
|
+
}), t.type === "select" && e.set(i, {
|
|
53
54
|
type: "select",
|
|
54
55
|
validate: t.validate,
|
|
55
56
|
onUpdate: t.onUpdate
|
|
56
|
-
}), t.type === "input" && e.set(
|
|
57
|
+
}), t.type === "input" && e.set(i, {
|
|
57
58
|
type: "input",
|
|
58
59
|
validate: t.validate,
|
|
59
60
|
onUpdate: t.onUpdate
|
|
60
61
|
});
|
|
61
62
|
});
|
|
62
63
|
}), e;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
64
|
+
}, R = (o, e) => `${o}:${e}`, b = "@rozenite/controls-plugin", v = {
|
|
65
|
+
listSections: g({
|
|
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: g({
|
|
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: g({
|
|
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: g({
|
|
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
|
+
}, w = (o, e, n) => {
|
|
104
110
|
const t = o.find((s) => s.id === e);
|
|
105
111
|
if (!t) {
|
|
106
112
|
const s = o.map((u) => u.id).join(", ");
|
|
@@ -108,18 +114,18 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
108
114
|
`Section "${e}" not found. Available: ${s || "(none)"}`
|
|
109
115
|
);
|
|
110
116
|
}
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
117
|
+
const i = t.items.find((s) => s.id === n);
|
|
118
|
+
if (!i) {
|
|
113
119
|
const s = t.items.map((u) => u.id).join(", ");
|
|
114
120
|
throw new Error(
|
|
115
121
|
`Item "${n}" not found in section "${e}". Available: ${s || "(none)"}`
|
|
116
122
|
);
|
|
117
123
|
}
|
|
118
|
-
return { section: t, item:
|
|
119
|
-
},
|
|
124
|
+
return { section: t, item: i };
|
|
125
|
+
}, L = (o) => {
|
|
120
126
|
f({
|
|
121
|
-
pluginId:
|
|
122
|
-
tool:
|
|
127
|
+
pluginId: b,
|
|
128
|
+
tool: v.listSections,
|
|
123
129
|
handler: () => ({
|
|
124
130
|
sections: o.map((e) => ({
|
|
125
131
|
id: e.id,
|
|
@@ -134,10 +140,10 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
134
140
|
}))
|
|
135
141
|
})
|
|
136
142
|
}), f({
|
|
137
|
-
pluginId:
|
|
138
|
-
tool:
|
|
143
|
+
pluginId: b,
|
|
144
|
+
tool: v.getItem,
|
|
139
145
|
handler: ({ sectionId: e, itemId: n }) => {
|
|
140
|
-
const { item: t } =
|
|
146
|
+
const { item: t } = w(o, e, n);
|
|
141
147
|
return t.type === "text" ? {
|
|
142
148
|
sectionId: e,
|
|
143
149
|
item: {
|
|
@@ -193,55 +199,55 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
193
199
|
};
|
|
194
200
|
}
|
|
195
201
|
}), f({
|
|
196
|
-
pluginId:
|
|
197
|
-
tool:
|
|
202
|
+
pluginId: b,
|
|
203
|
+
tool: v.setValue,
|
|
198
204
|
handler: async ({ sectionId: e, itemId: n, value: t }) => {
|
|
199
|
-
const { item:
|
|
200
|
-
if (
|
|
205
|
+
const { item: i } = w(o, e, n);
|
|
206
|
+
if (i.type === "text")
|
|
201
207
|
throw new Error(
|
|
202
208
|
`Item "${n}" is a read-only text item and cannot be updated.`
|
|
203
209
|
);
|
|
204
|
-
if (
|
|
210
|
+
if (i.type === "button")
|
|
205
211
|
throw new Error(
|
|
206
212
|
`Item "${n}" is a button. Use press-button to trigger its action.`
|
|
207
213
|
);
|
|
208
|
-
if (
|
|
214
|
+
if (i.disabled)
|
|
209
215
|
throw new Error(`Item "${n}" is disabled.`);
|
|
210
|
-
if (
|
|
216
|
+
if (i.type === "toggle") {
|
|
211
217
|
if (typeof t != "boolean")
|
|
212
218
|
throw new Error(
|
|
213
219
|
`Expected boolean value for toggle item "${n}".`
|
|
214
220
|
);
|
|
215
|
-
if (
|
|
216
|
-
const s =
|
|
221
|
+
if (i.validate) {
|
|
222
|
+
const s = i.validate(t);
|
|
217
223
|
if (!s.valid)
|
|
218
224
|
throw new Error(s.message);
|
|
219
225
|
}
|
|
220
|
-
return await
|
|
226
|
+
return await i.onUpdate(t), { applied: !0, sectionId: e, itemId: n };
|
|
221
227
|
}
|
|
222
228
|
if (typeof t != "string")
|
|
223
229
|
throw new Error(
|
|
224
|
-
`Expected string value for ${
|
|
230
|
+
`Expected string value for ${i.type} item "${n}".`
|
|
225
231
|
);
|
|
226
|
-
if (
|
|
227
|
-
const s =
|
|
232
|
+
if (i.type === "select") {
|
|
233
|
+
const s = i.options.map((u) => u.value);
|
|
228
234
|
if (!s.includes(t))
|
|
229
235
|
throw new Error(
|
|
230
236
|
`Invalid option "${t}" for item "${n}". Valid options: ${s.join(", ")}`
|
|
231
237
|
);
|
|
232
238
|
}
|
|
233
|
-
if (
|
|
234
|
-
const s =
|
|
239
|
+
if (i.validate) {
|
|
240
|
+
const s = i.validate(t);
|
|
235
241
|
if (!s.valid)
|
|
236
242
|
throw new Error(s.message);
|
|
237
243
|
}
|
|
238
|
-
return await
|
|
244
|
+
return await i.onUpdate(t), { applied: !0, sectionId: e, itemId: n };
|
|
239
245
|
}
|
|
240
246
|
}), f({
|
|
241
|
-
pluginId:
|
|
242
|
-
tool:
|
|
247
|
+
pluginId: b,
|
|
248
|
+
tool: v.pressButton,
|
|
243
249
|
handler: async ({ sectionId: e, itemId: n }) => {
|
|
244
|
-
const { item: t } =
|
|
250
|
+
const { item: t } = w(o, e, n);
|
|
245
251
|
if (t.type !== "button")
|
|
246
252
|
throw new Error(
|
|
247
253
|
`Item "${n}" is not a button (type: ${t.type}). Use set-value to update its value.`
|
|
@@ -251,35 +257,35 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
251
257
|
return await t.onPress(), { pressed: !0, sectionId: e, itemId: n };
|
|
252
258
|
}
|
|
253
259
|
});
|
|
254
|
-
},
|
|
260
|
+
}, j = ({
|
|
255
261
|
sections: o
|
|
256
262
|
}) => {
|
|
257
|
-
const e =
|
|
263
|
+
const e = S({
|
|
258
264
|
pluginId: "@rozenite/controls-plugin"
|
|
259
265
|
});
|
|
260
|
-
|
|
261
|
-
const n =
|
|
262
|
-
return
|
|
263
|
-
|
|
264
|
-
}, [t]),
|
|
266
|
+
L(o);
|
|
267
|
+
const n = E(() => A(o), [o]), t = E(() => D(o), [o]), i = P(t);
|
|
268
|
+
return h(() => {
|
|
269
|
+
i.current = t;
|
|
270
|
+
}, [t]), h(() => {
|
|
265
271
|
e && e.send("snapshot", {
|
|
266
272
|
type: "snapshot",
|
|
267
273
|
sections: n
|
|
268
274
|
});
|
|
269
|
-
}, [e, n]),
|
|
275
|
+
}, [e, n]), h(() => {
|
|
270
276
|
if (!e)
|
|
271
277
|
return;
|
|
272
278
|
const s = async ({
|
|
273
|
-
requestId:
|
|
279
|
+
requestId: r,
|
|
274
280
|
sectionId: a,
|
|
275
281
|
itemId: l,
|
|
276
282
|
value: d
|
|
277
283
|
}) => {
|
|
278
|
-
const c =
|
|
284
|
+
const c = R(a, l), p = i.current.get(c);
|
|
279
285
|
if (!p || p.type === "button") {
|
|
280
286
|
e.send("update-result", {
|
|
281
287
|
type: "update-result",
|
|
282
|
-
requestId:
|
|
288
|
+
requestId: r,
|
|
283
289
|
sectionId: a,
|
|
284
290
|
itemId: l,
|
|
285
291
|
status: "error",
|
|
@@ -292,7 +298,7 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
292
298
|
if (typeof d != "boolean") {
|
|
293
299
|
e.send("update-result", {
|
|
294
300
|
type: "update-result",
|
|
295
|
-
requestId:
|
|
301
|
+
requestId: r,
|
|
296
302
|
sectionId: a,
|
|
297
303
|
itemId: l,
|
|
298
304
|
status: "error",
|
|
@@ -300,21 +306,21 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
300
306
|
});
|
|
301
307
|
return;
|
|
302
308
|
}
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
309
|
+
const $ = U(p.validate, d);
|
|
310
|
+
if (!$.valid) {
|
|
305
311
|
e.send("update-result", {
|
|
306
312
|
type: "update-result",
|
|
307
|
-
requestId:
|
|
313
|
+
requestId: r,
|
|
308
314
|
sectionId: a,
|
|
309
315
|
itemId: l,
|
|
310
316
|
status: "error",
|
|
311
|
-
message:
|
|
317
|
+
message: $.message
|
|
312
318
|
});
|
|
313
319
|
return;
|
|
314
320
|
}
|
|
315
321
|
await p.onUpdate(d), e.send("update-result", {
|
|
316
322
|
type: "update-result",
|
|
317
|
-
requestId:
|
|
323
|
+
requestId: r,
|
|
318
324
|
sectionId: a,
|
|
319
325
|
itemId: l,
|
|
320
326
|
status: "ok"
|
|
@@ -324,7 +330,7 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
324
330
|
if (typeof d != "string") {
|
|
325
331
|
e.send("update-result", {
|
|
326
332
|
type: "update-result",
|
|
327
|
-
requestId:
|
|
333
|
+
requestId: r,
|
|
328
334
|
sectionId: a,
|
|
329
335
|
itemId: l,
|
|
330
336
|
status: "error",
|
|
@@ -332,11 +338,11 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
332
338
|
});
|
|
333
339
|
return;
|
|
334
340
|
}
|
|
335
|
-
const y =
|
|
341
|
+
const y = U(p.validate, d);
|
|
336
342
|
if (!y.valid) {
|
|
337
343
|
e.send("update-result", {
|
|
338
344
|
type: "update-result",
|
|
339
|
-
requestId:
|
|
345
|
+
requestId: r,
|
|
340
346
|
sectionId: a,
|
|
341
347
|
itemId: l,
|
|
342
348
|
status: "error",
|
|
@@ -346,7 +352,7 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
346
352
|
}
|
|
347
353
|
await p.onUpdate(d), e.send("update-result", {
|
|
348
354
|
type: "update-result",
|
|
349
|
-
requestId:
|
|
355
|
+
requestId: r,
|
|
350
356
|
sectionId: a,
|
|
351
357
|
itemId: l,
|
|
352
358
|
status: "ok"
|
|
@@ -357,7 +363,7 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
357
363
|
y
|
|
358
364
|
), e.send("update-result", {
|
|
359
365
|
type: "update-result",
|
|
360
|
-
requestId:
|
|
366
|
+
requestId: r,
|
|
361
367
|
sectionId: a,
|
|
362
368
|
itemId: l,
|
|
363
369
|
status: "error",
|
|
@@ -365,56 +371,56 @@ const $ = (o, e) => o ? o(e) : { valid: !0 }, P = (o) => o.type === "text" ? o :
|
|
|
365
371
|
});
|
|
366
372
|
}
|
|
367
373
|
}, u = async ({
|
|
368
|
-
sectionId:
|
|
374
|
+
sectionId: r,
|
|
369
375
|
itemId: a,
|
|
370
376
|
action: l
|
|
371
377
|
}) => {
|
|
372
378
|
if (l !== "press") {
|
|
373
379
|
console.warn(
|
|
374
|
-
`[Rozenite] Controls Plugin: Unsupported action "${l}" for ${
|
|
380
|
+
`[Rozenite] Controls Plugin: Unsupported action "${l}" for ${r}/${a}.`
|
|
375
381
|
);
|
|
376
382
|
return;
|
|
377
383
|
}
|
|
378
|
-
const d =
|
|
384
|
+
const d = R(r, a), c = i.current.get(d);
|
|
379
385
|
if (!c) {
|
|
380
386
|
console.warn(
|
|
381
|
-
`[Rozenite] Controls Plugin: Action target not found for ${
|
|
387
|
+
`[Rozenite] Controls Plugin: Action target not found for ${r}/${a}.`
|
|
382
388
|
);
|
|
383
389
|
return;
|
|
384
390
|
}
|
|
385
391
|
try {
|
|
386
392
|
if (c.type !== "button") {
|
|
387
393
|
console.warn(
|
|
388
|
-
`[Rozenite] Controls Plugin: Invalid press action payload for ${
|
|
394
|
+
`[Rozenite] Controls Plugin: Invalid press action payload for ${r}/${a}.`
|
|
389
395
|
);
|
|
390
396
|
return;
|
|
391
397
|
}
|
|
392
398
|
await c.onPress();
|
|
393
399
|
} catch (p) {
|
|
394
400
|
console.warn(
|
|
395
|
-
`[Rozenite] Controls Plugin: Action failed for ${
|
|
401
|
+
`[Rozenite] Controls Plugin: Action failed for ${r}/${a}.`,
|
|
396
402
|
p
|
|
397
403
|
);
|
|
398
404
|
}
|
|
399
|
-
},
|
|
405
|
+
}, m = [
|
|
400
406
|
e.onMessage("get-snapshot", () => {
|
|
401
407
|
e.send("snapshot", {
|
|
402
408
|
type: "snapshot",
|
|
403
409
|
sections: n
|
|
404
410
|
});
|
|
405
411
|
}),
|
|
406
|
-
e.onMessage("update-request", (
|
|
407
|
-
s(
|
|
412
|
+
e.onMessage("update-request", (r) => {
|
|
413
|
+
s(r);
|
|
408
414
|
}),
|
|
409
|
-
e.onMessage("invoke-action", (
|
|
410
|
-
u(
|
|
415
|
+
e.onMessage("invoke-action", (r) => {
|
|
416
|
+
u(r);
|
|
411
417
|
})
|
|
412
418
|
];
|
|
413
419
|
return () => {
|
|
414
|
-
|
|
420
|
+
m.forEach((r) => r.remove());
|
|
415
421
|
};
|
|
416
422
|
}, [e, n]), e;
|
|
417
423
|
};
|
|
418
424
|
export {
|
|
419
|
-
|
|
425
|
+
j as useRozeniteControlsPlugin
|
|
420
426
|
};
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/controls-plugin","version":"1.
|
|
1
|
+
{"name":"@rozenite/controls-plugin","version":"1.8.0","description":"A Rozenite plugin for exposing app-defined controls directly in React Native DevTools.","panels":[{"name":"Controls","source":"/devtools/panel.html"}]}
|
|
@@ -0,0 +1 @@
|
|
|
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;
|