@commonlyai/cli 0.1.248 → 0.1.250
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/package.json +1 -1
- package/src/commands/agent.js +56 -11
- package/src/lib/adapters/codex.js +7 -1
- package/src/lib/adapters/opencode.js +9 -2
- package/src/lib/daemon-supervisor.js +10 -2
- package/src/lib/environment.js +21 -3
- package/src/lib/native-runtime-inventory.js +1 -1
- package/src/lib/reply-receipt.js +2 -0
- package/src/lib/seat-runtime-controls.js +61 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
refuseWorkspaceTrust,
|
|
68
68
|
resolveWorkspace,
|
|
69
69
|
validateEnvironmentSpec,
|
|
70
|
+
providerRefusal,
|
|
70
71
|
WORKSPACE_SANDBOX_ALLOW,
|
|
71
72
|
} from '../lib/environment.js';
|
|
72
73
|
import { firstRunWorkspace, podIsConfirmedPrivate, workspaceTurnPlacement } from '../lib/workspace-trust.js';
|
|
@@ -137,6 +138,7 @@ import {
|
|
|
137
138
|
resolveCascadeSettings,
|
|
138
139
|
} from '../lib/enforcement.js';
|
|
139
140
|
import { buildReplyReceipt } from '../lib/reply-receipt.js';
|
|
141
|
+
import { savedRuntimeControls, withSavedRuntimeControls, effortRefusedByDevice } from '../lib/seat-runtime-controls.js';
|
|
140
142
|
|
|
141
143
|
const isPodFocusDiagnostic = (error) => (
|
|
142
144
|
typeof error?.code === 'string'
|
|
@@ -313,6 +315,8 @@ export const printAttachRunGuidance = ({
|
|
|
313
315
|
}
|
|
314
316
|
};
|
|
315
317
|
|
|
318
|
+
export { providerRefusal };
|
|
319
|
+
|
|
316
320
|
// ── `agent run --adapter` against an existing token file (#2098) ────────────
|
|
317
321
|
// The flag picks the CLI once, at first-run bootstrap; after that the token
|
|
318
322
|
// file's adapter is what runs. A different `--adapter` used to be dropped
|
|
@@ -1047,9 +1051,10 @@ export const updateAgentConfiguration = async ({
|
|
|
1047
1051
|
if (!environment && Object.keys(environmentRuntime).length) {
|
|
1048
1052
|
environment = { ...environmentRuntime };
|
|
1049
1053
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1054
|
+
{
|
|
1055
|
+
const refusal = providerRefusal(environment,
|
|
1056
|
+
adapterRegistry.getAdapter(String(runtime.adapter || record.adapter || '').trim().toLowerCase()));
|
|
1057
|
+
if (refusal) throw new Error(refusal);
|
|
1053
1058
|
}
|
|
1054
1059
|
if (environment) config.environment = environmentForServer(environment);
|
|
1055
1060
|
if (!Object.keys(config).length) {
|
|
@@ -1205,8 +1210,9 @@ export const performAttach = async ({
|
|
|
1205
1210
|
// An explicit spec augments the seat; it does not remove the Commonly
|
|
1206
1211
|
// kernel server. The daemon applies this same baseline before every spawn.
|
|
1207
1212
|
environment = withDefaultMcpServer(await parseEnvironmentFile(envPath), adapterName);
|
|
1208
|
-
|
|
1209
|
-
|
|
1213
|
+
{
|
|
1214
|
+
const refusal = providerRefusal(environment, adapter);
|
|
1215
|
+
if (refusal) throw new Error(refusal);
|
|
1210
1216
|
}
|
|
1211
1217
|
workspace = await resolveWorkspace(environment, agentName, dirname(envPath));
|
|
1212
1218
|
if (typeof adapter.validateEnvironment === 'function') {
|
|
@@ -1657,6 +1663,10 @@ export const performRun = ({
|
|
|
1657
1663
|
// The agent to @mention when the model provider refuses a request's content
|
|
1658
1664
|
// (lib/content-refusal.js). Null: the refusal notice names no one.
|
|
1659
1665
|
reportRuntime = false,
|
|
1666
|
+
// D247: a listener seat (no daemon) reads the model and effort its owner
|
|
1667
|
+
// saved on the server before each turn. Off for daemon seats, whose daemon
|
|
1668
|
+
// projects the same values into `environment`.
|
|
1669
|
+
readSavedControls = false,
|
|
1660
1670
|
resolveOwnProviderKey = null,
|
|
1661
1671
|
runtimeReportClient = null,
|
|
1662
1672
|
refusalHandoff = null,
|
|
@@ -1678,8 +1688,9 @@ export const performRun = ({
|
|
|
1678
1688
|
}) => {
|
|
1679
1689
|
const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
|
|
1680
1690
|
reportRuntime = reportRuntime && WALKED_HARNESSES.includes(adapter?.name);
|
|
1681
|
-
|
|
1682
|
-
|
|
1691
|
+
{
|
|
1692
|
+
const refusal = providerRefusal(environment, adapter);
|
|
1693
|
+
if (refusal) throw new Error(refusal);
|
|
1683
1694
|
}
|
|
1684
1695
|
const requestedTurnTimeout = Number(turnTimeoutMs ?? process.env.COMMONLY_AGENT_RUN_TIMEOUT_MS);
|
|
1685
1696
|
const effectiveTurnTimeoutMs = Number.isFinite(requestedTurnTimeout) && requestedTurnTimeout > 0
|
|
@@ -1759,6 +1770,7 @@ export const performRun = ({
|
|
|
1759
1770
|
const runtimeInventoryPromise = reportRuntime ? Promise.resolve(adapter.inventory?.()).then((value) => value || { models: null, efforts: [] })
|
|
1760
1771
|
.catch(() => ({ models: null, efforts: [] })) : Promise.resolve(null);
|
|
1761
1772
|
let seatEnvironment = requestedSeatEnvironment;
|
|
1773
|
+
let lastSavedControls = null;
|
|
1762
1774
|
// OpenCode retains tool-call IDs in its resumed history. A Gemini proxy
|
|
1763
1775
|
// marks those IDs with signature references, so changing providers must
|
|
1764
1776
|
// start a fresh session before another upstream can receive them.
|
|
@@ -1842,7 +1854,43 @@ export const performRun = ({
|
|
|
1842
1854
|
// a conversation that read the workspace, whatever claude's resume would
|
|
1843
1855
|
// find from another folder.
|
|
1844
1856
|
let lastPlacementReason = null;
|
|
1857
|
+
// D247: the model and effort this turn spawns with. A listener seat reads
|
|
1858
|
+
// its saved controls first; then an effort is dropped only when the device
|
|
1859
|
+
// listed its levels and this one is not among them.
|
|
1860
|
+
let savedControlsNoticeShown = false;
|
|
1861
|
+
const refreshSeatEnvironment = async () => {
|
|
1862
|
+
const inventory = await runtimeInventoryPromise;
|
|
1863
|
+
let desiredEnvironment = requestedSeatEnvironment;
|
|
1864
|
+
if (readSavedControls) {
|
|
1865
|
+
try {
|
|
1866
|
+
const identity = await client.get('/api/agents/runtime/installations', {}, {
|
|
1867
|
+
signal: AbortSignal.timeout(5000),
|
|
1868
|
+
});
|
|
1869
|
+
lastSavedControls = savedRuntimeControls({
|
|
1870
|
+
installations: identity?.installations, podId, instanceId,
|
|
1871
|
+
...(identity && 'runtimeSourcePodId' in identity ? { runtimeSourcePodId: identity.runtimeSourcePodId } : {}),
|
|
1872
|
+
});
|
|
1873
|
+
} catch { /* keep the last controls read; a failed read changes nothing */ }
|
|
1874
|
+
desiredEnvironment = withSavedRuntimeControls(requestedSeatEnvironment, lastSavedControls);
|
|
1875
|
+
// A record with no environment (from before attach wrote one) isn't
|
|
1876
|
+
// given one silently. `agent config` writes one to the record, and from
|
|
1877
|
+
// then on saved controls apply. Say so once, with the command.
|
|
1878
|
+
if (!requestedSeatEnvironment && lastSavedControls && !savedControlsNoticeShown) {
|
|
1879
|
+
savedControlsNoticeShown = true;
|
|
1880
|
+
const flag = (name, value) => (value && /^[A-Za-z0-9._:/-]+$/.test(value) ? ` --${name} ${value}` : '');
|
|
1881
|
+
const flags = `${flag('model', lastSavedControls.model)}${flag('effort', lastSavedControls.effort)}` || ' --model <model>';
|
|
1882
|
+
log(`${agentName} has no saved environment on this computer, so the model and effort saved in Commonly `
|
|
1883
|
+
+ `don't apply to it yet. Run once: commonly agent config ${agentName}${flags}`);
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
// Dropped only when the device listed its levels and this one is not
|
|
1887
|
+
// among them; with nothing reported the harness decides (D247).
|
|
1888
|
+
seatEnvironment = reportRuntime && desiredEnvironment
|
|
1889
|
+
&& effortRefusedByDevice(inventory, desiredEnvironment.effort)
|
|
1890
|
+
? { ...desiredEnvironment, effort: undefined } : desiredEnvironment;
|
|
1891
|
+
};
|
|
1845
1892
|
const placeTurn = async () => {
|
|
1893
|
+
await refreshSeatEnvironment();
|
|
1846
1894
|
if (seatEnvironment?.sandbox?.trust !== 'workspace') {
|
|
1847
1895
|
return { environment: seatEnvironment, cwd: agentCwd, binding: sessionBinding };
|
|
1848
1896
|
}
|
|
@@ -1873,10 +1921,6 @@ export const performRun = ({
|
|
|
1873
1921
|
const batchLimit = Math.min(50, Math.max(1, Number(inboxBatchLimit) || 10));
|
|
1874
1922
|
|
|
1875
1923
|
const processEvent = async (event) => {
|
|
1876
|
-
const inventory = await runtimeInventoryPromise;
|
|
1877
|
-
if (reportRuntime && requestedSeatEnvironment && !inventory?.efforts.includes(requestedSeatEnvironment.effort)) {
|
|
1878
|
-
seatEnvironment = { ...requestedSeatEnvironment, effort: undefined };
|
|
1879
|
-
}
|
|
1880
1924
|
const eventPodId = event.podId || podId;
|
|
1881
1925
|
const prompt = extractPrompt(event);
|
|
1882
1926
|
if (!prompt || !eventPodId) {
|
|
@@ -4445,6 +4489,7 @@ Docs:
|
|
|
4445
4489
|
resolveOwnProviderKey: createOwnKeyResolver({ instanceUrl: record.instanceUrl,
|
|
4446
4490
|
machineId: record.machineId, agentName: record.agentName, instanceId: record.instanceId }),
|
|
4447
4491
|
reportRuntime: Boolean(record.machineId || process.env.COMMONLY_MANAGED_RUNNER === '1'),
|
|
4492
|
+
readSavedControls: !record.machineId && process.env.COMMONLY_MANAGED_RUNNER !== '1',
|
|
4448
4493
|
spawnCredentialTtlSeconds: resolveSpawnTtlSeconds(process.env),
|
|
4449
4494
|
refusalHandoff: opts.refusalHandoff || null,
|
|
4450
4495
|
log: (line) => console.log(`${stamp()} [${name}] ${line}`),
|
|
@@ -968,7 +968,13 @@ export default {
|
|
|
968
968
|
// came in with > null. The wrapper persists whichever non-null value
|
|
969
969
|
// we return so subsequent turns hit `codex exec resume <id>`.
|
|
970
970
|
const newSessionId = threadId || ctx.sessionId || null;
|
|
971
|
-
|
|
971
|
+
// D247: the reply receipt names the model and effort this spawn passed
|
|
972
|
+
// (`--model`, `model_reasoning_effort`); codex's own stream does not
|
|
973
|
+
// restate them.
|
|
974
|
+
const effort = ctx.environment?.effort;
|
|
975
|
+
const stats = { ...(seatModel ? { model: String(seatModel) } : {}),
|
|
976
|
+
...(typeof effort === 'string' && effort ? { effort } : {}) };
|
|
977
|
+
return { text, newSessionId, ...(Object.keys(stats).length ? { stats } : {}) };
|
|
972
978
|
} finally {
|
|
973
979
|
try { await rm(dir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
974
980
|
}
|
|
@@ -283,11 +283,14 @@ const buildProviderConfig = (provider, model, keyFile) => {
|
|
|
283
283
|
} else if (typeof selectedModel.name !== 'string' || !selectedModel.name) {
|
|
284
284
|
models[model] = { ...selectedModel, name: model };
|
|
285
285
|
}
|
|
286
|
+
// anthropic-messages: provider.baseURL is the host (as for Claude Code's
|
|
287
|
+
// ANTHROPIC_BASE_URL); @ai-sdk/anthropic appends /messages to a /v1 base.
|
|
288
|
+
const anthropic = provider.api === 'anthropic-messages';
|
|
286
289
|
return {
|
|
287
290
|
[provider.id]: {
|
|
288
|
-
npm: '@ai-sdk/openai-compatible',
|
|
291
|
+
npm: anthropic ? '@ai-sdk/anthropic' : '@ai-sdk/openai-compatible',
|
|
289
292
|
options: {
|
|
290
|
-
baseURL: provider.baseURL,
|
|
293
|
+
baseURL: anthropic ? `${provider.baseURL.replace(/\/+$/, '')}/v1` : provider.baseURL,
|
|
291
294
|
apiKey: `{file:${keyFile}}`,
|
|
292
295
|
},
|
|
293
296
|
models,
|
|
@@ -652,6 +655,9 @@ export default {
|
|
|
652
655
|
name: 'opencode',
|
|
653
656
|
runtimeType: 'opencode',
|
|
654
657
|
supportsProvider: true,
|
|
658
|
+
// `provider.api`: an OpenAI-compatible endpoint, or Anthropic's Messages API
|
|
659
|
+
// through OpenCode's own @ai-sdk/anthropic provider.
|
|
660
|
+
providerApis: ['openai-chat', 'anthropic-messages'],
|
|
655
661
|
|
|
656
662
|
async validateEnvironment(environment, workspacePath) {
|
|
657
663
|
return validateProviderEnvironment(environment, workspacePath);
|
|
@@ -787,6 +793,7 @@ export default {
|
|
|
787
793
|
// the bearer only prevents unrelated local processes from using it.
|
|
788
794
|
providerProxy = await startProviderProxy({
|
|
789
795
|
provider,
|
|
796
|
+
wire: provider.api || 'openai-chat',
|
|
790
797
|
keyFile: providerKeyFile, keyMaterial: ctx.providerKey,
|
|
791
798
|
tokenFile: join(tempDir, 'provider-proxy-token'),
|
|
792
799
|
...(sandboxMode === 'bwrap' ? {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
import { seatBaseline } from './default-environment.js';
|
|
10
10
|
import { getAdapter } from './adapters/index.js';
|
|
11
|
+
import { providerRefusal } from './environment.js';
|
|
11
12
|
import { withholdGrantBroker } from './grant-broker-guard.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -316,8 +317,15 @@ export const createDaemonSupervisor = ({
|
|
|
316
317
|
nextAdapter = declaredAdapter;
|
|
317
318
|
adapterChanged = existing.adapter !== nextAdapter;
|
|
318
319
|
}
|
|
319
|
-
|
|
320
|
-
|
|
320
|
+
const providerRefused = existing.environment?.provider
|
|
321
|
+
? providerRefusal(existing.environment, getAdapter(nextAdapter)) : null;
|
|
322
|
+
if (providerRefused) {
|
|
323
|
+
// The record stays as it is, and the seat is not started: a retained
|
|
324
|
+
// adapter that needs a server binding (opencode) refuses to run under
|
|
325
|
+
// the server's new one, so starting it would only crash-loop. The
|
|
326
|
+
// owner sets the adapter back, or moves the provider to one it speaks.
|
|
327
|
+
log(`[${row.agentName}] host-local provider: ${providerRefused} — keeping the current record and not starting it; `
|
|
328
|
+
+ `set the adapter back to ${existing.adapter || 'the previous one'} in Commonly, or change the provider`);
|
|
321
329
|
return false;
|
|
322
330
|
}
|
|
323
331
|
if (wanted) {
|
package/src/lib/environment.js
CHANGED
|
@@ -193,6 +193,19 @@ export const environmentForServer = (environment) => {
|
|
|
193
193
|
|
|
194
194
|
// ── validateEnvironmentSpec ─────────────────────────────────────────────────
|
|
195
195
|
|
|
196
|
+
export const PROVIDER_APIS = Object.freeze(['openai-chat', 'anthropic-messages']);
|
|
197
|
+
|
|
198
|
+
// One provider check for config, attach, run and the daemon's adapter swap: the adapter must take a
|
|
199
|
+
// provider block at all, and speak its `provider.api` (default openai-chat).
|
|
200
|
+
export const providerRefusal = (environment, adapter) => {
|
|
201
|
+
if (environment?.provider === undefined) return null;
|
|
202
|
+
if (!adapter?.supportsProvider) return 'environment.provider requires a provider-capable adapter';
|
|
203
|
+
const api = environment.provider?.api || 'openai-chat';
|
|
204
|
+
const apis = adapter.providerApis || ['openai-chat'];
|
|
205
|
+
return apis.includes(api) ? null
|
|
206
|
+
: `the ${adapter.name} adapter cannot use provider.api "${api}"; it supports ${apis.join(', ')}`;
|
|
207
|
+
};
|
|
208
|
+
|
|
196
209
|
export const validateEnvironmentSpec = (spec) => {
|
|
197
210
|
const errors = [];
|
|
198
211
|
|
|
@@ -226,13 +239,18 @@ export const validateEnvironmentSpec = (spec) => {
|
|
|
226
239
|
if (!spec.provider || typeof spec.provider !== 'object' || Array.isArray(spec.provider)) {
|
|
227
240
|
errors.push('provider must be an object');
|
|
228
241
|
} else {
|
|
229
|
-
const allowedProviderKeys = new Set(['id', 'baseURL', 'keyFile', 'models']);
|
|
242
|
+
const allowedProviderKeys = new Set(['id', 'baseURL', 'keyFile', 'models', 'api']);
|
|
230
243
|
for (const key of Object.keys(spec.provider)) {
|
|
231
244
|
if (!allowedProviderKeys.has(key)) {
|
|
232
|
-
errors.push(`unknown provider key: ${JSON.stringify(key)} (allowed: id, baseURL, keyFile, models)`);
|
|
245
|
+
errors.push(`unknown provider key: ${JSON.stringify(key)} (allowed: id, baseURL, keyFile, models, api)`);
|
|
233
246
|
}
|
|
234
247
|
}
|
|
235
|
-
const { id, baseURL, keyFile, models } = spec.provider;
|
|
248
|
+
const { id, baseURL, keyFile, models, api } = spec.provider;
|
|
249
|
+
// The wire the provider speaks. Absent means openai-chat; whether the
|
|
250
|
+
// chosen adapter can speak it is the adapter's `providerApis`.
|
|
251
|
+
if (api !== undefined && !PROVIDER_APIS.includes(api)) {
|
|
252
|
+
errors.push(`provider.api must be one of ${PROVIDER_APIS.join(', ')}`);
|
|
253
|
+
}
|
|
236
254
|
if (typeof id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(id)) {
|
|
237
255
|
errors.push('provider.id must be a safe OpenCode provider id');
|
|
238
256
|
}
|
|
@@ -11,7 +11,7 @@ export const claudeEffortsFromHelp = (help) => {
|
|
|
11
11
|
};
|
|
12
12
|
export const codexModelsFromCache = (cache) => {
|
|
13
13
|
const models = Array.isArray(cache?.models) ? cache.models.filter((row) => typeof row.slug === 'string'
|
|
14
|
-
&& row.slug.length > 0 && row.slug.length <= 256 && row.visibility !== 'hidden') : [];
|
|
14
|
+
&& row.slug.length > 0 && row.slug.length <= 256 && row.visibility !== 'hidden' && row.visibility !== 'hide') : [];
|
|
15
15
|
const levels = models.map((row) => (Array.isArray(row.supported_reasoning_levels)
|
|
16
16
|
? row.supported_reasoning_levels.flatMap((level) => typeof level.effort === 'string' ? [level.effort] : []) : []));
|
|
17
17
|
return { models: models.length ? models.map((row) => row.slug) : null,
|
package/src/lib/reply-receipt.js
CHANGED
|
@@ -43,6 +43,8 @@ export const buildReplyReceipt = ({ adapterName, stats = {}, durationMs } = {})
|
|
|
43
43
|
// carries the account or project it runs in; that is not this reply's to
|
|
44
44
|
// publish, so such a model id is left out.
|
|
45
45
|
if (isName(stats?.model) && !/^arn:|(^|\/)projects\//i.test(stats.model)) receipt.model = stats.model;
|
|
46
|
+
// D247: the effort level the adapter passed, as a bare level name.
|
|
47
|
+
if (isName(stats?.effort) && /^[a-z0-9][a-z0-9._-]{0,19}$/i.test(stats.effort)) receipt.effort = stats.effort;
|
|
46
48
|
if (isCount(stats?.turns)) receipt.turns = stats.turns;
|
|
47
49
|
if (Array.isArray(stats?.tools)) {
|
|
48
50
|
const tools = stats.tools.filter(isName);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// D247: the model and effort a seat spawns with.
|
|
2
|
+
//
|
|
3
|
+
// Two rules live here so the run loop and its tests share them:
|
|
4
|
+
//
|
|
5
|
+
// 1. A listener seat (`agent run` with no daemon behind it) reads the model and
|
|
6
|
+
// effort its owner saved in Settings or on the add page from
|
|
7
|
+
// GET /api/agents/runtime/installations before each turn. A saved value
|
|
8
|
+
// replaces the one in the local record; an absent one leaves it alone, so an
|
|
9
|
+
// older server changes nothing.
|
|
10
|
+
// 2. An effort is dropped only when the device reported a NON-EMPTY list of
|
|
11
|
+
// levels that leaves it out. A device that reported nothing says nothing
|
|
12
|
+
// about the level, so the level is passed through and the harness decides.
|
|
13
|
+
|
|
14
|
+
const isControl = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256;
|
|
15
|
+
|
|
16
|
+
const controlsOf = (row) => {
|
|
17
|
+
const controls = {};
|
|
18
|
+
if (isControl(row.runtimeControls.model)) controls.model = row.runtimeControls.model;
|
|
19
|
+
if (isControl(row.runtimeControls.effort)) controls.effort = row.runtimeControls.effort;
|
|
20
|
+
return Object.keys(controls).length ? controls : null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The saved controls for this seat, or null when none are reported.
|
|
25
|
+
*
|
|
26
|
+
* A server that names `runtimeSourcePodId` (the installation Settings reads)
|
|
27
|
+
* is followed exactly: that row's controls, or null when it has none or the
|
|
28
|
+
* server names no source. An older server names none, and the seat reads its
|
|
29
|
+
* own pod's row, then any row of this instance that has controls.
|
|
30
|
+
*/
|
|
31
|
+
export const savedRuntimeControls = ({ installations, podId, instanceId, runtimeSourcePodId } = {}) => {
|
|
32
|
+
if (!Array.isArray(installations)) return null;
|
|
33
|
+
const rows = installations.filter((row) => row?.type === 'installation'
|
|
34
|
+
&& row.runtimeControls && typeof row.runtimeControls === 'object');
|
|
35
|
+
const wantedInstance = String(instanceId || 'default');
|
|
36
|
+
if (runtimeSourcePodId !== undefined) {
|
|
37
|
+
const source = runtimeSourcePodId === null ? null
|
|
38
|
+
: rows.find((entry) => String(entry.podId || '') === String(runtimeSourcePodId)
|
|
39
|
+
&& String(entry.instanceId || 'default') === wantedInstance);
|
|
40
|
+
return source ? controlsOf(source) : null;
|
|
41
|
+
}
|
|
42
|
+
// /installations returns runtimeControls on every row, `{}` when nothing is
|
|
43
|
+
// saved, so both matches require a value: an empty row in this pod must not
|
|
44
|
+
// hide the controls saved on the identity's other installation.
|
|
45
|
+
const hasControls = (entry) => isControl(entry.runtimeControls.model) || isControl(entry.runtimeControls.effort);
|
|
46
|
+
const row = rows.find((entry) => String(entry.podId || '') === String(podId || '')
|
|
47
|
+
&& String(entry.instanceId || 'default') === wantedInstance && hasControls(entry))
|
|
48
|
+
|| rows.find((entry) => String(entry.instanceId || 'default') === wantedInstance && hasControls(entry));
|
|
49
|
+
return row ? controlsOf(row) : null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** The environment with saved controls laid over it. A null environment stays null. */
|
|
53
|
+
export const withSavedRuntimeControls = (environment, controls) => {
|
|
54
|
+
if (!environment || typeof environment !== 'object' || !controls) return environment;
|
|
55
|
+
return { ...environment, ...controls };
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** True only when the device listed its effort levels and this one is not among them. */
|
|
59
|
+
export const effortRefusedByDevice = (inventory, effort) => Boolean(effort)
|
|
60
|
+
&& Array.isArray(inventory?.efforts) && inventory.efforts.length > 0
|
|
61
|
+
&& !inventory.efforts.includes(effort);
|