smart-home-engine 1.51.2 → 1.52.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/README.md +1 -0
- package/dist/web/assets/index-BswjzIm1.css +1 -0
- package/dist/web/assets/index-CD6lY3HK.js +296 -0
- package/dist/web/assets/{tsMode-4A8DZYIU.js → tsMode-CQwwRC_t.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/src/index.js +67 -47
- package/src/lib/log-file.js +81 -0
- package/src/lib/logger.js +33 -0
- package/src/lib/script-timers.js +1 -0
- package/src/lib/text-diff.js +116 -0
- package/src/web/ai-api.js +481 -69
- package/src/web/ai-context.js +172 -61
- package/src/web/ai-drafts.js +68 -0
- package/src/web/ai-memory.js +106 -0
- package/src/web/ai-tools.js +941 -66
- package/src/web/log-ws.js +27 -7
- package/src/web/prompts/api-ref-compact.md +16 -0
- package/src/web/prompts/api-ref.md +60 -0
- package/src/web/prompts/compact.md +5 -0
- package/src/web/prompts/conventions.md +5 -0
- package/src/web/prompts/db-doc.md +1 -1
- package/src/web/prompts/db-view.md +3 -3
- package/src/web/prompts/formats.md +14 -0
- package/src/web/prompts/role.md +6 -0
- package/src/web/prompts/tools.md +9 -0
- package/dist/web/assets/index-CSKTxEh5.js +0 -295
- package/dist/web/assets/index-DPDW78ru.css +0 -1
- package/src/web/prompts/scripts-base.md +0 -25
- package/src/web/prompts/she-api-ref.md +0 -94
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
You are SHE Assistant, an expert AI pair programmer for she (smart-home-engine).
|
|
2
|
-
she is a Node.js daemon that runs user JavaScript scripts in a sandboxed VM for home automation.
|
|
3
|
-
When proposing changes to a script, always output the COMPLETE new file content in a single fenced ```javascript code block. Never output partial diffs or fragments — the user applies the full file at once.
|
|
4
|
-
Keep any existing header comments and the 'use strict'; directive.
|
|
5
|
-
When the user asks you to CREATE a new script (not modify the current one), place a special hint as the very first line INSIDE the code block (right after the opening ```javascript fence line), like this:
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
// @new-file: descriptive-name.js
|
|
9
|
-
/* global she */
|
|
10
|
-
'use strict';
|
|
11
|
-
// ... rest of script
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Use a short kebab-case filename. Do NOT put the hint outside or before the code block. The UI will detect it and offer to save the file.
|
|
15
|
-
|
|
16
|
-
### MQTT publishing rules
|
|
17
|
-
When sending a command to a device (e.g. turning a light on/off, triggering an action), ALWAYS use `she.mqtt.pub()` WITHOUT retain — never set `retain: true` on command topics.
|
|
18
|
-
Only use `she.mqtt.set()` or `retain: true` for storing persistent state or configuration values that must survive restarts, not for commands.
|
|
19
|
-
|
|
20
|
-
### Tool usage
|
|
21
|
-
When the user asks about a specific MQTT topic, its current value or state — use `search_mqtt_topics` to discover topics or `get_mqtt_topic` for a direct lookup. Never invent topic names.
|
|
22
|
-
When the user asks about a Matter device or smart home hardware — call `list_matter_devices` to retrieve the actual device list, endpoints and clusters.
|
|
23
|
-
When the user asks about a sheDB document — call `list_shedb_docs` to find the ID, then `get_shedb_doc` to read it.
|
|
24
|
-
Always look up real data before writing scripts that reference specific topics, documents or devices.
|
|
25
|
-
If `search_mqtt_topics` returns several plausible matches and it is unclear which one the user means, ask the user to confirm the correct topic before writing the script — never guess.
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
## she sandbox API
|
|
2
|
-
|
|
3
|
-
Scripts run in a sandboxed VM. The `she` object is injected automatically.
|
|
4
|
-
|
|
5
|
-
### Script conventions
|
|
6
|
-
- First lines: /* global she */ then 'use strict';
|
|
7
|
-
- No require() — the module system is not available
|
|
8
|
-
- All subscriptions and schedules persist across reconnects
|
|
9
|
-
|
|
10
|
-
### MQTT
|
|
11
|
-
```
|
|
12
|
-
she.mqtt.sub(topic, [opts], cb) Subscribe; wildcards: + (1 level) # (multi)
|
|
13
|
-
opts.change: only fire when value changes
|
|
14
|
-
opts.retain: also fire for retained msgs on connect and script start
|
|
15
|
-
opts.shift: delay execution by N seconds
|
|
16
|
-
opts.random: additional random delay in seconds
|
|
17
|
-
opts.condition: fn(val) or JS string — skip cb if falsy
|
|
18
|
-
cb(topic, val, obj, objPrev, msg)
|
|
19
|
-
topic: the topic that fired
|
|
20
|
-
val: new value (parsed)
|
|
21
|
-
obj: full new state { val, ts, lc }
|
|
22
|
-
objPrev: previous state object
|
|
23
|
-
msg: raw MQTT.js message object
|
|
24
|
-
she.mqtt.pub(topic, payload, [opts]) Publish; opts: { qos, retain }
|
|
25
|
-
she.mqtt.get(topic) Current retained value (sync)
|
|
26
|
-
she.mqtt.link(src, target, [fn]) Forward src changes to target; optional transform
|
|
27
|
-
she.mqtt.age(topic) Seconds since topic last received a message
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Scheduling
|
|
31
|
-
```
|
|
32
|
-
she.schedule(pattern, [opts], cb)
|
|
33
|
-
pattern: cron string | Date | suncalc event name
|
|
34
|
-
suncalc events: 'sunrise' 'sunset' 'dawn' 'dusk'
|
|
35
|
-
'nauticalDawn' 'nauticalDusk' 'solarNoon' 'night'
|
|
36
|
-
opts.shift: seconds offset (e.g. -1800 = 30 min before event)
|
|
37
|
-
opts.random: max random delay in seconds added to the trigger time
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Variable system (var:: namespace)
|
|
41
|
-
Topics prefixed with "var" (default) are persisted as retained MQTT messages
|
|
42
|
-
and available across scripts via she.get('var::name') / she.set('var::name', v).
|
|
43
|
-
|
|
44
|
-
### sheDB
|
|
45
|
-
```
|
|
46
|
-
she.db.get(id) Get document (undefined if not found)
|
|
47
|
-
she.db.set(id, doc) Create or overwrite document
|
|
48
|
-
she.db.extend(id, partial) Deep-merge partial into existing document
|
|
49
|
-
she.db.delete(id) Delete document
|
|
50
|
-
she.db.sub(pattern, cb) Subscribe to document changes (MQTT wildcard)
|
|
51
|
-
she.db.query(filter, mapFn, [reduceFn]) Synchronous ad-hoc query → Array
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Matter
|
|
55
|
-
|
|
56
|
-
Use names for nodeId, endpointId and cluster, not numbers
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
she.matter.sub(nodeId, endpointId, cluster, attr, cb) Subscribe to attribute
|
|
60
|
-
she.matter.unsub(listenerId)
|
|
61
|
-
she.matter.get(nodeId, endpointId, cluster, attr) → Promise<value>
|
|
62
|
-
she.matter.send(nodeId, endpointId, cluster, cmd, [args]) → Promise<result>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Helpers
|
|
66
|
-
```
|
|
67
|
-
she.mqtt.timer(src, ms, topicOrCb) Pulse topicOrCb=1 for ms after src goes truthy
|
|
68
|
-
topicOrCb: topic string or callback(topic, val)
|
|
69
|
-
she.mqtt.or(srcs[], topicOrCb) Publish 1 if any source truthy, else 0
|
|
70
|
-
she.mqtt.and(srcs[], topicOrCb) Publish 1 if all sources truthy, else 0
|
|
71
|
-
she.mqtt.max(srcs[], topicOrCb) Publish maximum of source values
|
|
72
|
-
she.mqtt.min(srcs[], topicOrCb) Publish minimum of source values (0 if none set)
|
|
73
|
-
All topicOrCb: topic string or callback(topic, val)
|
|
74
|
-
she.now() Current timestamp in ms
|
|
75
|
-
she.debug / .info / .warn / .error Structured logging (prefixed with script name)
|
|
76
|
-
she.global Shared mutable object across all scripts
|
|
77
|
-
she.http.fetch(url, [opts], [cb]) HTTP/HTTPS fetch → { body, code, headers }; or cb(err, res)
|
|
78
|
-
Auto-parses JSON by Content-Type. Rejects/errs on non-2xx.
|
|
79
|
-
she.http.sub(path, cb) Register POST /api/<script><path> webhook endpoint
|
|
80
|
-
cb(body, { params, query, headers })
|
|
81
|
-
she.config.latitude Read-only: geographic latitude from daemon config
|
|
82
|
-
she.config.longitude Read-only: geographic longitude from daemon config
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Script HTTP API
|
|
86
|
-
Scripts can expose HTTP endpoints under `/api/<scriptName>/`.
|
|
87
|
-
```
|
|
88
|
-
she.api.get(path, handler) GET /api/<script><path> → handler(req)
|
|
89
|
-
she.api.post(path, handler) POST /api/<script><path> → handler(req, body)
|
|
90
|
-
she.api.put(path, handler) PUT /api/<script><path> → handler(req, body)
|
|
91
|
-
she.api.delete(path, handler) DELETE /api/<script><path> → handler(req)
|
|
92
|
-
```
|
|
93
|
-
req = { params, query, headers }. Return value (or resolved Promise) is JSON-serialised.
|
|
94
|
-
Express path params supported: she.api.get('/items/:id', (req) => ...).
|