@tpsdev-ai/flair 0.62.0 → 0.63.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.
- package/README.md +14 -13
- package/SECURITY.md +73 -43
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +4 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +309 -205
- package/dist/commands/agent.js +325 -137
- package/dist/commands/attention.js +2 -0
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +5 -1
- package/dist/commands/bridge.js +10 -0
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +206 -42
- package/dist/commands/export.js +144 -15
- package/dist/commands/federation.js +653 -68
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/idp.js +14 -19
- package/dist/commands/import.js +167 -34
- package/dist/commands/init.js +380 -164
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/keys.js +12 -8
- package/dist/commands/mcp.js +157 -79
- package/dist/commands/memory.js +38 -17
- package/dist/commands/migrate-harness-memory.js +9 -3
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +32 -39
- package/dist/commands/quality.js +26 -3
- package/dist/commands/reembed.js +468 -111
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/search.js +2 -0
- package/dist/commands/service.js +109 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +165 -124
- package/dist/commands/test.js +4 -1
- package/dist/commands/upgrade.js +53 -22
- package/dist/commands/workspace.js +7 -8
- package/dist/deploy.js +59 -3
- package/dist/doctor-client.js +9 -25
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation/scheduler.js +148 -12
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +77 -10
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/agent-key-file.js +509 -0
- package/dist/lib/agent-rotation-lock.js +249 -0
- package/dist/lib/atomic-write.js +3 -3
- package/dist/lib/auth-resolve.js +1040 -64
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/daemon-liveness.js +2 -1
- package/dist/lib/federation-pair-access.js +4 -0
- package/dist/lib/federation-retry-queue.js +283 -0
- package/dist/lib/federation-retry-row.js +101 -0
- package/dist/lib/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/key-dir.js +203 -0
- package/dist/lib/launchd-management.js +21 -6
- package/dist/lib/local-instance-pair.js +8 -1
- package/dist/lib/mcp-enable.js +14 -15
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/node-alias-path.js +50 -2
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/remote-admin-pass.js +157 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/scheduler-platform.js +13 -0
- package/dist/lib/service-repoint.js +13 -4
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +125 -10
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/terminal-text.js +32 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +7 -14
- package/dist/memory-id-checkpoint.js +28 -7
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +302 -26
- package/dist/rem/runner.js +220 -58
- package/dist/rem/scheduler.js +21 -4
- package/dist/resources/A2AAdapter.js +131 -178
- package/dist/resources/AdminMemory.js +2 -0
- package/dist/resources/AdminMemoryCandidates.js +116 -0
- package/dist/resources/Agent.js +155 -45
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +56 -22
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +232 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -84
- package/dist/resources/Credential.js +6 -8
- package/dist/resources/Federation.js +219 -57
- package/dist/resources/FederationRetry.js +4 -4
- package/dist/resources/InstructionVersion.js +1 -1
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +1348 -271
- package/dist/resources/MemoryArchive.js +149 -64
- package/dist/resources/MemoryBootstrap.js +12 -22
- package/dist/resources/MemoryCandidate.js +16 -2
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryFeed.js +360 -147
- package/dist/resources/MemoryMaintenance.js +290 -72
- package/dist/resources/MemoryPurge.js +138 -22
- package/dist/resources/MemoryReflect.js +68 -14
- package/dist/resources/MemoryReindex.js +91 -13
- package/dist/resources/Message.js +11 -2
- package/dist/resources/OAuth.js +156 -39
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +292 -29
- package/dist/resources/OrgEventCatchup.js +7 -0
- package/dist/resources/OrgEventMaintenance.js +48 -10
- package/dist/resources/PairingToken.js +1 -1
- package/dist/resources/Presence.js +31 -11
- package/dist/resources/PromoteMemoryCandidate.js +8 -2
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Soul.js +2 -0
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/XAA.js +36 -10
- package/dist/resources/a2a-stream.js +313 -0
- package/dist/resources/a2a-url.js +4 -5
- package/dist/resources/agent-admin.js +10 -1
- package/dist/resources/agent-auth.js +98 -68
- package/dist/resources/agent-read-position-lib.js +4 -1
- package/dist/resources/agent-status-guard.js +9 -7
- package/dist/resources/auth-middleware.js +166 -42
- package/dist/resources/authority-field-guard.js +9 -11
- package/dist/resources/auto-promote-lib.js +8 -5
- package/dist/resources/basic-auth-header.js +21 -0
- package/dist/resources/bm25-index-service.js +4 -5
- package/dist/resources/dedup-cluster.js +6 -1
- package/dist/resources/embeddings-provider.js +25 -0
- package/dist/resources/federation-classify.js +89 -0
- package/dist/resources/federation-retry-lib.js +6 -81
- package/dist/resources/health.js +75 -19
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/in-process-api.js +74 -11
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instruction-version-record.js +251 -7
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/mcp-client-metadata-fields.js +4 -0
- package/dist/resources/mcp-handler.js +146 -13
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +446 -53
- package/dist/resources/mcp-tool-scopes.js +69 -0
- package/dist/resources/mcp-tools.js +70 -22
- package/dist/resources/memory-declared-attributes.js +1 -0
- package/dist/resources/memory-embed-hash.js +56 -0
- package/dist/resources/memory-host-source.js +5 -2
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-write-lock.js +202 -23
- package/dist/resources/memory-write-response.js +1 -1
- package/dist/resources/memory-write-transaction.js +243 -0
- package/dist/resources/migration-boot.js +17 -12
- package/dist/resources/migrations/boot-progress.js +25 -0
- package/dist/resources/migrations/data-dir.js +16 -3
- package/dist/resources/migrations/dir-safety.js +60 -2
- package/dist/resources/migrations/embedding-stamp.js +315 -49
- package/dist/resources/migrations/graph-heal.js +9 -2
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +867 -80
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +78 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +111 -70
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +12 -5
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/owner-field-guard.js +1 -1
- package/dist/resources/owner-scoped-write-policy.js +65 -21
- package/dist/resources/owner-scoped-writes.js +37 -6
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +124 -33
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/request-target.js +28 -1
- package/dist/resources/request-transaction.js +11 -1
- package/dist/resources/seed-reservation.js +1 -2
- package/dist/resources/semantic-retrieval-core.js +7 -6
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +4 -3
- package/dist/resources/skill-version-write.js +400 -27
- package/dist/resources/skill-write-fault.js +6 -3
- package/dist/resources/skill-write-policy.js +2 -1
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +1 -1
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/txn-pause-point.js +122 -5
- package/dist/resources/usage-recording.js +54 -46
- package/dist/resources/write-back.js +176 -11
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/keystore.js +77 -10
- package/dist/src/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +3 -3
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/key-dir.js +203 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/scheduler-platform.js +13 -0
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +39 -21
- package/docs/api-reference.md +161 -52
- package/docs/auth.md +69 -38
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +118 -2
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +23 -21
- package/docs/entity-vocabulary.md +7 -11
- package/docs/federation.md +29 -2
- package/docs/hosted-on-fabric.md +1 -1
- package/docs/integrations.md +11 -11
- package/docs/mcp-clients.md +7 -5
- package/docs/notes/mcp-agent-auth-consumer.md +4 -9
- package/docs/notes/mcp-oauth-model2.md +6 -6
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +3 -3
- package/docs/releasing.md +13 -13
- package/docs/rem.md +24 -3
- package/docs/secrets-and-keys.md +9 -14
- package/docs/standalone-local.md +29 -2
- package/docs/supply-chain-policy.md +28 -20
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +29 -5
- package/package.json +18 -11
- package/schemas/agent.graphql +3 -3
- package/schemas/federation.graphql +10 -7
- package/schemas/memory.graphql +7 -2
- package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
- package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
- package/dist/resources/soul-adk-guard.js +0 -68
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mqtt-off-deploy.ts — the component-deployment channel's MQTT-off step
|
|
3
|
+
* (`flair deploy`, `flair upgrade --target`; called by deploy() in
|
|
4
|
+
* src/deploy.ts).
|
|
5
|
+
*
|
|
6
|
+
* A component's config.yaml cannot set Harper's MQTT listeners off: `mqtt` is
|
|
7
|
+
* a section of the instance's ROOT configuration (config-root.schema.json),
|
|
8
|
+
* not of an application's (config-app.schema.json), and an application that
|
|
9
|
+
* lists `mqtt` only adds a handler of its own. Flair's local spawns set the
|
|
10
|
+
* root section through HARPER_SET_CONFIG and MQTT_* variables; a component
|
|
11
|
+
* deployment does not go through those spawns. So the channel sets the
|
|
12
|
+
* instance's `mqtt` section through the target's operations API, and requests
|
|
13
|
+
* the worker restart that applies it:
|
|
14
|
+
*
|
|
15
|
+
* 1. Before the deploy — applyMqttOffConfiguration: `set_configuration` with
|
|
16
|
+
* MQTT_DISABLED_SET_CONFIGURATION (`mqtt.network.port` and
|
|
17
|
+
* `mqtt.network.securePort` null, `mqtt.webSocket` false), sent with the
|
|
18
|
+
* deploy's Basic credential to the operations API URL the caller
|
|
19
|
+
* resolved, replicated to the cluster's nodes when the deploy is. The
|
|
20
|
+
* origin refusing it, or a node the replicated answer names as failed,
|
|
21
|
+
* stops the deploy before anything is deployed. A standalone instance (no
|
|
22
|
+
* replication) is set on its own.
|
|
23
|
+
*
|
|
24
|
+
* 2. After the deploy's restart — completeMqttOff. Harper applies a changed
|
|
25
|
+
* `mqtt` section when the HTTP worker threads that start the MQTT
|
|
26
|
+
* listeners restart. The deploy's own restart covers them, except for a
|
|
27
|
+
* fresh isolated deploy: when the root configuration marks the
|
|
28
|
+
* application `isolated` and Harper does not find it already active,
|
|
29
|
+
* Harper restarts only that application's dedicated worker
|
|
30
|
+
* (components/operations.js `restartScope`;
|
|
31
|
+
* server/threads/manageThreads.js `restartWorkers` skips the shared
|
|
32
|
+
* workers); for an application it finds already active it restarts every
|
|
33
|
+
* worker. The step cannot tell which happened, so it requests the shared
|
|
34
|
+
* workers' restart for every isolated application. This step:
|
|
35
|
+
* - reads the target's configuration through its operations API: an
|
|
36
|
+
* answer that is not a recognizable root configuration
|
|
37
|
+
* (rootConfigurationProblem) is reported as not confirmed, never as
|
|
38
|
+
* off, and the saved `mqtt` section must show the MQTT-off values
|
|
39
|
+
* (mqttOffConfirmed, mismatches by field name and category);
|
|
40
|
+
* - when the application is isolated, requests the shared worker
|
|
41
|
+
* threads' restart through `restart_service` (`scope: ""`, Harper's
|
|
42
|
+
* pool scope; replicated when the deploy is) and follows Harper's job:
|
|
43
|
+
* a job read that does not succeed is refused before its body is
|
|
44
|
+
* parsed, only Harper's exact completed-job message for the requested
|
|
45
|
+
* job id counts as completed (isCompletedJobMessage), and any other
|
|
46
|
+
* failure the job reports fails the step, with every node its result
|
|
47
|
+
* lists without Harper's completed-job message
|
|
48
|
+
* (reportedRestartFailure); nodes are judged as that result lists
|
|
49
|
+
* them, not compared with the nodes the configuration answer named.
|
|
50
|
+
* A completed job is not proof that
|
|
51
|
+
* a node's workers restarted: Harper sends a node's restart-complete
|
|
52
|
+
* from a `finally` (bin/restart.ts) and drops the worker
|
|
53
|
+
* replacement's outcome;
|
|
54
|
+
* - reports, and claims nothing else: "MQTT listeners configured off on
|
|
55
|
+
* <nodes>; shared workers restart requested (<job and per-node
|
|
56
|
+
* outcomes>); the saved configuration on <target ops host> reads off.
|
|
57
|
+
* Listeners stop when each node's workers restart; flair does not
|
|
58
|
+
* probe them. To confirm on a node, connect an MQTT client to its MQTT
|
|
59
|
+
* ports or WebSocket path."
|
|
60
|
+
*
|
|
61
|
+
* URLs: the deploy target and its operations API URL must be http or https
|
|
62
|
+
* URLs with a host, and nothing but scheme, host, port and path — any other
|
|
63
|
+
* scheme, a URL without a host, a user name, password, query or fragment is
|
|
64
|
+
* refused before anything is sent or printed (assertSafeUrl). Every URL these
|
|
65
|
+
* MQTT-off steps print goes through safeUrl, including the operations API URL it
|
|
66
|
+
* names for a cluster node (peerOpsUrl), which it builds only for a node name
|
|
67
|
+
* that is a valid host name or IP address. The operations API calls follow no
|
|
68
|
+
* redirect: a 3xx answer fails by its status.
|
|
69
|
+
*
|
|
70
|
+
* Output: the errors and progress lines of these steps quote a remote
|
|
71
|
+
* answer's HTTP status code, a restart job's id (only when it is a plain token)
|
|
72
|
+
* and state (only Harper's ERROR, PENDING or IN_PROGRESS), and cluster node
|
|
73
|
+
* names as its answers give them (only when they are valid host names or IP
|
|
74
|
+
* addresses); never its body, reason phrase, a job's message, a configuration
|
|
75
|
+
* value or a transport error's text. This covers only these steps: the Harper
|
|
76
|
+
* deploy between them (deploy() runs Harper's CLI) streams that child's output
|
|
77
|
+
* as it comes.
|
|
78
|
+
*/
|
|
79
|
+
import { isIP } from "node:net";
|
|
80
|
+
import { MQTT_DISABLED_SET_CONFIGURATION, mqttOffConfirmed, rootConfigurationProblem } from "./lib/mqtt-config.js";
|
|
81
|
+
/** The operations-API request that turns every MQTT listener off on a deploy target. */
|
|
82
|
+
export function buildMqttOffOperation(replicated) {
|
|
83
|
+
return {
|
|
84
|
+
operation: "set_configuration",
|
|
85
|
+
...MQTT_DISABLED_SET_CONFIGURATION,
|
|
86
|
+
...(replicated ? { replicated: true } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** The operations-API request that restarts the shared HTTP worker threads (Harper's pool scope). */
|
|
90
|
+
export function buildSharedWorkerRestartOperation(replicated) {
|
|
91
|
+
return {
|
|
92
|
+
operation: "restart_service",
|
|
93
|
+
service: "http_workers",
|
|
94
|
+
scope: "",
|
|
95
|
+
...(replicated ? { replicated: true } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a Harper instance without replication answers a `replicated: true`
|
|
100
|
+
* operation with (harper server/Server.ts, the default `server.replication`).
|
|
101
|
+
* Such a standalone instance is set or restarted on its own.
|
|
102
|
+
*/
|
|
103
|
+
export const REPLICATION_NOT_IMPLEMENTED = "Replication not implemented";
|
|
104
|
+
/**
|
|
105
|
+
* The message Harper's job runner gives a job that completed
|
|
106
|
+
* (server/jobs/jobProcess.ts: `'Successfully completed job: ' + JOB_ID`), and
|
|
107
|
+
* nothing else: exactly that text, then the job's id and nothing after it.
|
|
108
|
+
*/
|
|
109
|
+
const JOB_COMPLETED_PREFIX = "Successfully completed job: ";
|
|
110
|
+
/** A Harper job id as a cluster node's job record carries it: a plain token. */
|
|
111
|
+
const JOB_ID_TOKEN = /^[A-Za-z0-9._-]{1,64}$/;
|
|
112
|
+
/**
|
|
113
|
+
* Whether `message` is Harper's completed-job message: for the requested job,
|
|
114
|
+
* exactly `Successfully completed job: <jobId>`; for a cluster node's own job
|
|
115
|
+
* (whose id the origin does not know), that text followed by a plain-token id
|
|
116
|
+
* and nothing else.
|
|
117
|
+
*/
|
|
118
|
+
export function isCompletedJobMessage(message, jobId) {
|
|
119
|
+
if (typeof message !== "string" || !message.startsWith(JOB_COMPLETED_PREFIX))
|
|
120
|
+
return false;
|
|
121
|
+
const id = message.slice(JOB_COMPLETED_PREFIX.length);
|
|
122
|
+
return jobId !== undefined ? id === jobId : JOB_ID_TOKEN.test(id);
|
|
123
|
+
}
|
|
124
|
+
/** The closing sentences of every report: what flair does not do, and how to confirm. */
|
|
125
|
+
export const MQTT_OFF_REPORT_LIMIT = "Listeners stop when each node's workers restart; flair does not probe them. " +
|
|
126
|
+
"To confirm on a node, connect an MQTT client to its MQTT ports or WebSocket path.";
|
|
127
|
+
// ─── URLs: http or https with a host, and nothing but scheme, host, port and path ─
|
|
128
|
+
/**
|
|
129
|
+
* Why `url` may not be used (as the deploy target or its operations API URL),
|
|
130
|
+
* or null when it may: it must parse; its scheme must be http or https; it
|
|
131
|
+
* must name a host; and it may carry no user name or password, no query and no
|
|
132
|
+
* fragment. The deploy's credential goes in its Basic header, never in a URL.
|
|
133
|
+
*/
|
|
134
|
+
/**
|
|
135
|
+
* Whether the authority of `url` as written — after the scheme's colon and any
|
|
136
|
+
* slashes or backslashes, up to the next "/", "\\", "?", "#" or the end, with
|
|
137
|
+
* the tabs and newlines and the leading spaces and control characters the URL
|
|
138
|
+
* parser drops removed first — contains an "@". The parser normalizes an empty
|
|
139
|
+
* user name and password away (`https://@host`, `https://:@host`), so the
|
|
140
|
+
* parsed URL alone cannot show that one was given.
|
|
141
|
+
*/
|
|
142
|
+
function rawAuthorityHasUserinfo(url) {
|
|
143
|
+
const cleaned = url.replace(/[\t\n\r]/g, "").replace(/^[\u0000-\u0020]+/, "");
|
|
144
|
+
const match = /^[A-Za-z][A-Za-z0-9+.-]*:[\/\\]*([^\/\\?#]*)/.exec(cleaned);
|
|
145
|
+
return match !== null && match[1].includes("@");
|
|
146
|
+
}
|
|
147
|
+
export function unsafeUrlProblem(url) {
|
|
148
|
+
let parsed;
|
|
149
|
+
try {
|
|
150
|
+
parsed = new URL(url);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return "it is not a valid URL";
|
|
154
|
+
}
|
|
155
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
156
|
+
return "its scheme is not http or https";
|
|
157
|
+
if (rawAuthorityHasUserinfo(url))
|
|
158
|
+
return "it carries a user name or password";
|
|
159
|
+
// The URL parser already refuses an http or https URL without a host
|
|
160
|
+
// ("it is not a valid URL" above); this keeps the rule explicit here.
|
|
161
|
+
if (!parsed.hostname)
|
|
162
|
+
return "it names no host";
|
|
163
|
+
if (parsed.username || parsed.password)
|
|
164
|
+
return "it carries a user name or password";
|
|
165
|
+
if (parsed.search || url.includes("?"))
|
|
166
|
+
return "it carries a query";
|
|
167
|
+
if (parsed.hash || url.includes("#"))
|
|
168
|
+
return "it carries a fragment";
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `url` as flair prints it: scheme, host, port and path only — never a user
|
|
173
|
+
* name, password, query or fragment — and only for an http or https URL with a
|
|
174
|
+
* host; any other URL is printed as a placeholder. Every URL the deploy
|
|
175
|
+
* channel prints goes through this.
|
|
176
|
+
*/
|
|
177
|
+
export function safeUrl(url) {
|
|
178
|
+
let parsed;
|
|
179
|
+
try {
|
|
180
|
+
parsed = new URL(url);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return "(an unparseable URL)";
|
|
184
|
+
}
|
|
185
|
+
if ((parsed.protocol !== "http:" && parsed.protocol !== "https:") || !parsed.hostname)
|
|
186
|
+
return "(a URL that is not http or https with a host)";
|
|
187
|
+
const path = parsed.pathname === "/" ? "" : parsed.pathname;
|
|
188
|
+
return `${parsed.protocol}//${parsed.host}${path}`;
|
|
189
|
+
}
|
|
190
|
+
/** Throw, before anything is sent or printed, when `url` may not be used; `label` names it. */
|
|
191
|
+
export function assertSafeUrl(url, label) {
|
|
192
|
+
const problem = unsafeUrlProblem(url);
|
|
193
|
+
if (problem) {
|
|
194
|
+
throw new Error(`flair deploy: the ${label} ${safeUrl(url)} cannot be used: ${problem}. Nothing was sent. ` +
|
|
195
|
+
`Give it as an http or https URL with a host: scheme, host, port and path only, and pass the credential with FABRIC_USER / FABRIC_PASSWORD (or --fabric-user / --fabric-password-file).`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The refusal a CLI prints, before anything else, when a URL the deploy
|
|
200
|
+
* channel would use may not be used; null when every one may. `urls` pairs
|
|
201
|
+
* each URL (absent ones are skipped) with how the refusal names it; the
|
|
202
|
+
* message shows the URL only through safeUrl.
|
|
203
|
+
*/
|
|
204
|
+
export function deployUrlRefusal(urls) {
|
|
205
|
+
for (const [url, label] of urls) {
|
|
206
|
+
if (url === undefined || url === "")
|
|
207
|
+
continue;
|
|
208
|
+
try {
|
|
209
|
+
assertSafeUrl(url, label);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
return err.message;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
// ─── What a remote answered, as printed: never its text ─────────────────────
|
|
218
|
+
/** An HTTP answer as printed: its status code only, never its body or reason phrase. */
|
|
219
|
+
function httpAnswer(status) {
|
|
220
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? `HTTP ${status}` : "an HTTP answer without a valid status";
|
|
221
|
+
}
|
|
222
|
+
/** A transport failure as printed: a fixed message, with the error's code when it is a plain identifier. */
|
|
223
|
+
function transportFailure(err) {
|
|
224
|
+
const code = err?.code ?? err?.name;
|
|
225
|
+
return typeof code === "string" && /^[A-Za-z][A-Za-z0-9_]{0,40}$/.test(code) ? `the request failed (${code})` : "the request failed";
|
|
226
|
+
}
|
|
227
|
+
/** One DNS label (RFC 1123): letters, digits and inner hyphens, 1 to 63 characters. */
|
|
228
|
+
const HOST_LABEL = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/;
|
|
229
|
+
/**
|
|
230
|
+
* Whether `value` is a valid host name (dot-separated RFC 1123 labels, at most
|
|
231
|
+
* 253 characters) or an IP address (node:net isIP; an IPv6 address is given
|
|
232
|
+
* without brackets). Anything else — a port suffix, a path, an empty label,
|
|
233
|
+
* a lone ":" — is not.
|
|
234
|
+
*/
|
|
235
|
+
export function isNodeHost(value) {
|
|
236
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 253)
|
|
237
|
+
return false;
|
|
238
|
+
if (isIP(value) !== 0)
|
|
239
|
+
return true;
|
|
240
|
+
return value.split(".").every((label) => HOST_LABEL.test(label));
|
|
241
|
+
}
|
|
242
|
+
/** A cluster node's name as printed: a valid host name or IP address, else a fixed placeholder. */
|
|
243
|
+
function nodeName(value) {
|
|
244
|
+
return isNodeHost(value) ? value : "(a node whose name is not a host name or address)";
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The operations API URL of cluster node `node`, assuming the target's
|
|
248
|
+
* operations scheme and port, printed through safeUrl. A fixed phrase instead
|
|
249
|
+
* when the node name is not a valid host name or IP address, or when the
|
|
250
|
+
* operations URL has a path.
|
|
251
|
+
*/
|
|
252
|
+
export function peerOpsUrl(opsUrl, node) {
|
|
253
|
+
if (!isNodeHost(node))
|
|
254
|
+
return "that node's operations API";
|
|
255
|
+
try {
|
|
256
|
+
const parsed = new URL(opsUrl);
|
|
257
|
+
// A node's address is built from the scheme and port only; an operations
|
|
258
|
+
// URL with a path would lose it, so none is built.
|
|
259
|
+
if (parsed.pathname !== "/" && parsed.pathname !== "")
|
|
260
|
+
return "that node's operations API";
|
|
261
|
+
const host = isIP(node) === 6 ? `[${node}]` : node;
|
|
262
|
+
return safeUrl(`${parsed.protocol}//${host}${parsed.port ? `:${parsed.port}` : ""}`);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return "that node's operations API";
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** A Harper job id as printed: a plain token, else a fixed placeholder. */
|
|
269
|
+
function jobIdText(value) {
|
|
270
|
+
return typeof value === "string" && /^[A-Za-z0-9._-]{1,64}$/.test(value) ? value : "(an id that is not a plain token)";
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* POST one operation to the endpoint's root, as flair's other ops calls do.
|
|
274
|
+
* A redirect is not followed: its 3xx answer is returned as not ok, and its
|
|
275
|
+
* location receives nothing. Throws on a transport failure.
|
|
276
|
+
*/
|
|
277
|
+
async function postOperation(t, body) {
|
|
278
|
+
assertSafeUrl(t.url, "operations API URL");
|
|
279
|
+
const fetchImpl = t.fetchImpl ?? globalThis.fetch;
|
|
280
|
+
const auth = Buffer.from(`${t.fabricUser}:${t.fabricPassword}`).toString("base64");
|
|
281
|
+
const res = await fetchImpl(`${t.url.replace(/\/+$/, "")}/`, {
|
|
282
|
+
method: "POST",
|
|
283
|
+
headers: { "Content-Type": "application/json", Authorization: `Basic ${auth}` },
|
|
284
|
+
body: JSON.stringify(body),
|
|
285
|
+
signal: AbortSignal.timeout(t.timeoutMs ?? 60_000),
|
|
286
|
+
redirect: "manual",
|
|
287
|
+
});
|
|
288
|
+
const redirected = res.status >= 300 && res.status < 400;
|
|
289
|
+
return { status: res.status, ok: res.ok && !redirected, text: redirected ? "" : await res.text().catch(() => "") };
|
|
290
|
+
}
|
|
291
|
+
/** The entries of a replicated answer (Harper's per-node results), or [] when it lists none. */
|
|
292
|
+
function replicatedEntries(answer) {
|
|
293
|
+
const peers = answer?.replicated;
|
|
294
|
+
return Array.isArray(peers) ? peers.filter((p) => !!p && typeof p === "object") : [];
|
|
295
|
+
}
|
|
296
|
+
function entryName(p) {
|
|
297
|
+
return nodeName(p.node ?? p.name ?? p.hostname);
|
|
298
|
+
}
|
|
299
|
+
/** A node in a replicated answer that reports a failure (Harper's peer-result shapes). */
|
|
300
|
+
export function failedPeerNodes(answer) {
|
|
301
|
+
const failed = [];
|
|
302
|
+
for (const p of replicatedEntries(answer)) {
|
|
303
|
+
const error = p.error ?? (p.status === "failed" ? p.reason : undefined);
|
|
304
|
+
if ((error != null && error !== "") || p.status === "failed")
|
|
305
|
+
failed.push(entryName(p));
|
|
306
|
+
}
|
|
307
|
+
return failed;
|
|
308
|
+
}
|
|
309
|
+
/** The nodes a replicated answer names (failed or not). */
|
|
310
|
+
export function replicatedNodes(answer) {
|
|
311
|
+
return replicatedEntries(answer).map(entryName);
|
|
312
|
+
}
|
|
313
|
+
function parseJson(text) {
|
|
314
|
+
try {
|
|
315
|
+
return text ? JSON.parse(text) : null;
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** The operations API URL's host as the report names it (host and port). */
|
|
322
|
+
function opsHost(opsUrl) {
|
|
323
|
+
try {
|
|
324
|
+
return new URL(opsUrl).host;
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
return safeUrl(opsUrl);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Step 1: send the MQTT-off configuration to the operations API at `url`.
|
|
332
|
+
* Throws, naming the endpoint and the HTTP status (never the answer's text),
|
|
333
|
+
* when the origin does not accept it, and naming every node the replicated
|
|
334
|
+
* answer reports as failed, with the request to send to each; nothing has been
|
|
335
|
+
* deployed when it throws. Answers the cluster nodes the replicated answer
|
|
336
|
+
* names.
|
|
337
|
+
*/
|
|
338
|
+
export async function applyMqttOffConfiguration(o) {
|
|
339
|
+
assertSafeUrl(o.url, "operations API URL");
|
|
340
|
+
const shown = safeUrl(o.url);
|
|
341
|
+
const send = async (replicated) => {
|
|
342
|
+
try {
|
|
343
|
+
return await postOperation(o, buildMqttOffOperation(replicated));
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
throw new Error(`flair deploy: could not send the MQTT-off configuration to ${shown} (${transportFailure(err)}), so nothing was deployed. ` +
|
|
347
|
+
`Check that the target's operations API is reachable (--ops-target / FLAIR_OPS_TARGET name it), or pass --keep-mqtt-config to deploy without changing its MQTT configuration.`);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
let replicated = o.replicated;
|
|
351
|
+
let answer = await send(replicated);
|
|
352
|
+
if (!answer.ok && replicated && answer.text.includes(REPLICATION_NOT_IMPLEMENTED)) {
|
|
353
|
+
// A standalone instance: it has no cluster nodes to reach.
|
|
354
|
+
o.onProgress?.(`${shown} has no replication; setting MQTT off on that instance alone`);
|
|
355
|
+
replicated = false;
|
|
356
|
+
answer = await send(false);
|
|
357
|
+
}
|
|
358
|
+
if (!answer.ok) {
|
|
359
|
+
throw new Error(`flair deploy: ${shown} refused the MQTT-off configuration (${httpAnswer(answer.status)}), so nothing was deployed. ` +
|
|
360
|
+
`Fix the cause, or pass --keep-mqtt-config to deploy without changing the target's MQTT configuration.`);
|
|
361
|
+
}
|
|
362
|
+
const parsed = parseJson(answer.text);
|
|
363
|
+
const failed = failedPeerNodes(parsed);
|
|
364
|
+
if (failed.length > 0) {
|
|
365
|
+
throw new Error(`flair deploy: the MQTT-off configuration did not reach ${failed.join(", ")}, so nothing was deployed. ` +
|
|
366
|
+
`Re-run the deploy once ${failed.length === 1 ? "that node is" : "those nodes are"} reachable, or send ` +
|
|
367
|
+
`${JSON.stringify(buildMqttOffOperation(false))} (Basic admin credential) to ${failed.map((n) => peerOpsUrl(o.url, n)).join(", ")} and restart ${failed.length === 1 ? "its" : "their"} worker threads, ` +
|
|
368
|
+
`or pass --keep-mqtt-config to deploy without changing the target's MQTT configuration.`);
|
|
369
|
+
}
|
|
370
|
+
// Step 1 accepts an answer without a node list (the origin's own answer still
|
|
371
|
+
// confirms the write); our replicated restart-job check rejects a result
|
|
372
|
+
// without a node-list array. Add the cluster phrase only when the answer
|
|
373
|
+
// lists nodes, so this line and the final report agree on whether the
|
|
374
|
+
// answer listed cluster nodes.
|
|
375
|
+
const peers = replicated ? replicatedNodes(parsed) : [];
|
|
376
|
+
o.onProgress?.(`MQTT listeners set off in the configuration of ${shown}${peers.length > 0 ? " and its cluster nodes" : ""}`);
|
|
377
|
+
return { peers };
|
|
378
|
+
}
|
|
379
|
+
/** The restart an operator sends when the channel's own restart request failed or was not made. */
|
|
380
|
+
export function sharedWorkerRestartInstruction(opsUrl) {
|
|
381
|
+
return `send ${JSON.stringify(buildSharedWorkerRestartOperation(false))} to ${safeUrl(opsUrl)} (Basic admin credential)`;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Why a finished restart job reports a failure, or null when it reports none.
|
|
385
|
+
* A completed restart job is not proof of a node's restart: Harper sends a
|
|
386
|
+
* node's restart-complete from a `finally` and does not carry the worker
|
|
387
|
+
* replacement's outcome, so this catches only the failures Harper reports — a
|
|
388
|
+
* job that did not complete, a completion message that is not exactly
|
|
389
|
+
* Harper's for `jobId` (isCompletedJobMessage), a replicated result without
|
|
390
|
+
* its node list, and a node recorded without Harper's completed-job message
|
|
391
|
+
* (each named). It never echoes the job's text.
|
|
392
|
+
*/
|
|
393
|
+
export function reportedRestartFailure(job, replicated, jobId) {
|
|
394
|
+
if (job.status !== "COMPLETE") {
|
|
395
|
+
const status = job.status === "ERROR" || job.status === "PENDING" || job.status === "IN_PROGRESS" ? job.status : "with an unrecognized status";
|
|
396
|
+
return `the job ended ${status}`;
|
|
397
|
+
}
|
|
398
|
+
if (!isCompletedJobMessage(job.message, jobId)) {
|
|
399
|
+
return "the job completed with a message other than Harper's completed-job message for this job";
|
|
400
|
+
}
|
|
401
|
+
if (!replicated)
|
|
402
|
+
return null;
|
|
403
|
+
const nodes = job.result?.replicated;
|
|
404
|
+
if (!Array.isArray(nodes))
|
|
405
|
+
return "the replicated job's result lists no cluster nodes";
|
|
406
|
+
const failed = restartFailedNodes(job);
|
|
407
|
+
return failed.length ? `the job records these nodes without Harper's completed-job message: ${failed.join(", ")}` : null;
|
|
408
|
+
}
|
|
409
|
+
/** The cluster nodes a replicated restart job's result lists without Harper's completed-job message, as printed. */
|
|
410
|
+
function restartFailedNodes(job) {
|
|
411
|
+
const nodes = job.result?.replicated;
|
|
412
|
+
if (!Array.isArray(nodes))
|
|
413
|
+
return [];
|
|
414
|
+
const failed = [];
|
|
415
|
+
for (const entry of nodes) {
|
|
416
|
+
const e = (entry ?? {});
|
|
417
|
+
if (!isCompletedJobMessage(e.message))
|
|
418
|
+
failed.push(nodeName(e.node));
|
|
419
|
+
}
|
|
420
|
+
return failed;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Request the shared HTTP worker threads' restart through `restart_service`
|
|
424
|
+
* (pool scope), replicated when asked, and wait for Harper's job. The answer
|
|
425
|
+
* must carry a job id, and the finished job must report no failure
|
|
426
|
+
* (reportedRestartFailure) — which is not proof that a node's workers
|
|
427
|
+
* restarted. A standalone instance (no replication) is restarted on its own.
|
|
428
|
+
* Throws naming the reported failure and every node the job names as failed;
|
|
429
|
+
* answers the job id and the per-node outcomes.
|
|
430
|
+
*/
|
|
431
|
+
export async function restartSharedWorkers(o) {
|
|
432
|
+
const shown = safeUrl(o.url);
|
|
433
|
+
const run = async (replicated) => {
|
|
434
|
+
let started;
|
|
435
|
+
try {
|
|
436
|
+
started = await postOperation(o, buildSharedWorkerRestartOperation(replicated));
|
|
437
|
+
}
|
|
438
|
+
catch (err) {
|
|
439
|
+
return { kind: "failed", message: transportFailure(err) };
|
|
440
|
+
}
|
|
441
|
+
if (!started.ok) {
|
|
442
|
+
return { kind: "failed", message: httpAnswer(started.status), standalone: replicated && started.text.includes(REPLICATION_NOT_IMPLEMENTED) };
|
|
443
|
+
}
|
|
444
|
+
const jobId = parseJson(started.text)?.job_id;
|
|
445
|
+
if (typeof jobId !== "string" || jobId.length === 0) {
|
|
446
|
+
return { kind: "failed", message: "the restart was answered without a job id, so its outcome cannot be followed" };
|
|
447
|
+
}
|
|
448
|
+
const deadline = Date.now() + (o.jobTimeoutMs ?? 600_000);
|
|
449
|
+
while (Date.now() < deadline) {
|
|
450
|
+
let job;
|
|
451
|
+
try {
|
|
452
|
+
job = await postOperation(o, { operation: "get_job", id: jobId });
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
return { kind: "failed", message: transportFailure(err) };
|
|
456
|
+
}
|
|
457
|
+
// A job read that did not succeed establishes nothing about the job: it
|
|
458
|
+
// is refused before its body is parsed, whatever the body says.
|
|
459
|
+
if (!job.ok)
|
|
460
|
+
return { kind: "failed", message: `the job's status read was answered ${httpAnswer(job.status)}` };
|
|
461
|
+
const rows = parseJson(job.text);
|
|
462
|
+
const row = (Array.isArray(rows) ? rows[0] : rows);
|
|
463
|
+
if (row?.status === "COMPLETE" || row?.status === "ERROR") {
|
|
464
|
+
const problem = reportedRestartFailure(row, replicated, jobId);
|
|
465
|
+
if (problem) {
|
|
466
|
+
return {
|
|
467
|
+
kind: "failed",
|
|
468
|
+
message: problem,
|
|
469
|
+
standalone: replicated && typeof row.message === "string" && row.message.includes(REPLICATION_NOT_IMPLEMENTED),
|
|
470
|
+
failedNodes: replicated ? restartFailedNodes(row) : [],
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return { kind: "done", jobId, nodes: replicated ? replicatedNodes(row.result) : [] };
|
|
474
|
+
}
|
|
475
|
+
await new Promise((r) => setTimeout(r, o.pollIntervalMs ?? 500));
|
|
476
|
+
}
|
|
477
|
+
return { kind: "failed", message: "the restart job did not finish in time" };
|
|
478
|
+
};
|
|
479
|
+
o.onProgress?.(`requesting a restart of the shared HTTP worker threads of ${shown}${o.replicated ? " and its cluster nodes" : ""} (they start the MQTT listeners)`);
|
|
480
|
+
let outcome = await run(o.replicated);
|
|
481
|
+
if (outcome.kind === "failed" && o.replicated && outcome.standalone) {
|
|
482
|
+
o.onProgress?.(`${shown} has no replication; requesting the restart of that instance's shared workers alone`);
|
|
483
|
+
outcome = await run(false);
|
|
484
|
+
}
|
|
485
|
+
if (outcome.kind === "failed") {
|
|
486
|
+
const peers = (outcome.failedNodes ?? []).map((n) => peerOpsUrl(o.url, n));
|
|
487
|
+
throw new Error(`flair deploy: the restart of the shared worker threads of ${shown} failed (${outcome.message}). The MQTT-off configuration is set, and the listeners' live state is unconfirmed: ` +
|
|
488
|
+
`unless the deploy's own restart covered the shared workers (Harper restarts every worker only for an application it finds already active), workers that have not restarted may still serve their previous listener configuration. ` +
|
|
489
|
+
`Deployed; ${sharedWorkerRestartInstruction(o.url)}${peers.length ? `, and the same request to ${peers.join(", ")}` : ""}.`);
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
jobId: jobIdText(outcome.jobId),
|
|
493
|
+
outcomes: [`${opsHost(o.url)} completed`, ...outcome.nodes.map((n) => `${n} completed`)],
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Step 2: after the deploy's restart, read the target's configuration, request
|
|
498
|
+
* the shared worker threads' restart when the application is isolated, and
|
|
499
|
+
* answer the report (see this module's header). Throws — after the deploy,
|
|
500
|
+
* naming the restart to send — when the configuration cannot be read, the
|
|
501
|
+
* answer is not a recognizable root configuration (not confirmed, never taken
|
|
502
|
+
* for off), its `mqtt` section does not show the MQTT-off values (by field
|
|
503
|
+
* name and category), or the restart request fails.
|
|
504
|
+
*/
|
|
505
|
+
export async function completeMqttOff(o) {
|
|
506
|
+
assertSafeUrl(o.url, "operations API URL");
|
|
507
|
+
const shown = safeUrl(o.url);
|
|
508
|
+
let configuration;
|
|
509
|
+
let readProblem = null;
|
|
510
|
+
try {
|
|
511
|
+
const read = await postOperation(o, { operation: "get_configuration" });
|
|
512
|
+
if (!read.ok)
|
|
513
|
+
readProblem = httpAnswer(read.status);
|
|
514
|
+
else
|
|
515
|
+
configuration = parseJson(read.text);
|
|
516
|
+
}
|
|
517
|
+
catch (err) {
|
|
518
|
+
readProblem = transportFailure(err);
|
|
519
|
+
}
|
|
520
|
+
if (readProblem) {
|
|
521
|
+
throw new Error(`flair deploy: could not read the configuration of ${shown} after the deploy (${readProblem}), so the MQTT-off configuration is not confirmed there. ` +
|
|
522
|
+
`Deployed; read its mqtt section with get_configuration, and ${sharedWorkerRestartInstruction(o.url)} so the listeners stop.`);
|
|
523
|
+
}
|
|
524
|
+
const notRoot = rootConfigurationProblem(configuration);
|
|
525
|
+
if (notRoot) {
|
|
526
|
+
throw new Error(`flair deploy: the configuration answer of ${shown} is not a recognizable root configuration (${notRoot}), so the MQTT-off configuration is not confirmed there. ` +
|
|
527
|
+
`Deployed; read its mqtt section with get_configuration, and ${sharedWorkerRestartInstruction(o.url)} so the listeners stop.`);
|
|
528
|
+
}
|
|
529
|
+
const notOff = mqttOffConfirmed(configuration);
|
|
530
|
+
if (notOff) {
|
|
531
|
+
throw new Error(`flair deploy: the saved configuration on ${shown} does not read off: ${notOff}. ` +
|
|
532
|
+
`Deployed; send ${JSON.stringify(buildMqttOffOperation(false))} to ${shown}, then ${sharedWorkerRestartInstruction(o.url)}.`);
|
|
533
|
+
}
|
|
534
|
+
const entry = configuration[o.project];
|
|
535
|
+
const isolated = entry !== null && typeof entry === "object" && entry.isolated === true;
|
|
536
|
+
let restartPart;
|
|
537
|
+
if (isolated) {
|
|
538
|
+
o.onProgress?.(`${o.project} is an isolated application on ${shown}: unless Harper found it already active, the deploy's restart covered only its own worker`);
|
|
539
|
+
const restart = await restartSharedWorkers({ ...o, onProgress: o.onProgress });
|
|
540
|
+
restartPart = `job ${restart.jobId}: ${restart.outcomes.join(", ")}`;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
restartPart = "with the deploy's own restart";
|
|
544
|
+
}
|
|
545
|
+
const nodes = [opsHost(o.url), ...(o.peers ?? [])];
|
|
546
|
+
const report = `MQTT listeners configured off on ${nodes.join(", ")}; shared workers restart requested (${restartPart}); ` +
|
|
547
|
+
`the saved configuration on ${opsHost(o.url)} reads off. ${MQTT_OFF_REPORT_LIMIT}`;
|
|
548
|
+
o.onProgress?.(report);
|
|
549
|
+
return { report };
|
|
550
|
+
}
|
|
@@ -207,9 +207,9 @@ export function validateHumanReviewerId(reviewerId) {
|
|
|
207
207
|
// lives server-side in resources/auto-promote-lib.ts (decideAutoPromote — the
|
|
208
208
|
// UNATTENDED path), which IMPORTS these from here. The direction is deliberate
|
|
209
209
|
// and established in this repo: a server file may import a PURE helper from src/
|
|
210
|
-
// (resources/PromoteMemoryCandidate.ts
|
|
211
|
-
//
|
|
212
|
-
//
|
|
210
|
+
// (resources/PromoteMemoryCandidate.ts already imports this very module); it is
|
|
211
|
+
// a CLI file importing FROM resources/ that does not survive npm packaging.
|
|
212
|
+
// Defining it here lets the CLI side
|
|
213
213
|
// (src/commands/rem.ts, `flair rem candidates`) and the server gate share ONE
|
|
214
214
|
// implementation rather than a hand-kept pair.
|
|
215
215
|
//
|