signalk-piper 0.0.1 → 0.2.0
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 +88 -8
- package/dist/config.d.ts +127 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/service.d.ts +142 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +596 -0
- package/dist/service.js.map +1 -0
- package/dist/wyoming.d.ts +29 -0
- package/dist/wyoming.d.ts.map +1 -0
- package/dist/wyoming.js +124 -0
- package/dist/wyoming.js.map +1 -0
- package/package.json +63 -5
- package/public/172.mjs +1 -0
- package/public/540.mjs +2 -0
- package/public/540.mjs.LICENSE.txt +9 -0
- package/public/main.mjs +1 -0
- package/public/remoteEntry.js +1 -0
- package/index.js +0 -23
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PiperService — the plugin's whole runtime: managed container lifecycle,
|
|
3
|
+
* Wyoming describe readiness gate, periodic health loop, `wyoming-service`
|
|
4
|
+
* PropertyValues emission (with the family's emission discipline) and the
|
|
5
|
+
* plugin router endpoints.
|
|
6
|
+
*
|
|
7
|
+
* One instance lives for the whole server process (plugin routers cannot be
|
|
8
|
+
* deregistered); `start()`/`stop()` may run many times against it.
|
|
9
|
+
*/
|
|
10
|
+
import { ManagedContainer, type RouterLike } from "signalk-container-helper";
|
|
11
|
+
import { type PiperSettings } from "./config.js";
|
|
12
|
+
export declare const PLUGIN_ID = "signalk-piper";
|
|
13
|
+
export declare const SERVICE_TYPE = "tts";
|
|
14
|
+
export declare const NOTIFICATION_PATH = "notifications.voice.piper";
|
|
15
|
+
export type ServiceStatus = "starting" | "ready" | "stopped" | "error";
|
|
16
|
+
/** The subset of the Signal K plugin app surface this plugin uses. */
|
|
17
|
+
export interface ServiceApp {
|
|
18
|
+
debug(msg: string): void;
|
|
19
|
+
error(msg: string): void;
|
|
20
|
+
setPluginStatus(msg: string): void;
|
|
21
|
+
setPluginError(msg: string): void;
|
|
22
|
+
emitPropertyValue(name: string, value: unknown): void;
|
|
23
|
+
handleMessage(id: string, delta: unknown): void;
|
|
24
|
+
savePluginOptions(configuration: object, callback: (err: unknown) => void): void;
|
|
25
|
+
}
|
|
26
|
+
/** All intervals/deadlines, overridable for tests. Defaults per family spec. */
|
|
27
|
+
export interface ServiceTiming {
|
|
28
|
+
/** Delay between describe attempts while waiting for readiness. */
|
|
29
|
+
gateIntervalMs: number;
|
|
30
|
+
/** Give up on the readiness gate after this long (model downloads are slow). */
|
|
31
|
+
gateDeadlineMs: number;
|
|
32
|
+
/** Progress line frequency while the gate is waiting. */
|
|
33
|
+
gateStatusEveryMs: number;
|
|
34
|
+
/** Per-attempt describe timeout (gate + health loop). */
|
|
35
|
+
describeTimeoutMs: number;
|
|
36
|
+
/** Health loop period. */
|
|
37
|
+
healthIntervalMs: number;
|
|
38
|
+
/** Consecutive failed probes before alarming. */
|
|
39
|
+
healthFailThreshold: number;
|
|
40
|
+
/** Minimum spacing between wyoming-service emissions (flap collapse). */
|
|
41
|
+
emitDebounceMs: number;
|
|
42
|
+
/** Flap guard window and transition budget. */
|
|
43
|
+
flapWindowMs: number;
|
|
44
|
+
flapMaxTransitions: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_TIMING: ServiceTiming;
|
|
47
|
+
export interface HealthSample {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
at: number;
|
|
50
|
+
latencyMs: number | null;
|
|
51
|
+
}
|
|
52
|
+
export declare class PiperService {
|
|
53
|
+
readonly container: ManagedContainer;
|
|
54
|
+
settings: PiperSettings;
|
|
55
|
+
private readonly app;
|
|
56
|
+
private readonly timing;
|
|
57
|
+
private running;
|
|
58
|
+
/** Increments per start() so stale async work from a prior run is inert. */
|
|
59
|
+
private runId;
|
|
60
|
+
private uri;
|
|
61
|
+
private lastInfo;
|
|
62
|
+
private lastHealth;
|
|
63
|
+
private consecutiveFailures;
|
|
64
|
+
private probeInFlight;
|
|
65
|
+
/** True while an update apply recreates the container (pauses probes). */
|
|
66
|
+
private updating;
|
|
67
|
+
private healthTimer;
|
|
68
|
+
private currentStatus;
|
|
69
|
+
private lastEmittedStatus;
|
|
70
|
+
private lastEmittedUri;
|
|
71
|
+
private lastEmitAt;
|
|
72
|
+
private pendingEmitTimer;
|
|
73
|
+
private transitionTimes;
|
|
74
|
+
private flapSuppressed;
|
|
75
|
+
private emissionsDisabled;
|
|
76
|
+
constructor(app: ServiceApp, timing?: Partial<ServiceTiming>);
|
|
77
|
+
get isRunning(): boolean;
|
|
78
|
+
/** Called from the synchronous plugin start(). */
|
|
79
|
+
start(rawConfig: unknown): void;
|
|
80
|
+
/** Async server stop() — awaited by Signal K before a restart. */
|
|
81
|
+
stop(): Promise<void>;
|
|
82
|
+
private startAsync;
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the service address, gate on Wyoming `describe`, go ready and
|
|
85
|
+
* start the health loop. Shared by first start and the post-update resume.
|
|
86
|
+
* A gate failure after the uri is known is surfaced loudly (spec §3.3:
|
|
87
|
+
* wyoming-service 'error' + notification alarm) and the health loop still
|
|
88
|
+
* starts, so eventual recovery is detected without a manual restart.
|
|
89
|
+
*/
|
|
90
|
+
private becomeReady;
|
|
91
|
+
/**
|
|
92
|
+
* host:port of the Wyoming port. Default networking declares the port via
|
|
93
|
+
* signalkAccessiblePorts and must resolve; the explicit 0.0.0.0 publish
|
|
94
|
+
* ("bind") is not manager-resolvable, but is by definition reachable on
|
|
95
|
+
* the loopback of the host.
|
|
96
|
+
*/
|
|
97
|
+
private resolveServiceAddress;
|
|
98
|
+
/**
|
|
99
|
+
* Poll Wyoming `describe` until the service answers with `info` — which
|
|
100
|
+
* proves the model is downloaded and the service is actually serving.
|
|
101
|
+
* Returns null when the run was superseded while waiting.
|
|
102
|
+
*/
|
|
103
|
+
private describeGate;
|
|
104
|
+
private validateInfo;
|
|
105
|
+
/** Warn (loudly, once per start) about 16 kHz voices; never block. */
|
|
106
|
+
private validateVoice;
|
|
107
|
+
private runningStatusLine;
|
|
108
|
+
private startHealthLoop;
|
|
109
|
+
private stopHealthLoop;
|
|
110
|
+
private healthProbe;
|
|
111
|
+
/** Boolean describe probe for signalk-container's recurring healthCheck. */
|
|
112
|
+
private probeOk;
|
|
113
|
+
/**
|
|
114
|
+
* Request an emission of `status`. Rules:
|
|
115
|
+
* - never emit the same (status, uri) pair twice in a row — a uri change
|
|
116
|
+
* (post-update port move) re-emits even when the status is unchanged;
|
|
117
|
+
* - at most one emission per emitDebounceMs (later requests collapse into
|
|
118
|
+
* the trailing timer, so a flap that settles back emits nothing);
|
|
119
|
+
* - >flapMaxTransitions transitions per flapWindowMs → warn and suppress;
|
|
120
|
+
* - omitted while the uri is unknown, except "stopped";
|
|
121
|
+
* - a throwing emitPropertyValue (server-wide PropertyValues cap) disables
|
|
122
|
+
* all further emissions for this run;
|
|
123
|
+
* - "stopped" flushes immediately (stop() must not race the debounce).
|
|
124
|
+
*/
|
|
125
|
+
private emit;
|
|
126
|
+
private emitNow;
|
|
127
|
+
private notify;
|
|
128
|
+
/**
|
|
129
|
+
* The container was just recreated (and started) by an update apply: the
|
|
130
|
+
* host port can change and the new instance must answer `describe` before
|
|
131
|
+
* it is advertised again. Supersede the current run and re-run the
|
|
132
|
+
* readiness flow (resolve → gate → ready → health loop) against it.
|
|
133
|
+
*/
|
|
134
|
+
private resumeAfterUpdate;
|
|
135
|
+
/**
|
|
136
|
+
* Mount plugin routes. Called once per server process (even while the
|
|
137
|
+
* plugin is disabled), so every handler checks the running flag.
|
|
138
|
+
*/
|
|
139
|
+
registerRoutes(router: RouterLike, rawOptionsForSave: () => unknown): void;
|
|
140
|
+
private active;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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