@rivus/gateway 0.21.2 → 0.22.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.
Files changed (31) hide show
  1. package/README.md +4 -1
  2. package/assets/audio-transcriber/fetch-model.mjs +63 -70
  3. package/assets/audio-transcriber/transcribe.mjs +38 -47
  4. package/assets/installation-policy.json +4 -3
  5. package/dist/bootstrap/feishu.d.ts +4 -2
  6. package/dist/bootstrap/feishu.js +19389 -17389
  7. package/dist/bootstrap/herdr-feishu.d.ts +1 -7
  8. package/dist/bootstrap/herdr-feishu.js +23 -12
  9. package/dist/chunks/automation-presentation.js +58 -60
  10. package/dist/chunks/feishu-receive-message.js +113 -0
  11. package/dist/chunks/herdr-feishu-runtime.js +1011 -626
  12. package/dist/chunks/public.d.ts +278 -0
  13. package/dist/chunks/public2.d.ts +10 -0
  14. package/dist/chunks/rivus-deployment-cli-process.d.ts +127 -455
  15. package/dist/chunks/rivus-home-deployment-env.js +1342 -1781
  16. package/dist/chunks/rivus-node-entrypoint.js +4574 -4199
  17. package/dist/index.d.ts +23 -11
  18. package/dist/mcp.d.ts +10 -9
  19. package/dist/mcp.js +43 -43
  20. package/package.json +18 -11
  21. package/templates/a-share-briefing-analysis.mjs +32 -34
  22. package/templates/a-share-briefing-renderer.mjs +175 -186
  23. package/templates/a-share-index-evidence.mjs +50 -54
  24. package/templates/a-share-market-briefing.mjs +37 -39
  25. package/templates/a-share-overseas-evidence.mjs +35 -39
  26. package/templates/a-share-policy-evidence.mjs +90 -96
  27. package/templates/a-share-sector-evidence.mjs +32 -35
  28. package/templates/acp-stdio-proxy.mjs +21 -22
  29. package/templates/current-weather.mjs +56 -58
  30. package/templates/html-drive-tools.mjs +130 -141
  31. package/templates/rivus-agents.plugin.mjs +55 -57
package/README.md CHANGED
@@ -5,6 +5,9 @@ Feishu adapters, management, project initialization, and the Gateway CLI resourc
5
5
 
6
6
  The package has no npm bin. Applications choose the public entrypoint or an explicit template resource.
7
7
 
8
+ The private `@rivus/utils` workspace supplies the shared Result type and unwrapping implementation during development.
9
+ Gateway inlines both into its JS and declarations; installed consumers require no Utils package or private imports.
10
+
8
11
  Gateway assembles the product CLI's `rivus upgrade [--json]` workflow for existing macOS LaunchAgents and Linux user
9
12
  systemd services. It validates a separate installation of the latest stable four-package release against the actual Home before
10
13
  stop, then backs up, switches and requires the service PID to match fresh readiness evidence. Home and application
@@ -16,7 +19,7 @@ See [managed Home upgrades](../../docs/en/operations/local-deployment.md#managed
16
19
 
17
20
  The root exposes `createRivusPluginCatalog`, `resolveRivusAgentDefinition`, `RIVUS_PLUGIN_API_VERSION` and
18
21
  `runRivusNodeEntrypoint`, plus nine plugin contracts. Catalog construction and resolution are implemented in Bootstrap.
19
- Host, Deployment, Automation, Human, Inbox, Recovery, Delegation and presentation helpers remain internal; use the
22
+ Host, Deployment, Automation, Human, Inbox, Recovery and presentation helpers remain internal; use the
20
23
  published Bootstrap and MCP entrypoints for complete process graphs.
21
24
 
22
25
  `@rivus/gateway/bootstrap/feishu` exports only `createRivusDeploymentAdapters` for manifest deployments.
@@ -30,7 +30,66 @@ const STALL_MS = 60_000;
30
30
  const ATTEMPTS = 2;
31
31
 
32
32
  class IntegrityError extends Error {}
33
+ /**
34
+ * Unpacks only the listed archive members, each under its installed name directly in `directory`. A listed member
35
+ * must be a regular file of exactly its pinned size, checked against its tar header before any of it is written, so the
36
+ * extracted bytes never exceed the sum of the pinned sizes.
37
+ */
38
+ async function extractMembers(archive, directory, members) {
39
+ /** @type {Error | undefined} */
40
+ let mismatch;
41
+ const unpack = extract({
42
+ cwd: directory,
43
+ filter: (path, entry) => {
44
+ if (!Object.hasOwn(members, path)) {
45
+ return false;
46
+ }
47
+ if (entry.type !== "File" || entry.size !== members[path].size) {
48
+ // Skipped rather than aborted: an abort fails the pipeline while earlier members are still being written,
49
+ // which would race the removal of the staging directory.
50
+ mismatch ??= new Error(`${path} is a ${entry.size}-byte ${entry.type}, not a ${members[path].size}-byte file`);
51
+ return false;
52
+ }
53
+ return true;
54
+ },
55
+ onReadEntry: (entry) => {
56
+ entry.path = members[entry.path].file;
57
+ },
58
+ preserveOwner: false,
59
+ strict: true
60
+ });
61
+ await pipeline(createReadStream(archive), bunzip2(), unpack);
62
+ if (mismatch) {
63
+ throw mismatch;
64
+ }
65
+ for (const [member, { file, size }] of Object.entries(members)) {
66
+ const info = await stat(join(directory, file)).catch(() => undefined);
67
+ if (info?.size !== size) {
68
+ throw new Error(`the archive has no ${size}-byte member ${member}`);
69
+ }
70
+ }
71
+ }
33
72
 
73
+ async function writeByteTokens(directory) {
74
+ const source = join(directory, "tokens.txt");
75
+ await writeFile(join(directory, "tokens.bytes.txt"), spellByteTokens(await readFile(source, "latin1")));
76
+ // Pointing sherpa-onnx at the original table would silently lose characters again.
77
+ await rm(source);
78
+ }
79
+ function firstLine(error) {
80
+ return String(error instanceof Error ? error.message : error).split("\n")[0];
81
+ }
82
+ // sherpa-onnx-node's loader replaces the dlopen error with a list of the paths it tried. Loading the platform binary
83
+ // directly reports the actual cause, such as a missing package or GLIBC version.
84
+ function nativeLoadError(error) {
85
+ const platform = process.platform === "win32" ? "win" : process.platform;
86
+ try {
87
+ createRequire(import.meta.url)(`sherpa-onnx-${platform}-${process.arch}/sherpa-onnx.node`);
88
+ } catch (direct) {
89
+ return firstLine(direct);
90
+ }
91
+ return firstLine(error);
92
+ }
34
93
  async function chooseRuntime(requested) {
35
94
  if (!RUNTIMES.includes(requested)) {
36
95
  throw new Error(`RIVUS_AUDIO_RUNTIME must be one of ${RUNTIMES.join(", ")}, not ${JSON.stringify(requested)}`);
@@ -49,19 +108,11 @@ async function chooseRuntime(requested) {
49
108
  return { nativeError: reason, runtime: "wasm" };
50
109
  }
51
110
  }
52
-
53
- // sherpa-onnx-node's loader replaces the dlopen error with a list of the paths it tried. Loading the platform binary
54
- // directly reports the actual cause, such as a missing package or GLIBC version.
55
- function nativeLoadError(error) {
56
- const platform = process.platform === "win32" ? "win" : process.platform;
57
- try {
58
- createRequire(import.meta.url)(`sherpa-onnx-${platform}-${process.arch}/sherpa-onnx.node`);
59
- } catch (direct) {
60
- return firstLine(direct);
61
- }
62
- return firstLine(error);
111
+ // fetch() reports network failures as "fetch failed" with the reason in `cause`.
112
+ function describe(error) {
113
+ const cause = error instanceof Error && error.cause instanceof Error ? ` (${error.cause.message})` : "";
114
+ return `${firstLine(error)}${cause}`;
63
115
  }
64
-
65
116
  /** Downloads `url` into `file`, failing as soon as it exceeds `size` and when it does not match `sha256`. */
66
117
  async function download(url, { sha256, size }, file, stallMs) {
67
118
  const hash = createHash("sha256");
@@ -116,53 +167,6 @@ async function downloadWithRetry(url, pin, file, stallMs) {
116
167
  }
117
168
  }
118
169
  }
119
-
120
- /**
121
- * Unpacks only the listed archive members, each under its installed name directly in `directory`. A listed member
122
- * must be a regular file of exactly its pinned size, checked against its tar header before any of it is written, so the
123
- * extracted bytes never exceed the sum of the pinned sizes.
124
- */
125
- async function extractMembers(archive, directory, members) {
126
- let mismatch;
127
- const unpack = extract({
128
- cwd: directory,
129
- filter: (path, entry) => {
130
- if (!Object.hasOwn(members, path)) {
131
- return false;
132
- }
133
- if (entry.type !== "File" || entry.size !== members[path].size) {
134
- // Skipped rather than aborted: an abort fails the pipeline while earlier members are still being written,
135
- // which would race the removal of the staging directory.
136
- mismatch ??= new Error(`${path} is a ${entry.size}-byte ${entry.type}, not a ${members[path].size}-byte file`);
137
- return false;
138
- }
139
- return true;
140
- },
141
- onReadEntry: (entry) => {
142
- entry.path = members[entry.path].file;
143
- },
144
- preserveOwner: false,
145
- strict: true
146
- });
147
- await pipeline(createReadStream(archive), bunzip2(), unpack);
148
- if (mismatch) {
149
- throw mismatch;
150
- }
151
- for (const [member, { file, size }] of Object.entries(members)) {
152
- const info = await stat(join(directory, file)).catch(() => undefined);
153
- if (info?.size !== size) {
154
- throw new Error(`the archive has no ${size}-byte member ${member}`);
155
- }
156
- }
157
- }
158
-
159
- async function writeByteTokens(directory) {
160
- const source = join(directory, "tokens.txt");
161
- await writeFile(join(directory, "tokens.bytes.txt"), spellByteTokens(await readFile(source, "latin1")));
162
- // Pointing sherpa-onnx at the original table would silently lose characters again.
163
- await rm(source);
164
- }
165
-
166
170
  /**
167
171
  * Installs the model that `manifest` pins for this host's runtime into `modelDirectory`, replacing what is there only
168
172
  * once everything is in place. Tests call it directly with a short `stallMs`.
@@ -198,17 +202,6 @@ export async function install(manifest, modelDirectory, { env = process.env, sta
198
202
  throw error;
199
203
  }
200
204
  }
201
-
202
- function firstLine(error) {
203
- return String(error instanceof Error ? error.message : error).split("\n")[0];
204
- }
205
-
206
- // fetch() reports network failures as "fetch failed" with the reason in `cause`.
207
- function describe(error) {
208
- const cause = error instanceof Error && error.cause instanceof Error ? ` (${error.cause.message})` : "";
209
- return `${firstLine(error)}${cause}`;
210
- }
211
-
212
205
  if (import.meta.main) {
213
206
  try {
214
207
  const [manifestPath, modelDirectory] = process.argv.slice(2);
@@ -104,7 +104,18 @@ export function detectFormat(buffer) {
104
104
  }
105
105
  return "unknown";
106
106
  }
107
-
107
+ function downmix(channelData, length) {
108
+ if (channelData.length === 1) {
109
+ return channelData[0].subarray(0, length);
110
+ }
111
+ const mono = new Float32Array(length);
112
+ for (const channel of channelData) {
113
+ for (let i = 0; i < length; i++) {
114
+ mono[i] += channel[i] / channelData.length;
115
+ }
116
+ }
117
+ return mono;
118
+ }
108
119
  async function decodeOggOpus(buffer) {
109
120
  const { OggOpusDecoder } = await import("ogg-opus-decoder");
110
121
  const decoder = new OggOpusDecoder({ sampleRate: SAMPLE_RATE });
@@ -122,20 +133,6 @@ async function decodeOggOpus(buffer) {
122
133
  decoder.free();
123
134
  }
124
135
  }
125
-
126
- function downmix(channelData, length) {
127
- if (channelData.length === 1) {
128
- return channelData[0].subarray(0, length);
129
- }
130
- const mono = new Float32Array(length);
131
- for (const channel of channelData) {
132
- for (let i = 0; i < length; i++) {
133
- mono[i] += channel[i] / channelData.length;
134
- }
135
- }
136
- return mono;
137
- }
138
-
139
136
  // sherpa's WAV reader keeps only the first channel and the transcriber has no resampler, so only 16 kHz mono 16-bit
140
137
  // PCM (format code 1) with the fmt chunk first is accepted.
141
138
  export function checkWav(buffer) {
@@ -158,7 +155,15 @@ function readWav(engine, buffer, path) {
158
155
  }
159
156
  return wave.samples;
160
157
  }
161
-
158
+ function bindVad(vad) {
159
+ return {
160
+ acceptWaveform: (samples) => vad.acceptWaveform(samples),
161
+ flush: () => vad.flush(),
162
+ front: () => vad.front(),
163
+ isEmpty: () => vad.isEmpty(),
164
+ pop: () => vad.pop()
165
+ };
166
+ }
162
167
  // The two packages expose the same engine through different call shapes; these adapters give the rest of the script
163
168
  // one interface.
164
169
  function nativeEngine(sherpa) {
@@ -225,17 +230,6 @@ function wasmEngine(sherpa) {
225
230
  readWave: (buffer) => quietly(() => sherpa.readWaveFromBinaryData(new Uint8Array(buffer)))
226
231
  };
227
232
  }
228
-
229
- function bindVad(vad) {
230
- return {
231
- acceptWaveform: (samples) => vad.acceptWaveform(samples),
232
- flush: () => vad.flush(),
233
- front: () => vad.front(),
234
- isEmpty: () => vad.isEmpty(),
235
- pop: () => vad.pop()
236
- };
237
- }
238
-
239
233
  async function loadEngine(runtime) {
240
234
  if (runtime === "wasm") {
241
235
  return wasmEngine(await quietly(async () => (await import("sherpa-onnx")).default));
@@ -275,7 +269,23 @@ function speechSegments(engine, samples) {
275
269
  }
276
270
  return segments;
277
271
  }
278
-
272
+ // Centre of the 100 ms window with the least energy in [from, to).
273
+ function quietestPoint(samples, from, to) {
274
+ const window = SAMPLE_RATE / 10;
275
+ let best = to;
276
+ let bestEnergy = Infinity;
277
+ for (let i = from; i + window <= to; i += window / 2) {
278
+ let energy = 0;
279
+ for (let j = i; j < i + window; j++) {
280
+ energy += samples[j] * samples[j];
281
+ }
282
+ if (energy < bestEnergy) {
283
+ best = i + window / 2;
284
+ bestEnergy = energy;
285
+ }
286
+ }
287
+ return best;
288
+ }
279
289
  // Merges consecutive VAD segments into chunks, widens each by a little context without overlapping its neighbours,
280
290
  // then splits any chunk that is still longer than CHUNK_SECONDS.
281
291
  export function chunkSegments(segments, samples) {
@@ -303,25 +313,6 @@ export function chunkSegments(segments, samples) {
303
313
  return pieces;
304
314
  });
305
315
  }
306
-
307
- // Centre of the 100 ms window with the least energy in [from, to).
308
- function quietestPoint(samples, from, to) {
309
- const window = SAMPLE_RATE / 10;
310
- let best = to;
311
- let bestEnergy = Infinity;
312
- for (let i = from; i + window <= to; i += window / 2) {
313
- let energy = 0;
314
- for (let j = i; j < i + window; j++) {
315
- energy += samples[j] * samples[j];
316
- }
317
- if (energy < bestEnergy) {
318
- best = i + window / 2;
319
- bestEnergy = energy;
320
- }
321
- }
322
- return best;
323
- }
324
-
325
316
  function recognizerConfig(engine, language) {
326
317
  return {
327
318
  featConfig: { featureDim: 80, sampleRate: SAMPLE_RATE },
@@ -6,8 +6,9 @@
6
6
  "overrides": {
7
7
  "brace-expansion@>=5.0.0 <5.0.12": "5.0.12",
8
8
  "undici@>=8.0.0 <8.12.3": "8.12.3",
9
- "@opentelemetry/api": "1.9.1",
10
- "zod@>=4.0.0 <4.6.6": "4.6.6"
9
+ "follow-redirects@>=1.16.0 <1.16.2": "1.16.2",
10
+ "@opentelemetry/api": "1.10.0",
11
+ "zod@^4.0.0": "4.6.7"
11
12
  },
12
- "allowBuilds": { "@google/genai": false, "protobufjs": false }
13
+ "allowBuilds": { "@google/genai": false, "protobufjs": false, "unrs-resolver": false }
13
14
  }
@@ -1,13 +1,15 @@
1
- import { c as CreateRivusDeploymentEndpointPortInput, d as RivusDeploymentEndpointPort, f as RivusDeploymentRuntimePort, l as CreateRivusDeploymentRuntimePortInput, o as CreateRivusDeploymentAutomationPortInput, s as CreateRivusDeploymentBackgroundSessionPortInput, t as RivusDeploymentBootstrapContext, u as RivusDeploymentBackgroundSessionPort, x as AutomationScheduler, z as RecoveryControl } from "../chunks/rivus-deployment-cli-process.js";
1
+ import { c as CreateRivusDeploymentEndpointPortInput, d as RivusDeploymentEndpointPort, f as RivusDeploymentRuntimePort, l as CreateRivusDeploymentRuntimePortInput, o as CreateRivusDeploymentAutomationPortInput, p as RecoveryControl, s as CreateRivusDeploymentBackgroundSessionPortInput, t as RivusDeploymentBootstrapContext, u as RivusDeploymentBackgroundSessionPort } from "../chunks/rivus-deployment-cli-process.js";
2
+ import { _ as AutomationScheduler } from "../chunks/public.js";
2
3
  import { Effect } from "effect";
3
4
  //#region src/bootstrap/feishu.d.ts
5
+ /** Assemble the deployment adapters for a manifest-driven daemon. */
4
6
  export declare function createRivusDeploymentAdapters(context: RivusDeploymentBootstrapContext): Promise<{
5
7
  dispose: () => Promise<void>;
6
8
  createRecoveryControl: () => Effect.Effect<RecoveryControl, unknown, never>;
7
9
  createBackgroundSession: ((input: CreateRivusDeploymentBackgroundSessionPortInput) => Effect.Effect<RivusDeploymentBackgroundSessionPort, unknown, never>) | undefined;
8
10
  createAutomation: (input: CreateRivusDeploymentAutomationPortInput) => Effect.Effect<AutomationScheduler, unknown, never>;
9
11
  createEndpoint: (input: CreateRivusDeploymentEndpointPortInput) => Effect.Effect<RivusDeploymentEndpointPort, unknown, never>;
10
- createRuntime: (input: CreateRivusDeploymentRuntimePortInput) => Effect.Effect<RivusDeploymentRuntimePort, unknown>;
12
+ createRuntime: (input: CreateRivusDeploymentRuntimePortInput) => Effect.Effect<RivusDeploymentRuntimePort, unknown, never>;
11
13
  }>;
12
14
  //#endregion
13
15
  export {};