@camstack/addon-terminal 0.1.31 → 0.1.32
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/dist/addon.js +473 -363
- package/dist/addon.mjs +473 -363
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -8119,6 +8119,15 @@ var LabelDefinitionSchema = object({
|
|
|
8119
8119
|
description: string().optional(),
|
|
8120
8120
|
icon: string().optional()
|
|
8121
8121
|
});
|
|
8122
|
+
var ClassMapDefinitionSchema = object({
|
|
8123
|
+
mapping: record(string(), _enum([
|
|
8124
|
+
"person",
|
|
8125
|
+
"vehicle",
|
|
8126
|
+
"animal",
|
|
8127
|
+
"package"
|
|
8128
|
+
])),
|
|
8129
|
+
preserveOriginal: boolean()
|
|
8130
|
+
});
|
|
8122
8131
|
var MODEL_FORMATS = [
|
|
8123
8132
|
"onnx",
|
|
8124
8133
|
"coreml",
|
|
@@ -8297,7 +8306,13 @@ var ModelCatalogEntrySchema = object({
|
|
|
8297
8306
|
* `id` stays the source of truth for resolution/download/persistence; grouping
|
|
8298
8307
|
* is a presentation overlay resolved back to an `id`.
|
|
8299
8308
|
*/
|
|
8300
|
-
group: ModelVariantGroupSchema.optional()
|
|
8309
|
+
group: ModelVariantGroupSchema.optional(),
|
|
8310
|
+
/**
|
|
8311
|
+
* Per-MODEL class map override. Absent ⇒ the step's `StepDefinition.classMap`
|
|
8312
|
+
* applies (Frigate / COCO public catalog). Set on a custom model whose raw
|
|
8313
|
+
* labels already ARE the CamStack macros (Scrypted identity map).
|
|
8314
|
+
*/
|
|
8315
|
+
classMap: ClassMapDefinitionSchema.optional()
|
|
8301
8316
|
});
|
|
8302
8317
|
var ConvertTargetSchema = discriminatedUnion("format", [object({
|
|
8303
8318
|
format: literal("openvino"),
|
|
@@ -8326,7 +8341,8 @@ var ModelConvertMetadataSchema = object({
|
|
|
8326
8341
|
"ocr",
|
|
8327
8342
|
"segmentation"
|
|
8328
8343
|
]),
|
|
8329
|
-
faceAlignment: boolean().optional()
|
|
8344
|
+
faceAlignment: boolean().optional(),
|
|
8345
|
+
classMap: ClassMapDefinitionSchema.optional()
|
|
8330
8346
|
});
|
|
8331
8347
|
var ConvertResultSchema = object({
|
|
8332
8348
|
entry: ModelCatalogEntrySchema,
|
|
@@ -17564,6 +17580,33 @@ var NativeCropRefSchema = object({
|
|
|
17564
17580
|
h: number()
|
|
17565
17581
|
})
|
|
17566
17582
|
});
|
|
17583
|
+
object({
|
|
17584
|
+
crop: object({
|
|
17585
|
+
left: number(),
|
|
17586
|
+
top: number(),
|
|
17587
|
+
width: number().positive(),
|
|
17588
|
+
height: number().positive()
|
|
17589
|
+
}).optional(),
|
|
17590
|
+
content: object({
|
|
17591
|
+
width: number().int().positive(),
|
|
17592
|
+
height: number().int().positive()
|
|
17593
|
+
}),
|
|
17594
|
+
fit: _enum(["stretch", "contain"]),
|
|
17595
|
+
format: _enum([
|
|
17596
|
+
"rgb",
|
|
17597
|
+
"gray",
|
|
17598
|
+
"jpeg"
|
|
17599
|
+
])
|
|
17600
|
+
});
|
|
17601
|
+
var FrameRefSchema = object({
|
|
17602
|
+
registryId: string().min(1),
|
|
17603
|
+
id: string().min(1),
|
|
17604
|
+
width: number().int().positive(),
|
|
17605
|
+
height: number().int().positive(),
|
|
17606
|
+
format: _enum(["rgb", "gray"]),
|
|
17607
|
+
timestamp: number(),
|
|
17608
|
+
capturedAt: number().optional()
|
|
17609
|
+
});
|
|
17567
17610
|
var ModelFormatSchema$1 = _enum([
|
|
17568
17611
|
"onnx",
|
|
17569
17612
|
"coreml",
|
|
@@ -17808,6 +17851,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
17808
17851
|
steps: array(PipelineStepInputSchema).min(1),
|
|
17809
17852
|
frame: FrameInputSchema.optional(),
|
|
17810
17853
|
/**
|
|
17854
|
+
* Process-local lazy frame. Valid only when caller and provider resolve
|
|
17855
|
+
* in the same execution-group process; split/cross-node callers use
|
|
17856
|
+
* `frame`/`image` inline compatibility instead.
|
|
17857
|
+
*/
|
|
17858
|
+
frameRef: FrameRefSchema.optional(),
|
|
17859
|
+
/**
|
|
17811
17860
|
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
17812
17861
|
* the decoded pixels live in. One more member of the one-of
|
|
17813
17862
|
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
@@ -18103,7 +18152,10 @@ var NativeCropResultSchema = object({
|
|
|
18103
18152
|
* Which source served this crop, so a quality-sensitive consumer (the native
|
|
18104
18153
|
* `keyFrame`) can reject a degraded fallback:
|
|
18105
18154
|
* - `native` — cut from the decode worker's retained NATIVE surface (the
|
|
18106
|
-
* quality path).
|
|
18155
|
+
* quality path). A subject-tile serve is also native-resolution and stays
|
|
18156
|
+
* `native` here: the public enum cannot name `tile` without a breaking cap
|
|
18157
|
+
* change. Runner telemetry distinguishes lease vs tile via `source` on the
|
|
18158
|
+
* internal crop result (`nativeHits` vs `tileHits`).
|
|
18107
18159
|
* - `ram-fullframe` — the native surface MISSED but the request was full-frame,
|
|
18108
18160
|
* so the ≤640 RAM `RetainedFrameStore` served it (honest lower-res; legit for
|
|
18109
18161
|
* the blank-frame guard / 640-snapshot resolve, NOT for the clean keyFrame).
|
|
@@ -18594,12 +18646,41 @@ var RunnerLocalLoadSchema = object({
|
|
|
18594
18646
|
* legacy `OrchestratorMetricsSchema` shape so existing dashboards keep
|
|
18595
18647
|
* working unchanged when they switch to reading from the runner cap.
|
|
18596
18648
|
*/
|
|
18649
|
+
var FrameLazyCountersSchema = object({
|
|
18650
|
+
framesDecoded: number(),
|
|
18651
|
+
framesAdmitted: number(),
|
|
18652
|
+
framesDroppedPixelFree: number(),
|
|
18653
|
+
viewsMaterialized: number(),
|
|
18654
|
+
viewsSkipped: number(),
|
|
18655
|
+
workerToRunnerBytes: number(),
|
|
18656
|
+
runnerToPoolRawBytes: number(),
|
|
18657
|
+
runnerToPoolJpegBytes: number(),
|
|
18658
|
+
onDemandFullFrameRequests: number(),
|
|
18659
|
+
onDemandCropRequests: number(),
|
|
18660
|
+
nativeHits: number(),
|
|
18661
|
+
nativeMisses: number(),
|
|
18662
|
+
tileHits: number(),
|
|
18663
|
+
tileMisses: number(),
|
|
18664
|
+
fallbackHits: number(),
|
|
18665
|
+
fallbackMisses: number(),
|
|
18666
|
+
retainedWritesAvoided: number(),
|
|
18667
|
+
residentRefs: number(),
|
|
18668
|
+
residentBytes: number(),
|
|
18669
|
+
releases: number(),
|
|
18670
|
+
evictions: number(),
|
|
18671
|
+
staleMisses: number()
|
|
18672
|
+
});
|
|
18673
|
+
var FrameLazyMetricsSchema = object({
|
|
18674
|
+
node: FrameLazyCountersSchema,
|
|
18675
|
+
cameras: array(FrameLazyCountersSchema.extend({ deviceId: number() }))
|
|
18676
|
+
});
|
|
18597
18677
|
var RunnerLocalMetricsSchema = object({
|
|
18598
18678
|
nodeId: string(),
|
|
18599
18679
|
activeCameras: number(),
|
|
18600
18680
|
throttledCameras: number(),
|
|
18601
18681
|
avgInferenceTimeMs: number(),
|
|
18602
|
-
queueDepth: number()
|
|
18682
|
+
queueDepth: number(),
|
|
18683
|
+
frameLazy: FrameLazyMetricsSchema.optional()
|
|
18603
18684
|
});
|
|
18604
18685
|
method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mutation" }), method(object({ deviceId: number() }), object({ success: literal(true) }), { kind: "mutation" }), method(ReportMotionInputSchema, object({ success: literal(true) }), { kind: "mutation" }), method(_void(), RunnerLocalLoadSchema), method(_void(), RunnerLocalMetricsSchema), method(object({ deviceId: number() }), CameraMetricsSchema.nullable()), method(_void(), array(CameraMetricsWithDeviceIdSchema).readonly()), method(_void(), array(number()).readonly()), method(object({
|
|
18605
18686
|
handle: FrameHandleSchema,
|
|
@@ -24209,6 +24290,17 @@ var NotificationEndpointSchema = object({
|
|
|
24209
24290
|
/** What the ranking currently resolves to (null when nothing is reachable). */
|
|
24210
24291
|
resolved: string().nullable()
|
|
24211
24292
|
});
|
|
24293
|
+
/**
|
|
24294
|
+
* The URLs the SDK / viewer should race for API access. `baseUrls` empty =
|
|
24295
|
+
* AUTO (every LAN IPv4 + the public tunnel). `resolved` is what that choice
|
|
24296
|
+
* currently expands to, so the UI can show the effective set either way.
|
|
24297
|
+
*/
|
|
24298
|
+
var ViewerEndpointsSchema = object({
|
|
24299
|
+
/** The operator's explicit race set, or empty for AUTO. */
|
|
24300
|
+
baseUrls: array(string()).readonly(),
|
|
24301
|
+
/** What the ranking currently resolves to (may be empty if nothing is up). */
|
|
24302
|
+
resolved: array(string()).readonly()
|
|
24303
|
+
});
|
|
24212
24304
|
var AllowedAddressesSchema = object({
|
|
24213
24305
|
/**
|
|
24214
24306
|
* Allowlist of interface addresses operators have explicitly opted
|
|
@@ -24240,17 +24332,18 @@ method(_void(), ListResultSchema), method(_void(), PreferredSchema), method(obje
|
|
|
24240
24332
|
*/
|
|
24241
24333
|
port: number().int().min(1).max(65535).optional(),
|
|
24242
24334
|
/** Include `http(s)://127.0.0.1:<port>` as the lowest-priority
|
|
24243
|
-
* candidate. Default `
|
|
24335
|
+
* candidate. Default `false` — loopback is not a client route. */
|
|
24244
24336
|
includeLoopback: boolean().optional(),
|
|
24245
|
-
/** Skip IPv6 entries.
|
|
24246
|
-
*
|
|
24337
|
+
/** Skip IPv6 entries. Default `false` — the palette includes stable
|
|
24338
|
+
* LAN IPv6 (ICE/WebRTC uses dual-stack regardless). Pass `true` to
|
|
24339
|
+
* hide them. The viewer HTTP/WS race is `getViewerEndpoints`. */
|
|
24247
24340
|
ipv4Only: boolean().optional(),
|
|
24248
24341
|
/** Scheme to emit for LAN/loopback URLs. Default `'http'`.
|
|
24249
24342
|
* Pass `'https'` when the caller is itself loaded over HTTPS
|
|
24250
24343
|
* to avoid mixed-content blocks in the browser. The public
|
|
24251
24344
|
* tunnel always emits `https://` regardless. */
|
|
24252
24345
|
scheme: _enum(["http", "https"]).optional()
|
|
24253
|
-
}), GetConnectionEndpointsResultSchema), method(_void(), NotificationEndpointSchema), method(object({ baseUrl: string().nullable() }), NotificationEndpointSchema, { kind: "mutation" }), method(_void(), AllowedAddressesSchema), method(AllowedAddressesSchema, object({ success: literal(true) }), { kind: "mutation" }), method(_void(), AllowedAddressesSchema, { kind: "mutation" }), method(_void(), TlsStatusSchema), method(object({ reason: string().optional() }), TlsStatusSchema, {
|
|
24346
|
+
}), GetConnectionEndpointsResultSchema), method(_void(), NotificationEndpointSchema), method(object({ baseUrl: string().nullable() }), NotificationEndpointSchema, { kind: "mutation" }), method(_void(), ViewerEndpointsSchema), method(object({ baseUrls: array(string()).readonly() }), ViewerEndpointsSchema, { kind: "mutation" }), method(_void(), AllowedAddressesSchema), method(AllowedAddressesSchema, object({ success: literal(true) }), { kind: "mutation" }), method(_void(), AllowedAddressesSchema, { kind: "mutation" }), method(_void(), TlsStatusSchema), method(object({ reason: string().optional() }), TlsStatusSchema, {
|
|
24254
24347
|
kind: "mutation",
|
|
24255
24348
|
auth: "admin"
|
|
24256
24349
|
}), method(object({
|
|
@@ -32324,6 +32417,12 @@ Object.freeze({
|
|
|
32324
32417
|
addonId: null,
|
|
32325
32418
|
access: "view"
|
|
32326
32419
|
},
|
|
32420
|
+
"localNetwork.getViewerEndpoints": {
|
|
32421
|
+
capName: "local-network",
|
|
32422
|
+
capScope: "system",
|
|
32423
|
+
addonId: null,
|
|
32424
|
+
access: "view"
|
|
32425
|
+
},
|
|
32327
32426
|
"localNetwork.list": {
|
|
32328
32427
|
capName: "local-network",
|
|
32329
32428
|
capScope: "system",
|
|
@@ -32360,6 +32459,12 @@ Object.freeze({
|
|
|
32360
32459
|
addonId: null,
|
|
32361
32460
|
access: "create"
|
|
32362
32461
|
},
|
|
32462
|
+
"localNetwork.setViewerEndpoints": {
|
|
32463
|
+
capName: "local-network",
|
|
32464
|
+
capScope: "system",
|
|
32465
|
+
addonId: null,
|
|
32466
|
+
access: "create"
|
|
32467
|
+
},
|
|
32363
32468
|
"localNetwork.uploadCertificate": {
|
|
32364
32469
|
capName: "local-network",
|
|
32365
32470
|
capScope: "system",
|
|
@@ -38139,356 +38244,6 @@ async function silenceAnalysisFor(deps, deviceId) {
|
|
|
38139
38244
|
if (failures.length > 0) throw new Error(`terminal camera ${deviceId}: could not switch off ${failures.length} analyzer(s) — it will run at full detection cost (${failures.join("; ")})`);
|
|
38140
38245
|
}
|
|
38141
38246
|
//#endregion
|
|
38142
|
-
//#region src/terminal-camera-declarations.ts
|
|
38143
|
-
/**
|
|
38144
|
-
* Feed DeclaredDevices every live declaration plus one deterministic orphan
|
|
38145
|
-
* batch. The generic sweep intentionally refuses an over-limit set; selecting
|
|
38146
|
-
* a batch here drains large historical Terminal orphan sets across convergence
|
|
38147
|
-
* passes without weakening that global safety guard.
|
|
38148
|
-
*/
|
|
38149
|
-
function terminalCameraReconciliationIndex(rows, integrationId, declarations, managedStableIds = /* @__PURE__ */ new Set()) {
|
|
38150
|
-
if (!integrationId) return [];
|
|
38151
|
-
const declared = new Set(declarations.map((camera) => camera.stableId));
|
|
38152
|
-
const owned = rows.filter((row) => row.integrationId === integrationId && (declared.has(row.stableId) || managedStableIds.has(row.stableId) || row.stableId.startsWith("terminal-camera-instance-")));
|
|
38153
|
-
return [...owned.filter((row) => declared.has(row.stableId)), ...owned.filter((row) => !declared.has(row.stableId)).sort((left, right) => left.id - right.id).slice(0, 32)];
|
|
38154
|
-
}
|
|
38155
|
-
/** Explicit persisted instances, never the node × profile template matrix. */
|
|
38156
|
-
function buildTerminalInstanceCameraDeclarations(instances) {
|
|
38157
|
-
return instances.filter((instance) => instance.enabled).map((instance) => ({
|
|
38158
|
-
stableId: instance.cameraStableId,
|
|
38159
|
-
name: instance.name,
|
|
38160
|
-
config: {
|
|
38161
|
-
instanceId: instance.id,
|
|
38162
|
-
nodeId: instance.nodeId,
|
|
38163
|
-
profileId: instance.profileId,
|
|
38164
|
-
profileLabel: instance.profileLabel
|
|
38165
|
-
}
|
|
38166
|
-
}));
|
|
38167
|
-
}
|
|
38168
|
-
/**
|
|
38169
|
-
* `DeviceConfig` materializes schema defaults in memory, so comparing
|
|
38170
|
-
* `config.get()` cannot detect a legacy `{ nodeId }` row. Reconciliation must
|
|
38171
|
-
* inspect the raw persisted blob to make the profile migration durable.
|
|
38172
|
-
*/
|
|
38173
|
-
function needsTerminalCameraConfigMigration(persistedConfig, declaration) {
|
|
38174
|
-
return persistedConfig.instanceId !== declaration.config.instanceId || persistedConfig.nodeId !== declaration.config.nodeId || persistedConfig.profileId !== declaration.config.profileId || persistedConfig.profileLabel !== declaration.config.profileLabel;
|
|
38175
|
-
}
|
|
38176
|
-
//#endregion
|
|
38177
|
-
//#region src/terminal-cell-runs.ts
|
|
38178
|
-
var TERMINAL_DEFAULT_FG = "#d7dce2";
|
|
38179
|
-
var TERMINAL_DEFAULT_BG = "#0b0d10";
|
|
38180
|
-
/**
|
|
38181
|
-
* The 16 ANSI colours, in a dark-theme variant chosen to sit with the existing
|
|
38182
|
-
* frame (`#0b0d10` ground, `#d7dce2` text) rather than the raw xterm defaults,
|
|
38183
|
-
* whose pure `#0000ff` blue and `#008000` green are close to unreadable on a
|
|
38184
|
-
* near-black background at 13px. Index 7 IS the default foreground, so plain
|
|
38185
|
-
* `CSI 37m` text renders identically to unstyled text.
|
|
38186
|
-
*/
|
|
38187
|
-
var TERMINAL_ANSI_PALETTE = [
|
|
38188
|
-
"#282c34",
|
|
38189
|
-
"#e06c75",
|
|
38190
|
-
"#98c379",
|
|
38191
|
-
"#e5c07b",
|
|
38192
|
-
"#61afef",
|
|
38193
|
-
"#c678dd",
|
|
38194
|
-
"#56b6c2",
|
|
38195
|
-
TERMINAL_DEFAULT_FG,
|
|
38196
|
-
"#5c6370",
|
|
38197
|
-
"#ef596f",
|
|
38198
|
-
"#89ca78",
|
|
38199
|
-
"#f0c674",
|
|
38200
|
-
"#6cb6ff",
|
|
38201
|
-
"#d55fde",
|
|
38202
|
-
"#2bbac5",
|
|
38203
|
-
"#ffffff"
|
|
38204
|
-
];
|
|
38205
|
-
/** The six levels of the xterm 6×6×6 colour cube (indices 16-231). */
|
|
38206
|
-
var TERMINAL_CUBE_LEVELS = [
|
|
38207
|
-
0,
|
|
38208
|
-
95,
|
|
38209
|
-
135,
|
|
38210
|
-
175,
|
|
38211
|
-
215,
|
|
38212
|
-
255
|
|
38213
|
-
];
|
|
38214
|
-
var TERMINAL_CUBE_FIRST = 16;
|
|
38215
|
-
var TERMINAL_GRAYSCALE_FIRST = 232;
|
|
38216
|
-
var TERMINAL_GRAYSCALE_BASE = 8;
|
|
38217
|
-
var TERMINAL_GRAYSCALE_STEP = 10;
|
|
38218
|
-
/** SGR 2 keeps the foreground legible; it must not become the background. */
|
|
38219
|
-
var TERMINAL_DIM_WEIGHT = .6;
|
|
38220
|
-
function channel(value) {
|
|
38221
|
-
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
|
|
38222
|
-
}
|
|
38223
|
-
function hex(red, green, blue) {
|
|
38224
|
-
return `#${channel(red)}${channel(green)}${channel(blue)}`;
|
|
38225
|
-
}
|
|
38226
|
-
function parseHex(color) {
|
|
38227
|
-
return [
|
|
38228
|
-
Number.parseInt(color.slice(1, 3), 16),
|
|
38229
|
-
Number.parseInt(color.slice(3, 5), 16),
|
|
38230
|
-
Number.parseInt(color.slice(5, 7), 16)
|
|
38231
|
-
];
|
|
38232
|
-
}
|
|
38233
|
-
/** Resolve an xterm palette index (0-255) to a hex colour. */
|
|
38234
|
-
function terminalPaletteColor(index) {
|
|
38235
|
-
const ansi = TERMINAL_ANSI_PALETTE[index];
|
|
38236
|
-
if (ansi !== void 0) return ansi;
|
|
38237
|
-
if (index >= TERMINAL_GRAYSCALE_FIRST) {
|
|
38238
|
-
const level = TERMINAL_GRAYSCALE_BASE + (index - TERMINAL_GRAYSCALE_FIRST) * TERMINAL_GRAYSCALE_STEP;
|
|
38239
|
-
return hex(level, level, level);
|
|
38240
|
-
}
|
|
38241
|
-
if (index >= TERMINAL_CUBE_FIRST) {
|
|
38242
|
-
const offset = index - TERMINAL_CUBE_FIRST;
|
|
38243
|
-
return hex(TERMINAL_CUBE_LEVELS[Math.floor(offset / 36) % 6] ?? 0, TERMINAL_CUBE_LEVELS[Math.floor(offset / 6) % 6] ?? 0, TERMINAL_CUBE_LEVELS[offset % 6] ?? 0);
|
|
38244
|
-
}
|
|
38245
|
-
return TERMINAL_DEFAULT_FG;
|
|
38246
|
-
}
|
|
38247
|
-
/** Resolve a 0xRRGGBB truecolor value to a hex colour. */
|
|
38248
|
-
function terminalRgbColor(value) {
|
|
38249
|
-
return hex(value >> 16 & 255, value >> 8 & 255, value & 255);
|
|
38250
|
-
}
|
|
38251
|
-
function blend(color, toward, weight) {
|
|
38252
|
-
const [red, green, blue] = parseHex(color);
|
|
38253
|
-
const [targetRed, targetGreen, targetBlue] = parseHex(toward);
|
|
38254
|
-
return hex(red * weight + targetRed * (1 - weight), green * weight + targetGreen * (1 - weight), blue * weight + targetBlue * (1 - weight));
|
|
38255
|
-
}
|
|
38256
|
-
function resolveForeground(cell) {
|
|
38257
|
-
if (cell.isFgRGB()) return terminalRgbColor(cell.getFgColor());
|
|
38258
|
-
if (cell.isFgPalette()) return terminalPaletteColor(cell.getFgColor());
|
|
38259
|
-
return TERMINAL_DEFAULT_FG;
|
|
38260
|
-
}
|
|
38261
|
-
function resolveBackground(cell) {
|
|
38262
|
-
if (cell.isBgRGB()) return terminalRgbColor(cell.getBgColor());
|
|
38263
|
-
if (cell.isBgPalette()) return terminalPaletteColor(cell.getBgColor());
|
|
38264
|
-
return TERMINAL_DEFAULT_BG;
|
|
38265
|
-
}
|
|
38266
|
-
/**
|
|
38267
|
-
* Resolve one cell's attributes into concrete colours.
|
|
38268
|
-
*
|
|
38269
|
-
* Inverse is applied by SWAPPING the already-resolved pair, so inverse over two
|
|
38270
|
-
* defaults is still a visible swap rather than a no-op — that is how a selected
|
|
38271
|
-
* or highlighted row in Glances reads. Invisible is then conceal-by-equality
|
|
38272
|
-
* (foreground painted in its own background): the cell keeps its columns, which
|
|
38273
|
-
* a dropped cell would not, and dropping it would shift the whole rest of the
|
|
38274
|
-
* row left.
|
|
38275
|
-
*/
|
|
38276
|
-
function resolveCellStyle(cell) {
|
|
38277
|
-
const inverse = cell.isInverse() !== 0;
|
|
38278
|
-
const plainFg = resolveForeground(cell);
|
|
38279
|
-
const plainBg = resolveBackground(cell);
|
|
38280
|
-
const background = inverse ? plainFg : plainBg;
|
|
38281
|
-
let foreground = inverse ? plainBg : plainFg;
|
|
38282
|
-
if (cell.isDim() !== 0) foreground = blend(foreground, background, TERMINAL_DIM_WEIGHT);
|
|
38283
|
-
if (cell.isInvisible() !== 0) foreground = background;
|
|
38284
|
-
return {
|
|
38285
|
-
fg: foreground === "#d7dce2" ? null : foreground,
|
|
38286
|
-
bg: background === "#0b0d10" ? null : background,
|
|
38287
|
-
bold: cell.isBold() !== 0
|
|
38288
|
-
};
|
|
38289
|
-
}
|
|
38290
|
-
function sameStyle(left, right) {
|
|
38291
|
-
return left.fg === right.fg && left.bg === right.bg && left.bold === right.bold;
|
|
38292
|
-
}
|
|
38293
|
-
/**
|
|
38294
|
-
* Merge adjacent same-style cells into runs, then drop the trailing run of
|
|
38295
|
-
* default-styled whitespace so a row costs what it draws — the same trim
|
|
38296
|
-
* `translateToString(true)` performs. Whitespace carrying a BACKGROUND is kept:
|
|
38297
|
-
* a green bar of spaces out to the right margin is a pixel Glances drew.
|
|
38298
|
-
*/
|
|
38299
|
-
function buildCellRuns(cells) {
|
|
38300
|
-
const runs = [];
|
|
38301
|
-
let text = "";
|
|
38302
|
-
let style = null;
|
|
38303
|
-
for (const cell of cells) {
|
|
38304
|
-
if (style !== null && sameStyle(style, cell.style)) {
|
|
38305
|
-
text += cell.text;
|
|
38306
|
-
continue;
|
|
38307
|
-
}
|
|
38308
|
-
if (style !== null) runs.push({
|
|
38309
|
-
text,
|
|
38310
|
-
...style
|
|
38311
|
-
});
|
|
38312
|
-
text = cell.text;
|
|
38313
|
-
style = cell.style;
|
|
38314
|
-
}
|
|
38315
|
-
if (style !== null) runs.push({
|
|
38316
|
-
text,
|
|
38317
|
-
...style
|
|
38318
|
-
});
|
|
38319
|
-
while (runs.length > 0) {
|
|
38320
|
-
const last = runs[runs.length - 1];
|
|
38321
|
-
if (last === void 0 || last.bg !== null) break;
|
|
38322
|
-
const trimmed = last.text.replace(/\s+$/u, "");
|
|
38323
|
-
if (trimmed === last.text) break;
|
|
38324
|
-
if (trimmed === "") {
|
|
38325
|
-
runs.pop();
|
|
38326
|
-
continue;
|
|
38327
|
-
}
|
|
38328
|
-
runs[runs.length - 1] = {
|
|
38329
|
-
...last,
|
|
38330
|
-
text: trimmed
|
|
38331
|
-
};
|
|
38332
|
-
break;
|
|
38333
|
-
}
|
|
38334
|
-
return runs;
|
|
38335
|
-
}
|
|
38336
|
-
/**
|
|
38337
|
-
* Monospace families to try, in order — NOT one family and a generic.
|
|
38338
|
-
*
|
|
38339
|
-
* A terminal screen is mostly box-drawing and block characters, and a font
|
|
38340
|
-
* without them renders the frame as noise rather than as missing detail.
|
|
38341
|
-
* `DejaVu Sans Mono` covers them and ships in the hub image; macOS has neither
|
|
38342
|
-
* DejaVu nor fontconfig, so the Mac agent fell through to a generic whose
|
|
38343
|
-
* coverage is not, and its Glances camera came out unreadable while the hub's
|
|
38344
|
-
* was pixel-perfect (measured 2026-08-11, same Glances, two nodes).
|
|
38345
|
-
*
|
|
38346
|
-
* `Menlo` is the fix rather than a guess: it is macOS's default terminal face,
|
|
38347
|
-
* present on every install, and derived from DejaVu Sans Mono — the same glyph
|
|
38348
|
-
* coverage by ancestry. Monaco and Courier New follow as older fallbacks; the
|
|
38349
|
-
* generic stays last so a host with none of them still draws something.
|
|
38350
|
-
*/
|
|
38351
|
-
var TERMINAL_FONT_STACK = "DejaVu Sans Mono,Menlo,Monaco,Courier New,monospace";
|
|
38352
|
-
var TERMINAL_FONT_SIZE = 13;
|
|
38353
|
-
var TERMINAL_TEXT_MARGIN_X = 8;
|
|
38354
|
-
var TERMINAL_ROW_HEIGHT = 15;
|
|
38355
|
-
var TERMINAL_BASELINE_Y = 18;
|
|
38356
|
-
/**
|
|
38357
|
-
* Distance from a row's baseline up to the top of its cell box. Chosen so
|
|
38358
|
-
* consecutive rows tile exactly: row N's box runs from `baseline - this` for
|
|
38359
|
-
* `TERMINAL_ROW_HEIGHT`, and row N+1's box starts where it ends. A background
|
|
38360
|
-
* bar that stopped short would draw as stripes across a `CSI 42m` panel.
|
|
38361
|
-
*/
|
|
38362
|
-
var TERMINAL_CELL_ASCENT = 11.5;
|
|
38363
|
-
var TERMINAL_CELL_WIDTH = TERMINAL_FONT_SIZE * (1233 / 2048);
|
|
38364
|
-
/** Two decimals is under a tenth of a pixel and keeps the SVG small. */
|
|
38365
|
-
function coordinate(value) {
|
|
38366
|
-
return String(Number(value.toFixed(2)));
|
|
38367
|
-
}
|
|
38368
|
-
function escapeXml(value) {
|
|
38369
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
38370
|
-
}
|
|
38371
|
-
/**
|
|
38372
|
-
* Render already-interpreted terminal rows into a compact MJPEG frame.
|
|
38373
|
-
*
|
|
38374
|
-
* `xml:space="preserve"` is load-bearing, not tidiness. SVG `<text>` collapses
|
|
38375
|
-
* runs of whitespace by default, and a terminal's entire column alignment IS
|
|
38376
|
-
* runs of whitespace — Glances pads every field with spaces. Without it the
|
|
38377
|
-
* frame drew each line at roughly half its true width, crammed into the
|
|
38378
|
-
* top-left of a mostly-black image, while the SAME session over `attach`
|
|
38379
|
-
* looked perfect — which is exactly how the operator reported it. Measured in
|
|
38380
|
-
* the hub's own rasterizer 2026-08-11: `AAA<10 spaces>BBB<3>CCC` drew 92 px
|
|
38381
|
-
* collapsed against 178 px preserved.
|
|
38382
|
-
*
|
|
38383
|
-
* Every run is anchored at its OWN column (`x = margin + startCol * cellW`),
|
|
38384
|
-
* never appended to the one before it, so the background rects and the glyphs
|
|
38385
|
-
* are placed off the same grid and cannot drift apart. `textLength` is emitted
|
|
38386
|
-
* with it because it is the correct declaration and renderers that honour it
|
|
38387
|
-
* get an exact grid — but it is not what makes this work: librsvg, which sharp
|
|
38388
|
-
* uses, ignores it outright (measured 2026-08-12, a 120-glyph run pinned to
|
|
38389
|
-
* 600 px still drew its natural 937 px). The anchoring is the guarantee.
|
|
38390
|
-
*/
|
|
38391
|
-
function renderTerminalSvg(rows) {
|
|
38392
|
-
const backgrounds = [];
|
|
38393
|
-
const texts = [];
|
|
38394
|
-
rows.slice(0, 40).forEach((row, index) => {
|
|
38395
|
-
const baseline = TERMINAL_BASELINE_Y + index * TERMINAL_ROW_HEIGHT;
|
|
38396
|
-
const top = baseline - TERMINAL_CELL_ASCENT;
|
|
38397
|
-
let column = 0;
|
|
38398
|
-
for (const run of row) {
|
|
38399
|
-
if (column >= 120) break;
|
|
38400
|
-
const clipped = clipRun(run, 120 - column);
|
|
38401
|
-
const columns = [...clipped].length;
|
|
38402
|
-
if (columns === 0) continue;
|
|
38403
|
-
const x = TERMINAL_TEXT_MARGIN_X + column * TERMINAL_CELL_WIDTH;
|
|
38404
|
-
const width = columns * TERMINAL_CELL_WIDTH;
|
|
38405
|
-
if (run.bg !== null) backgrounds.push(`<rect x="${coordinate(x)}" y="${coordinate(top)}" width="${coordinate(width)}" height="${String(TERMINAL_ROW_HEIGHT)}" fill="${run.bg}"/>`);
|
|
38406
|
-
if (clipped.trim() !== "") {
|
|
38407
|
-
const fill = run.fg === null ? "" : ` fill="${run.fg}"`;
|
|
38408
|
-
const weight = run.bold ? " font-weight=\"bold\"" : "";
|
|
38409
|
-
texts.push(`<text xml:space="preserve" x="${coordinate(x)}" y="${coordinate(baseline)}" textLength="${coordinate(width)}" lengthAdjust="spacingAndGlyphs"${fill}${weight}>${escapeXml(clipped)}</text>`);
|
|
38410
|
-
}
|
|
38411
|
-
column += columns;
|
|
38412
|
-
}
|
|
38413
|
-
});
|
|
38414
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" width="${String(960)}" height="${String(640)}"><rect width="100%" height="100%" fill="${TERMINAL_DEFAULT_BG}"/>${backgrounds.join("")}<g fill="${TERMINAL_DEFAULT_FG}" font-family="${TERMINAL_FONT_STACK}" font-size="${String(TERMINAL_FONT_SIZE)}">${texts.join("")}</g></svg>`;
|
|
38415
|
-
}
|
|
38416
|
-
/** Cut a run to the columns still left in the row, by code point not unit. */
|
|
38417
|
-
function clipRun(run, remaining) {
|
|
38418
|
-
const points = [...run.text];
|
|
38419
|
-
return points.length <= remaining ? run.text : points.slice(0, remaining).join("");
|
|
38420
|
-
}
|
|
38421
|
-
async function renderTerminalJpeg(rows) {
|
|
38422
|
-
return (0, sharp.default)(Buffer.from(renderTerminalSvg(rows))).jpeg({
|
|
38423
|
-
quality: 82,
|
|
38424
|
-
chromaSubsampling: "4:2:0"
|
|
38425
|
-
}).toBuffer();
|
|
38426
|
-
}
|
|
38427
|
-
//#endregion
|
|
38428
|
-
//#region src/terminal-camera-device.ts
|
|
38429
|
-
var terminalCameraSchema = object({
|
|
38430
|
-
instanceId: string().min(1).optional(),
|
|
38431
|
-
nodeId: string().min(1),
|
|
38432
|
-
profileId: string().min(1).default("monitor"),
|
|
38433
|
-
profileLabel: string().min(1).default("BTM")
|
|
38434
|
-
});
|
|
38435
|
-
var relay = null;
|
|
38436
|
-
function installTerminalCameraRelay(next) {
|
|
38437
|
-
relay = next;
|
|
38438
|
-
}
|
|
38439
|
-
var TerminalCameraDevice = class extends BaseDevice {
|
|
38440
|
-
features = [DeviceFeature.NativeSnapshot];
|
|
38441
|
-
constructor(ctx) {
|
|
38442
|
-
super(ctx, terminalCameraSchema, { type: ctx.deviceMeta.type });
|
|
38443
|
-
this.ctx.registerNativeCap(streamCatalogCapability, { getCatalog: async ({ deviceId }) => {
|
|
38444
|
-
if (deviceId !== this.id) return [];
|
|
38445
|
-
return this.catalog();
|
|
38446
|
-
} });
|
|
38447
|
-
this.ctx.registerNativeCap(snapshotCapability, {
|
|
38448
|
-
getSnapshot: async ({ deviceId }) => {
|
|
38449
|
-
if (deviceId !== this.id) throw new Error(`TerminalCameraDevice: deviceId mismatch, expected ${String(this.id)}, got ${String(deviceId)}`);
|
|
38450
|
-
const activeRelay = relay;
|
|
38451
|
-
if (!activeRelay) throw new Error("terminal camera relay is unavailable");
|
|
38452
|
-
return {
|
|
38453
|
-
base64: (await activeRelay.snapshot(this.relayInstanceId(), this.config.get("nodeId"), this.config.get("profileId"))).toString("base64"),
|
|
38454
|
-
contentType: "image/jpeg"
|
|
38455
|
-
};
|
|
38456
|
-
},
|
|
38457
|
-
invalidateCache: async () => {}
|
|
38458
|
-
});
|
|
38459
|
-
this.markOnline(true);
|
|
38460
|
-
}
|
|
38461
|
-
async catalog() {
|
|
38462
|
-
const activeRelay = relay;
|
|
38463
|
-
if (!activeRelay) throw new Error("terminal camera relay is unavailable");
|
|
38464
|
-
const nodeId = this.config.get("nodeId");
|
|
38465
|
-
const profileId = this.config.get("profileId");
|
|
38466
|
-
const instanceId = this.relayInstanceId();
|
|
38467
|
-
return [{
|
|
38468
|
-
camStreamId: profileId,
|
|
38469
|
-
kind: "pull-http",
|
|
38470
|
-
url: activeRelay.streamUrl(instanceId, nodeId, profileId),
|
|
38471
|
-
codec: "h264",
|
|
38472
|
-
resolution: {
|
|
38473
|
-
width: 960,
|
|
38474
|
-
height: 640
|
|
38475
|
-
},
|
|
38476
|
-
fps: 2,
|
|
38477
|
-
label: this.config.get("profileLabel")
|
|
38478
|
-
}];
|
|
38479
|
-
}
|
|
38480
|
-
setNodeOnline(online) {
|
|
38481
|
-
this.markOnline(online);
|
|
38482
|
-
if (!online) relay?.closeInstance(this.relayInstanceId());
|
|
38483
|
-
}
|
|
38484
|
-
async removeDevice() {
|
|
38485
|
-
await relay?.closeInstance(this.relayInstanceId());
|
|
38486
|
-
}
|
|
38487
|
-
relayInstanceId() {
|
|
38488
|
-
return this.config.get("instanceId") ?? `legacy:${this.stableId}`;
|
|
38489
|
-
}
|
|
38490
|
-
};
|
|
38491
|
-
//#endregion
|
|
38492
38247
|
//#region ../../node_modules/@xterm/addon-serialize/lib/addon-serialize.js
|
|
38493
38248
|
var require_addon_serialize = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
38494
38249
|
(function(e, t) {
|
|
@@ -43296,11 +43051,176 @@ var require_xterm_headless = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
43296
43051
|
})();
|
|
43297
43052
|
}));
|
|
43298
43053
|
//#endregion
|
|
43299
|
-
//#region src/
|
|
43054
|
+
//#region src/terminal-cell-runs.ts
|
|
43300
43055
|
var import_addon_serialize = require_addon_serialize();
|
|
43301
43056
|
var import_xterm_headless = require_xterm_headless();
|
|
43057
|
+
var TERMINAL_DEFAULT_FG = "#d7dce2";
|
|
43058
|
+
var TERMINAL_DEFAULT_BG = "#0b0d10";
|
|
43059
|
+
/**
|
|
43060
|
+
* The 16 ANSI colours, in a dark-theme variant chosen to sit with the existing
|
|
43061
|
+
* frame (`#0b0d10` ground, `#d7dce2` text) rather than the raw xterm defaults,
|
|
43062
|
+
* whose pure `#0000ff` blue and `#008000` green are close to unreadable on a
|
|
43063
|
+
* near-black background at 13px. Index 7 IS the default foreground, so plain
|
|
43064
|
+
* `CSI 37m` text renders identically to unstyled text.
|
|
43065
|
+
*/
|
|
43066
|
+
var TERMINAL_ANSI_PALETTE = [
|
|
43067
|
+
"#282c34",
|
|
43068
|
+
"#e06c75",
|
|
43069
|
+
"#98c379",
|
|
43070
|
+
"#e5c07b",
|
|
43071
|
+
"#61afef",
|
|
43072
|
+
"#c678dd",
|
|
43073
|
+
"#56b6c2",
|
|
43074
|
+
TERMINAL_DEFAULT_FG,
|
|
43075
|
+
"#5c6370",
|
|
43076
|
+
"#ef596f",
|
|
43077
|
+
"#89ca78",
|
|
43078
|
+
"#f0c674",
|
|
43079
|
+
"#6cb6ff",
|
|
43080
|
+
"#d55fde",
|
|
43081
|
+
"#2bbac5",
|
|
43082
|
+
"#ffffff"
|
|
43083
|
+
];
|
|
43084
|
+
/** The six levels of the xterm 6×6×6 colour cube (indices 16-231). */
|
|
43085
|
+
var TERMINAL_CUBE_LEVELS = [
|
|
43086
|
+
0,
|
|
43087
|
+
95,
|
|
43088
|
+
135,
|
|
43089
|
+
175,
|
|
43090
|
+
215,
|
|
43091
|
+
255
|
|
43092
|
+
];
|
|
43093
|
+
var TERMINAL_CUBE_FIRST = 16;
|
|
43094
|
+
var TERMINAL_GRAYSCALE_FIRST = 232;
|
|
43095
|
+
var TERMINAL_GRAYSCALE_BASE = 8;
|
|
43096
|
+
var TERMINAL_GRAYSCALE_STEP = 10;
|
|
43097
|
+
/** SGR 2 keeps the foreground legible; it must not become the background. */
|
|
43098
|
+
var TERMINAL_DIM_WEIGHT = .6;
|
|
43099
|
+
function channel(value) {
|
|
43100
|
+
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
|
|
43101
|
+
}
|
|
43102
|
+
function hex(red, green, blue) {
|
|
43103
|
+
return `#${channel(red)}${channel(green)}${channel(blue)}`;
|
|
43104
|
+
}
|
|
43105
|
+
function parseHex(color) {
|
|
43106
|
+
return [
|
|
43107
|
+
Number.parseInt(color.slice(1, 3), 16),
|
|
43108
|
+
Number.parseInt(color.slice(3, 5), 16),
|
|
43109
|
+
Number.parseInt(color.slice(5, 7), 16)
|
|
43110
|
+
];
|
|
43111
|
+
}
|
|
43112
|
+
/** Resolve an xterm palette index (0-255) to a hex colour. */
|
|
43113
|
+
function terminalPaletteColor(index) {
|
|
43114
|
+
const ansi = TERMINAL_ANSI_PALETTE[index];
|
|
43115
|
+
if (ansi !== void 0) return ansi;
|
|
43116
|
+
if (index >= TERMINAL_GRAYSCALE_FIRST) {
|
|
43117
|
+
const level = TERMINAL_GRAYSCALE_BASE + (index - TERMINAL_GRAYSCALE_FIRST) * TERMINAL_GRAYSCALE_STEP;
|
|
43118
|
+
return hex(level, level, level);
|
|
43119
|
+
}
|
|
43120
|
+
if (index >= TERMINAL_CUBE_FIRST) {
|
|
43121
|
+
const offset = index - TERMINAL_CUBE_FIRST;
|
|
43122
|
+
return hex(TERMINAL_CUBE_LEVELS[Math.floor(offset / 36) % 6] ?? 0, TERMINAL_CUBE_LEVELS[Math.floor(offset / 6) % 6] ?? 0, TERMINAL_CUBE_LEVELS[offset % 6] ?? 0);
|
|
43123
|
+
}
|
|
43124
|
+
return TERMINAL_DEFAULT_FG;
|
|
43125
|
+
}
|
|
43126
|
+
/** Resolve a 0xRRGGBB truecolor value to a hex colour. */
|
|
43127
|
+
function terminalRgbColor(value) {
|
|
43128
|
+
return hex(value >> 16 & 255, value >> 8 & 255, value & 255);
|
|
43129
|
+
}
|
|
43130
|
+
function blend(color, toward, weight) {
|
|
43131
|
+
const [red, green, blue] = parseHex(color);
|
|
43132
|
+
const [targetRed, targetGreen, targetBlue] = parseHex(toward);
|
|
43133
|
+
return hex(red * weight + targetRed * (1 - weight), green * weight + targetGreen * (1 - weight), blue * weight + targetBlue * (1 - weight));
|
|
43134
|
+
}
|
|
43135
|
+
function resolveForeground(cell) {
|
|
43136
|
+
if (cell.isFgRGB()) return terminalRgbColor(cell.getFgColor());
|
|
43137
|
+
if (cell.isFgPalette()) return terminalPaletteColor(cell.getFgColor());
|
|
43138
|
+
return TERMINAL_DEFAULT_FG;
|
|
43139
|
+
}
|
|
43140
|
+
function resolveBackground(cell) {
|
|
43141
|
+
if (cell.isBgRGB()) return terminalRgbColor(cell.getBgColor());
|
|
43142
|
+
if (cell.isBgPalette()) return terminalPaletteColor(cell.getBgColor());
|
|
43143
|
+
return TERMINAL_DEFAULT_BG;
|
|
43144
|
+
}
|
|
43145
|
+
/**
|
|
43146
|
+
* Resolve one cell's attributes into concrete colours.
|
|
43147
|
+
*
|
|
43148
|
+
* Inverse is applied by SWAPPING the already-resolved pair, so inverse over two
|
|
43149
|
+
* defaults is still a visible swap rather than a no-op — that is how a selected
|
|
43150
|
+
* or highlighted row in Glances reads. Invisible is then conceal-by-equality
|
|
43151
|
+
* (foreground painted in its own background): the cell keeps its columns, which
|
|
43152
|
+
* a dropped cell would not, and dropping it would shift the whole rest of the
|
|
43153
|
+
* row left.
|
|
43154
|
+
*/
|
|
43155
|
+
function resolveCellStyle(cell) {
|
|
43156
|
+
const inverse = cell.isInverse() !== 0;
|
|
43157
|
+
const plainFg = resolveForeground(cell);
|
|
43158
|
+
const plainBg = resolveBackground(cell);
|
|
43159
|
+
const background = inverse ? plainFg : plainBg;
|
|
43160
|
+
let foreground = inverse ? plainBg : plainFg;
|
|
43161
|
+
if (cell.isDim() !== 0) foreground = blend(foreground, background, TERMINAL_DIM_WEIGHT);
|
|
43162
|
+
if (cell.isInvisible() !== 0) foreground = background;
|
|
43163
|
+
return {
|
|
43164
|
+
fg: foreground === "#d7dce2" ? null : foreground,
|
|
43165
|
+
bg: background === "#0b0d10" ? null : background,
|
|
43166
|
+
bold: cell.isBold() !== 0
|
|
43167
|
+
};
|
|
43168
|
+
}
|
|
43169
|
+
function sameStyle(left, right) {
|
|
43170
|
+
return left.fg === right.fg && left.bg === right.bg && left.bold === right.bold;
|
|
43171
|
+
}
|
|
43172
|
+
/**
|
|
43173
|
+
* Merge adjacent same-style cells into runs, then drop the trailing run of
|
|
43174
|
+
* default-styled whitespace so a row costs what it draws — the same trim
|
|
43175
|
+
* `translateToString(true)` performs. Whitespace carrying a BACKGROUND is kept:
|
|
43176
|
+
* a green bar of spaces out to the right margin is a pixel Glances drew.
|
|
43177
|
+
*/
|
|
43178
|
+
function buildCellRuns(cells) {
|
|
43179
|
+
const runs = [];
|
|
43180
|
+
let text = "";
|
|
43181
|
+
let style = null;
|
|
43182
|
+
for (const cell of cells) {
|
|
43183
|
+
if (style !== null && sameStyle(style, cell.style)) {
|
|
43184
|
+
text += cell.text;
|
|
43185
|
+
continue;
|
|
43186
|
+
}
|
|
43187
|
+
if (style !== null) runs.push({
|
|
43188
|
+
text,
|
|
43189
|
+
...style
|
|
43190
|
+
});
|
|
43191
|
+
text = cell.text;
|
|
43192
|
+
style = cell.style;
|
|
43193
|
+
}
|
|
43194
|
+
if (style !== null) runs.push({
|
|
43195
|
+
text,
|
|
43196
|
+
...style
|
|
43197
|
+
});
|
|
43198
|
+
while (runs.length > 0) {
|
|
43199
|
+
const last = runs[runs.length - 1];
|
|
43200
|
+
if (last === void 0 || last.bg !== null) break;
|
|
43201
|
+
const trimmed = last.text.replace(/\s+$/u, "");
|
|
43202
|
+
if (trimmed === last.text) break;
|
|
43203
|
+
if (trimmed === "") {
|
|
43204
|
+
runs.pop();
|
|
43205
|
+
continue;
|
|
43206
|
+
}
|
|
43207
|
+
runs[runs.length - 1] = {
|
|
43208
|
+
...last,
|
|
43209
|
+
text: trimmed
|
|
43210
|
+
};
|
|
43211
|
+
break;
|
|
43212
|
+
}
|
|
43213
|
+
return runs;
|
|
43214
|
+
}
|
|
43215
|
+
//#endregion
|
|
43216
|
+
//#region src/xterm-screen.ts
|
|
43217
|
+
/**
|
|
43218
|
+
* Real {@link ScreenBuffer} backed by `@xterm/headless` — the DOM-less xterm
|
|
43219
|
+
* build — plus the serialize addon, which turns the current buffer into a
|
|
43220
|
+
* self-contained repaint escape sequence for reconnecting clients.
|
|
43221
|
+
*/
|
|
43302
43222
|
var SCROLLBACK_LINES = 2e3;
|
|
43303
|
-
function createXtermScreen
|
|
43223
|
+
function createXtermScreen(cols, rows) {
|
|
43304
43224
|
const term = new import_xterm_headless.Terminal({
|
|
43305
43225
|
cols,
|
|
43306
43226
|
rows,
|
|
@@ -43365,6 +43285,196 @@ function createXtermScreen$1(cols, rows) {
|
|
|
43365
43285
|
};
|
|
43366
43286
|
}
|
|
43367
43287
|
//#endregion
|
|
43288
|
+
//#region src/terminal-camera-declarations.ts
|
|
43289
|
+
/**
|
|
43290
|
+
* Feed DeclaredDevices every live declaration plus one deterministic orphan
|
|
43291
|
+
* batch. The generic sweep intentionally refuses an over-limit set; selecting
|
|
43292
|
+
* a batch here drains large historical Terminal orphan sets across convergence
|
|
43293
|
+
* passes without weakening that global safety guard.
|
|
43294
|
+
*/
|
|
43295
|
+
function terminalCameraReconciliationIndex(rows, integrationId, declarations, managedStableIds = /* @__PURE__ */ new Set()) {
|
|
43296
|
+
if (!integrationId) return [];
|
|
43297
|
+
const declared = new Set(declarations.map((camera) => camera.stableId));
|
|
43298
|
+
const owned = rows.filter((row) => row.integrationId === integrationId && (declared.has(row.stableId) || managedStableIds.has(row.stableId) || row.stableId.startsWith("terminal-camera-instance-")));
|
|
43299
|
+
return [...owned.filter((row) => declared.has(row.stableId)), ...owned.filter((row) => !declared.has(row.stableId)).sort((left, right) => left.id - right.id).slice(0, 32)];
|
|
43300
|
+
}
|
|
43301
|
+
/** Explicit persisted instances, never the node × profile template matrix. */
|
|
43302
|
+
function buildTerminalInstanceCameraDeclarations(instances) {
|
|
43303
|
+
return instances.filter((instance) => instance.enabled).map((instance) => ({
|
|
43304
|
+
stableId: instance.cameraStableId,
|
|
43305
|
+
name: instance.name,
|
|
43306
|
+
config: {
|
|
43307
|
+
instanceId: instance.id,
|
|
43308
|
+
nodeId: instance.nodeId,
|
|
43309
|
+
profileId: instance.profileId,
|
|
43310
|
+
profileLabel: instance.profileLabel
|
|
43311
|
+
}
|
|
43312
|
+
}));
|
|
43313
|
+
}
|
|
43314
|
+
/**
|
|
43315
|
+
* `DeviceConfig` materializes schema defaults in memory, so comparing
|
|
43316
|
+
* `config.get()` cannot detect a legacy `{ nodeId }` row. Reconciliation must
|
|
43317
|
+
* inspect the raw persisted blob to make the profile migration durable.
|
|
43318
|
+
*/
|
|
43319
|
+
function needsTerminalCameraConfigMigration(persistedConfig, declaration) {
|
|
43320
|
+
return persistedConfig.instanceId !== declaration.config.instanceId || persistedConfig.nodeId !== declaration.config.nodeId || persistedConfig.profileId !== declaration.config.profileId || persistedConfig.profileLabel !== declaration.config.profileLabel;
|
|
43321
|
+
}
|
|
43322
|
+
/**
|
|
43323
|
+
* Monospace families to try, in order — NOT one family and a generic.
|
|
43324
|
+
*
|
|
43325
|
+
* A terminal screen is mostly box-drawing and block characters, and a font
|
|
43326
|
+
* without them renders the frame as noise rather than as missing detail.
|
|
43327
|
+
* `DejaVu Sans Mono` covers them and ships in the hub image; macOS has neither
|
|
43328
|
+
* DejaVu nor fontconfig, so the Mac agent fell through to a generic whose
|
|
43329
|
+
* coverage is not, and its Glances camera came out unreadable while the hub's
|
|
43330
|
+
* was pixel-perfect (measured 2026-08-11, same Glances, two nodes).
|
|
43331
|
+
*
|
|
43332
|
+
* `Menlo` is the fix rather than a guess: it is macOS's default terminal face,
|
|
43333
|
+
* present on every install, and derived from DejaVu Sans Mono — the same glyph
|
|
43334
|
+
* coverage by ancestry. Monaco and Courier New follow as older fallbacks; the
|
|
43335
|
+
* generic stays last so a host with none of them still draws something.
|
|
43336
|
+
*/
|
|
43337
|
+
var TERMINAL_FONT_STACK = "DejaVu Sans Mono,Menlo,Monaco,Courier New,monospace";
|
|
43338
|
+
var TERMINAL_FONT_SIZE = 13;
|
|
43339
|
+
var TERMINAL_TEXT_MARGIN_X = 8;
|
|
43340
|
+
var TERMINAL_ROW_HEIGHT = 15;
|
|
43341
|
+
var TERMINAL_BASELINE_Y = 18;
|
|
43342
|
+
/**
|
|
43343
|
+
* Distance from a row's baseline up to the top of its cell box. Chosen so
|
|
43344
|
+
* consecutive rows tile exactly: row N's box runs from `baseline - this` for
|
|
43345
|
+
* `TERMINAL_ROW_HEIGHT`, and row N+1's box starts where it ends. A background
|
|
43346
|
+
* bar that stopped short would draw as stripes across a `CSI 42m` panel.
|
|
43347
|
+
*/
|
|
43348
|
+
var TERMINAL_CELL_ASCENT = 11.5;
|
|
43349
|
+
var TERMINAL_CELL_WIDTH = TERMINAL_FONT_SIZE * (1233 / 2048);
|
|
43350
|
+
/** Two decimals is under a tenth of a pixel and keeps the SVG small. */
|
|
43351
|
+
function coordinate(value) {
|
|
43352
|
+
return String(Number(value.toFixed(2)));
|
|
43353
|
+
}
|
|
43354
|
+
function escapeXml(value) {
|
|
43355
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
43356
|
+
}
|
|
43357
|
+
/**
|
|
43358
|
+
* Render already-interpreted terminal rows into a compact MJPEG frame.
|
|
43359
|
+
*
|
|
43360
|
+
* `xml:space="preserve"` is load-bearing, not tidiness. SVG `<text>` collapses
|
|
43361
|
+
* runs of whitespace by default, and a terminal's entire column alignment IS
|
|
43362
|
+
* runs of whitespace — Glances pads every field with spaces. Without it the
|
|
43363
|
+
* frame drew each line at roughly half its true width, crammed into the
|
|
43364
|
+
* top-left of a mostly-black image, while the SAME session over `attach`
|
|
43365
|
+
* looked perfect — which is exactly how the operator reported it. Measured in
|
|
43366
|
+
* the hub's own rasterizer 2026-08-11: `AAA<10 spaces>BBB<3>CCC` drew 92 px
|
|
43367
|
+
* collapsed against 178 px preserved.
|
|
43368
|
+
*
|
|
43369
|
+
* Every run is anchored at its OWN column (`x = margin + startCol * cellW`),
|
|
43370
|
+
* never appended to the one before it, so the background rects and the glyphs
|
|
43371
|
+
* are placed off the same grid and cannot drift apart. `textLength` is emitted
|
|
43372
|
+
* with it because it is the correct declaration and renderers that honour it
|
|
43373
|
+
* get an exact grid — but it is not what makes this work: librsvg, which sharp
|
|
43374
|
+
* uses, ignores it outright (measured 2026-08-12, a 120-glyph run pinned to
|
|
43375
|
+
* 600 px still drew its natural 937 px). The anchoring is the guarantee.
|
|
43376
|
+
*/
|
|
43377
|
+
function renderTerminalSvg(rows) {
|
|
43378
|
+
const backgrounds = [];
|
|
43379
|
+
const texts = [];
|
|
43380
|
+
rows.slice(0, 40).forEach((row, index) => {
|
|
43381
|
+
const baseline = TERMINAL_BASELINE_Y + index * TERMINAL_ROW_HEIGHT;
|
|
43382
|
+
const top = baseline - TERMINAL_CELL_ASCENT;
|
|
43383
|
+
let column = 0;
|
|
43384
|
+
for (const run of row) {
|
|
43385
|
+
if (column >= 120) break;
|
|
43386
|
+
const clipped = clipRun(run, 120 - column);
|
|
43387
|
+
const columns = [...clipped].length;
|
|
43388
|
+
if (columns === 0) continue;
|
|
43389
|
+
const x = TERMINAL_TEXT_MARGIN_X + column * TERMINAL_CELL_WIDTH;
|
|
43390
|
+
const width = columns * TERMINAL_CELL_WIDTH;
|
|
43391
|
+
if (run.bg !== null) backgrounds.push(`<rect x="${coordinate(x)}" y="${coordinate(top)}" width="${coordinate(width)}" height="${String(TERMINAL_ROW_HEIGHT)}" fill="${run.bg}"/>`);
|
|
43392
|
+
if (clipped.trim() !== "") {
|
|
43393
|
+
const fill = run.fg === null ? "" : ` fill="${run.fg}"`;
|
|
43394
|
+
const weight = run.bold ? " font-weight=\"bold\"" : "";
|
|
43395
|
+
texts.push(`<text xml:space="preserve" x="${coordinate(x)}" y="${coordinate(baseline)}" textLength="${coordinate(width)}" lengthAdjust="spacingAndGlyphs"${fill}${weight}>${escapeXml(clipped)}</text>`);
|
|
43396
|
+
}
|
|
43397
|
+
column += columns;
|
|
43398
|
+
}
|
|
43399
|
+
});
|
|
43400
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${String(960)}" height="${String(640)}"><rect width="100%" height="100%" fill="${TERMINAL_DEFAULT_BG}"/>${backgrounds.join("")}<g fill="${TERMINAL_DEFAULT_FG}" font-family="${TERMINAL_FONT_STACK}" font-size="${String(TERMINAL_FONT_SIZE)}">${texts.join("")}</g></svg>`;
|
|
43401
|
+
}
|
|
43402
|
+
/** Cut a run to the columns still left in the row, by code point not unit. */
|
|
43403
|
+
function clipRun(run, remaining) {
|
|
43404
|
+
const points = [...run.text];
|
|
43405
|
+
return points.length <= remaining ? run.text : points.slice(0, remaining).join("");
|
|
43406
|
+
}
|
|
43407
|
+
async function renderTerminalJpeg(rows) {
|
|
43408
|
+
return (0, sharp.default)(Buffer.from(renderTerminalSvg(rows))).jpeg({
|
|
43409
|
+
quality: 82,
|
|
43410
|
+
chromaSubsampling: "4:2:0"
|
|
43411
|
+
}).toBuffer();
|
|
43412
|
+
}
|
|
43413
|
+
//#endregion
|
|
43414
|
+
//#region src/terminal-camera-device.ts
|
|
43415
|
+
var terminalCameraSchema = object({
|
|
43416
|
+
instanceId: string().min(1).optional(),
|
|
43417
|
+
nodeId: string().min(1),
|
|
43418
|
+
profileId: string().min(1).default("monitor"),
|
|
43419
|
+
profileLabel: string().min(1).default("BTM")
|
|
43420
|
+
});
|
|
43421
|
+
var relay = null;
|
|
43422
|
+
function installTerminalCameraRelay(next) {
|
|
43423
|
+
relay = next;
|
|
43424
|
+
}
|
|
43425
|
+
var TerminalCameraDevice = class extends BaseDevice {
|
|
43426
|
+
features = [DeviceFeature.NativeSnapshot];
|
|
43427
|
+
constructor(ctx) {
|
|
43428
|
+
super(ctx, terminalCameraSchema, { type: ctx.deviceMeta.type });
|
|
43429
|
+
this.ctx.registerNativeCap(streamCatalogCapability, { getCatalog: async ({ deviceId }) => {
|
|
43430
|
+
if (deviceId !== this.id) return [];
|
|
43431
|
+
return this.catalog();
|
|
43432
|
+
} });
|
|
43433
|
+
this.ctx.registerNativeCap(snapshotCapability, {
|
|
43434
|
+
getSnapshot: async ({ deviceId }) => {
|
|
43435
|
+
if (deviceId !== this.id) throw new Error(`TerminalCameraDevice: deviceId mismatch, expected ${String(this.id)}, got ${String(deviceId)}`);
|
|
43436
|
+
const activeRelay = relay;
|
|
43437
|
+
if (!activeRelay) throw new Error("terminal camera relay is unavailable");
|
|
43438
|
+
return {
|
|
43439
|
+
base64: (await activeRelay.snapshot(this.relayInstanceId(), this.config.get("nodeId"), this.config.get("profileId"))).toString("base64"),
|
|
43440
|
+
contentType: "image/jpeg"
|
|
43441
|
+
};
|
|
43442
|
+
},
|
|
43443
|
+
invalidateCache: async () => {}
|
|
43444
|
+
});
|
|
43445
|
+
this.markOnline(true);
|
|
43446
|
+
}
|
|
43447
|
+
async catalog() {
|
|
43448
|
+
const activeRelay = relay;
|
|
43449
|
+
if (!activeRelay) throw new Error("terminal camera relay is unavailable");
|
|
43450
|
+
const nodeId = this.config.get("nodeId");
|
|
43451
|
+
const profileId = this.config.get("profileId");
|
|
43452
|
+
const instanceId = this.relayInstanceId();
|
|
43453
|
+
return [{
|
|
43454
|
+
camStreamId: profileId,
|
|
43455
|
+
kind: "pull-http",
|
|
43456
|
+
url: activeRelay.streamUrl(instanceId, nodeId, profileId),
|
|
43457
|
+
codec: "h264",
|
|
43458
|
+
resolution: {
|
|
43459
|
+
width: 960,
|
|
43460
|
+
height: 640
|
|
43461
|
+
},
|
|
43462
|
+
fps: 2,
|
|
43463
|
+
label: this.config.get("profileLabel")
|
|
43464
|
+
}];
|
|
43465
|
+
}
|
|
43466
|
+
setNodeOnline(online) {
|
|
43467
|
+
this.markOnline(online);
|
|
43468
|
+
if (!online) relay?.closeInstance(this.relayInstanceId());
|
|
43469
|
+
}
|
|
43470
|
+
async removeDevice() {
|
|
43471
|
+
await relay?.closeInstance(this.relayInstanceId());
|
|
43472
|
+
}
|
|
43473
|
+
relayInstanceId() {
|
|
43474
|
+
return this.config.get("instanceId") ?? `legacy:${this.stableId}`;
|
|
43475
|
+
}
|
|
43476
|
+
};
|
|
43477
|
+
//#endregion
|
|
43368
43478
|
//#region src/terminal-camera-relay.ts
|
|
43369
43479
|
var MJPEG_BOUNDARY = "camstack-terminal-frame";
|
|
43370
43480
|
var SESSION_IDLE_MS = 3e4;
|
|
@@ -43444,7 +43554,7 @@ var TerminalCameraRelay = class {
|
|
|
43444
43554
|
instanceId,
|
|
43445
43555
|
nodeId,
|
|
43446
43556
|
profileId,
|
|
43447
|
-
screen: createXtermScreen
|
|
43557
|
+
screen: createXtermScreen(120, 40),
|
|
43448
43558
|
sessionId: null,
|
|
43449
43559
|
cursor: 0,
|
|
43450
43560
|
clients: 0,
|
|
@@ -43501,7 +43611,7 @@ var TerminalCameraRelay = class {
|
|
|
43501
43611
|
applyBatch(state, batch) {
|
|
43502
43612
|
if (batch.reset) {
|
|
43503
43613
|
state.screen.dispose();
|
|
43504
|
-
state.screen = createXtermScreen
|
|
43614
|
+
state.screen = createXtermScreen(120, 40);
|
|
43505
43615
|
if (batch.snapshot) state.screen.write(batch.snapshot);
|
|
43506
43616
|
}
|
|
43507
43617
|
let exited = false;
|
|
@@ -45267,7 +45377,7 @@ exports.buildCellRuns = buildCellRuns;
|
|
|
45267
45377
|
exports.buildProfiles = buildProfiles;
|
|
45268
45378
|
exports.createNodePtySpawner = createNodePtySpawner;
|
|
45269
45379
|
exports.createTerminalDataPlaneHandler = createTerminalDataPlaneHandler;
|
|
45270
|
-
exports.createXtermScreen = createXtermScreen
|
|
45380
|
+
exports.createXtermScreen = createXtermScreen;
|
|
45271
45381
|
exports.findProfile = findProfile;
|
|
45272
45382
|
exports.resolveCellStyle = resolveCellStyle;
|
|
45273
45383
|
exports.terminalPaletteColor = terminalPaletteColor;
|