@camstack/server 1.2.857 → 1.2.859
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 +13 -0
- package/dist/api/trpc/generated-cap-mounts.js +2 -1
- package/dist/api/trpc/generated-cap-routers.js +15 -1
- package/dist/core/addon/instance-links.service.js +6 -2
- package/package.json +10 -12
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +4 -4
- package/system/dist/builtins/composer/composer.addon.mjs +4 -4
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/automation-template-instances.d.ts +38 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +6 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +227 -21
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +227 -21
- package/system/dist/builtins/core-blocks/remote-wiring.d.ts +3 -0
- package/system/dist/builtins/core-blocks/templates-service.d.ts +11 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-BpTIydES.mjs → capture-engine-B4_fq2JB.mjs} +1 -1
- package/system/dist/{capture-engine-OjKUSU7_.js → capture-engine-yhFFC7F8.js} +1 -1
- package/system/dist/{composition-sources-eLYlvnnR.mjs → composition-sources-BQOEYCJG.mjs} +1 -1
- package/system/dist/{composition-sources-WroUQ4J-.js → composition-sources-CKSSe5ny.js} +1 -1
- package/system/dist/{constants-B8nWtzwq.js → constants-dfnEfsX7.js} +1 -1
- package/system/dist/{constants-DO33IJ7k.mjs → constants-h8wJE_8O.mjs} +1 -1
- package/system/dist/{device-ca-EtzHeETW.js → device-ca-_o0-3jJ6.js} +1 -1
- package/system/dist/{device-ca-BOquIg22.mjs → device-ca-h54CenJx.mjs} +1 -1
- package/system/dist/{dist-n0kCY8sq.js → dist-WEGVb8qV.js} +2961 -64
- package/system/dist/{dist-7eN_r5dA.mjs → dist-atHH8IeD.mjs} +2902 -65
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-C_6dgozE.mjs → hub-identity-DLF698tj.mjs} +1 -1
- package/system/dist/{hub-identity-Cz0pt7Ho.js → hub-identity-nIMYA24i.js} +1 -1
- package/system/dist/{hub-mdns-ciao-CmGrhCgY.js → hub-mdns-ciao-B6ZHStt1.js} +2 -2
- package/system/dist/{hub-mdns-ciao-CdHseQBh.mjs → hub-mdns-ciao-DchpUVAk.mjs} +2 -2
- package/system/dist/index.js +12 -8
- package/system/dist/index.mjs +12 -8
- package/system/dist/{legacy-integration-rows-door-Bm1OQy6O.js → legacy-integration-rows-door-BbaIE1qF.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-Cnqq1aq-.mjs → legacy-integration-rows-door-DBO3ZLmn.mjs} +1 -1
- package/system/dist/{rename-composition-block-CuKj9mH0.mjs → rename-composition-block-6ISzMLgj.mjs} +1 -1
- package/system/dist/{rename-composition-block-D82Y4jGp.js → rename-composition-block-IIfaFnEl.js} +1 -1
- package/system/dist/{restore-archive-C2kHLNPq.js → restore-archive-ChRNoqGg.js} +1 -1
- package/system/dist/{restore-archive-BOnkR2ZT.mjs → restore-archive-DeDRh7Lf.mjs} +1 -1
- package/system/dist/{wal-maintenance-Bdrc5v7T.mjs → wal-maintenance-BXj9xnDD.mjs} +0 -0
- package/system/dist/{wal-maintenance-CBrmyT6U.js → wal-maintenance-l3CsKEaJ.js} +0 -0
- package/system/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
3
|
-
const require_dist = require("../../dist-
|
|
3
|
+
const require_dist = require("../../dist-WEGVb8qV.js");
|
|
4
4
|
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
5
|
-
const require_composition_sources = require("../../composition-sources-
|
|
6
|
-
const require_capture_engine = require("../../capture-engine-
|
|
5
|
+
const require_composition_sources = require("../../composition-sources-CKSSe5ny.js");
|
|
6
|
+
const require_capture_engine = require("../../capture-engine-yhFFC7F8.js");
|
|
7
7
|
const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
|
|
8
8
|
const require_prefix_walk = require("../../prefix-walk-Dv6MLZlM.js");
|
|
9
9
|
const require_cap_call_scope = require("../../cap-call-scope-8eiugfLl.js");
|
|
@@ -4119,7 +4119,7 @@ var PowerSourceService = class {
|
|
|
4119
4119
|
await this.deps.devices.setOn(switchId, false);
|
|
4120
4120
|
} catch (err) {
|
|
4121
4121
|
this.restarting.delete(deviceId);
|
|
4122
|
-
return this.refuse(deviceId, "switch-call-failed", errorText$
|
|
4122
|
+
return this.refuse(deviceId, "switch-call-failed", errorText$3(err), switchId);
|
|
4123
4123
|
}
|
|
4124
4124
|
this.deps.logger.info("power-source: forced restart, power is off", {
|
|
4125
4125
|
tags: { deviceId },
|
|
@@ -4157,7 +4157,7 @@ var PowerSourceService = class {
|
|
|
4157
4157
|
tags: { deviceId },
|
|
4158
4158
|
meta: {
|
|
4159
4159
|
switchId,
|
|
4160
|
-
error: errorText$
|
|
4160
|
+
error: errorText$3(err)
|
|
4161
4161
|
}
|
|
4162
4162
|
});
|
|
4163
4163
|
} finally {
|
|
@@ -4172,7 +4172,7 @@ var PowerSourceService = class {
|
|
|
4172
4172
|
try {
|
|
4173
4173
|
await this.deps.devices.setOn(switchDevice.id, on);
|
|
4174
4174
|
} catch (err) {
|
|
4175
|
-
return this.refuse(deviceId, "switch-call-failed", errorText$
|
|
4175
|
+
return this.refuse(deviceId, "switch-call-failed", errorText$3(err), switchDevice.id);
|
|
4176
4176
|
}
|
|
4177
4177
|
this.deps.logger.info(`power-source: ${action}`, {
|
|
4178
4178
|
tags: { deviceId },
|
|
@@ -4255,7 +4255,7 @@ var PowerSourceService = class {
|
|
|
4255
4255
|
};
|
|
4256
4256
|
}
|
|
4257
4257
|
};
|
|
4258
|
-
function errorText$
|
|
4258
|
+
function errorText$3(err) {
|
|
4259
4259
|
return err instanceof Error ? err.message : String(err);
|
|
4260
4260
|
}
|
|
4261
4261
|
var TIMED_RUN_SETTLE_MS = 3e3;
|
|
@@ -6700,7 +6700,7 @@ function rolesFor(command) {
|
|
|
6700
6700
|
case "playMedia": return [];
|
|
6701
6701
|
}
|
|
6702
6702
|
}
|
|
6703
|
-
function errorText$
|
|
6703
|
+
function errorText$2(err) {
|
|
6704
6704
|
return err instanceof Error ? err.message : String(err);
|
|
6705
6705
|
}
|
|
6706
6706
|
var RemoteService = class {
|
|
@@ -6803,7 +6803,7 @@ var RemoteService = class {
|
|
|
6803
6803
|
} catch (err) {
|
|
6804
6804
|
this.deps.logger.warn("remote: the media-player slice could not be written", {
|
|
6805
6805
|
tags: { deviceId },
|
|
6806
|
-
meta: { error: errorText$
|
|
6806
|
+
meta: { error: errorText$2(err) }
|
|
6807
6807
|
});
|
|
6808
6808
|
}
|
|
6809
6809
|
}
|
|
@@ -7198,13 +7198,13 @@ var RemoteService = class {
|
|
|
7198
7198
|
meta: {
|
|
7199
7199
|
source: source.name,
|
|
7200
7200
|
transmitterId,
|
|
7201
|
-
error: errorText$
|
|
7201
|
+
error: errorText$2(err)
|
|
7202
7202
|
}
|
|
7203
7203
|
});
|
|
7204
7204
|
return {
|
|
7205
7205
|
status: "refused",
|
|
7206
7206
|
reason: "action-failed",
|
|
7207
|
-
detail: errorText$
|
|
7207
|
+
detail: errorText$2(err)
|
|
7208
7208
|
};
|
|
7209
7209
|
}
|
|
7210
7210
|
const kept = await this.readAssumed(deviceId);
|
|
@@ -7286,13 +7286,13 @@ var RemoteService = class {
|
|
|
7286
7286
|
meta: {
|
|
7287
7287
|
role,
|
|
7288
7288
|
sent,
|
|
7289
|
-
error: errorText$
|
|
7289
|
+
error: errorText$2(err)
|
|
7290
7290
|
}
|
|
7291
7291
|
});
|
|
7292
7292
|
return {
|
|
7293
7293
|
status: "refused",
|
|
7294
7294
|
reason: "action-failed",
|
|
7295
|
-
detail: errorText$
|
|
7295
|
+
detail: errorText$2(err)
|
|
7296
7296
|
};
|
|
7297
7297
|
}
|
|
7298
7298
|
}
|
|
@@ -7364,8 +7364,12 @@ var RemoteService = class {
|
|
|
7364
7364
|
* it does not know what a remote is.
|
|
7365
7365
|
*
|
|
7366
7366
|
* A delete asks the {@link TemplateUsage} port who still points at the record
|
|
7367
|
-
* and refuses with the devices named (typed `in-use`), so a
|
|
7368
|
-
* vanish under a device that draws from it
|
|
7367
|
+
* and refuses with the devices and automations named (typed `in-use`), so a
|
|
7368
|
+
* button grid cannot vanish under a device that draws from it, nor an automation
|
|
7369
|
+
* template under the automations made from it.
|
|
7370
|
+
*
|
|
7371
|
+
* Saving an `automation` template re-expands every automation made from it
|
|
7372
|
+
* (#527) through the {@link AutomationTemplateInstances} port.
|
|
7369
7373
|
*/
|
|
7370
7374
|
function recordOf(id, body) {
|
|
7371
7375
|
return {
|
|
@@ -7377,6 +7381,18 @@ function recordOf(id, body) {
|
|
|
7377
7381
|
updatedAt: body.updatedAt
|
|
7378
7382
|
};
|
|
7379
7383
|
}
|
|
7384
|
+
/** A shipped template as a record: read-only, timeless. */
|
|
7385
|
+
function builtinRecordOf(template) {
|
|
7386
|
+
return {
|
|
7387
|
+
id: template.id,
|
|
7388
|
+
kind: "automation",
|
|
7389
|
+
name: template.name,
|
|
7390
|
+
payload: template.payload,
|
|
7391
|
+
createdAt: 0,
|
|
7392
|
+
updatedAt: 0,
|
|
7393
|
+
builtIn: true
|
|
7394
|
+
};
|
|
7395
|
+
}
|
|
7380
7396
|
var TemplatesService = class {
|
|
7381
7397
|
deps;
|
|
7382
7398
|
now;
|
|
@@ -7397,9 +7413,12 @@ var TemplatesService = class {
|
|
|
7397
7413
|
for (const row of page.records) out.push(recordOf(row.id, row.data));
|
|
7398
7414
|
cursor = page.nextCursor ?? void 0;
|
|
7399
7415
|
} while (cursor !== void 0);
|
|
7416
|
+
if (kind === void 0 || kind === "automation") out.push(...require_dist.BUILTIN_AUTOMATION_TEMPLATES.map(builtinRecordOf));
|
|
7400
7417
|
return out;
|
|
7401
7418
|
};
|
|
7402
7419
|
get = async ({ id }) => {
|
|
7420
|
+
const builtin = require_dist.builtinAutomationTemplate(id);
|
|
7421
|
+
if (builtin !== void 0) return builtinRecordOf(builtin);
|
|
7403
7422
|
const row = await this.deps.templates.get(id);
|
|
7404
7423
|
return row === null ? null : recordOf(row.id, row.data);
|
|
7405
7424
|
};
|
|
@@ -7435,6 +7454,11 @@ var TemplatesService = class {
|
|
|
7435
7454
|
};
|
|
7436
7455
|
};
|
|
7437
7456
|
update = async ({ id, name, payload }) => {
|
|
7457
|
+
if (require_dist.isBuiltinTemplateId(id)) return {
|
|
7458
|
+
status: "refused",
|
|
7459
|
+
reason: "read-only",
|
|
7460
|
+
detail: `"${id}" ships with CamStack`
|
|
7461
|
+
};
|
|
7438
7462
|
const existing = await this.deps.templates.get(id);
|
|
7439
7463
|
if (existing === null) return {
|
|
7440
7464
|
status: "refused",
|
|
@@ -7469,22 +7493,43 @@ var TemplatesService = class {
|
|
|
7469
7493
|
id,
|
|
7470
7494
|
data: body
|
|
7471
7495
|
});
|
|
7496
|
+
if (payload !== void 0) await this.reexpandInstances(id, body);
|
|
7472
7497
|
return {
|
|
7473
7498
|
status: "saved",
|
|
7474
7499
|
template: recordOf(id, body)
|
|
7475
7500
|
};
|
|
7476
7501
|
};
|
|
7502
|
+
/**
|
|
7503
|
+
* The shipped templates change only with a release: their instances are
|
|
7504
|
+
* re-expanded once per start, and an instance whose code comes out the same
|
|
7505
|
+
* is not saved (no restart).
|
|
7506
|
+
*/
|
|
7507
|
+
async reexpandBuiltinInstances() {
|
|
7508
|
+
if (this.deps.automations === void 0) return;
|
|
7509
|
+
for (const template of require_dist.BUILTIN_AUTOMATION_TEMPLATES) await this.deps.automations.reexpand(template.id, template.payload);
|
|
7510
|
+
}
|
|
7511
|
+
/** A changed automation template reaches every automation made from it. */
|
|
7512
|
+
async reexpandInstances(id, body) {
|
|
7513
|
+
if (body.kind !== "automation" || this.deps.automations === void 0) return;
|
|
7514
|
+
const parsed = require_dist.AutomationTemplatePayloadSchema.safeParse(body.payload);
|
|
7515
|
+
if (!parsed.success) return;
|
|
7516
|
+
await this.deps.automations.reexpand(id, parsed.data);
|
|
7517
|
+
}
|
|
7477
7518
|
delete = async ({ id }) => {
|
|
7519
|
+
if (require_dist.isBuiltinTemplateId(id)) return { status: "read-only" };
|
|
7478
7520
|
if (await this.deps.templates.get(id) === null) return { status: "not-found" };
|
|
7479
|
-
const
|
|
7480
|
-
|
|
7481
|
-
|
|
7521
|
+
const devices = await this.deps.usage.devicesUsing(id);
|
|
7522
|
+
const automations = await this.deps.automations?.using(id) ?? [];
|
|
7523
|
+
if (devices.length > 0 || automations.length > 0) {
|
|
7524
|
+
this.deps.logger.info("template: delete refused, something still uses it", { meta: {
|
|
7482
7525
|
id,
|
|
7483
|
-
devices:
|
|
7526
|
+
devices: devices.length,
|
|
7527
|
+
automations: automations.length
|
|
7484
7528
|
} });
|
|
7485
7529
|
return {
|
|
7486
7530
|
status: "in-use",
|
|
7487
|
-
devices: [
|
|
7531
|
+
devices: [...devices],
|
|
7532
|
+
automations: [...automations]
|
|
7488
7533
|
};
|
|
7489
7534
|
}
|
|
7490
7535
|
await this.deps.templates.delete(id);
|
|
@@ -7727,6 +7772,7 @@ function buildRemoteRuntime(deps) {
|
|
|
7727
7772
|
templates: new TemplatesService({
|
|
7728
7773
|
templates: templateRows,
|
|
7729
7774
|
usage: templateUsageOver(deps.settings, deps.api),
|
|
7775
|
+
...deps.automationInstances === void 0 ? {} : { automations: deps.automationInstances },
|
|
7730
7776
|
logger: deps.logger.child("templates")
|
|
7731
7777
|
}),
|
|
7732
7778
|
remote: new RemoteService({
|
|
@@ -7751,6 +7797,140 @@ function buildRemoteRuntime(deps) {
|
|
|
7751
7797
|
};
|
|
7752
7798
|
}
|
|
7753
7799
|
//#endregion
|
|
7800
|
+
//#region src/builtins/core-blocks/automation-template-instances.ts
|
|
7801
|
+
/**
|
|
7802
|
+
* The automations made from a template (#527), found and re-expanded where they
|
|
7803
|
+
* live: the core-block store. An instance is a block whose recipe literal links
|
|
7804
|
+
* to the template (`AutomationRecipe.template`) — there is no second list of
|
|
7805
|
+
* instances to keep in step with the blocks.
|
|
7806
|
+
*
|
|
7807
|
+
* When a template is saved, every instance is re-expanded with its stored
|
|
7808
|
+
* values through the same pure function the editor uses, and its code is
|
|
7809
|
+
* regenerated and saved through the ordinary block update (compile gate,
|
|
7810
|
+
* converge). An instance whose values no longer fit keeps its last good body
|
|
7811
|
+
* and is flagged on its link; it is never dropped and never left silent.
|
|
7812
|
+
*
|
|
7813
|
+
* A block whose code was edited outside the generator (its fingerprint no
|
|
7814
|
+
* longer matches `template.codeHash`) is never regenerated over: only its
|
|
7815
|
+
* literal is rewritten, to flag it `edited-by-hand`.
|
|
7816
|
+
*/
|
|
7817
|
+
var EDITED_BY_HAND_DETAIL = "the code was edited by hand, so the template no longer updates it; convert it to a free automation or create it again from the template";
|
|
7818
|
+
/** True when the block's code is still exactly what the generator wrote. */
|
|
7819
|
+
function isGeneratedCode(code, recipe) {
|
|
7820
|
+
const stamped = recipe.template?.codeHash;
|
|
7821
|
+
return stamped !== void 0 && require_dist.instanceCodeHash(code) === stamped;
|
|
7822
|
+
}
|
|
7823
|
+
/** The hand-edited block, flagged in its literal and otherwise byte for byte; null when already flagged. */
|
|
7824
|
+
function flaggedAsEdited(code, recipe) {
|
|
7825
|
+
const link = recipe.template;
|
|
7826
|
+
if (link === void 0) return null;
|
|
7827
|
+
if (link.problems?.some((p) => p.code === "edited-by-hand") === true) return null;
|
|
7828
|
+
return require_dist.replaceRecipeLiteral(code, {
|
|
7829
|
+
...recipe,
|
|
7830
|
+
template: {
|
|
7831
|
+
...link,
|
|
7832
|
+
problems: [{
|
|
7833
|
+
code: "edited-by-hand",
|
|
7834
|
+
detail: EDITED_BY_HAND_DETAIL
|
|
7835
|
+
}]
|
|
7836
|
+
}
|
|
7837
|
+
});
|
|
7838
|
+
}
|
|
7839
|
+
function errorText$1(error) {
|
|
7840
|
+
return error instanceof Error ? error.message : String(error);
|
|
7841
|
+
}
|
|
7842
|
+
function automationTemplateInstancesOver(deps) {
|
|
7843
|
+
const units = deps.units ?? require_dist.capUnitResolver(require_dist.ALL_CAPABILITY_DEFINITIONS);
|
|
7844
|
+
const instancesOf = (templateId) => deps.blocks().flatMap((block) => {
|
|
7845
|
+
const read = require_dist.readRecipeLiteral(block.code);
|
|
7846
|
+
if (read.status !== "recipe" || read.recipe.template?.templateId !== templateId) return [];
|
|
7847
|
+
return [{
|
|
7848
|
+
block,
|
|
7849
|
+
recipe: read.recipe
|
|
7850
|
+
}];
|
|
7851
|
+
});
|
|
7852
|
+
return {
|
|
7853
|
+
using: async (templateId) => instancesOf(templateId).map(({ block }) => ({
|
|
7854
|
+
blockId: block.id,
|
|
7855
|
+
name: block.name
|
|
7856
|
+
})),
|
|
7857
|
+
reexpand: async (templateId, payload) => {
|
|
7858
|
+
let updated = 0;
|
|
7859
|
+
let flagged = 0;
|
|
7860
|
+
let failed = 0;
|
|
7861
|
+
for (const { block, recipe } of instancesOf(templateId)) {
|
|
7862
|
+
if (!isGeneratedCode(block.code, recipe)) {
|
|
7863
|
+
const flaggedCode = flaggedAsEdited(block.code, recipe);
|
|
7864
|
+
if (flaggedCode === null) continue;
|
|
7865
|
+
try {
|
|
7866
|
+
await deps.saveCode(block.id, flaggedCode);
|
|
7867
|
+
} catch (error) {
|
|
7868
|
+
failed += 1;
|
|
7869
|
+
deps.logger.warn("automation template: a hand-edited instance could not be flagged", { meta: {
|
|
7870
|
+
templateId,
|
|
7871
|
+
blockId: block.id,
|
|
7872
|
+
error: errorText$1(error)
|
|
7873
|
+
} });
|
|
7874
|
+
continue;
|
|
7875
|
+
}
|
|
7876
|
+
flagged += 1;
|
|
7877
|
+
deps.logger.warn("automation template: an instance was edited by hand, it is flagged and not regenerated", { meta: {
|
|
7878
|
+
templateId,
|
|
7879
|
+
blockId: block.id
|
|
7880
|
+
} });
|
|
7881
|
+
continue;
|
|
7882
|
+
}
|
|
7883
|
+
const next = require_dist.reexpandAutomationInstance(payload, recipe);
|
|
7884
|
+
const prepared = require_dist.prepareRecipeUnits(next.recipe, units);
|
|
7885
|
+
if (!prepared.ok) {
|
|
7886
|
+
failed += 1;
|
|
7887
|
+
deps.logger.warn("automation template: an instance could not be prepared, left as it was", { meta: {
|
|
7888
|
+
templateId,
|
|
7889
|
+
blockId: block.id,
|
|
7890
|
+
error: prepared.error
|
|
7891
|
+
} });
|
|
7892
|
+
continue;
|
|
7893
|
+
}
|
|
7894
|
+
const code = require_dist.generateAutomationBlock({
|
|
7895
|
+
name: block.name,
|
|
7896
|
+
recipe: prepared.recipe
|
|
7897
|
+
});
|
|
7898
|
+
if (code === block.code) continue;
|
|
7899
|
+
try {
|
|
7900
|
+
await deps.saveCode(block.id, code);
|
|
7901
|
+
} catch (error) {
|
|
7902
|
+
failed += 1;
|
|
7903
|
+
deps.logger.warn("automation template: an instance could not be saved, left as it was", { meta: {
|
|
7904
|
+
templateId,
|
|
7905
|
+
blockId: block.id,
|
|
7906
|
+
error: errorText$1(error)
|
|
7907
|
+
} });
|
|
7908
|
+
continue;
|
|
7909
|
+
}
|
|
7910
|
+
if (next.flagged) {
|
|
7911
|
+
flagged += 1;
|
|
7912
|
+
deps.logger.warn("automation template: an instance no longer fits the template, its last body is kept and it is flagged", { meta: {
|
|
7913
|
+
templateId,
|
|
7914
|
+
blockId: block.id,
|
|
7915
|
+
problems: next.recipe.template?.problems?.map((p) => p.detail)
|
|
7916
|
+
} });
|
|
7917
|
+
} else updated += 1;
|
|
7918
|
+
}
|
|
7919
|
+
deps.logger.info("automation template: instances re-expanded", { meta: {
|
|
7920
|
+
templateId,
|
|
7921
|
+
updated,
|
|
7922
|
+
flagged,
|
|
7923
|
+
failed
|
|
7924
|
+
} });
|
|
7925
|
+
return {
|
|
7926
|
+
updated,
|
|
7927
|
+
flagged,
|
|
7928
|
+
failed
|
|
7929
|
+
};
|
|
7930
|
+
}
|
|
7931
|
+
};
|
|
7932
|
+
}
|
|
7933
|
+
//#endregion
|
|
7754
7934
|
//#region src/builtins/core-blocks/fan-presets-action-source.ts
|
|
7755
7935
|
/**
|
|
7756
7936
|
* Lists every fan preset as an `action-source` entry so the surfaces that
|
|
@@ -9201,6 +9381,7 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
|
|
|
9201
9381
|
});
|
|
9202
9382
|
armTimedRuns(timedRun, this.ctx.logger.child("timed-run"), { isDisposed: () => this.disposed });
|
|
9203
9383
|
this.transpiler = await loadTranspiler(this.ctx.logger);
|
|
9384
|
+
this.remoteRuntime?.templates.reexpandBuiltinInstances().catch((error) => this.ctx.logger.warn("automation templates: built-in instances were not re-expanded", { meta: { error: error instanceof Error ? error.message : String(error) } }));
|
|
9204
9385
|
armBlocksIntegration({
|
|
9205
9386
|
logger: this.ctx.logger,
|
|
9206
9387
|
reconcile: () => this.declareBlocksIntegration(),
|
|
@@ -9336,9 +9517,34 @@ var CoreBlocksAddon = class extends require_dist.BaseAddon {
|
|
|
9336
9517
|
settings,
|
|
9337
9518
|
api: () => this.ctx.api,
|
|
9338
9519
|
logger: this.ctx.logger,
|
|
9339
|
-
hasNative: (deviceId) => this.hasNativeMediaPlayer(deviceId)
|
|
9520
|
+
hasNative: (deviceId) => this.hasNativeMediaPlayer(deviceId),
|
|
9521
|
+
automationInstances: automationTemplateInstancesOver({
|
|
9522
|
+
blocks: () => this.requireStore().list(),
|
|
9523
|
+
saveCode: (blockId, code) => this.saveGeneratedCode(blockId, code),
|
|
9524
|
+
logger: this.ctx.logger.child("automation-templates")
|
|
9525
|
+
})
|
|
9340
9526
|
});
|
|
9341
9527
|
}
|
|
9528
|
+
/**
|
|
9529
|
+
* A regenerated automation (a template instance re-expanded, #527) saved the
|
|
9530
|
+
* way an operator's edit is: through the compile gate, then the store, then a
|
|
9531
|
+
* converge that restarts its runner.
|
|
9532
|
+
*/
|
|
9533
|
+
async saveGeneratedCode(blockId, code) {
|
|
9534
|
+
const existing = this.requireStore().get(blockId);
|
|
9535
|
+
if (existing === null) throw new Error(`core-blocks: no block "${blockId}"`);
|
|
9536
|
+
const write = existing.files === void 0 ? { code } : {
|
|
9537
|
+
code,
|
|
9538
|
+
files: {
|
|
9539
|
+
...existing.files,
|
|
9540
|
+
[require_dist.resolveCoreBlockEntry(existing.entry)]: code
|
|
9541
|
+
},
|
|
9542
|
+
entry: require_dist.resolveCoreBlockEntry(existing.entry)
|
|
9543
|
+
};
|
|
9544
|
+
await this.gate(write);
|
|
9545
|
+
await this.requireStore().update(blockId, write);
|
|
9546
|
+
this.convergeSoon();
|
|
9547
|
+
}
|
|
9342
9548
|
/** A driver's native media-player cap reads the device; the composer's own native holds no reading. */
|
|
9343
9549
|
hasNativeMediaPlayer(deviceId) {
|
|
9344
9550
|
const owner = this.ctx.kernel?.capabilityRegistry?.getNativeAddonId("media-player", deviceId);
|