smart-home-engine 0.22.0 → 0.23.1

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.
@@ -1,4 +1,4 @@
1
- import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-BZSPXz4N.js";/*!-----------------------------------------------------------------------------
1
+ import{m as O}from"./monaco-langs-BW2J83t5.js";import{t as I}from"./index-CI4cnkU8.js";/*!-----------------------------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
4
4
  * Released under the MIT license
@@ -155,7 +155,7 @@
155
155
  }
156
156
  })();
157
157
  </script>
158
- <script type="module" crossorigin src="/assets/index-BZSPXz4N.js"></script>
158
+ <script type="module" crossorigin src="/assets/index-CI4cnkU8.js"></script>
159
159
  <link rel="modulepreload" crossorigin href="/assets/monaco-langs-BW2J83t5.js">
160
160
  <link rel="stylesheet" crossorigin href="/assets/monaco-langs-DyX1CsEw.css">
161
161
  <link rel="stylesheet" crossorigin href="/assets/index-BPk8Jr3B.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smart-home-engine",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "description": "Node.js based script runner for use in MQTT based Smart Home environments",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -32,8 +32,9 @@ else
32
32
  echo "user '$SHE_USER' already exists, skipping"
33
33
  fi
34
34
 
35
- # --- state directory (required by ReadWritePaths before first start) ------
36
- install -d -o "$SHE_USER" -g "$SHE_USER" -m 700 /home/she/.she
35
+ # --- state directory ------------------------------------------------------
36
+ install -d -o "$SHE_USER" -g "$SHE_USER" -m 750 /var/lib/she
37
+ echo "created /var/lib/she"
37
38
 
38
39
  # --- sudoers rules -------------------------------------------------------
39
40
  NPM_BIN="$(command -v npm)"
@@ -11,9 +11,9 @@ Group=she
11
11
  Restart=on-failure
12
12
  RestartSec=5s
13
13
 
14
- ExecStart=/usr/local/bin/she
14
+ ExecStart=/usr/local/bin/she --data-dir /var/lib/she
15
15
 
16
- ReadWritePaths=/home/she/.she
16
+ ReadWritePaths=/var/lib/she
17
17
 
18
18
  StandardOutput=journal
19
19
  StandardError=journal
package/src/config.js CHANGED
@@ -4,23 +4,29 @@ const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
 
7
- // Default config file location (can be overridden with --config on the CLI)
8
- const configPath = path.join(os.homedir(), '.she', 'config', 'config.json');
7
+ // Resolve data root: --data-dir is pre-parsed in index.js and written to SHE_DATA_DIR
8
+ // so that this module and storage.js both see the same root when first required.
9
+ const DATA_ROOT = process.env.SHE_DATA_DIR || path.join(os.homedir(), '.she');
9
10
 
10
11
  const config = require('yargs')
12
+ .option('data-dir', {
13
+ describe: 'root data directory for scripts, db, config, etc. (default: ~/.she)',
14
+ default: DATA_ROOT,
15
+ type: 'string',
16
+ })
11
17
  .option('dir', {
12
18
  alias: 'd',
13
19
  describe: 'directory to load user scripts from',
14
- default: path.join(os.homedir(), '.she', 'scripts'),
20
+ default: path.join(DATA_ROOT, 'scripts'),
15
21
  type: 'string',
16
22
  })
17
23
  .option('db-path', {
18
24
  describe: 'path to sheDB data directory (empty string to disable)',
19
- default: path.join(os.homedir(), '.she', 'db'),
25
+ default: path.join(DATA_ROOT, 'db'),
20
26
  type: 'string',
21
27
  })
22
28
  .option('matter-storage', {
23
- describe: 'enable Matter controller; pass a directory path or true to use ~/.she/matter',
29
+ describe: 'enable Matter controller; pass a directory path or true to use <data-dir>/matter',
24
30
  type: 'string',
25
31
  })
26
32
  .option('port', {
@@ -36,7 +42,7 @@ const config = require('yargs')
36
42
  return {};
37
43
  }
38
44
  })
39
- .default('config', configPath)
45
+ .default('config', path.join(DATA_ROOT, 'config', 'config.json'))
40
46
  .hide('config')
41
47
  // Sensible defaults for values not present in config.json
42
48
  .default({
package/src/index.js CHANGED
@@ -25,7 +25,16 @@ if (process.argv.includes('--install')) {
25
25
  process.exit(0);
26
26
  }
27
27
 
28
- // Ensure ~/.she/ exists before anything else runs
28
+ // Resolve --data-dir early so that storage.js and config.js both see the correct
29
+ // data root when they are first require()'d below.
30
+ ;(function () {
31
+ const idx = process.argv.indexOf('--data-dir');
32
+ if (idx !== -1 && process.argv[idx + 1] && !process.argv[idx + 1].startsWith('-')) {
33
+ process.env.SHE_DATA_DIR = process.argv[idx + 1];
34
+ }
35
+ }());
36
+
37
+ // Ensure the data directory exists before anything else runs
29
38
  require('./lib/storage').ensureRoot();
30
39
 
31
40
  const PinoPretty = require('pino-pretty');
@@ -4,7 +4,7 @@ const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
 
7
- const STORAGE_ROOT = path.join(os.homedir(), '.she');
7
+ const STORAGE_ROOT = process.env.SHE_DATA_DIR || path.join(os.homedir(), '.she');
8
8
  const CONFIG_ROOT = path.join(STORAGE_ROOT, 'config');
9
9
  const SCRIPTS_ROOT = path.join(STORAGE_ROOT, 'scripts');
10
10
  const DB_ROOT = path.join(STORAGE_ROOT, 'db');
package/src/web/ai-api.js CHANGED
@@ -441,14 +441,15 @@ router.post('/prompt', (req, res) => {
441
441
  // POST /she/ai/chat — non-streaming
442
442
  router.post('/chat', async (req, res) => {
443
443
  const ai = readAiConfig(req.app.locals.configPath);
444
- if (!ai?.provider || !ai?.model) {
444
+ const { messages = [], currentScript, currentView, currentDoc, context = {}, modelOverride, extraFiles } = req.body || {};
445
+ const effectiveModel = (modelOverride && typeof modelOverride === 'string') ? modelOverride : ai?.model;
446
+ if (!ai?.provider || !effectiveModel) {
445
447
  return res.status(400).json({ error: 'AI provider not configured. Set ai.provider and ai.model in Config.' });
446
448
  }
447
449
 
448
- const { messages = [], currentScript, currentView, currentDoc, context = {}, modelOverride, extraFiles } = req.body || {};
449
450
  if (!Array.isArray(messages)) return res.status(400).json({ error: 'messages must be an array' });
450
451
 
451
- const aiWithModel = modelOverride && typeof modelOverride === 'string' ? { ...ai, model: modelOverride } : ai;
452
+ const aiWithModel = { ...ai, model: effectiveModel };
452
453
  const systemPrompt = buildSystemPrompt(context, currentScript ?? null, currentView ?? null, currentDoc ?? null, _store, extraFiles || []);
453
454
  const fullMessages = [{ role: 'system', content: systemPrompt }, ...messages];
454
455
 
@@ -471,14 +472,15 @@ router.post('/chat', async (req, res) => {
471
472
  // POST /she/ai/chat/stream — SSE streaming
472
473
  router.post('/chat/stream', async (req, res) => {
473
474
  const ai = readAiConfig(req.app.locals.configPath);
474
- if (!ai?.provider || !ai?.model) {
475
+ const { messages = [], currentScript, currentView, currentDoc, context = {}, modelOverride, extraFiles } = req.body || {};
476
+ const effectiveModel = (modelOverride && typeof modelOverride === 'string') ? modelOverride : ai?.model;
477
+ if (!ai?.provider || !effectiveModel) {
475
478
  return res.status(400).json({ error: 'AI provider not configured. Set ai.provider and ai.model in Config.' });
476
479
  }
477
480
 
478
- const { messages = [], currentScript, currentView, currentDoc, context = {}, modelOverride, extraFiles } = req.body || {};
479
481
  if (!Array.isArray(messages)) return res.status(400).json({ error: 'messages must be an array' });
480
482
 
481
- const aiWithModel = modelOverride && typeof modelOverride === 'string' ? { ...ai, model: modelOverride } : ai;
483
+ const aiWithModel = { ...ai, model: effectiveModel };
482
484
 
483
485
  // Build system prompt BEFORE flushing headers so errors can still return a proper HTTP status
484
486
  let systemPrompt;
package/src/web/server.js CHANGED
@@ -107,6 +107,7 @@ function setStatsProvider(fn) {
107
107
  app.get('/she/status', (req, res) => {
108
108
  const s = _getStats ? _getStats() : { scripts: 0, topics: 0 };
109
109
  if (_latestNpmVersion) s.latestVersion = _latestNpmVersion;
110
+ s.dataDir = require('../lib/storage').STORAGE_ROOT;
110
111
  res.json(s);
111
112
  });
112
113