@rivus/gateway 0.18.2 → 0.20.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 +16 -7
- package/assets/audio-transcriber/THIRD_PARTY_NOTICES.md +86 -0
- package/assets/audio-transcriber/byte-tokens.mjs +33 -0
- package/assets/audio-transcriber/fetch-model.mjs +225 -0
- package/assets/audio-transcriber/manifest.json +64 -0
- package/assets/audio-transcriber/npm-shrinkwrap.json +345 -0
- package/assets/audio-transcriber/package.json +15 -0
- package/assets/audio-transcriber/transcribe.mjs +411 -0
- package/dist/bootstrap/feishu.d.ts +13 -0
- package/dist/bootstrap/{pi-feishu.js → feishu.js} +16021 -15670
- package/dist/chunks/automation-presentation.js +265 -0
- package/dist/chunks/herdr-feishu-runtime.js +2 -2
- package/dist/chunks/{rivus-daemon-cli.d.ts → rivus-deployment-cli-process.d.ts} +136 -355
- package/dist/chunks/{runtime-cache.js → rivus-home-deployment-env.js} +971 -91
- package/dist/chunks/rivus-node-entrypoint.js +485 -655
- package/dist/index.d.ts +27 -3
- package/dist/index.js +2 -1
- package/dist/mcp.d.ts +11 -15
- package/dist/mcp.js +64 -86
- package/package.json +20 -15
- package/templates/{pi-feishu-deployment.bootstrap.ts → feishu-deployment.bootstrap.ts} +1 -1
- package/dist/bootstrap/pi-feishu.d.ts +0 -285
- package/dist/chunks/background-session-authority.js +0 -194
- package/templates/pi-feishu.bootstrap.ts +0 -1
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as narrowBackgroundSessionDefinition, t as createBackgroundSessionToolContracts } from "./background-session-authority.js";
|
|
1
|
+
import { A as resolveFeishuEndpointCredentials, C as gatewayTemplateDirectory, D as parseRivusModelManagementEnabled, F as narrowBackgroundSessionDefinition, I as deepFreeze, M as validateRivusDeploymentManifest, N as validateRivusProjectSpaceDeployment, P as createBackgroundSessionToolContracts, T as resolveAcpRuntimeEnvironment, _ as readRivusAudioInstalledRelease, a as invokeRuntimeControl, d as renderRivusModelCliArgumentError, f as renderRivusModelCliHelp, g as installRivusAudioTranscriber, i as disposeRuntimeCacheEntries, j as InvalidRivusProjectSpace, k as loadMergedLocalEnvFile, l as createRivusModelManagementWireRequest, m as runRivusAudioProcess, n as withoutRivusHomeDeployment, o as RIVUS_RELEASE_DESCRIPTOR, p as runRivusAudioPassthroughProcess, r as createRuntimeCache, t as RIVUS_HOME_DEPLOYMENT_ENV, u as parseRivusModelCliArguments, v as readRivusAudioStatus, w as loadRivusDeploymentManifest, x as gatewayPackageManifestPath, y as gatewayAudioTranscriberAssetDirectory } from "./rivus-home-deployment-env.js";
|
|
3
2
|
import { createRequire } from "node:module";
|
|
4
3
|
import { createSha256Digest, createStableId } from "@rivus/platform/identity";
|
|
4
|
+
import { Cause, Deferred, Effect, Exit, Result, Schema, Semaphore } from "effect";
|
|
5
5
|
import { RIVUS_MEMORY_TOOL_PLUGIN_ID, RIVUS_RUNTIME_TOOL_IDS, createRivusMemoryToolContract, isRivusRuntimeToolId } from "@rivus/runtime";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
8
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
-
import { Cause, Deferred, Effect, Exit, Result, Semaphore } from "effect";
|
|
10
9
|
import { lstat, mkdir, open, readFile, readdir, realpath, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
11
10
|
import { randomUUID } from "node:crypto";
|
|
12
11
|
import { assertPathWithin, isPathWithin } from "@rivus/platform/filesystem";
|
|
13
|
-
import { createConnection } from "node:net";
|
|
14
12
|
import { constants as constants$1 } from "node:fs";
|
|
13
|
+
import { createConnection } from "node:net";
|
|
15
14
|
import { unwrapExit } from "@rivus/platform/effect";
|
|
16
15
|
//#region src/core/application/agent-catalog/contracts/rivus-plugin.ts
|
|
17
16
|
const RIVUS_PLUGIN_API_VERSION = "1";
|
|
@@ -20,6 +19,28 @@ var InvalidRivusPlugin = class extends Error {
|
|
|
20
19
|
};
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/core/application/agent-catalog/catalog/rivus-catalog-validation.ts
|
|
22
|
+
const automationRetryPolicySchema = Schema.Struct({
|
|
23
|
+
maxAttempts: Schema.Number,
|
|
24
|
+
terminalFailureCodes: Schema.optional(Schema.Array(Schema.String))
|
|
25
|
+
});
|
|
26
|
+
function validateRivusAutomationRetryPolicy(value, automationId) {
|
|
27
|
+
if (value === void 0) return;
|
|
28
|
+
const reject = (field, requirement) => {
|
|
29
|
+
throw new InvalidRivusPlugin(`automation ${automationId} retry ${field} ${requirement}`);
|
|
30
|
+
};
|
|
31
|
+
const decoded = Schema.decodeUnknownResult(automationRetryPolicySchema, { onExcessProperty: "error" })(value);
|
|
32
|
+
if (Result.isFailure(decoded)) return reject("policy", decoded.failure.message);
|
|
33
|
+
const policy = decoded.success;
|
|
34
|
+
if (!Number.isInteger(policy.maxAttempts) || policy.maxAttempts < 1 || policy.maxAttempts > 10) reject("maxAttempts", "must be an integer from 1 to 10");
|
|
35
|
+
const codes = policy.terminalFailureCodes ?? [];
|
|
36
|
+
if (codes.length > 16) reject("terminalFailureCodes", "must contain at most 16 codes");
|
|
37
|
+
const seen = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const [index, code] of codes.entries()) {
|
|
39
|
+
if (!/^[A-Z][A-Z0-9_]{0,63}$/.test(code)) reject(`terminalFailureCodes[${index}]`, "must match ^[A-Z][A-Z0-9_]{0,63}$");
|
|
40
|
+
if (seen.has(code)) reject(`terminalFailureCodes[${index}]`, "must not duplicate another code");
|
|
41
|
+
seen.add(code);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
23
44
|
const MEMORY_SCOPES = [
|
|
24
45
|
"conversation",
|
|
25
46
|
"agent-private",
|
|
@@ -122,6 +143,7 @@ function createRivusPluginCatalog$1(runtime) {
|
|
|
122
143
|
validateRivusCatalogReferences(profile.skills.allow, availableSkillIds, `profile ${profile.id}`, "skill");
|
|
123
144
|
}
|
|
124
145
|
for (const automation of pendingAutomations) {
|
|
146
|
+
validateRivusAutomationRetryPolicy(automation.retry, automation.id);
|
|
125
147
|
validateRivusCatalogReference(automation.profileId, availableProfileIds, `automation ${automation.id}`, "profile");
|
|
126
148
|
validateRivusCatalogReferences(automation.requestedToolIds, availableToolIds, `automation ${automation.id}`, "tool");
|
|
127
149
|
validateRivusCatalogReferences(automation.requestedSkillIds, availableSkillIds, `automation ${automation.id}`, "skill");
|
|
@@ -311,6 +333,16 @@ function resolveRivusAgentDefinition$1(catalog, deployment, providers, runtime)
|
|
|
311
333
|
profileId: deployment.profileId,
|
|
312
334
|
...deployment.projectSpaceId ? { projectSpaceId: deployment.projectSpaceId } : {},
|
|
313
335
|
profileRevision,
|
|
336
|
+
...deployment.runtime ? { runtime: {
|
|
337
|
+
args: [...deployment.runtime.args ?? []],
|
|
338
|
+
command: deployment.runtime.command,
|
|
339
|
+
env: { ...deployment.runtime.env },
|
|
340
|
+
initializationTimeoutMs: deployment.runtime.initializationTimeoutMs ?? 1e4,
|
|
341
|
+
permissions: deployment.runtime.permissions ?? "ask",
|
|
342
|
+
steering: deployment.runtime.steering ?? "disabled",
|
|
343
|
+
type: deployment.runtime.type,
|
|
344
|
+
unattended: deployment.runtime.unattended ?? false
|
|
345
|
+
} } : {},
|
|
314
346
|
runtimeToolGrantSet,
|
|
315
347
|
skillGrantSet,
|
|
316
348
|
skills,
|
|
@@ -514,14 +546,13 @@ function toError$3(error) {
|
|
|
514
546
|
}
|
|
515
547
|
//#endregion
|
|
516
548
|
//#region src/adapters/deployment/inspection/rivus-home-deployment-inspector.ts
|
|
517
|
-
const
|
|
549
|
+
const FEISHU_BOOTSTRAP = "@rivus/gateway/bootstrap/feishu";
|
|
518
550
|
function createRivusHomeDeploymentInspector(options = {}) {
|
|
519
|
-
const resolveModule = options.resolveModule ?? ((specifier) => defaultResolveModule(specifier, options.packageManifestPath));
|
|
520
551
|
const resolvePluginModule = options.resolvePluginModule ?? ((request) => resolveNodeRivusPluginModulePath(request, options.packageManifestPath ? { packageManifestPath: options.packageManifestPath } : {}));
|
|
521
552
|
return { inspect: (input) => Effect.gen(function* () {
|
|
522
553
|
const manifestResult = yield* checkManifest$1(input.home);
|
|
523
554
|
const credentials = yield* checkCredentials$1(input.home, manifestResult.manifest, input.env, input.envFilePath);
|
|
524
|
-
const modules = yield* checkModules(input.home, manifestResult.manifest, resolveModule, resolvePluginModule);
|
|
555
|
+
const modules = yield* checkModules(input.home, manifestResult.manifest, options.resolveModule ?? ((specifier) => defaultResolveModule(specifier, options.packageManifestPath, input.home.directory)), resolvePluginModule);
|
|
525
556
|
return {
|
|
526
557
|
credentials,
|
|
527
558
|
manifest: manifestResult.check,
|
|
@@ -552,7 +583,7 @@ function checkModules(home, manifest, resolveModule, resolvePluginModule) {
|
|
|
552
583
|
name: "modules",
|
|
553
584
|
status: "fail"
|
|
554
585
|
});
|
|
555
|
-
const specifiers = [home.bootstrap, ...home.bootstrap === "@
|
|
586
|
+
const specifiers = [home.bootstrap, ...home.bootstrap === FEISHU_BOOTSTRAP ? ["@larksuiteoapi/node-sdk", ...manifest.agents.some(({ runtime }) => !runtime) ? ["@earendil-works/pi-coding-agent"] : []] : []];
|
|
556
587
|
return Effect.gen(function* () {
|
|
557
588
|
const missing = [];
|
|
558
589
|
for (const specifier of specifiers) {
|
|
@@ -568,7 +599,7 @@ function checkModules(home, manifest, resolveModule, resolvePluginModule) {
|
|
|
568
599
|
if (result._tag === "Failure") missing.push(`${plugin.module} (${formatError(result.failure)})`);
|
|
569
600
|
}
|
|
570
601
|
return missing.length === 0 ? {
|
|
571
|
-
message: "Bootstrap, Plugin,
|
|
602
|
+
message: "Bootstrap, Plugin, runtime, and Feishu modules resolve from the global installation",
|
|
572
603
|
name: "modules",
|
|
573
604
|
status: "pass"
|
|
574
605
|
} : {
|
|
@@ -602,27 +633,33 @@ function checkCredentials$1(home, manifest, env, envFilePath) {
|
|
|
602
633
|
try: async () => {
|
|
603
634
|
const merged = await loadMergedLocalEnvFile(envFilePath ? resolve(home.directory, envFilePath) : home.envFilePath, env);
|
|
604
635
|
for (const endpoint of manifest.endpoints.filter(({ enabled }) => enabled)) resolveFeishuEndpointCredentials(endpoint.credentialRef, merged);
|
|
636
|
+
for (const agent of manifest.agents) if (agent.runtime) await resolveAcpRuntimeEnvironment(agent.runtime, merged);
|
|
637
|
+
if (parseRivusModelManagementEnabled(merged.RIVUS_MODEL_MANAGEMENT_ENABLED) && manifest.agents.find(({ agentId }) => agentId === manifest.defaultAgentId)?.runtime) throw new Error("RIVUS_MODEL_MANAGEMENT_ENABLED requires a Pi default Agent");
|
|
605
638
|
return {
|
|
606
|
-
message: "
|
|
639
|
+
message: "Endpoint credentials and Agent runtime environment references resolve",
|
|
607
640
|
name: "credentials",
|
|
608
641
|
status: "pass"
|
|
609
642
|
};
|
|
610
643
|
},
|
|
611
644
|
catch: toError$2
|
|
612
645
|
}).pipe(Effect.catch((error) => Effect.succeed({
|
|
613
|
-
message: `
|
|
646
|
+
message: `deployment environment is incomplete: ${formatError(error)}`,
|
|
614
647
|
name: "credentials",
|
|
615
648
|
status: "fail"
|
|
616
649
|
})));
|
|
617
650
|
}
|
|
618
|
-
function defaultResolveModule(specifier, packageManifestPath) {
|
|
619
|
-
|
|
651
|
+
function defaultResolveModule(specifier, packageManifestPath, homeDirectory) {
|
|
652
|
+
const homeLocal = isAbsolute(specifier);
|
|
653
|
+
if (!homeLocal && !packageManifestPath) return Effect.fail(/* @__PURE__ */ new Error("Rivus package manifest path is required for trusted module resolution"));
|
|
620
654
|
return Effect.gen(function* () {
|
|
621
655
|
const resolvedRealpath = yield* Effect.tryPromise({
|
|
622
656
|
try: () => realpath(fileURLToPath(import.meta.resolve(specifier))),
|
|
623
657
|
catch: toError$2
|
|
624
658
|
});
|
|
625
|
-
return yield* validateTrustedModulePath(yield*
|
|
659
|
+
return yield* validateTrustedModulePath(homeLocal ? yield* Effect.tryPromise({
|
|
660
|
+
try: () => realpath(homeDirectory),
|
|
661
|
+
catch: toError$2
|
|
662
|
+
}) : yield* findTrustedPackageRoot(packageManifestPath), resolvedRealpath, `module ${specifier}`);
|
|
626
663
|
});
|
|
627
664
|
}
|
|
628
665
|
function toError$2(error) {
|
|
@@ -799,7 +836,7 @@ function createRivusHomeLayout() {
|
|
|
799
836
|
}
|
|
800
837
|
function homeConfig() {
|
|
801
838
|
return `${JSON.stringify({
|
|
802
|
-
bootstrap: "@rivus/gateway/bootstrap/
|
|
839
|
+
bootstrap: "@rivus/gateway/bootstrap/feishu",
|
|
803
840
|
envFile: ".env",
|
|
804
841
|
logs: "logs",
|
|
805
842
|
manifest: "rivus.config.json",
|
|
@@ -953,15 +990,292 @@ function createNodeRivusHome(options) {
|
|
|
953
990
|
};
|
|
954
991
|
}
|
|
955
992
|
//#endregion
|
|
993
|
+
//#region src/adapters/cli/recovery/rivus-recovery-cli.ts
|
|
994
|
+
function createRivusRecoveryCliParser() {
|
|
995
|
+
const input = { recoveryList: false };
|
|
996
|
+
return {
|
|
997
|
+
build: () => buildCommand(input),
|
|
998
|
+
consume: (argument, next) => consumeArgument(input, argument, next)
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
async function runRivusRecoveryCliCommand(control, command) {
|
|
1002
|
+
switch (command.type) {
|
|
1003
|
+
case "inspect": return Effect.runPromise(control.inspect());
|
|
1004
|
+
case "grant-automation-attempt": return Effect.runPromise(control.grantAutomationAttempt({
|
|
1005
|
+
actorId: "local-cli",
|
|
1006
|
+
automationId: command.automationId,
|
|
1007
|
+
expectedRevision: command.expectedRevision,
|
|
1008
|
+
note: await readPrivateTextFile(command.noteFilePath, "Recovery note", 16384),
|
|
1009
|
+
occurrence: command.occurrence
|
|
1010
|
+
}));
|
|
1011
|
+
case "requeue-dead-letter": return Effect.runPromise(control.requeueDeadLetter({
|
|
1012
|
+
actorId: "local-cli",
|
|
1013
|
+
deliveryId: command.deliveryId,
|
|
1014
|
+
endpointId: command.endpointId,
|
|
1015
|
+
expectedRevision: command.expectedRevision,
|
|
1016
|
+
note: await readPrivateTextFile(command.noteFilePath, "Recovery note", 16384)
|
|
1017
|
+
}));
|
|
1018
|
+
case "resolve-tool-operation": {
|
|
1019
|
+
const note = await readPrivateTextFile(command.noteFilePath, "Recovery note", 16384);
|
|
1020
|
+
const outcome = command.outcome.status === "applied" ? {
|
|
1021
|
+
result: parseToolResult(await readPrivateTextFile(command.outcome.resultFilePath, "Tool result", 1048576)),
|
|
1022
|
+
status: "applied"
|
|
1023
|
+
} : command.outcome;
|
|
1024
|
+
return Effect.runPromise(control.resolveToolOperation({
|
|
1025
|
+
actorId: "local-cli",
|
|
1026
|
+
expectedRevision: command.expectedRevision,
|
|
1027
|
+
instanceId: command.instanceId,
|
|
1028
|
+
note,
|
|
1029
|
+
operationId: command.operationId,
|
|
1030
|
+
outcome
|
|
1031
|
+
}));
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function consumeArgument(input, argument, next) {
|
|
1036
|
+
if (argument === "--recovery-list") {
|
|
1037
|
+
input.recoveryList = true;
|
|
1038
|
+
return {
|
|
1039
|
+
consumed: 0,
|
|
1040
|
+
handled: true
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
for (const [flag, key] of [
|
|
1044
|
+
["--grant-automation-attempt", "grantAutomationAttemptId"],
|
|
1045
|
+
["--occurrence", "occurrence"],
|
|
1046
|
+
["--requeue-dead-letter", "requeueDeadLetterId"],
|
|
1047
|
+
["--resolve-tool-operation", "resolveToolOperationId"],
|
|
1048
|
+
["--endpoint-id", "endpointId"],
|
|
1049
|
+
["--instance-id", "instanceId"],
|
|
1050
|
+
["--expected-revision", "expectedRevision"],
|
|
1051
|
+
["--recovery-note-file", "recoveryNoteFile"],
|
|
1052
|
+
["--tool-outcome", "toolOutcome"],
|
|
1053
|
+
["--tool-result-file", "toolResultFile"]
|
|
1054
|
+
]) {
|
|
1055
|
+
if (argument === flag) {
|
|
1056
|
+
if (!next || next.startsWith("--")) return {
|
|
1057
|
+
consumed: 0,
|
|
1058
|
+
error: `${flag} requires a value`,
|
|
1059
|
+
handled: true
|
|
1060
|
+
};
|
|
1061
|
+
input[key] = next;
|
|
1062
|
+
return {
|
|
1063
|
+
consumed: 1,
|
|
1064
|
+
handled: true
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
if (argument?.startsWith(`${flag}=`)) {
|
|
1068
|
+
const value = argument.slice(flag.length + 1);
|
|
1069
|
+
if (!value) return {
|
|
1070
|
+
consumed: 0,
|
|
1071
|
+
error: `${flag} requires a value`,
|
|
1072
|
+
handled: true
|
|
1073
|
+
};
|
|
1074
|
+
input[key] = value;
|
|
1075
|
+
return {
|
|
1076
|
+
consumed: 0,
|
|
1077
|
+
handled: true
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
consumed: 0,
|
|
1083
|
+
handled: false
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
function buildCommand(input) {
|
|
1087
|
+
const actionCount = Number(input.recoveryList) + Number(input.grantAutomationAttemptId !== void 0) + Number(input.requeueDeadLetterId !== void 0) + Number(input.resolveToolOperationId !== void 0);
|
|
1088
|
+
const hasOptions = input.occurrence !== void 0 || input.endpointId !== void 0 || input.expectedRevision !== void 0 || input.instanceId !== void 0 || input.recoveryNoteFile !== void 0 || input.toolOutcome !== void 0 || input.toolResultFile !== void 0;
|
|
1089
|
+
if (actionCount === 0) return hasOptions ? { error: "Recovery options require --recovery-list, --grant-automation-attempt, --requeue-dead-letter, or --resolve-tool-operation" } : {};
|
|
1090
|
+
if (actionCount > 1) return { error: "Choose only one recovery command" };
|
|
1091
|
+
if (input.recoveryList) return hasOptions ? { error: "--recovery-list does not accept mutation options" } : { command: { type: "inspect" } };
|
|
1092
|
+
const expectedRevision = parsePositiveInteger(input.expectedRevision);
|
|
1093
|
+
if (expectedRevision === void 0) return { error: "Recovery mutations require --expected-revision with a positive integer" };
|
|
1094
|
+
const noteFilePath = input.recoveryNoteFile?.trim();
|
|
1095
|
+
if (!noteFilePath) return { error: "Recovery mutations require --recovery-note-file" };
|
|
1096
|
+
if (input.grantAutomationAttemptId !== void 0) return buildAutomationAttemptCommand(input, expectedRevision, noteFilePath);
|
|
1097
|
+
if (input.occurrence !== void 0) return { error: "--occurrence is only valid with --grant-automation-attempt" };
|
|
1098
|
+
if (input.requeueDeadLetterId !== void 0) return buildDeadLetterCommand(input, expectedRevision, noteFilePath);
|
|
1099
|
+
return buildToolOperationCommand(input, expectedRevision, noteFilePath);
|
|
1100
|
+
}
|
|
1101
|
+
function buildAutomationAttemptCommand(input, expectedRevision, noteFilePath) {
|
|
1102
|
+
const automationId = input.grantAutomationAttemptId?.trim();
|
|
1103
|
+
const occurrence = input.occurrence?.trim();
|
|
1104
|
+
if (!automationId || !occurrence) return { error: "--grant-automation-attempt requires an automation id and --occurrence" };
|
|
1105
|
+
if (input.endpointId !== void 0 || input.instanceId !== void 0 || input.toolOutcome !== void 0 || input.toolResultFile !== void 0) return { error: "--grant-automation-attempt cannot use Endpoint or Tool reconciliation options" };
|
|
1106
|
+
return { command: {
|
|
1107
|
+
automationId,
|
|
1108
|
+
expectedRevision,
|
|
1109
|
+
noteFilePath,
|
|
1110
|
+
occurrence,
|
|
1111
|
+
type: "grant-automation-attempt"
|
|
1112
|
+
} };
|
|
1113
|
+
}
|
|
1114
|
+
function buildDeadLetterCommand(input, expectedRevision, noteFilePath) {
|
|
1115
|
+
const endpointId = input.endpointId?.trim();
|
|
1116
|
+
if (!endpointId) return { error: "--requeue-dead-letter requires --endpoint-id" };
|
|
1117
|
+
if (input.instanceId !== void 0 || input.toolOutcome !== void 0 || input.toolResultFile !== void 0) return { error: "--requeue-dead-letter cannot use Tool reconciliation options" };
|
|
1118
|
+
return { command: {
|
|
1119
|
+
deliveryId: input.requeueDeadLetterId,
|
|
1120
|
+
endpointId,
|
|
1121
|
+
expectedRevision,
|
|
1122
|
+
noteFilePath,
|
|
1123
|
+
type: "requeue-dead-letter"
|
|
1124
|
+
} };
|
|
1125
|
+
}
|
|
1126
|
+
function buildToolOperationCommand(input, expectedRevision, noteFilePath) {
|
|
1127
|
+
const instanceId = input.instanceId?.trim();
|
|
1128
|
+
if (!instanceId) return { error: "--resolve-tool-operation requires --instance-id" };
|
|
1129
|
+
if (input.endpointId !== void 0) return { error: "--resolve-tool-operation cannot use --endpoint-id" };
|
|
1130
|
+
if (input.toolOutcome !== "applied" && input.toolOutcome !== "not-applied") return { error: "--resolve-tool-operation requires --tool-outcome applied or not-applied" };
|
|
1131
|
+
if (input.toolOutcome === "not-applied") {
|
|
1132
|
+
if (input.toolResultFile !== void 0) return { error: "--tool-result-file is only valid when --tool-outcome is applied" };
|
|
1133
|
+
return { command: {
|
|
1134
|
+
expectedRevision,
|
|
1135
|
+
instanceId,
|
|
1136
|
+
noteFilePath,
|
|
1137
|
+
operationId: input.resolveToolOperationId,
|
|
1138
|
+
outcome: { status: "not-applied" },
|
|
1139
|
+
type: "resolve-tool-operation"
|
|
1140
|
+
} };
|
|
1141
|
+
}
|
|
1142
|
+
const resultFilePath = input.toolResultFile?.trim();
|
|
1143
|
+
if (!resultFilePath) return { error: "--tool-outcome applied requires --tool-result-file" };
|
|
1144
|
+
return { command: {
|
|
1145
|
+
expectedRevision,
|
|
1146
|
+
instanceId,
|
|
1147
|
+
noteFilePath,
|
|
1148
|
+
operationId: input.resolveToolOperationId,
|
|
1149
|
+
outcome: {
|
|
1150
|
+
resultFilePath,
|
|
1151
|
+
status: "applied"
|
|
1152
|
+
},
|
|
1153
|
+
type: "resolve-tool-operation"
|
|
1154
|
+
} };
|
|
1155
|
+
}
|
|
1156
|
+
function parsePositiveInteger(value) {
|
|
1157
|
+
const number = value && /^[1-9]\d*$/.test(value) ? Number(value) : void 0;
|
|
1158
|
+
return Number.isSafeInteger(number) ? number : void 0;
|
|
1159
|
+
}
|
|
1160
|
+
async function readPrivateTextFile(filePath, label, maxBytes) {
|
|
1161
|
+
const handle = await open(filePath, constants$1.O_RDONLY | constants$1.O_NOFOLLOW);
|
|
1162
|
+
try {
|
|
1163
|
+
const metadata = await handle.stat();
|
|
1164
|
+
if (!metadata.isFile()) throw new Error(`${label} must be a regular file`);
|
|
1165
|
+
if ((metadata.mode & 127) !== 0) throw new Error(`${label} file permissions must be 0600 or stricter`);
|
|
1166
|
+
if (metadata.size > maxBytes) throw new Error(`${label} file exceeds ${maxBytes} bytes`);
|
|
1167
|
+
const value = (await handle.readFile("utf8")).trim();
|
|
1168
|
+
if (!value) throw new Error(`${label} file must not be empty`);
|
|
1169
|
+
return value;
|
|
1170
|
+
} finally {
|
|
1171
|
+
await handle.close();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function parseToolResult(value) {
|
|
1175
|
+
try {
|
|
1176
|
+
return JSON.parse(value);
|
|
1177
|
+
} catch {
|
|
1178
|
+
throw new Error("Tool result file must contain valid JSON");
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
const RIVUS_AUDIO_CLI_USAGE = `Usage:
|
|
1182
|
+
rivus audio install [--force] [--json]
|
|
1183
|
+
rivus audio status
|
|
1184
|
+
rivus audio transcribe <path>
|
|
1185
|
+
|
|
1186
|
+
Commands:
|
|
1187
|
+
install Install or upgrade the managed audio transcriber in the current Home's state directory
|
|
1188
|
+
status Print the installed and shipped transcriber releases as JSON
|
|
1189
|
+
transcribe Print the transcript of one audio file; exits 2 when no speech is detected
|
|
1190
|
+
and ${String(3)} when the transcriber is not installed
|
|
1191
|
+
`;
|
|
1192
|
+
function parseRivusAudioCliArguments(argv) {
|
|
1193
|
+
if (argv.includes("--help") || argv.includes("-h")) return { help: true };
|
|
1194
|
+
const [operation, ...rest] = argv;
|
|
1195
|
+
if (operation === "install") {
|
|
1196
|
+
const flags = new Set(rest);
|
|
1197
|
+
const unknown = rest.find((argument) => argument !== "--force" && argument !== "--json");
|
|
1198
|
+
if (unknown !== void 0) return { error: `Unknown audio install option: ${unknown}` };
|
|
1199
|
+
if (flags.size !== rest.length) return { error: "audio install options may only be provided once" };
|
|
1200
|
+
return {
|
|
1201
|
+
force: flags.has("--force"),
|
|
1202
|
+
json: flags.has("--json"),
|
|
1203
|
+
operation
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
if (operation === "status") return rest.length === 0 ? { operation } : { error: "audio status accepts no arguments" };
|
|
1207
|
+
if (operation === "transcribe") {
|
|
1208
|
+
const path = rest[0];
|
|
1209
|
+
if (rest.length !== 1 || !path || path.startsWith("-")) return { error: "audio transcribe requires exactly one audio path" };
|
|
1210
|
+
return {
|
|
1211
|
+
operation,
|
|
1212
|
+
path
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
return { error: "audio requires one of install, status, transcribe" };
|
|
1216
|
+
}
|
|
1217
|
+
function renderRivusAudioCliArgumentError(error) {
|
|
1218
|
+
return `${error}\n\n${RIVUS_AUDIO_CLI_USAGE}`;
|
|
1219
|
+
}
|
|
1220
|
+
function renderRivusAudioCliStatus(status) {
|
|
1221
|
+
return `${JSON.stringify(status)}\n`;
|
|
1222
|
+
}
|
|
1223
|
+
function renderRivusAudioCliInstallResult(result, json) {
|
|
1224
|
+
if (json) return `${JSON.stringify(result)}\n`;
|
|
1225
|
+
return result.status === "installed" ? `Installed audio transcriber ${result.id} in ${result.release}\n` : `Audio transcriber ${result.id} is already installed in ${result.release}\n`;
|
|
1226
|
+
}
|
|
1227
|
+
function renderRivusAudioCliNotInstalled() {
|
|
1228
|
+
return "audio transcriber is not installed; run: rivus audio install\n";
|
|
1229
|
+
}
|
|
1230
|
+
//#endregion
|
|
1231
|
+
//#region src/adapters/cli/audio/rivus-audio-cli.ts
|
|
1232
|
+
/** Runs one parsed `rivus audio` command and returns its exit code; installation failures are thrown. */
|
|
1233
|
+
async function runRivusAudioCliCommand(command, context) {
|
|
1234
|
+
if (command.operation === "install") {
|
|
1235
|
+
const result = await installRivusAudioTranscriber({
|
|
1236
|
+
assetDirectory: context.assetDirectory,
|
|
1237
|
+
env: context.env,
|
|
1238
|
+
force: command.force,
|
|
1239
|
+
installRoot: context.installRoot,
|
|
1240
|
+
nodeExecutable: context.nodeExecutable,
|
|
1241
|
+
runProcess: context.runProcess,
|
|
1242
|
+
...context.signal ? { signal: context.signal } : {}
|
|
1243
|
+
});
|
|
1244
|
+
context.stdout.write(renderRivusAudioCliInstallResult(result, command.json));
|
|
1245
|
+
return 0;
|
|
1246
|
+
}
|
|
1247
|
+
if (command.operation === "status") {
|
|
1248
|
+
context.stdout.write(renderRivusAudioCliStatus(await readRivusAudioStatus(context.installRoot, context.assetDirectory)));
|
|
1249
|
+
return 0;
|
|
1250
|
+
}
|
|
1251
|
+
const release = await readRivusAudioInstalledRelease(context.installRoot);
|
|
1252
|
+
if (release === void 0) {
|
|
1253
|
+
context.stderr.write(renderRivusAudioCliNotInstalled());
|
|
1254
|
+
return 3;
|
|
1255
|
+
}
|
|
1256
|
+
const exitCode = await runRivusAudioPassthroughProcess({
|
|
1257
|
+
args: [join(release.directory, "transcribe.mjs"), resolve(context.cwd, command.path)],
|
|
1258
|
+
command: context.nodeExecutable,
|
|
1259
|
+
cwd: release.directory,
|
|
1260
|
+
env: context.env,
|
|
1261
|
+
...context.signal ? { signal: context.signal } : {},
|
|
1262
|
+
stderr: context.stderr,
|
|
1263
|
+
stdout: context.stdout
|
|
1264
|
+
});
|
|
1265
|
+
return exitCode === 0 || exitCode === 1 || exitCode === 2 ? exitCode : 1;
|
|
1266
|
+
}
|
|
1267
|
+
//#endregion
|
|
956
1268
|
//#region src/adapters/cli/command/rivus-cli-protocol.ts
|
|
957
1269
|
const RIVUS_CLI_USAGE = `Usage:
|
|
958
1270
|
rivus setup [directory]
|
|
959
1271
|
rivus start
|
|
960
1272
|
rivus status
|
|
961
1273
|
rivus check-config
|
|
1274
|
+
rivus recovery <recovery options>
|
|
962
1275
|
rivus init [directory]
|
|
963
1276
|
rivus doctor [directory] [--env-file <path>]
|
|
964
1277
|
rivus model <status|set|rollback> ...
|
|
1278
|
+
rivus audio <install|status|transcribe> ...
|
|
965
1279
|
rivus --bootstrap <module> [--manifest <rivus.config.json>] [options]
|
|
966
1280
|
|
|
967
1281
|
Commands:
|
|
@@ -970,9 +1284,11 @@ Commands:
|
|
|
970
1284
|
status Print Rivus Home deployment status without activating Endpoints
|
|
971
1285
|
check-config
|
|
972
1286
|
Validate and print the redacted Rivus Home manifest
|
|
1287
|
+
recovery Inspect or recover local state after stopping the Home daemon
|
|
973
1288
|
init Create a standalone local Rivus project without overwriting files
|
|
974
1289
|
doctor Check Rivus Home by default, or an explicit standalone project directory
|
|
975
1290
|
model Query or change the managed default model through the current Home
|
|
1291
|
+
audio Install, inspect, or run the managed audio transcriber of the current Home
|
|
976
1292
|
|
|
977
1293
|
Run rivus --help for the complete daemon option list.
|
|
978
1294
|
`;
|
|
@@ -986,7 +1302,7 @@ function renderRivusDirectoryCommandUsage(command) {
|
|
|
986
1302
|
return `Usage: rivus ${command} [directory]\n`;
|
|
987
1303
|
}
|
|
988
1304
|
function renderRivusHomeCommandUsage(command) {
|
|
989
|
-
return `Usage: rivus ${command}\n`;
|
|
1305
|
+
return `Usage: rivus ${command}${command === "recovery" ? " <recovery options>" : ""}\n`;
|
|
990
1306
|
}
|
|
991
1307
|
function renderRivusDoctorUsage() {
|
|
992
1308
|
return "Usage: rivus doctor [directory] [--env-file <path>]\n";
|
|
@@ -1294,7 +1610,7 @@ const TEMPLATE_FILES = Object.freeze({
|
|
|
1294
1610
|
"current-weather.mjs": "current-weather.mjs",
|
|
1295
1611
|
"https-response-reader.mjs": "https-response-reader.mjs",
|
|
1296
1612
|
"rivus-agents.plugin.mjs": "rivus-starter.plugin.mjs",
|
|
1297
|
-
"rivus.bootstrap.ts": "
|
|
1613
|
+
"rivus.bootstrap.ts": "feishu-deployment.bootstrap.ts"
|
|
1298
1614
|
});
|
|
1299
1615
|
async function initializeRivusProject(options) {
|
|
1300
1616
|
const directory = resolve(options.directory);
|
|
@@ -1697,243 +2013,65 @@ function readPath(record, path) {
|
|
|
1697
2013
|
async function loadRivusEnvFromOpenClawConfig(filePath, piApiKeyFile) {
|
|
1698
2014
|
return createRivusEnvFromOpenClawConfig(JSON.parse(await readFile(filePath, "utf8")), piApiKeyFile ? { piApiKeyFile } : {});
|
|
1699
2015
|
}
|
|
1700
|
-
function toRedactedConfig(config) {
|
|
1701
|
-
return {
|
|
1702
|
-
agentId: config.agentId,
|
|
1703
|
-
feishu: {
|
|
1704
|
-
appIdPresent: Boolean(config.feishu.appId),
|
|
1705
|
-
appSecretPresent: Boolean(config.feishu.appSecret),
|
|
1706
|
-
baseUrl: config.feishu.baseUrl,
|
|
1707
|
-
cardStreamLeaseMs: config.feishu.cardStreamLeaseMs,
|
|
1708
|
-
streamMinIntervalMs: config.feishu.streamMinIntervalMs
|
|
1709
|
-
},
|
|
1710
|
-
pi: {
|
|
1711
|
-
apiKeyPresent: Boolean(config.pi.apiKey),
|
|
1712
|
-
...config.pi.baseUrl ? { baseUrl: config.pi.baseUrl } : {},
|
|
1713
|
-
...config.pi.model ? { model: config.pi.model } : {},
|
|
1714
|
-
...config.pi.thinkingLevel ? { thinkingLevel: config.pi.thinkingLevel } : {}
|
|
1715
|
-
}
|
|
1716
|
-
};
|
|
1717
|
-
}
|
|
1718
2016
|
function toRedactedDeploymentManifest(manifest) {
|
|
1719
2017
|
return {
|
|
1720
|
-
agents: manifest.agents.map(({ agentId, endpointIds, pluginId, profileId }) => ({
|
|
2018
|
+
agents: manifest.agents.map(({ agentId, endpointIds, pluginId, profileId, runtime }) => ({
|
|
1721
2019
|
agentId,
|
|
1722
2020
|
endpointIds,
|
|
1723
2021
|
pluginId,
|
|
1724
|
-
profileId
|
|
2022
|
+
profileId,
|
|
2023
|
+
...runtime ? { runtime } : {}
|
|
1725
2024
|
})),
|
|
1726
2025
|
automations: (manifest.automations ?? []).map(({ agentId, delivery, enabled, id, required, schedule, templateId, timeZone }) => ({
|
|
1727
2026
|
agentId,
|
|
1728
2027
|
delivery: {
|
|
1729
2028
|
endpointId: delivery.endpointId,
|
|
1730
|
-
targetRef: delivery.targetRef,
|
|
1731
|
-
targetType: delivery.targetType
|
|
1732
|
-
},
|
|
1733
|
-
enabled,
|
|
1734
|
-
id,
|
|
1735
|
-
required,
|
|
1736
|
-
schedule,
|
|
1737
|
-
templateId,
|
|
1738
|
-
timeZone
|
|
1739
|
-
})),
|
|
1740
|
-
...manifest.backgroundSessions ? { backgroundSessions: {
|
|
1741
|
-
enabled: manifest.backgroundSessions.enabled,
|
|
1742
|
-
leaseMs: manifest.backgroundSessions.leaseMs,
|
|
1743
|
-
leaseRenewalIntervalMs: manifest.backgroundSessions.leaseRenewalIntervalMs,
|
|
1744
|
-
maxConsecutiveFailures: manifest.backgroundSessions.maxConsecutiveFailures,
|
|
1745
|
-
maxConcurrentSessions: manifest.backgroundSessions.maxConcurrentSessions,
|
|
1746
|
-
required: manifest.backgroundSessions.required,
|
|
1747
|
-
retryBackoffMs: manifest.backgroundSessions.retryBackoffMs,
|
|
1748
|
-
sessionLifetimeMs: manifest.backgroundSessions.sessionLifetimeMs,
|
|
1749
|
-
stepTimeoutMs: manifest.backgroundSessions.stepTimeoutMs
|
|
1750
|
-
} } : {},
|
|
1751
|
-
defaultAgentId: manifest.defaultAgentId,
|
|
1752
|
-
defaultEndpointId: manifest.defaultEndpointId,
|
|
1753
|
-
endpoints: manifest.endpoints.map(({ agentId, credentialRef, enabled, id, required, sessionNamespace }) => ({
|
|
1754
|
-
agentId,
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
}
|
|
1768
|
-
async function loadCliEnv(envFilePath, overrideEnv) {
|
|
1769
|
-
if (!envFilePath) return overrideEnv;
|
|
1770
|
-
return loadMergedLocalEnvFile(envFilePath, overrideEnv);
|
|
1771
|
-
}
|
|
1772
|
-
//#endregion
|
|
1773
|
-
//#region src/adapters/cli/recovery/rivus-recovery-cli.ts
|
|
1774
|
-
function createRivusRecoveryCliParser() {
|
|
1775
|
-
const input = { recoveryList: false };
|
|
1776
|
-
return {
|
|
1777
|
-
build: () => buildCommand(input),
|
|
1778
|
-
consume: (argument, next) => consumeArgument(input, argument, next)
|
|
1779
|
-
};
|
|
1780
|
-
}
|
|
1781
|
-
async function runRivusRecoveryCliCommand(control, command) {
|
|
1782
|
-
switch (command.type) {
|
|
1783
|
-
case "inspect": return Effect.runPromise(control.inspect());
|
|
1784
|
-
case "requeue-dead-letter": return Effect.runPromise(control.requeueDeadLetter({
|
|
1785
|
-
actorId: "local-cli",
|
|
1786
|
-
deliveryId: command.deliveryId,
|
|
1787
|
-
endpointId: command.endpointId,
|
|
1788
|
-
expectedRevision: command.expectedRevision,
|
|
1789
|
-
note: await readPrivateTextFile(command.noteFilePath, "Recovery note", 16384)
|
|
1790
|
-
}));
|
|
1791
|
-
case "resolve-tool-operation": {
|
|
1792
|
-
const note = await readPrivateTextFile(command.noteFilePath, "Recovery note", 16384);
|
|
1793
|
-
const outcome = command.outcome.status === "applied" ? {
|
|
1794
|
-
result: parseToolResult(await readPrivateTextFile(command.outcome.resultFilePath, "Tool result", 1048576)),
|
|
1795
|
-
status: "applied"
|
|
1796
|
-
} : command.outcome;
|
|
1797
|
-
return Effect.runPromise(control.resolveToolOperation({
|
|
1798
|
-
actorId: "local-cli",
|
|
1799
|
-
expectedRevision: command.expectedRevision,
|
|
1800
|
-
instanceId: command.instanceId,
|
|
1801
|
-
note,
|
|
1802
|
-
operationId: command.operationId,
|
|
1803
|
-
outcome
|
|
1804
|
-
}));
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
function consumeArgument(input, argument, next) {
|
|
1809
|
-
if (argument === "--recovery-list") {
|
|
1810
|
-
input.recoveryList = true;
|
|
1811
|
-
return {
|
|
1812
|
-
consumed: 0,
|
|
1813
|
-
handled: true
|
|
1814
|
-
};
|
|
1815
|
-
}
|
|
1816
|
-
for (const [flag, key] of [
|
|
1817
|
-
["--requeue-dead-letter", "requeueDeadLetterId"],
|
|
1818
|
-
["--resolve-tool-operation", "resolveToolOperationId"],
|
|
1819
|
-
["--endpoint-id", "endpointId"],
|
|
1820
|
-
["--instance-id", "instanceId"],
|
|
1821
|
-
["--expected-revision", "expectedRevision"],
|
|
1822
|
-
["--recovery-note-file", "recoveryNoteFile"],
|
|
1823
|
-
["--tool-outcome", "toolOutcome"],
|
|
1824
|
-
["--tool-result-file", "toolResultFile"]
|
|
1825
|
-
]) {
|
|
1826
|
-
if (argument === flag) {
|
|
1827
|
-
if (!next) return {
|
|
1828
|
-
consumed: 0,
|
|
1829
|
-
error: `${flag} requires a value`,
|
|
1830
|
-
handled: true
|
|
1831
|
-
};
|
|
1832
|
-
input[key] = next;
|
|
1833
|
-
return {
|
|
1834
|
-
consumed: 1,
|
|
1835
|
-
handled: true
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
if (argument?.startsWith(`${flag}=`)) {
|
|
1839
|
-
const value = argument.slice(flag.length + 1);
|
|
1840
|
-
if (!value) return {
|
|
1841
|
-
consumed: 0,
|
|
1842
|
-
error: `${flag} requires a value`,
|
|
1843
|
-
handled: true
|
|
1844
|
-
};
|
|
1845
|
-
input[key] = value;
|
|
1846
|
-
return {
|
|
1847
|
-
consumed: 0,
|
|
1848
|
-
handled: true
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
return {
|
|
1853
|
-
consumed: 0,
|
|
1854
|
-
handled: false
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
|
-
function buildCommand(input) {
|
|
1858
|
-
const actionCount = Number(input.recoveryList) + Number(input.requeueDeadLetterId !== void 0) + Number(input.resolveToolOperationId !== void 0);
|
|
1859
|
-
const hasOptions = input.endpointId !== void 0 || input.expectedRevision !== void 0 || input.instanceId !== void 0 || input.recoveryNoteFile !== void 0 || input.toolOutcome !== void 0 || input.toolResultFile !== void 0;
|
|
1860
|
-
if (actionCount === 0) return hasOptions ? { error: "Recovery options require --recovery-list, --requeue-dead-letter, or --resolve-tool-operation" } : {};
|
|
1861
|
-
if (actionCount > 1) return { error: "Choose only one recovery command" };
|
|
1862
|
-
if (input.recoveryList) return hasOptions ? { error: "--recovery-list does not accept mutation options" } : { command: { type: "inspect" } };
|
|
1863
|
-
const expectedRevision = parsePositiveInteger(input.expectedRevision);
|
|
1864
|
-
if (expectedRevision === void 0) return { error: "Recovery mutations require --expected-revision with a positive integer" };
|
|
1865
|
-
const noteFilePath = input.recoveryNoteFile?.trim();
|
|
1866
|
-
if (!noteFilePath) return { error: "Recovery mutations require --recovery-note-file" };
|
|
1867
|
-
if (input.requeueDeadLetterId !== void 0) return buildDeadLetterCommand(input, expectedRevision, noteFilePath);
|
|
1868
|
-
return buildToolOperationCommand(input, expectedRevision, noteFilePath);
|
|
1869
|
-
}
|
|
1870
|
-
function buildDeadLetterCommand(input, expectedRevision, noteFilePath) {
|
|
1871
|
-
const endpointId = input.endpointId?.trim();
|
|
1872
|
-
if (!endpointId) return { error: "--requeue-dead-letter requires --endpoint-id" };
|
|
1873
|
-
if (input.instanceId !== void 0 || input.toolOutcome !== void 0 || input.toolResultFile !== void 0) return { error: "--requeue-dead-letter cannot use Tool reconciliation options" };
|
|
1874
|
-
return { command: {
|
|
1875
|
-
deliveryId: input.requeueDeadLetterId,
|
|
1876
|
-
endpointId,
|
|
1877
|
-
expectedRevision,
|
|
1878
|
-
noteFilePath,
|
|
1879
|
-
type: "requeue-dead-letter"
|
|
1880
|
-
} };
|
|
1881
|
-
}
|
|
1882
|
-
function buildToolOperationCommand(input, expectedRevision, noteFilePath) {
|
|
1883
|
-
const instanceId = input.instanceId?.trim();
|
|
1884
|
-
if (!instanceId) return { error: "--resolve-tool-operation requires --instance-id" };
|
|
1885
|
-
if (input.endpointId !== void 0) return { error: "--resolve-tool-operation cannot use --endpoint-id" };
|
|
1886
|
-
if (input.toolOutcome !== "applied" && input.toolOutcome !== "not-applied") return { error: "--resolve-tool-operation requires --tool-outcome applied or not-applied" };
|
|
1887
|
-
if (input.toolOutcome === "not-applied") {
|
|
1888
|
-
if (input.toolResultFile !== void 0) return { error: "--tool-result-file is only valid when --tool-outcome is applied" };
|
|
1889
|
-
return { command: {
|
|
1890
|
-
expectedRevision,
|
|
1891
|
-
instanceId,
|
|
1892
|
-
noteFilePath,
|
|
1893
|
-
operationId: input.resolveToolOperationId,
|
|
1894
|
-
outcome: { status: "not-applied" },
|
|
1895
|
-
type: "resolve-tool-operation"
|
|
1896
|
-
} };
|
|
1897
|
-
}
|
|
1898
|
-
const resultFilePath = input.toolResultFile?.trim();
|
|
1899
|
-
if (!resultFilePath) return { error: "--tool-outcome applied requires --tool-result-file" };
|
|
1900
|
-
return { command: {
|
|
1901
|
-
expectedRevision,
|
|
1902
|
-
instanceId,
|
|
1903
|
-
noteFilePath,
|
|
1904
|
-
operationId: input.resolveToolOperationId,
|
|
1905
|
-
outcome: {
|
|
1906
|
-
resultFilePath,
|
|
1907
|
-
status: "applied"
|
|
1908
|
-
},
|
|
1909
|
-
type: "resolve-tool-operation"
|
|
1910
|
-
} };
|
|
1911
|
-
}
|
|
1912
|
-
function parsePositiveInteger(value) {
|
|
1913
|
-
return value && /^[1-9]\d*$/.test(value) ? Number(value) : void 0;
|
|
1914
|
-
}
|
|
1915
|
-
async function readPrivateTextFile(filePath, label, maxBytes) {
|
|
1916
|
-
const handle = await open(filePath, constants$1.O_RDONLY | constants$1.O_NOFOLLOW);
|
|
1917
|
-
try {
|
|
1918
|
-
const metadata = await handle.stat();
|
|
1919
|
-
if (!metadata.isFile()) throw new Error(`${label} must be a regular file`);
|
|
1920
|
-
if ((metadata.mode & 63) !== 0) throw new Error(`${label} file permissions must be 0600 or stricter`);
|
|
1921
|
-
if (metadata.size > maxBytes) throw new Error(`${label} file exceeds ${maxBytes} bytes`);
|
|
1922
|
-
return (await handle.readFile("utf8")).trim();
|
|
1923
|
-
} finally {
|
|
1924
|
-
await handle.close();
|
|
1925
|
-
}
|
|
2029
|
+
targetRef: delivery.targetRef,
|
|
2030
|
+
targetType: delivery.targetType
|
|
2031
|
+
},
|
|
2032
|
+
enabled,
|
|
2033
|
+
id,
|
|
2034
|
+
required,
|
|
2035
|
+
schedule,
|
|
2036
|
+
templateId,
|
|
2037
|
+
timeZone
|
|
2038
|
+
})),
|
|
2039
|
+
...manifest.backgroundSessions ? { backgroundSessions: {
|
|
2040
|
+
enabled: manifest.backgroundSessions.enabled,
|
|
2041
|
+
leaseMs: manifest.backgroundSessions.leaseMs,
|
|
2042
|
+
leaseRenewalIntervalMs: manifest.backgroundSessions.leaseRenewalIntervalMs,
|
|
2043
|
+
maxConsecutiveFailures: manifest.backgroundSessions.maxConsecutiveFailures,
|
|
2044
|
+
maxConcurrentSessions: manifest.backgroundSessions.maxConcurrentSessions,
|
|
2045
|
+
required: manifest.backgroundSessions.required,
|
|
2046
|
+
retryBackoffMs: manifest.backgroundSessions.retryBackoffMs,
|
|
2047
|
+
sessionLifetimeMs: manifest.backgroundSessions.sessionLifetimeMs,
|
|
2048
|
+
stepTimeoutMs: manifest.backgroundSessions.stepTimeoutMs
|
|
2049
|
+
} } : {},
|
|
2050
|
+
defaultAgentId: manifest.defaultAgentId,
|
|
2051
|
+
defaultEndpointId: manifest.defaultEndpointId,
|
|
2052
|
+
endpoints: manifest.endpoints.map(({ agentId, allowedActors, credentialRef, enabled, id, required, sessionNamespace }) => ({
|
|
2053
|
+
agentId,
|
|
2054
|
+
...allowedActors ? { allowedActorsCount: allowedActors.length } : {},
|
|
2055
|
+
credentialRef,
|
|
2056
|
+
enabled,
|
|
2057
|
+
id,
|
|
2058
|
+
required,
|
|
2059
|
+
sessionNamespace
|
|
2060
|
+
})),
|
|
2061
|
+
plugins: manifest.plugins.map(({ id, module, required }) => ({
|
|
2062
|
+
id,
|
|
2063
|
+
module,
|
|
2064
|
+
required
|
|
2065
|
+
}))
|
|
2066
|
+
};
|
|
1926
2067
|
}
|
|
1927
|
-
function
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
} catch {
|
|
1931
|
-
throw new Error("Tool result file must contain valid JSON");
|
|
1932
|
-
}
|
|
2068
|
+
async function loadCliEnv(envFilePath, overrideEnv) {
|
|
2069
|
+
if (!envFilePath) return overrideEnv;
|
|
2070
|
+
return loadMergedLocalEnvFile(envFilePath, overrideEnv);
|
|
1933
2071
|
}
|
|
1934
2072
|
//#endregion
|
|
1935
2073
|
//#region src/adapters/cli/command/rivus-daemon-arguments.ts
|
|
1936
|
-
const RIVUS_DAEMON_USAGE = `Usage: rivus --bootstrap <module>
|
|
2074
|
+
const RIVUS_DAEMON_USAGE = `Usage: rivus --bootstrap <module> --manifest <rivus.config.json>
|
|
1937
2075
|
|
|
1938
2076
|
Starts a local Rivus Agent daemon from an injected bootstrap module.
|
|
1939
2077
|
|
|
@@ -1942,13 +2080,15 @@ Project commands:
|
|
|
1942
2080
|
rivus start
|
|
1943
2081
|
rivus status
|
|
1944
2082
|
rivus check-config
|
|
2083
|
+
rivus recovery <recovery options>
|
|
1945
2084
|
rivus init [directory]
|
|
1946
2085
|
rivus doctor [directory] [--env-file <path>]
|
|
1947
2086
|
rivus model <status|set|rollback> ...
|
|
2087
|
+
rivus audio <install|status|transcribe> ...
|
|
1948
2088
|
|
|
1949
2089
|
Options:
|
|
1950
|
-
--bootstrap <module> Module exporting
|
|
1951
|
-
--manifest <path>
|
|
2090
|
+
--bootstrap <module> Module exporting createRivusDeploymentAdapters(context)
|
|
2091
|
+
--manifest <path> Deployment manifest to load
|
|
1952
2092
|
--env-file <path> Load local KEY=value config before reading environment
|
|
1953
2093
|
--check-config Print redacted local config JSON and exit
|
|
1954
2094
|
--prompt <text> Run one local prompt through bootstrap promptText() and exit
|
|
@@ -1969,7 +2109,12 @@ Options:
|
|
|
1969
2109
|
Add PI_API_KEY_FILE when using --print-openclaw-env
|
|
1970
2110
|
--session-key <key> Session key for --prompt (default local:<agent-id>:cli)
|
|
1971
2111
|
--status Print bootstrap status JSON without starting the daemon
|
|
1972
|
-
--recovery-list List Dead Letters and Tool operations requiring reconciliation
|
|
2112
|
+
--recovery-list List stopped Automation occurrences, Dead Letters, and Tool operations requiring reconciliation
|
|
2113
|
+
--grant-automation-attempt <automation-id>
|
|
2114
|
+
Grant one stopped occurrence another attempt; requires --occurrence,
|
|
2115
|
+
--expected-revision, and --recovery-note-file
|
|
2116
|
+
--occurrence <occurrence>
|
|
2117
|
+
Scheduled occurrence selected by --grant-automation-attempt
|
|
1973
2118
|
--requeue-dead-letter <message-id>
|
|
1974
2119
|
Requeue one Dead Letter; requires --endpoint-id, --expected-revision, and --recovery-note-file
|
|
1975
2120
|
--resolve-tool-operation <operation-id>
|
|
@@ -1985,23 +2130,11 @@ Options:
|
|
|
1985
2130
|
Confirm whether the external Tool effect occurred
|
|
1986
2131
|
--tool-result-file <path>
|
|
1987
2132
|
Private (0600) JSON file required when --tool-outcome is applied
|
|
1988
|
-
--status-url <url> Print live daemon status JSON from a running daemon
|
|
1989
|
-
--wait-receive <kind> Wait with --status-url or a started bootstrap daemon until receive.lastAccepted or receive.lastHandled exists
|
|
1990
|
-
--wait-receive-text <text>
|
|
1991
|
-
With --wait-receive handled, wait until receive.lastHandled.intake.text contains text
|
|
1992
|
-
--wait-receive-message-id <id>
|
|
1993
|
-
With --wait-receive, wait until the accepted or handled receive observation has this Feishu message id
|
|
1994
|
-
--wait-receive-observed-after <iso>
|
|
1995
|
-
With --wait-receive, ignore receive observations at or before this ISO timestamp
|
|
1996
|
-
--wait-timeout-ms <n> Timeout for --wait-receive (default 30000)
|
|
1997
|
-
--wait-poll-ms <n> Poll interval for --wait-receive (default 500)
|
|
1998
2133
|
--help Show this help
|
|
1999
2134
|
|
|
2000
2135
|
Environment:
|
|
2001
2136
|
RIVUS_HOME selects Rivus Home (default ~/.rivus-agent) for Home commands.
|
|
2002
2137
|
RIVUS_BOOTSTRAP_MODULE may be used instead of --bootstrap.
|
|
2003
|
-
FEISHU_APP_ID and FEISHU_APP_SECRET are required by the default config loader.
|
|
2004
|
-
FEISHU_CARD_STREAM_LEASE_MS shortens or extends the proactive CardKit rollover threshold.
|
|
2005
2138
|
PI_API_KEY_FILE may point to a local BYOK key file instead of PI_API_KEY.
|
|
2006
2139
|
`;
|
|
2007
2140
|
function parseRivusDaemonArguments(argv) {
|
|
@@ -2021,19 +2154,11 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2021
2154
|
const recoveryCli = createRivusRecoveryCliParser();
|
|
2022
2155
|
let sessionKey;
|
|
2023
2156
|
let status = false;
|
|
2024
|
-
let statusUrl;
|
|
2025
|
-
let waitPollMs;
|
|
2026
|
-
let waitReceive;
|
|
2027
|
-
let waitReceiveMessageId;
|
|
2028
|
-
let waitReceiveObservedAfter;
|
|
2029
|
-
let waitReceiveText;
|
|
2030
|
-
let waitTimeoutMs;
|
|
2031
2157
|
for (let index = 0; index < argv.length; index += 1) {
|
|
2032
2158
|
const arg = argv[index];
|
|
2033
2159
|
if (arg === "--help" || arg === "-h") return {
|
|
2034
2160
|
help: true,
|
|
2035
|
-
status
|
|
2036
|
-
...statusUrl ? { statusUrl } : {}
|
|
2161
|
+
status
|
|
2037
2162
|
};
|
|
2038
2163
|
if (arg === "--status") {
|
|
2039
2164
|
status = true;
|
|
@@ -2273,150 +2398,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2273
2398
|
};
|
|
2274
2399
|
continue;
|
|
2275
2400
|
}
|
|
2276
|
-
if (arg === "--status-url") {
|
|
2277
|
-
const value = argv[index + 1];
|
|
2278
|
-
if (!value) return {
|
|
2279
|
-
error: "--status-url requires a URL",
|
|
2280
|
-
help: false,
|
|
2281
|
-
status
|
|
2282
|
-
};
|
|
2283
|
-
statusUrl = value;
|
|
2284
|
-
index += 1;
|
|
2285
|
-
continue;
|
|
2286
|
-
}
|
|
2287
|
-
if (arg?.startsWith("--status-url=")) {
|
|
2288
|
-
statusUrl = arg.slice(13);
|
|
2289
|
-
if (!statusUrl) return {
|
|
2290
|
-
error: "--status-url requires a URL",
|
|
2291
|
-
help: false,
|
|
2292
|
-
status
|
|
2293
|
-
};
|
|
2294
|
-
continue;
|
|
2295
|
-
}
|
|
2296
|
-
if (arg === "--wait-receive") {
|
|
2297
|
-
const parsedWait = parseWaitReceive(argv[index + 1]);
|
|
2298
|
-
if (!parsedWait) return {
|
|
2299
|
-
error: "--wait-receive requires accepted or handled",
|
|
2300
|
-
help: false,
|
|
2301
|
-
status
|
|
2302
|
-
};
|
|
2303
|
-
waitReceive = parsedWait;
|
|
2304
|
-
index += 1;
|
|
2305
|
-
continue;
|
|
2306
|
-
}
|
|
2307
|
-
if (arg?.startsWith("--wait-receive=")) {
|
|
2308
|
-
const parsedWait = parseWaitReceive(arg.slice(15));
|
|
2309
|
-
if (!parsedWait) return {
|
|
2310
|
-
error: "--wait-receive requires accepted or handled",
|
|
2311
|
-
help: false,
|
|
2312
|
-
status
|
|
2313
|
-
};
|
|
2314
|
-
waitReceive = parsedWait;
|
|
2315
|
-
continue;
|
|
2316
|
-
}
|
|
2317
|
-
if (arg === "--wait-receive-text") {
|
|
2318
|
-
const value = argv[index + 1];
|
|
2319
|
-
if (!value) return {
|
|
2320
|
-
error: "--wait-receive-text requires text",
|
|
2321
|
-
help: false,
|
|
2322
|
-
status
|
|
2323
|
-
};
|
|
2324
|
-
waitReceiveText = value;
|
|
2325
|
-
index += 1;
|
|
2326
|
-
continue;
|
|
2327
|
-
}
|
|
2328
|
-
if (arg?.startsWith("--wait-receive-text=")) {
|
|
2329
|
-
waitReceiveText = arg.slice(20);
|
|
2330
|
-
if (!waitReceiveText) return {
|
|
2331
|
-
error: "--wait-receive-text requires text",
|
|
2332
|
-
help: false,
|
|
2333
|
-
status
|
|
2334
|
-
};
|
|
2335
|
-
continue;
|
|
2336
|
-
}
|
|
2337
|
-
if (arg === "--wait-receive-message-id") {
|
|
2338
|
-
const value = argv[index + 1];
|
|
2339
|
-
if (!value) return {
|
|
2340
|
-
error: "--wait-receive-message-id requires a message id",
|
|
2341
|
-
help: false,
|
|
2342
|
-
status
|
|
2343
|
-
};
|
|
2344
|
-
waitReceiveMessageId = value;
|
|
2345
|
-
index += 1;
|
|
2346
|
-
continue;
|
|
2347
|
-
}
|
|
2348
|
-
if (arg?.startsWith("--wait-receive-message-id=")) {
|
|
2349
|
-
waitReceiveMessageId = arg.slice(26);
|
|
2350
|
-
if (!waitReceiveMessageId) return {
|
|
2351
|
-
error: "--wait-receive-message-id requires a message id",
|
|
2352
|
-
help: false,
|
|
2353
|
-
status
|
|
2354
|
-
};
|
|
2355
|
-
continue;
|
|
2356
|
-
}
|
|
2357
|
-
if (arg === "--wait-receive-observed-after") {
|
|
2358
|
-
const value = parseIsoTimestampArgument(argv[index + 1]);
|
|
2359
|
-
if (!value) return {
|
|
2360
|
-
error: "--wait-receive-observed-after requires an ISO timestamp",
|
|
2361
|
-
help: false,
|
|
2362
|
-
status
|
|
2363
|
-
};
|
|
2364
|
-
waitReceiveObservedAfter = value;
|
|
2365
|
-
index += 1;
|
|
2366
|
-
continue;
|
|
2367
|
-
}
|
|
2368
|
-
if (arg?.startsWith("--wait-receive-observed-after=")) {
|
|
2369
|
-
const value = parseIsoTimestampArgument(arg.slice(30));
|
|
2370
|
-
if (!value) return {
|
|
2371
|
-
error: "--wait-receive-observed-after requires an ISO timestamp",
|
|
2372
|
-
help: false,
|
|
2373
|
-
status
|
|
2374
|
-
};
|
|
2375
|
-
waitReceiveObservedAfter = value;
|
|
2376
|
-
continue;
|
|
2377
|
-
}
|
|
2378
|
-
if (arg === "--wait-timeout-ms") {
|
|
2379
|
-
const parsedMs = parsePositiveIntegerArgument(argv[index + 1]);
|
|
2380
|
-
if (parsedMs === void 0) return {
|
|
2381
|
-
error: "--wait-timeout-ms requires a positive integer",
|
|
2382
|
-
help: false,
|
|
2383
|
-
status
|
|
2384
|
-
};
|
|
2385
|
-
waitTimeoutMs = parsedMs;
|
|
2386
|
-
index += 1;
|
|
2387
|
-
continue;
|
|
2388
|
-
}
|
|
2389
|
-
if (arg?.startsWith("--wait-timeout-ms=")) {
|
|
2390
|
-
const parsedMs = parsePositiveIntegerArgument(arg.slice(18));
|
|
2391
|
-
if (parsedMs === void 0) return {
|
|
2392
|
-
error: "--wait-timeout-ms requires a positive integer",
|
|
2393
|
-
help: false,
|
|
2394
|
-
status
|
|
2395
|
-
};
|
|
2396
|
-
waitTimeoutMs = parsedMs;
|
|
2397
|
-
continue;
|
|
2398
|
-
}
|
|
2399
|
-
if (arg === "--wait-poll-ms") {
|
|
2400
|
-
const parsedMs = parsePositiveIntegerArgument(argv[index + 1]);
|
|
2401
|
-
if (parsedMs === void 0) return {
|
|
2402
|
-
error: "--wait-poll-ms requires a positive integer",
|
|
2403
|
-
help: false,
|
|
2404
|
-
status
|
|
2405
|
-
};
|
|
2406
|
-
waitPollMs = parsedMs;
|
|
2407
|
-
index += 1;
|
|
2408
|
-
continue;
|
|
2409
|
-
}
|
|
2410
|
-
if (arg?.startsWith("--wait-poll-ms=")) {
|
|
2411
|
-
const parsedMs = parsePositiveIntegerArgument(arg.slice(15));
|
|
2412
|
-
if (parsedMs === void 0) return {
|
|
2413
|
-
error: "--wait-poll-ms requires a positive integer",
|
|
2414
|
-
help: false,
|
|
2415
|
-
status
|
|
2416
|
-
};
|
|
2417
|
-
waitPollMs = parsedMs;
|
|
2418
|
-
continue;
|
|
2419
|
-
}
|
|
2420
2401
|
if (arg === "--bootstrap") {
|
|
2421
2402
|
const value = argv[index + 1];
|
|
2422
2403
|
if (!value) return {
|
|
@@ -2498,17 +2479,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2498
2479
|
status,
|
|
2499
2480
|
checkConfig
|
|
2500
2481
|
};
|
|
2501
|
-
if (checkConfig && statusUrl) return {
|
|
2502
|
-
error: "--check-config cannot be combined with --status-url",
|
|
2503
|
-
help: false,
|
|
2504
|
-
status,
|
|
2505
|
-
checkConfig
|
|
2506
|
-
};
|
|
2507
|
-
if (prompt !== void 0 && statusUrl) return {
|
|
2508
|
-
error: "--prompt cannot be combined with --status-url",
|
|
2509
|
-
help: false,
|
|
2510
|
-
status
|
|
2511
|
-
};
|
|
2512
2482
|
if (printOpenClawEnvPath !== void 0 && prompt !== void 0) return {
|
|
2513
2483
|
error: "--print-openclaw-env cannot be combined with --prompt",
|
|
2514
2484
|
help: false,
|
|
@@ -2529,11 +2499,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2529
2499
|
help: false,
|
|
2530
2500
|
status
|
|
2531
2501
|
};
|
|
2532
|
-
if (printOpenClawEnvPath !== void 0 && statusUrl) return {
|
|
2533
|
-
error: "--print-openclaw-env cannot be combined with --status-url",
|
|
2534
|
-
help: false,
|
|
2535
|
-
status
|
|
2536
|
-
};
|
|
2537
2502
|
if (piApiKeyFile !== void 0 && printOpenClawEnvPath === void 0) return {
|
|
2538
2503
|
error: "--pi-api-key-file requires --print-openclaw-env",
|
|
2539
2504
|
help: false,
|
|
@@ -2554,11 +2519,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2554
2519
|
help: false,
|
|
2555
2520
|
status
|
|
2556
2521
|
};
|
|
2557
|
-
if (replayFeishuEventPath !== void 0 && statusUrl) return {
|
|
2558
|
-
error: "--replay-feishu-event cannot be combined with --status-url",
|
|
2559
|
-
help: false,
|
|
2560
|
-
status
|
|
2561
|
-
};
|
|
2562
2522
|
if (replayFeishuText !== void 0 && prompt !== void 0) return {
|
|
2563
2523
|
error: "--replay-feishu-text cannot be combined with --prompt",
|
|
2564
2524
|
help: false,
|
|
@@ -2569,11 +2529,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2569
2529
|
help: false,
|
|
2570
2530
|
status
|
|
2571
2531
|
};
|
|
2572
|
-
if (replayFeishuText !== void 0 && statusUrl) return {
|
|
2573
|
-
error: "--replay-feishu-text cannot be combined with --status-url",
|
|
2574
|
-
help: false,
|
|
2575
|
-
status
|
|
2576
|
-
};
|
|
2577
2532
|
if (feishuReplayMessageId !== void 0 && replayFeishuText === void 0) return {
|
|
2578
2533
|
error: "--feishu-message-id requires --replay-feishu-text",
|
|
2579
2534
|
help: false,
|
|
@@ -2599,62 +2554,6 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2599
2554
|
help: false,
|
|
2600
2555
|
status
|
|
2601
2556
|
};
|
|
2602
|
-
if (waitReceive !== void 0 && status) return {
|
|
2603
|
-
error: "--wait-receive cannot be combined with --status",
|
|
2604
|
-
help: false,
|
|
2605
|
-
status
|
|
2606
|
-
};
|
|
2607
|
-
if (waitReceive !== void 0 && checkConfig) return {
|
|
2608
|
-
error: "--wait-receive cannot be combined with --check-config",
|
|
2609
|
-
help: false,
|
|
2610
|
-
status,
|
|
2611
|
-
checkConfig
|
|
2612
|
-
};
|
|
2613
|
-
if (waitReceive !== void 0 && prompt !== void 0) return {
|
|
2614
|
-
error: "--wait-receive cannot be combined with --prompt",
|
|
2615
|
-
help: false,
|
|
2616
|
-
status
|
|
2617
|
-
};
|
|
2618
|
-
if (waitReceive !== void 0 && replayFeishuEventPath !== void 0) return {
|
|
2619
|
-
error: "--wait-receive cannot be combined with --replay-feishu-event",
|
|
2620
|
-
help: false,
|
|
2621
|
-
status
|
|
2622
|
-
};
|
|
2623
|
-
if (waitReceive !== void 0 && replayFeishuText !== void 0) return {
|
|
2624
|
-
error: "--wait-receive cannot be combined with --replay-feishu-text",
|
|
2625
|
-
help: false,
|
|
2626
|
-
status
|
|
2627
|
-
};
|
|
2628
|
-
if (waitReceive !== void 0 && printOpenClawEnvPath !== void 0) return {
|
|
2629
|
-
error: "--wait-receive cannot be combined with --print-openclaw-env",
|
|
2630
|
-
help: false,
|
|
2631
|
-
status
|
|
2632
|
-
};
|
|
2633
|
-
if (waitTimeoutMs !== void 0 && waitReceive === void 0) return {
|
|
2634
|
-
error: "--wait-timeout-ms requires --wait-receive",
|
|
2635
|
-
help: false,
|
|
2636
|
-
status
|
|
2637
|
-
};
|
|
2638
|
-
if (waitPollMs !== void 0 && waitReceive === void 0) return {
|
|
2639
|
-
error: "--wait-poll-ms requires --wait-receive",
|
|
2640
|
-
help: false,
|
|
2641
|
-
status
|
|
2642
|
-
};
|
|
2643
|
-
if (waitReceiveText !== void 0 && waitReceive !== "handled") return {
|
|
2644
|
-
error: "--wait-receive-text requires --wait-receive handled",
|
|
2645
|
-
help: false,
|
|
2646
|
-
status
|
|
2647
|
-
};
|
|
2648
|
-
if (waitReceiveMessageId !== void 0 && waitReceive === void 0) return {
|
|
2649
|
-
error: "--wait-receive-message-id requires --wait-receive",
|
|
2650
|
-
help: false,
|
|
2651
|
-
status
|
|
2652
|
-
};
|
|
2653
|
-
if (waitReceiveObservedAfter !== void 0 && waitReceive === void 0) return {
|
|
2654
|
-
error: "--wait-receive-observed-after requires --wait-receive",
|
|
2655
|
-
help: false,
|
|
2656
|
-
status
|
|
2657
|
-
};
|
|
2658
2557
|
const recovery = recoveryCli.build();
|
|
2659
2558
|
if (recovery.error) return {
|
|
2660
2559
|
error: recovery.error,
|
|
@@ -2667,7 +2566,7 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2667
2566
|
help: false,
|
|
2668
2567
|
status
|
|
2669
2568
|
};
|
|
2670
|
-
if (checkConfig || prompt !== void 0 || printOpenClawEnvPath !== void 0 || replayFeishuEventPath !== void 0 || replayFeishuText !== void 0 || status
|
|
2569
|
+
if (checkConfig || prompt !== void 0 || printOpenClawEnvPath !== void 0 || replayFeishuEventPath !== void 0 || replayFeishuText !== void 0 || status) return {
|
|
2671
2570
|
error: "Recovery commands cannot be combined with another one-shot command",
|
|
2672
2571
|
help: false,
|
|
2673
2572
|
status
|
|
@@ -2690,27 +2589,9 @@ function parseRivusDaemonArguments(argv) {
|
|
|
2690
2589
|
...replayFeishuText !== void 0 ? { replayFeishuText } : {},
|
|
2691
2590
|
...recovery.command ? { recoveryCommand: recovery.command } : {},
|
|
2692
2591
|
...sessionKey ? { sessionKey } : {},
|
|
2693
|
-
status
|
|
2694
|
-
...statusUrl ? { statusUrl } : {},
|
|
2695
|
-
...waitPollMs !== void 0 ? { waitPollMs } : {},
|
|
2696
|
-
...waitReceive !== void 0 ? { waitReceive } : {},
|
|
2697
|
-
...waitReceiveMessageId !== void 0 ? { waitReceiveMessageId } : {},
|
|
2698
|
-
...waitReceiveObservedAfter !== void 0 ? { waitReceiveObservedAfter } : {},
|
|
2699
|
-
...waitReceiveText !== void 0 ? { waitReceiveText } : {},
|
|
2700
|
-
...waitTimeoutMs !== void 0 ? { waitTimeoutMs } : {}
|
|
2592
|
+
status
|
|
2701
2593
|
};
|
|
2702
2594
|
}
|
|
2703
|
-
function parseWaitReceive(value) {
|
|
2704
|
-
return value === "accepted" || value === "handled" ? value : void 0;
|
|
2705
|
-
}
|
|
2706
|
-
function parsePositiveIntegerArgument(value) {
|
|
2707
|
-
return value && /^[1-9]\d*$/.test(value) ? Number(value) : void 0;
|
|
2708
|
-
}
|
|
2709
|
-
function parseIsoTimestampArgument(value) {
|
|
2710
|
-
if (!value) return;
|
|
2711
|
-
const time = Date.parse(value);
|
|
2712
|
-
return Number.isNaN(time) ? void 0 : new Date(time).toISOString();
|
|
2713
|
-
}
|
|
2714
2595
|
//#endregion
|
|
2715
2596
|
//#region src/adapters/cli/command/rivus-daemon-output.ts
|
|
2716
2597
|
const RIVUS_DAEMON_STARTED_MESSAGE = "Rivus Agent daemon started\n";
|
|
@@ -2754,84 +2635,11 @@ function createSyntheticFeishuTextReplayPayload(text, options) {
|
|
|
2754
2635
|
sender: { tenant_key: options.tenantKey ?? "tenant_cli" }
|
|
2755
2636
|
} };
|
|
2756
2637
|
}
|
|
2638
|
+
//#endregion
|
|
2639
|
+
//#region src/adapters/cli/status/rivus-daemon-status.ts
|
|
2757
2640
|
function formatRivusDaemonError(error) {
|
|
2758
|
-
if (error instanceof ReceiveWaitTimeoutError) return `${error.message}\nLast status:\n${JSON.stringify(error.lastStatus, null, 2)}`;
|
|
2759
2641
|
return error instanceof Error ? error.message : String(error);
|
|
2760
2642
|
}
|
|
2761
|
-
var ReceiveWaitTimeoutError = class extends Error {
|
|
2762
|
-
target;
|
|
2763
|
-
lastStatus;
|
|
2764
|
-
messageId;
|
|
2765
|
-
observedAfter;
|
|
2766
|
-
text;
|
|
2767
|
-
constructor(target, lastStatus, messageId, observedAfter, text) {
|
|
2768
|
-
super(`Timed out waiting for ${target === "accepted" ? "receive.lastAccepted" : "receive.lastHandled"}${messageId ? ` with message id ${JSON.stringify(messageId)}` : ""}${observedAfter ? ` observed after ${JSON.stringify(observedAfter)}` : ""}${text ? ` containing text ${JSON.stringify(text)}` : ""}`);
|
|
2769
|
-
this.target = target;
|
|
2770
|
-
this.lastStatus = lastStatus;
|
|
2771
|
-
this.messageId = messageId;
|
|
2772
|
-
this.observedAfter = observedAfter;
|
|
2773
|
-
this.text = text;
|
|
2774
|
-
this.name = "ReceiveWaitTimeoutError";
|
|
2775
|
-
}
|
|
2776
|
-
};
|
|
2777
|
-
async function fetchLiveStatus(url) {
|
|
2778
|
-
const response = await fetch(url, { headers: { accept: "application/json" } });
|
|
2779
|
-
if (!response.ok) throw new Error(`Status request failed with HTTP ${response.status}`);
|
|
2780
|
-
return response.json();
|
|
2781
|
-
}
|
|
2782
|
-
function waitForReceiveStatus(readStatus, target, options) {
|
|
2783
|
-
return Effect.suspend(() => {
|
|
2784
|
-
const startedAt = Date.now();
|
|
2785
|
-
let lastStatus;
|
|
2786
|
-
const poll = () => readStatus().pipe(Effect.flatMap((status) => {
|
|
2787
|
-
lastStatus = status;
|
|
2788
|
-
if (hasReceiveObservation(status, target, {
|
|
2789
|
-
...options.messageId ? { messageId: options.messageId } : {},
|
|
2790
|
-
...options.observedAfter ? { observedAfter: options.observedAfter } : {},
|
|
2791
|
-
...options.text ? { text: options.text } : {}
|
|
2792
|
-
})) return Effect.succeed(status);
|
|
2793
|
-
if (Date.now() - startedAt >= options.timeoutMs) return Effect.fail(new ReceiveWaitTimeoutError(target, lastStatus, options.messageId, options.observedAfter, options.text));
|
|
2794
|
-
return Effect.sleep(options.pollMs).pipe(Effect.flatMap(poll));
|
|
2795
|
-
}));
|
|
2796
|
-
return poll();
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
|
-
function hasReceiveObservation(status, target, criteria) {
|
|
2800
|
-
const receive = isStatusRecord(status) ? status.receive : void 0;
|
|
2801
|
-
if (!isStatusRecord(receive)) return false;
|
|
2802
|
-
if (target === "accepted") {
|
|
2803
|
-
const lastAccepted = receive.lastAccepted;
|
|
2804
|
-
if (!isStatusRecord(lastAccepted)) return false;
|
|
2805
|
-
if (criteria.messageId === void 0) return observedAfterMatches(lastAccepted, criteria.observedAfter);
|
|
2806
|
-
const message = lastAccepted.message;
|
|
2807
|
-
return isStatusRecord(message) && message.messageId === criteria.messageId && observedAfterMatches(lastAccepted, criteria.observedAfter);
|
|
2808
|
-
}
|
|
2809
|
-
const lastHandled = receive.lastHandled;
|
|
2810
|
-
if (!isStatusRecord(lastHandled)) return false;
|
|
2811
|
-
if (criteria.messageId !== void 0 && lastHandled.messageId !== criteria.messageId) return false;
|
|
2812
|
-
if (!observedAfterMatches(lastHandled, criteria.observedAfter)) return false;
|
|
2813
|
-
if (criteria.text === void 0) return true;
|
|
2814
|
-
const intake = lastHandled.intake;
|
|
2815
|
-
return isStatusRecord(intake) && typeof intake.text === "string" && intake.text.includes(criteria.text);
|
|
2816
|
-
}
|
|
2817
|
-
function isStatusRecord(value) {
|
|
2818
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2819
|
-
}
|
|
2820
|
-
function observedAfterMatches(observation, observedAfter) {
|
|
2821
|
-
if (observedAfter === void 0) return true;
|
|
2822
|
-
const observedAtMs = readObservedAtMs(observation.observedAt);
|
|
2823
|
-
return observedAtMs !== void 0 && observedAtMs > Date.parse(observedAfter);
|
|
2824
|
-
}
|
|
2825
|
-
function readObservedAtMs(value) {
|
|
2826
|
-
if (value instanceof Date) {
|
|
2827
|
-
const time = value.getTime();
|
|
2828
|
-
return Number.isNaN(time) ? void 0 : time;
|
|
2829
|
-
}
|
|
2830
|
-
if (typeof value === "string") {
|
|
2831
|
-
const time = Date.parse(value);
|
|
2832
|
-
return Number.isNaN(time) ? void 0 : time;
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
2643
|
//#endregion
|
|
2836
2644
|
//#region src/platform/daemon/process/rivus-daemon-shutdown-controller.ts
|
|
2837
2645
|
const DEFAULT_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
@@ -3927,16 +3735,6 @@ function runRivusDaemonCli(options) {
|
|
|
3927
3735
|
options.stderr.write(formatRivusDaemonUsageError(parsed.error));
|
|
3928
3736
|
return 1;
|
|
3929
3737
|
}
|
|
3930
|
-
if (parsed.statusUrl) {
|
|
3931
|
-
const statusUrl = parsed.statusUrl;
|
|
3932
|
-
const readStatus = () => Effect.tryPromise({
|
|
3933
|
-
try: () => fetchLiveStatus(statusUrl),
|
|
3934
|
-
catch: (error) => error
|
|
3935
|
-
});
|
|
3936
|
-
const status = parsed.waitReceive ? yield* waitForReceiveStatus(readStatus, parsed.waitReceive, createWaitReceiveOptions(parsed)) : yield* readStatus();
|
|
3937
|
-
options.stdout.write(formatRivusDaemonJson(status));
|
|
3938
|
-
return 0;
|
|
3939
|
-
}
|
|
3940
3738
|
if (parsed.printOpenClawEnvPath) {
|
|
3941
3739
|
const openClawConfigPath = parsed.printOpenClawEnvPath;
|
|
3942
3740
|
const result = yield* Effect.tryPromise({
|
|
@@ -3948,7 +3746,10 @@ function runRivusDaemonCli(options) {
|
|
|
3948
3746
|
return 0;
|
|
3949
3747
|
}
|
|
3950
3748
|
const env = yield* Effect.tryPromise({
|
|
3951
|
-
try: () =>
|
|
3749
|
+
try: async () => {
|
|
3750
|
+
const loaded = await loadCliEnv(parsed.envFilePath, options.env);
|
|
3751
|
+
return options.env["RIVUS_HOME_DEPLOYMENT_DIR"] === void 0 ? withoutRivusHomeDeployment(loaded) : loaded;
|
|
3752
|
+
},
|
|
3952
3753
|
catch: (error) => error
|
|
3953
3754
|
});
|
|
3954
3755
|
const bootstrapSpecifier = parsed.bootstrap ?? env.RIVUS_BOOTSTRAP_MODULE?.trim();
|
|
@@ -3956,29 +3757,18 @@ function runRivusDaemonCli(options) {
|
|
|
3956
3757
|
options.stderr.write(formatRivusDaemonUsageError("Missing --bootstrap <module> or RIVUS_BOOTSTRAP_MODULE"));
|
|
3957
3758
|
return 1;
|
|
3958
3759
|
}
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
} else {
|
|
3972
|
-
const configExit = yield* Effect.exit(loadRivusDaemonConfig(env));
|
|
3973
|
-
if (configExit._tag === "Failure") {
|
|
3974
|
-
options.stderr.write(formatRivusDaemonLine(configExit.cause.toString()));
|
|
3975
|
-
return 1;
|
|
3976
|
-
}
|
|
3977
|
-
legacyConfig = configExit.value;
|
|
3978
|
-
if (parsed.checkConfig) {
|
|
3979
|
-
options.stdout.write(formatRivusDaemonJson(toRedactedConfig(legacyConfig)));
|
|
3980
|
-
return 0;
|
|
3981
|
-
}
|
|
3760
|
+
if (!parsed.manifestPath) {
|
|
3761
|
+
options.stderr.write(formatRivusDaemonUsageError("Missing --manifest <rivus.config.json>"));
|
|
3762
|
+
return 1;
|
|
3763
|
+
}
|
|
3764
|
+
if (parsed.checkConfig) {
|
|
3765
|
+
const manifest = yield* loadRivusDeploymentManifest(parsed.manifestPath);
|
|
3766
|
+
yield* Effect.try({
|
|
3767
|
+
try: () => validateRivusDeploymentManifest(manifest),
|
|
3768
|
+
catch: (error) => error
|
|
3769
|
+
});
|
|
3770
|
+
options.stdout.write(formatRivusDaemonJson(toRedactedDeploymentManifest(manifest)));
|
|
3771
|
+
return 0;
|
|
3982
3772
|
}
|
|
3983
3773
|
if (!bootstrapSpecifier) {
|
|
3984
3774
|
options.stderr.write(formatRivusDaemonUsageError("Missing --bootstrap <module> or RIVUS_BOOTSTRAP_MODULE"));
|
|
@@ -3990,17 +3780,13 @@ function runRivusDaemonCli(options) {
|
|
|
3990
3780
|
catch: (error) => error
|
|
3991
3781
|
});
|
|
3992
3782
|
const daemon = yield* Effect.tryPromise({
|
|
3993
|
-
try: () =>
|
|
3783
|
+
try: () => createCliDeploymentDaemon(module.createRivusDeploymentAdapters, {
|
|
3994
3784
|
argv: options.argv,
|
|
3995
3785
|
env,
|
|
3996
3786
|
...parsed.envFilePath ? { envFilePath: parsed.envFilePath } : {},
|
|
3997
3787
|
environmentOverrides: options.env,
|
|
3998
3788
|
manifestPath: parsed.manifestPath,
|
|
3999
3789
|
...options.pluginPackageManifestPath ? { pluginPackageManifestPath: options.pluginPackageManifestPath } : {}
|
|
4000
|
-
}) : createCliLegacyDaemon(module, {
|
|
4001
|
-
argv: options.argv,
|
|
4002
|
-
config: legacyConfig,
|
|
4003
|
-
env
|
|
4004
3790
|
}),
|
|
4005
3791
|
catch: (error) => error
|
|
4006
3792
|
});
|
|
@@ -4033,7 +3819,7 @@ function runRivusDaemonCli(options) {
|
|
|
4033
3819
|
return 1;
|
|
4034
3820
|
}
|
|
4035
3821
|
const text = yield* daemon.promptText({
|
|
4036
|
-
sessionKey: parsed.sessionKey ?? daemon.defaultSessionKey ??
|
|
3822
|
+
sessionKey: parsed.sessionKey ?? daemon.defaultSessionKey ?? "local:cli",
|
|
4037
3823
|
text: prompt
|
|
4038
3824
|
});
|
|
4039
3825
|
options.stdout.write(formatRivusDaemonLine(text));
|
|
@@ -4056,19 +3842,6 @@ function runRivusDaemonCli(options) {
|
|
|
4056
3842
|
catch: (error) => error
|
|
4057
3843
|
}));
|
|
4058
3844
|
}
|
|
4059
|
-
if (parsed.waitReceive) {
|
|
4060
|
-
const waitReceive = parsed.waitReceive;
|
|
4061
|
-
return yield* runStatusOneShot(options, daemon, (statusDaemon) => Effect.gen(function* () {
|
|
4062
|
-
yield* Effect.try({
|
|
4063
|
-
try: () => installCliShutdownController(options, statusDaemon),
|
|
4064
|
-
catch: (error) => error
|
|
4065
|
-
});
|
|
4066
|
-
yield* statusDaemon.start();
|
|
4067
|
-
const status = yield* waitForReceiveStatus(() => statusDaemon.status(), waitReceive, createWaitReceiveOptions(parsed));
|
|
4068
|
-
options.stdout.write(formatRivusDaemonJson(status));
|
|
4069
|
-
return 0;
|
|
4070
|
-
}));
|
|
4071
|
-
}
|
|
4072
3845
|
yield* Effect.try({
|
|
4073
3846
|
try: () => installCliShutdownController(options, daemon),
|
|
4074
3847
|
catch: (error) => error
|
|
@@ -4081,11 +3854,6 @@ function runRivusDaemonCli(options) {
|
|
|
4081
3854
|
return 1;
|
|
4082
3855
|
})));
|
|
4083
3856
|
}
|
|
4084
|
-
async function createCliLegacyDaemon(module, context) {
|
|
4085
|
-
const factory = module.createRivusDaemonProcess ?? module.default;
|
|
4086
|
-
if (!factory) throw new Error("Bootstrap module must export createRivusDaemonProcess(context) or a default factory");
|
|
4087
|
-
return factory(context);
|
|
4088
|
-
}
|
|
4089
3857
|
async function createCliDeploymentDaemon(factory, context) {
|
|
4090
3858
|
if (!factory) throw new Error("Manifest bootstrap module must export createRivusDeploymentAdapters(context)");
|
|
4091
3859
|
return createRivusDeploymentCliProcess(factory, context);
|
|
@@ -4114,15 +3882,6 @@ function runReplayOneShot(options, daemon, createPayload, replayOptions) {
|
|
|
4114
3882
|
return 0;
|
|
4115
3883
|
}));
|
|
4116
3884
|
}
|
|
4117
|
-
function createWaitReceiveOptions(parsed) {
|
|
4118
|
-
return {
|
|
4119
|
-
...parsed.waitReceiveMessageId ? { messageId: parsed.waitReceiveMessageId } : {},
|
|
4120
|
-
...parsed.waitReceiveObservedAfter ? { observedAfter: parsed.waitReceiveObservedAfter } : {},
|
|
4121
|
-
pollMs: parsed.waitPollMs ?? 500,
|
|
4122
|
-
...parsed.waitReceiveText ? { text: parsed.waitReceiveText } : {},
|
|
4123
|
-
timeoutMs: parsed.waitTimeoutMs ?? 3e4
|
|
4124
|
-
};
|
|
4125
|
-
}
|
|
4126
3885
|
function installCliShutdownController(options, daemon) {
|
|
4127
3886
|
createRivusDaemonShutdownController({
|
|
4128
3887
|
daemon,
|
|
@@ -4156,14 +3915,52 @@ function runRivusCli(options) {
|
|
|
4156
3915
|
if (command === "start") return runHomeDaemonCommand(options, "start", []);
|
|
4157
3916
|
if (command === "status") return runHomeDaemonCommand(options, "status", ["--status"]);
|
|
4158
3917
|
if (command === "check-config") return runHomeDaemonCommand(options, "check-config", ["--check-config"]);
|
|
3918
|
+
if (command === "recovery") {
|
|
3919
|
+
const argv = options.argv.slice(1);
|
|
3920
|
+
const parser = createRivusRecoveryCliParser();
|
|
3921
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
3922
|
+
const argument = parser.consume(argv[index], argv[index + 1]);
|
|
3923
|
+
if (!argument.handled || argument.error) return Effect.sync(() => {
|
|
3924
|
+
options.stderr.write(renderRivusHomeCommandUsage("recovery"));
|
|
3925
|
+
return 1;
|
|
3926
|
+
});
|
|
3927
|
+
index += argument.consumed;
|
|
3928
|
+
}
|
|
3929
|
+
const parsed = parser.build();
|
|
3930
|
+
if (argv.length === 0 || parsed.error || !parsed.command) return Effect.sync(() => {
|
|
3931
|
+
options.stderr.write(renderRivusHomeCommandUsage("recovery"));
|
|
3932
|
+
return 1;
|
|
3933
|
+
});
|
|
3934
|
+
return runHomeDaemonCommand(options, "recovery", resolveHomeRecoveryFileArguments(argv, parsed.command, options.cwd));
|
|
3935
|
+
}
|
|
4159
3936
|
if (command === "init") return runInitCommand(options);
|
|
4160
3937
|
if (command === "doctor") return runDoctorCommand(options);
|
|
4161
3938
|
if (command === "model") return runModelCommand(options);
|
|
3939
|
+
if (command === "audio") return runAudioCommand(options);
|
|
4162
3940
|
if (command && !command.startsWith("-")) return Effect.sync(() => {
|
|
4163
3941
|
options.stderr.write(renderRivusCliUnknownCommand(command));
|
|
4164
3942
|
return 1;
|
|
4165
3943
|
});
|
|
4166
|
-
return runRivusDaemonCli(
|
|
3944
|
+
return runRivusDaemonCli({
|
|
3945
|
+
...options,
|
|
3946
|
+
env: withoutRivusHomeDeployment(options.env)
|
|
3947
|
+
});
|
|
3948
|
+
}
|
|
3949
|
+
function resolveHomeRecoveryFileArguments(argv, command, cwd) {
|
|
3950
|
+
if (command.type === "inspect") return argv;
|
|
3951
|
+
const files = /* @__PURE__ */ new Map([["--recovery-note-file", resolve(cwd, command.noteFilePath)]]);
|
|
3952
|
+
if (command.type === "resolve-tool-operation" && command.outcome.status === "applied") files.set("--tool-result-file", resolve(cwd, command.outcome.resultFilePath));
|
|
3953
|
+
const resolved = [];
|
|
3954
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
3955
|
+
const argument = argv[index];
|
|
3956
|
+
const file = [...files].find(([flag]) => argument === flag || argument.startsWith(`${flag}=`));
|
|
3957
|
+
if (!file) resolved.push(argument);
|
|
3958
|
+
else if (argument === file[0]) {
|
|
3959
|
+
resolved.push(argument, file[1]);
|
|
3960
|
+
index += 1;
|
|
3961
|
+
} else resolved.push(`${file[0]}=${file[1]}`);
|
|
3962
|
+
}
|
|
3963
|
+
return resolved;
|
|
4167
3964
|
}
|
|
4168
3965
|
function runModelCommand(options) {
|
|
4169
3966
|
const parsed = parseRivusModelCliArguments(options.argv.slice(1));
|
|
@@ -4223,11 +4020,43 @@ function modelTransportFailure(error) {
|
|
|
4223
4020
|
status: "failed"
|
|
4224
4021
|
};
|
|
4225
4022
|
}
|
|
4023
|
+
function runAudioCommand(options) {
|
|
4024
|
+
const parsed = parseRivusAudioCliArguments(options.argv.slice(1));
|
|
4025
|
+
if ("help" in parsed) return Effect.sync(() => {
|
|
4026
|
+
options.stdout.write(RIVUS_AUDIO_CLI_USAGE);
|
|
4027
|
+
return 0;
|
|
4028
|
+
});
|
|
4029
|
+
if ("error" in parsed) return Effect.sync(() => {
|
|
4030
|
+
options.stderr.write(renderRivusAudioCliArgumentError(parsed.error));
|
|
4031
|
+
return 1;
|
|
4032
|
+
});
|
|
4033
|
+
return resolveHomeDirectoryEffect(options).pipe(Effect.flatMap((directory) => options.homeApi.load(directory)), Effect.flatMap((home) => Effect.tryPromise({
|
|
4034
|
+
try: () => runRivusAudioCliCommand(parsed, {
|
|
4035
|
+
assetDirectory: gatewayAudioTranscriberAssetDirectory,
|
|
4036
|
+
cwd: options.cwd,
|
|
4037
|
+
env: options.env,
|
|
4038
|
+
installRoot: join(home.stateDirectory, "audio-transcriber"),
|
|
4039
|
+
nodeExecutable: options.nodeExecutable,
|
|
4040
|
+
runProcess: runRivusAudioProcess,
|
|
4041
|
+
signal: abortOnInterruption(options.signalSource),
|
|
4042
|
+
stderr: options.stderr,
|
|
4043
|
+
stdout: options.stdout
|
|
4044
|
+
}),
|
|
4045
|
+
catch: (error) => error
|
|
4046
|
+
})), Effect.catch((error) => writeError(options, error)));
|
|
4047
|
+
}
|
|
4048
|
+
/** Lets an interrupted install stop its child processes and remove its staging directory before the CLI exits. */
|
|
4049
|
+
function abortOnInterruption(signalSource) {
|
|
4050
|
+
const controller = new AbortController();
|
|
4051
|
+
signalSource.on("SIGINT", () => controller.abort());
|
|
4052
|
+
signalSource.on("SIGTERM", () => controller.abort());
|
|
4053
|
+
return controller.signal;
|
|
4054
|
+
}
|
|
4226
4055
|
function runSetupCommand(options) {
|
|
4227
4056
|
return withOptionalDirectoryArgument(options, "setup", (argument) => resolveHomeDirectoryEffect(options, argument).pipe(Effect.flatMap((directory) => options.homeApi.setup(directory).pipe(Effect.tap(() => Effect.sync(() => options.stdout.write(renderRivusSetupSuccess(directory)))), Effect.as(0))), Effect.catch((error) => writeError(options, error))));
|
|
4228
4057
|
}
|
|
4229
4058
|
function runHomeDaemonCommand(options, command, daemonArgs) {
|
|
4230
|
-
if (hasRivusHomeCommandArguments(options.argv.slice(1))) return Effect.sync(() => {
|
|
4059
|
+
if (command !== "recovery" && hasRivusHomeCommandArguments(options.argv.slice(1))) return Effect.sync(() => {
|
|
4231
4060
|
options.stderr.write(renderRivusHomeCommandUsage(command));
|
|
4232
4061
|
return 1;
|
|
4233
4062
|
});
|
|
@@ -4245,7 +4074,8 @@ function runHomeDaemonCommand(options, command, daemonArgs) {
|
|
|
4245
4074
|
env: {
|
|
4246
4075
|
...options.env,
|
|
4247
4076
|
RIVUS_DEPLOYMENT_STATE_DIR: home.stateDirectory,
|
|
4248
|
-
RIVUS_HOME: home.directory
|
|
4077
|
+
RIVUS_HOME: home.directory,
|
|
4078
|
+
[RIVUS_HOME_DEPLOYMENT_ENV]: home.directory
|
|
4249
4079
|
},
|
|
4250
4080
|
pluginPackageManifestPath: options.pluginPackageManifestPath ?? gatewayPackageManifestPath
|
|
4251
4081
|
})), Effect.catch((error) => writeError(options, error)));
|