@rivus/agent 0.1.1 → 0.4.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 +19 -4
- package/dist/acp.d.ts +98 -0
- package/dist/acp.js +436 -0
- package/dist/agent-loop.d.ts +420 -0
- package/dist/agent-loop.js +118 -0
- package/dist/agent-memory.d.ts +98 -0
- package/dist/cli.js +508 -5
- package/dist/index.d.ts +15 -427
- package/dist/index.js +131 -180
- package/dist/rivus-daemon-cli.js +558 -527
- package/dist/rivus-plugin-testkit.d.ts +3 -98
- package/dist/rivus-plugin-testkit.js +2 -2
- package/examples/a-share-briefing-analysis.mjs +93 -0
- package/examples/a-share-briefing-renderer.mjs +257 -0
- package/examples/a-share-index-evidence.mjs +99 -0
- package/examples/a-share-market-briefing.mjs +83 -0
- package/examples/a-share-market-date.mjs +10 -0
- package/examples/a-share-overseas-evidence.mjs +86 -0
- package/examples/a-share-policy-evidence.mjs +145 -0
- package/examples/a-share-provider-response.mjs +21 -0
- package/examples/a-share-sector-evidence.mjs +70 -0
- package/examples/acp-stdio-proxy.mjs +55 -0
- package/examples/current-weather.mjs +6 -32
- package/examples/https-response-reader.mjs +36 -0
- package/examples/pi-feishu-deployment.bootstrap.ts +2 -2
- package/examples/rivus-agents.plugin.mjs +55 -3
- package/examples/rivus-starter.plugin.mjs +45 -0
- package/examples/rivus.config.json +30 -1
- package/package.json +17 -7
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as createAgentLoopSkillExecutionStart, c as createAgentLoopToolExecutionEnd, d as createAsyncIterableAgentLoop, f as createEventAgentLoop, i as createAgentLoopSkillExecutionEnd, l as createAgentLoopToolExecutionStart, m as createTextAgentLoopFromCallback, n as createAgentLoopModelExecutionEnd, o as createAgentLoopTextDelta, p as createTextAgentLoop, r as createAgentLoopModelExecutionStart, s as createAgentLoopThinkingDelta, t as createAgentLoopFromCallback, u as createAgentLoopToolExecutionUpdate } from "./agent-loop.js";
|
|
2
2
|
import { a as RIVUS_MEMORY_TOOL_ID, c as createMemoryNamespace, d as InvalidRivusPlugin, f as RIVUS_PLUGIN_API_VERSION, i as MEMORY_SCOPES, l as createRivusMemoryToolContract, m as requiresToolApproval, n as resolveRivusAgentDefinition, o as RIVUS_MEMORY_TOOL_PLUGIN_ID, p as RivusToolInputRejected, s as RIVUS_MEMORY_TOOL_VERSION, t as createRivusPluginCatalog, u as restrictMemoryScopesForAudience } from "./rivus-plugin-registry.js";
|
|
3
|
+
import { A as loadRivusDeployment, D as resolveFeishuEndpointCredentials, E as FeishuEndpointCredentialError, S as loadNodeRivusPluginModule, T as loadRivusDeploymentManifest, _ as OpenClawEnvImportError, a as RivusDeploymentDaemonLifecycleError, b as RivusDaemonConfigError, c as InvalidRivusEndpointBinding, d as AgentRuntimeDisposed, f as createAgentRuntimePool, g as createRivusDaemonShutdownController, h as createStableId, i as RivusDeploymentAutomationReadinessError, j as validateRivusDeploymentManifest, k as RivusPluginLoadError, l as createRivusAgentHost, m as createAgentInstanceRegistry, n as createRivusDeploymentCliProcess, o as RivusDeploymentReadinessError, p as AgentInstanceConflict, r as createConfiguredRivusDeploymentDaemon, s as createRivusDeploymentDaemon, t as runRivusDaemonCli, u as AgentInstanceBusy, v as createRivusEnvFromOpenClawConfig, w as RivusDeploymentManifestError, x as loadRivusDaemonConfig, y as formatRivusEnvFile } from "./rivus-daemon-cli.js";
|
|
3
4
|
import { n as assertRivusPluginConforms, r as createFakeRivusPlugin, t as RivusPluginConformanceError } from "./rivus-plugin-testkit.js";
|
|
4
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { Cause, Deferred, Effect, Exit, Fiber, Option, Stream } from "effect";
|
|
6
|
-
import { appendFile, lstat, mkdir, readFile, readdir, realpath, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
7
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
|
+
import { appendFile, lstat, mkdir, readFile, readdir, realpath, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
8
9
|
import { isDeepStrictEqual } from "node:util";
|
|
9
10
|
import { createServer } from "node:http";
|
|
10
11
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
@@ -649,122 +650,6 @@ function assertNonNegativeInteger(value, name) {
|
|
|
649
650
|
if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${name} must be a non-negative integer`);
|
|
650
651
|
}
|
|
651
652
|
//#endregion
|
|
652
|
-
//#region src/application/agent/agent-loop.ts
|
|
653
|
-
function createAgentLoopTextDelta(delta) {
|
|
654
|
-
return {
|
|
655
|
-
delta,
|
|
656
|
-
type: "assistant_text_delta"
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
function normalizeAgentLoopEvent(event) {
|
|
660
|
-
return typeof event === "string" ? createAgentLoopTextDelta(event) : event;
|
|
661
|
-
}
|
|
662
|
-
function createAgentLoopThinkingDelta(delta) {
|
|
663
|
-
return {
|
|
664
|
-
delta,
|
|
665
|
-
type: "assistant_thinking_delta"
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
function createAgentLoopModelExecutionStart(options) {
|
|
669
|
-
return {
|
|
670
|
-
...options,
|
|
671
|
-
type: "model_execution_start"
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
function createAgentLoopModelExecutionEnd(options) {
|
|
675
|
-
return {
|
|
676
|
-
...options,
|
|
677
|
-
type: "model_execution_end"
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
function createAgentLoopSkillExecutionStart(options) {
|
|
681
|
-
return {
|
|
682
|
-
...options,
|
|
683
|
-
type: "skill_execution_start"
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
function createAgentLoopSkillExecutionEnd(options) {
|
|
687
|
-
return {
|
|
688
|
-
...options,
|
|
689
|
-
type: "skill_execution_end"
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
function createAgentLoopToolExecutionStart(options) {
|
|
693
|
-
return {
|
|
694
|
-
input: options.input,
|
|
695
|
-
toolCallId: options.toolCallId,
|
|
696
|
-
toolName: options.toolName,
|
|
697
|
-
type: "tool_execution_start"
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
function createAgentLoopToolExecutionUpdate(options) {
|
|
701
|
-
return {
|
|
702
|
-
input: options.input,
|
|
703
|
-
partialResult: options.partialResult,
|
|
704
|
-
toolCallId: options.toolCallId,
|
|
705
|
-
toolName: options.toolName,
|
|
706
|
-
type: "tool_execution_update"
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
function createAgentLoopToolExecutionEnd(options) {
|
|
710
|
-
return {
|
|
711
|
-
isError: options.isError,
|
|
712
|
-
result: options.result,
|
|
713
|
-
toolCallId: options.toolCallId,
|
|
714
|
-
toolName: options.toolName,
|
|
715
|
-
type: "tool_execution_end"
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
function createEventAgentLoop(options) {
|
|
719
|
-
return { run: (input) => {
|
|
720
|
-
const events = typeof options.events === "function" ? options.events(input) : options.events;
|
|
721
|
-
if (isPromiseLike(events)) return Stream.fromEffect(Effect.tryPromise({
|
|
722
|
-
try: () => events,
|
|
723
|
-
catch: (cause) => cause
|
|
724
|
-
})).pipe(Stream.flatMap((resolvedEvents) => Stream.fromIterable(resolvedEvents)), Stream.map(normalizeAgentLoopEvent));
|
|
725
|
-
return Stream.fromIterable(events).pipe(Stream.map(normalizeAgentLoopEvent));
|
|
726
|
-
} };
|
|
727
|
-
}
|
|
728
|
-
function createAsyncIterableAgentLoop(options) {
|
|
729
|
-
return { run: (input) => Stream.fromAsyncIterable(options.run(input), (error) => error).pipe(Stream.map(normalizeAgentLoopEvent)) };
|
|
730
|
-
}
|
|
731
|
-
function createAgentLoopFromCallback(run) {
|
|
732
|
-
return { run: (input) => Stream.fromEffect(Effect.try({
|
|
733
|
-
try: () => run(input),
|
|
734
|
-
catch: (cause) => cause
|
|
735
|
-
})).pipe(Stream.flatMap(streamFromAgentLoopCallbackResult)) };
|
|
736
|
-
}
|
|
737
|
-
function createTextAgentLoop(options) {
|
|
738
|
-
return { run: (input) => Stream.fromEffect(options.generate(input)).pipe(Stream.map((delta) => createAgentLoopTextDelta(delta))) };
|
|
739
|
-
}
|
|
740
|
-
function createTextAgentLoopFromCallback(generate) {
|
|
741
|
-
return createTextAgentLoop({ generate: (input) => Effect.tryPromise({
|
|
742
|
-
try: async () => generate(input),
|
|
743
|
-
catch: (cause) => cause
|
|
744
|
-
}) });
|
|
745
|
-
}
|
|
746
|
-
function isPromiseLike(value) {
|
|
747
|
-
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
748
|
-
}
|
|
749
|
-
function streamFromAgentLoopCallbackResult(result) {
|
|
750
|
-
if (Effect.isEffect(result)) return Stream.fromEffect(result).pipe(Stream.flatMap(streamFromAgentLoopCallbackOutput));
|
|
751
|
-
if (isPromiseLike(result)) return Stream.fromEffect(Effect.tryPromise({
|
|
752
|
-
try: () => Promise.resolve(result),
|
|
753
|
-
catch: (cause) => cause
|
|
754
|
-
})).pipe(Stream.flatMap(streamFromAgentLoopCallbackOutput));
|
|
755
|
-
return streamFromAgentLoopCallbackOutput(result);
|
|
756
|
-
}
|
|
757
|
-
function streamFromAgentLoopCallbackOutput(output) {
|
|
758
|
-
if (isEffectStream(output)) return output.pipe(Stream.map(normalizeAgentLoopEvent));
|
|
759
|
-
return (isAsyncIterable(output) ? Stream.fromAsyncIterable(output, (error) => error) : Stream.fromIterable(output)).pipe(Stream.map(normalizeAgentLoopEvent));
|
|
760
|
-
}
|
|
761
|
-
function isAsyncIterable(value) {
|
|
762
|
-
return Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
|
|
763
|
-
}
|
|
764
|
-
function isEffectStream(value) {
|
|
765
|
-
return typeof value === "object" && value !== null && Stream.StreamTypeId in value;
|
|
766
|
-
}
|
|
767
|
-
//#endregion
|
|
768
653
|
//#region src/infrastructure/http/json-fetch-request.ts
|
|
769
654
|
function createJsonFetchRequest(options = {}) {
|
|
770
655
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
@@ -1932,25 +1817,6 @@ function createAgentRuntime(harness, options = {}) {
|
|
|
1932
1817
|
};
|
|
1933
1818
|
}
|
|
1934
1819
|
//#endregion
|
|
1935
|
-
//#region src/infrastructure/config/feishu-endpoint-credentials.ts
|
|
1936
|
-
var FeishuEndpointCredentialError = class extends Error {
|
|
1937
|
-
name = "FeishuEndpointCredentialError";
|
|
1938
|
-
};
|
|
1939
|
-
function resolveFeishuEndpointCredentials(credentialRef, env) {
|
|
1940
|
-
if (!credentialRef.startsWith("env:")) throw new FeishuEndpointCredentialError("Feishu endpoint credentialRef must use env:<PREFIX>");
|
|
1941
|
-
const prefix = credentialRef.slice(4);
|
|
1942
|
-
if (!/^[A-Z][A-Z0-9_]*$/.test(prefix)) throw new FeishuEndpointCredentialError(`Invalid environment prefix in credentialRef: ${credentialRef}`);
|
|
1943
|
-
return Object.freeze({
|
|
1944
|
-
appId: required(env, `${prefix}_APP_ID`),
|
|
1945
|
-
appSecret: required(env, `${prefix}_APP_SECRET`)
|
|
1946
|
-
});
|
|
1947
|
-
}
|
|
1948
|
-
function required(env, variable) {
|
|
1949
|
-
const value = env[variable]?.trim();
|
|
1950
|
-
if (!value) throw new FeishuEndpointCredentialError(`${variable} is required`);
|
|
1951
|
-
return value;
|
|
1952
|
-
}
|
|
1953
|
-
//#endregion
|
|
1954
1820
|
//#region src/application/feishu/feishu-card-action-intake.ts
|
|
1955
1821
|
var InvalidFeishuCardAction = class {
|
|
1956
1822
|
reason;
|
|
@@ -2058,25 +1924,28 @@ function encodeSegment(value) {
|
|
|
2058
1924
|
}
|
|
2059
1925
|
//#endregion
|
|
2060
1926
|
//#region src/application/feishu/feishu-message-intake.ts
|
|
2061
|
-
var UnsupportedFeishuMessage = class {
|
|
1927
|
+
var UnsupportedFeishuMessage = class extends Error {
|
|
2062
1928
|
messageType;
|
|
1929
|
+
name = "UnsupportedFeishuMessage";
|
|
2063
1930
|
_tag = "UnsupportedFeishuMessage";
|
|
2064
1931
|
constructor(messageType) {
|
|
1932
|
+
super(`Unsupported Feishu message type: ${messageType}`);
|
|
2065
1933
|
this.messageType = messageType;
|
|
2066
1934
|
}
|
|
2067
1935
|
};
|
|
2068
|
-
var InvalidFeishuMessageContent = class {
|
|
1936
|
+
var InvalidFeishuMessageContent = class extends Error {
|
|
2069
1937
|
reason;
|
|
1938
|
+
name = "InvalidFeishuMessageContent";
|
|
2070
1939
|
_tag = "InvalidFeishuMessageContent";
|
|
2071
1940
|
constructor(reason) {
|
|
1941
|
+
super(reason);
|
|
2072
1942
|
this.reason = reason;
|
|
2073
1943
|
}
|
|
2074
1944
|
};
|
|
2075
1945
|
function createAgentCommandFromFeishuMessage(payload, options) {
|
|
2076
1946
|
return Effect.gen(function* () {
|
|
2077
1947
|
const message = payload.event.message;
|
|
2078
|
-
|
|
2079
|
-
const text = yield* parseTextContent(message.content);
|
|
1948
|
+
const text = message.message_type === "text" ? yield* parseTextContent(message.content) : message.message_type === "post" ? yield* parsePostContent(message.content) : yield* Effect.fail(new UnsupportedFeishuMessage(message.message_type));
|
|
2080
1949
|
const cancel = yield* parseCancelRunCommand(message.message_id, text);
|
|
2081
1950
|
const sessionReference = toSessionReference(payload, options);
|
|
2082
1951
|
const sessionKey = yield* createFeishuSessionKey(sessionReference);
|
|
@@ -2135,6 +2004,28 @@ function parseTextContent(content) {
|
|
|
2135
2004
|
catch: (error) => new InvalidFeishuMessageContent(error instanceof Error ? error.message : "invalid JSON content")
|
|
2136
2005
|
});
|
|
2137
2006
|
}
|
|
2007
|
+
function parsePostContent(content) {
|
|
2008
|
+
return Effect.try({
|
|
2009
|
+
try: () => {
|
|
2010
|
+
const parsed = JSON.parse(content);
|
|
2011
|
+
const paragraphs = Array.isArray(parsed.content_v2) ? parsed.content_v2 : parsed.content;
|
|
2012
|
+
if (!Array.isArray(paragraphs)) throw new Error("post content is missing");
|
|
2013
|
+
const body = paragraphs.map((paragraph) => {
|
|
2014
|
+
if (!Array.isArray(paragraph)) throw new Error("post paragraph is invalid");
|
|
2015
|
+
return paragraph.map((element) => {
|
|
2016
|
+
if (element === null || typeof element !== "object") return "";
|
|
2017
|
+
if ("text" in element && typeof element.text === "string") return element.text;
|
|
2018
|
+
if ("user_name" in element && typeof element.user_name === "string") return `@${element.user_name}`;
|
|
2019
|
+
return "";
|
|
2020
|
+
}).join("");
|
|
2021
|
+
}).join("\n").trim();
|
|
2022
|
+
const text = [typeof parsed.title === "string" ? parsed.title.trim() : "", body].filter((part) => part.length > 0).join("\n");
|
|
2023
|
+
if (!text) throw new Error("post content has no text");
|
|
2024
|
+
return text;
|
|
2025
|
+
},
|
|
2026
|
+
catch: (error) => new InvalidFeishuMessageContent(error instanceof Error ? error.message : "invalid JSON content")
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2138
2029
|
function parseCancelRunCommand(messageId, text) {
|
|
2139
2030
|
const trimmed = text.trim();
|
|
2140
2031
|
if (!/^\/cancel(?:\s|$)/.test(trimmed)) return Effect.succeed(void 0);
|
|
@@ -5495,9 +5386,9 @@ function createFeishuDeploymentEndpoint(options) {
|
|
|
5495
5386
|
running: () => websocket.running() && workerLoop.running(),
|
|
5496
5387
|
start: async () => {
|
|
5497
5388
|
execution.beginStart();
|
|
5498
|
-
workerLoop.start();
|
|
5499
5389
|
try {
|
|
5500
5390
|
await websocket.start();
|
|
5391
|
+
workerLoop.start();
|
|
5501
5392
|
} catch (startError) {
|
|
5502
5393
|
const cleanupErrors = await settleCleanup([() => websocket.stop(), () => workerLoop.stop()]);
|
|
5503
5394
|
if (cleanupErrors.length > 0) throw new AggregateError([startError, ...cleanupErrors], "Feishu endpoint startup and cleanup failed");
|
|
@@ -6164,7 +6055,7 @@ function createAutomationMandateStore() {
|
|
|
6164
6055
|
//#endregion
|
|
6165
6056
|
//#region src/application/automation/daily-automation-schedule.ts
|
|
6166
6057
|
function createDailyAutomationSchedule(expression, timeZone, now = /* @__PURE__ */ new Date()) {
|
|
6167
|
-
const { hour, minute } = parseDailySchedule(expression);
|
|
6058
|
+
const { hour, minute, weekdays } = parseDailySchedule(expression);
|
|
6168
6059
|
try {
|
|
6169
6060
|
zonedParts(now, timeZone);
|
|
6170
6061
|
} catch (cause) {
|
|
@@ -6173,6 +6064,7 @@ function createDailyAutomationSchedule(expression, timeZone, now = /* @__PURE__
|
|
|
6173
6064
|
return Object.freeze({
|
|
6174
6065
|
currentOccurrence: (at) => {
|
|
6175
6066
|
const local = zonedParts(at, timeZone);
|
|
6067
|
+
if (!matchesWeekday(local, weekdays)) return void 0;
|
|
6176
6068
|
const occurrence = zonedMinuteToInstant({
|
|
6177
6069
|
day: local.day,
|
|
6178
6070
|
hour,
|
|
@@ -6184,36 +6076,49 @@ function createDailyAutomationSchedule(expression, timeZone, now = /* @__PURE__
|
|
|
6184
6076
|
},
|
|
6185
6077
|
nextOccurrence: (at) => {
|
|
6186
6078
|
const local = zonedParts(at, timeZone);
|
|
6187
|
-
const
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
}, timeZone);
|
|
6079
|
+
const localDate = Date.UTC(local.year, local.month - 1, local.day);
|
|
6080
|
+
for (let offsetDays = 0; offsetDays <= 7; offsetDays += 1) {
|
|
6081
|
+
const date = new Date(localDate + offsetDays * 864e5);
|
|
6082
|
+
const candidateParts = {
|
|
6083
|
+
day: date.getUTCDate(),
|
|
6084
|
+
hour,
|
|
6085
|
+
minute,
|
|
6086
|
+
month: date.getUTCMonth() + 1,
|
|
6087
|
+
year: date.getUTCFullYear()
|
|
6088
|
+
};
|
|
6089
|
+
if (!matchesWeekday(candidateParts, weekdays)) continue;
|
|
6090
|
+
const candidate = zonedMinuteToInstant(candidateParts, timeZone);
|
|
6091
|
+
if (candidate.getTime() > at.getTime()) return candidate;
|
|
6092
|
+
}
|
|
6093
|
+
throw new Error(`Automation schedule does not resolve within one week: ${expression}`);
|
|
6203
6094
|
}
|
|
6204
6095
|
});
|
|
6205
6096
|
}
|
|
6206
6097
|
function parseDailySchedule(schedule) {
|
|
6207
|
-
const match = /^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s
|
|
6098
|
+
const match = /^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+(\*|1-5)$/.exec(schedule.trim());
|
|
6208
6099
|
if (!match) throw new Error(`unsupported Automation schedule: ${schedule}`);
|
|
6209
6100
|
const minute = Number(match[1]);
|
|
6210
6101
|
const hour = Number(match[2]);
|
|
6211
6102
|
if (!Number.isInteger(minute) || minute < 0 || minute > 59 || !Number.isInteger(hour) || hour < 0 || hour > 23) throw new Error(`invalid Automation schedule: ${schedule}`);
|
|
6212
|
-
return {
|
|
6103
|
+
return match[3] === "1-5" ? {
|
|
6104
|
+
hour,
|
|
6105
|
+
minute,
|
|
6106
|
+
weekdays: /* @__PURE__ */ new Set([
|
|
6107
|
+
1,
|
|
6108
|
+
2,
|
|
6109
|
+
3,
|
|
6110
|
+
4,
|
|
6111
|
+
5
|
|
6112
|
+
])
|
|
6113
|
+
} : {
|
|
6213
6114
|
hour,
|
|
6214
6115
|
minute
|
|
6215
6116
|
};
|
|
6216
6117
|
}
|
|
6118
|
+
function matchesWeekday(parts, weekdays) {
|
|
6119
|
+
if (!weekdays) return true;
|
|
6120
|
+
return weekdays.has(new Date(Date.UTC(parts.year, parts.month - 1, parts.day)).getUTCDay());
|
|
6121
|
+
}
|
|
6217
6122
|
function zonedParts(date, timeZone) {
|
|
6218
6123
|
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
6219
6124
|
day: "2-digit",
|
|
@@ -6305,7 +6210,7 @@ async function executeDue(options, schedule, at, claim) {
|
|
|
6305
6210
|
const occurrence = schedule.currentOccurrence(at);
|
|
6306
6211
|
if (!occurrence) return void 0;
|
|
6307
6212
|
const tick = claim(occurrence);
|
|
6308
|
-
const existing = await options.repository.get(
|
|
6213
|
+
const existing = await options.repository.get(options.automationId, occurrence);
|
|
6309
6214
|
if (existing?.status === "delivered") return existing;
|
|
6310
6215
|
let record = existing;
|
|
6311
6216
|
if (record?.status !== "generated") {
|
|
@@ -6378,15 +6283,18 @@ const systemClock = {
|
|
|
6378
6283
|
async function openJsonAutomationTickRepository(options) {
|
|
6379
6284
|
const records = /* @__PURE__ */ new Map();
|
|
6380
6285
|
const snapshot = await readSnapshot$1(options.filePath);
|
|
6381
|
-
for (const record of snapshot.records)
|
|
6286
|
+
for (const record of snapshot.records) {
|
|
6287
|
+
const recordKey = key(record.automationId, record.occurrence);
|
|
6288
|
+
records.set(recordKey, preferRecoveryRecord(records.get(recordKey), record));
|
|
6289
|
+
}
|
|
6382
6290
|
let pendingWrite = Promise.resolve();
|
|
6383
6291
|
return {
|
|
6384
|
-
get: async (
|
|
6292
|
+
get: async (automationId, occurrence) => records.get(key(automationId, occurrence)),
|
|
6385
6293
|
put: async (record) => {
|
|
6386
6294
|
const stored = Object.freeze({ ...record });
|
|
6387
6295
|
const operation = pendingWrite.then(async () => {
|
|
6388
6296
|
const next = new Map(records);
|
|
6389
|
-
next.set(key(record.
|
|
6297
|
+
next.set(key(record.automationId, record.occurrence), stored);
|
|
6390
6298
|
await writeSnapshot(options.filePath, [...next.values()]);
|
|
6391
6299
|
records.clear();
|
|
6392
6300
|
for (const [recordKey, value] of next) records.set(recordKey, value);
|
|
@@ -6401,13 +6309,13 @@ async function readSnapshot$1(filePath) {
|
|
|
6401
6309
|
const raw = await readPersistenceFile(filePath);
|
|
6402
6310
|
if (raw === void 0) return Object.freeze({
|
|
6403
6311
|
records: Object.freeze([]),
|
|
6404
|
-
version:
|
|
6312
|
+
version: 3
|
|
6405
6313
|
});
|
|
6406
6314
|
const value = JSON.parse(raw);
|
|
6407
|
-
if (!isRecord$4(value) || value.version !== 2 || !Array.isArray(value.records)) throw new Error("Automation Tick snapshot must contain version 2 records");
|
|
6315
|
+
if (!isRecord$4(value) || value.version !== 2 && value.version !== 3 || !Array.isArray(value.records)) throw new Error("Automation Tick snapshot must contain version 2 or 3 records");
|
|
6408
6316
|
return Object.freeze({
|
|
6409
6317
|
records: Object.freeze(value.records.map(readRecord)),
|
|
6410
|
-
version:
|
|
6318
|
+
version: value.version
|
|
6411
6319
|
});
|
|
6412
6320
|
}
|
|
6413
6321
|
async function writeSnapshot(filePath, records) {
|
|
@@ -6416,7 +6324,7 @@ async function writeSnapshot(filePath, records) {
|
|
|
6416
6324
|
try {
|
|
6417
6325
|
await writeFile(temporaryPath, `${JSON.stringify({
|
|
6418
6326
|
records,
|
|
6419
|
-
version:
|
|
6327
|
+
version: 3
|
|
6420
6328
|
})}\n`, {
|
|
6421
6329
|
encoding: "utf8",
|
|
6422
6330
|
flag: "wx"
|
|
@@ -6457,8 +6365,20 @@ function readRecord(value) {
|
|
|
6457
6365
|
tickId: value.tickId
|
|
6458
6366
|
});
|
|
6459
6367
|
}
|
|
6460
|
-
function key(
|
|
6461
|
-
return `${
|
|
6368
|
+
function key(automationId, occurrence) {
|
|
6369
|
+
return `${automationId}\0${occurrence}`;
|
|
6370
|
+
}
|
|
6371
|
+
function preferRecoveryRecord(current, candidate) {
|
|
6372
|
+
if (!current) return candidate;
|
|
6373
|
+
return recoveryRank(candidate.status) >= recoveryRank(current.status) ? candidate : current;
|
|
6374
|
+
}
|
|
6375
|
+
function recoveryRank(status) {
|
|
6376
|
+
switch (status) {
|
|
6377
|
+
case "delivered": return 4;
|
|
6378
|
+
case "generated": return 3;
|
|
6379
|
+
case "failed": return 2;
|
|
6380
|
+
case "running": return 1;
|
|
6381
|
+
}
|
|
6462
6382
|
}
|
|
6463
6383
|
function isStatus(value) {
|
|
6464
6384
|
return value === "running" || value === "failed" || value === "generated" || value === "delivered";
|
|
@@ -6951,17 +6871,14 @@ function createConfiguredFeishuTextReplySender(options) {
|
|
|
6951
6871
|
}) };
|
|
6952
6872
|
}
|
|
6953
6873
|
//#endregion
|
|
6954
|
-
//#region src/infrastructure/feishu/feishu-
|
|
6955
|
-
function
|
|
6874
|
+
//#region src/infrastructure/feishu/feishu-automation-card-sender.ts
|
|
6875
|
+
function createConfiguredFeishuAutomationCardSender(options) {
|
|
6956
6876
|
const baseUrl = options.config.feishu.baseUrl.replace(/\/$/, "");
|
|
6957
6877
|
return { send: (input) => Effect.gen(function* () {
|
|
6958
6878
|
const response = yield* options.client.request({
|
|
6959
6879
|
body: {
|
|
6960
|
-
content: JSON.stringify(
|
|
6961
|
-
|
|
6962
|
-
text: input.markdown
|
|
6963
|
-
}]] } }),
|
|
6964
|
-
msg_type: "post",
|
|
6880
|
+
content: JSON.stringify(createAutomationCard(input.markdown)),
|
|
6881
|
+
msg_type: "interactive",
|
|
6965
6882
|
receive_id: input.receiveId,
|
|
6966
6883
|
uuid: deliveryUuid(input.idempotencyKey)
|
|
6967
6884
|
},
|
|
@@ -6973,6 +6890,40 @@ function createConfiguredFeishuMarkdownMessageSender(options) {
|
|
|
6973
6890
|
return Object.freeze({ providerMessageId });
|
|
6974
6891
|
}) };
|
|
6975
6892
|
}
|
|
6893
|
+
function createAutomationCard(markdown) {
|
|
6894
|
+
const presentation = splitPresentation(markdown);
|
|
6895
|
+
return {
|
|
6896
|
+
body: { elements: [{
|
|
6897
|
+
content: presentation.content,
|
|
6898
|
+
tag: "markdown"
|
|
6899
|
+
}, {
|
|
6900
|
+
content: "_由 Rivus 自动生成_",
|
|
6901
|
+
tag: "markdown"
|
|
6902
|
+
}] },
|
|
6903
|
+
config: { update_multi: true },
|
|
6904
|
+
header: {
|
|
6905
|
+
template: "blue",
|
|
6906
|
+
title: {
|
|
6907
|
+
content: presentation.title,
|
|
6908
|
+
tag: "plain_text"
|
|
6909
|
+
}
|
|
6910
|
+
},
|
|
6911
|
+
schema: "2.0"
|
|
6912
|
+
};
|
|
6913
|
+
}
|
|
6914
|
+
function splitPresentation(markdown) {
|
|
6915
|
+
const normalized = markdown.trim();
|
|
6916
|
+
const lines = normalized.split("\n");
|
|
6917
|
+
const heading = /^#{1,6}\s+(.+)$/u.exec(lines[0] ?? "");
|
|
6918
|
+
if (!heading) return {
|
|
6919
|
+
content: normalized || "本次没有可展示的内容。",
|
|
6920
|
+
title: "Rivus 自动简报"
|
|
6921
|
+
};
|
|
6922
|
+
return {
|
|
6923
|
+
content: lines.slice(1).join("\n").trim() || "本次没有可展示的内容。",
|
|
6924
|
+
title: heading[1].trim()
|
|
6925
|
+
};
|
|
6926
|
+
}
|
|
6976
6927
|
function deliveryUuid(idempotencyKey) {
|
|
6977
6928
|
return `rivus-${createHash("sha256").update(idempotencyKey).digest("hex").slice(0, 32)}`;
|
|
6978
6929
|
}
|
|
@@ -7334,4 +7285,4 @@ function validateDecisionInput(input) {
|
|
|
7334
7285
|
if (input.recommendedOptionId && !optionIds.includes(input.recommendedOptionId)) throw new Error("recommended user decision option must be available");
|
|
7335
7286
|
}
|
|
7336
7287
|
//#endregion
|
|
7337
|
-
export { AgentContextBudgetExceeded, AgentEventHandlerFailed, AgentEventLogStoreError, AgentEventSinkFailed, AgentHarnessBusy, AgentInstanceBusy, AgentInstanceConflict, AgentLoopFailed, AgentMemoryError, AgentRunCancelled, AgentRuntimeDisposed, AutomationMandateError, CompactionError, DelegationDenied, DeliveryOutboxError, FeishuCardTargetNotFound, FeishuCardTargetRegistryStoreError, FeishuCotProtocolError, FeishuEndpointCredentialError, FeishuOpenApiError, FeishuTenantAccessTokenError, HumanInteractionRepositoryError, HumanInteractionTransitionDenied, InvalidFeishuCardAction, InvalidFeishuMessageContent, InvalidFeishuSessionReference, InvalidInvocationAuthority, InvalidRecoveryAction, InvalidRivusEndpointBinding, InvalidRivusPlugin, InvalidStableJson, InvalidToolInput, InvalidWorkspaceRoot, LangfuseTelemetryConfigError, MEMORY_SCOPES, OpenClawEnvImportError, PluginStateConflict, RIVUS_MEMORY_TOOL_ID, RIVUS_MEMORY_TOOL_PLUGIN_ID, RIVUS_MEMORY_TOOL_VERSION, RIVUS_PLUGIN_API_VERSION, RivusDaemonConfigError, RivusDeploymentAutomationReadinessError, RivusDeploymentDaemonLifecycleError, RivusDeploymentManifestError, RivusDeploymentReadinessError, RivusPluginConformanceError, RivusPluginLoadError, RivusToolInputRejected, SessionSchedulerCapacityExceeded, SessionSchedulerDisposed, ToolInvocationDenied, UnsupportedFeishuCardAction, UnsupportedFeishuMessage, WorkspaceInstructionsSourceError, assembleAgentContext, assertRivusPluginConforms, commitAutomationOutcome, createAgentCommandFromFeishuCardAction, createAgentCommandFromFeishuMessage, createAgentConversationMessages, createAgentDomainEventHandler, createAgentDomainEventSink, createAgentDomainEventSinkFromCallback, createAgentHarness, createAgentHarnessClient, createAgentHarnessPooledRuntime, createAgentInstanceRegistry, createAgentLoopFromCallback, createAgentLoopModelExecutionEnd, createAgentLoopModelExecutionStart, createAgentLoopSkillExecutionEnd, createAgentLoopSkillExecutionStart, createAgentLoopTextDelta, createAgentLoopThinkingDelta, createAgentLoopToolExecutionEnd, createAgentLoopToolExecutionStart, createAgentLoopToolExecutionUpdate, createAgentMemoryService, createAgentRunUpdateHandler, createAgentRuntime, createAgentRuntimePool, createAgentTranscriptMessages, createAgentTranscriptTurn, createAgentsMdInstructionsProvider, createAsyncIterableAgentLoop, createAutomationMandateStore, createCoalescingFeishuPublisher, createCompactionService, createCompositeRivusDaemonTransport, createConfiguredFeishuCardKitPublisher, createConfiguredFeishuCardKitTargetPreparation, createConfiguredFeishuHumanInteractionPresenter,
|
|
7288
|
+
export { AgentContextBudgetExceeded, AgentEventHandlerFailed, AgentEventLogStoreError, AgentEventSinkFailed, AgentHarnessBusy, AgentInstanceBusy, AgentInstanceConflict, AgentLoopFailed, AgentMemoryError, AgentRunCancelled, AgentRuntimeDisposed, AutomationMandateError, CompactionError, DelegationDenied, DeliveryOutboxError, FeishuCardTargetNotFound, FeishuCardTargetRegistryStoreError, FeishuCotProtocolError, FeishuEndpointCredentialError, FeishuOpenApiError, FeishuTenantAccessTokenError, HumanInteractionRepositoryError, HumanInteractionTransitionDenied, InvalidFeishuCardAction, InvalidFeishuMessageContent, InvalidFeishuSessionReference, InvalidInvocationAuthority, InvalidRecoveryAction, InvalidRivusEndpointBinding, InvalidRivusPlugin, InvalidStableJson, InvalidToolInput, InvalidWorkspaceRoot, LangfuseTelemetryConfigError, MEMORY_SCOPES, OpenClawEnvImportError, PluginStateConflict, RIVUS_MEMORY_TOOL_ID, RIVUS_MEMORY_TOOL_PLUGIN_ID, RIVUS_MEMORY_TOOL_VERSION, RIVUS_PLUGIN_API_VERSION, RivusDaemonConfigError, RivusDeploymentAutomationReadinessError, RivusDeploymentDaemonLifecycleError, RivusDeploymentManifestError, RivusDeploymentReadinessError, RivusPluginConformanceError, RivusPluginLoadError, RivusToolInputRejected, SessionSchedulerCapacityExceeded, SessionSchedulerDisposed, ToolInvocationDenied, UnsupportedFeishuCardAction, UnsupportedFeishuMessage, WorkspaceInstructionsSourceError, assembleAgentContext, assertRivusPluginConforms, commitAutomationOutcome, createAgentCommandFromFeishuCardAction, createAgentCommandFromFeishuMessage, createAgentConversationMessages, createAgentDomainEventHandler, createAgentDomainEventSink, createAgentDomainEventSinkFromCallback, createAgentHarness, createAgentHarnessClient, createAgentHarnessPooledRuntime, createAgentInstanceRegistry, createAgentLoopFromCallback, createAgentLoopModelExecutionEnd, createAgentLoopModelExecutionStart, createAgentLoopSkillExecutionEnd, createAgentLoopSkillExecutionStart, createAgentLoopTextDelta, createAgentLoopThinkingDelta, createAgentLoopToolExecutionEnd, createAgentLoopToolExecutionStart, createAgentLoopToolExecutionUpdate, createAgentMemoryService, createAgentRunUpdateHandler, createAgentRuntime, createAgentRuntimePool, createAgentTranscriptMessages, createAgentTranscriptTurn, createAgentsMdInstructionsProvider, createAsyncIterableAgentLoop, createAutomationMandateStore, createCoalescingFeishuPublisher, createCompactionService, createCompositeRivusDaemonTransport, createConfiguredFeishuAutomationCardSender, createConfiguredFeishuCardKitPublisher, createConfiguredFeishuCardKitTargetPreparation, createConfiguredFeishuHumanInteractionPresenter, createConfiguredFeishuOpenApiClient, createConfiguredFeishuTextReplySender, createConfiguredRivusDaemonBootstrap, createConfiguredRivusDeploymentDaemon, createDailyAutomationSchedule, createDefaultAgentHarness, createDefaultAgentHarnessClient, createDefaultAgentHarnessClientFromCallback, createDefaultAgentHarnessClientFromTextCallback, createDefaultAgentHarnessFromCallback, createDefaultAgentHarnessFromTextCallback, createDefaultAgentRuntime, createDefaultAgentRuntimeFromCallback, createDefaultAgentRuntimeFromTextCallback, createDelegationService, createDeliveryOutbox, createEventAgentLoop, createFakeRivusPlugin, createFeishuAgentDaemon, createFeishuAgentRunCard, createFeishuAgentRuntime, createFeishuCardActionCallbackResponse, createFeishuCardActionErrorResponse, createFeishuCardDeliveryLedger, createFeishuCardDeliveryReconciler, createFeishuCardKitOpenApiClient, createFeishuCardKitOpenApiTargetCreator, createFeishuCardKitPublisher, createFeishuCardTargetPreparation, createFeishuConversationId, createFeishuCotPublisher, createFeishuDeploymentEndpoint, createFeishuEventHandlers, createFeishuHumanInteractionCard, createFeishuHumanInteractionPresenter, createFeishuInboxRepository, createFeishuMessageQueue, createFeishuMessageWorker, createFeishuOpenApiClient, createFeishuPeriodicFlush, createFeishuPresentationPreparation, createFeishuSessionKey, createFeishuStreamProjector, createFeishuTenantAccessTokenProvider, createFeishuWebSocketDaemon, createFeishuWorkerLoop, createFixedClock, createHumanInteractionEndpointRegistry, createHumanInteractionService, createHumanInteractionToolApprovalGateway, createInMemoryFeishuCardTargetRegistry, createInMemoryHumanInteractionRepository, createInvocationAuthority, createJsonFetchRequest, createJsonFileFeishuCardTargetRegistry, createJsonlAgentEventLog, createJsonlHumanInteractionRepository, createLangfuseAgentTelemetry, createLazyFeishuWebSocketEventDispatcher, createMemoryNamespace, createOpenTelemetryAgentEventSink, createOpenTelemetryAgentTelemetry, createPiAgentLoop, createPiSdkAgentLoop, createPiSessionRegistry, createPiSkillRuntime, createPiToolNameResolver, createPiToolProxyDefinitions, createPluginStateStore, createRateLimitedFeishuPublisher, createRecoveryAction, createRecoveryControl, createRivusAgentHost, createRivusDaemonProcess, createRivusDaemonShutdownController, createRivusDaemonStatusHttpServer, createRivusDaemonStatusReporter, createRivusDeploymentCliProcess, createRivusDeploymentDaemon, createRivusEnvFromOpenClawConfig, createRivusMemoryTool, createRivusMemoryToolContract, createRivusMemoryToolDescriptor, createRivusPluginCatalog, createRoutedHumanInteractionToolApprovalService, createScheduledAutomation, createSequenceRunIds, createSessionScheduler, createSubagentCoordinator, createSystemClock, createTelemetryContentRedactor, createTextAgentLoop, createTextAgentLoopFromCallback, createToolBroker, createToolInputDigest, createToolOperationLedger, createUuidRunIds, createWorkspaceRootHandle, describeFeishuMessageIntake, evolveAgentRun, formatRivusEnvFile, initialAgentRunState, intersectToolIds, isAgentToolExecutionEvent, isAssistantTextDeltaEvent, isAssistantThinkingDeltaEvent, isTerminalAgentDomainEvent, isTerminalAgentRunPhase, loadNodeRivusPluginModule, loadRivusDaemonConfig, loadRivusDeployment, loadRivusDeploymentManifest, normalizeStableJson, openJsonAutomationTickRepository, openJsonlAgentMemoryService, openJsonlFeishuCardDeliveryLedger, openJsonlFeishuInboxRepository, openJsonlRecoveryControl, openJsonlToolOperationLedger, replayAgentHistory, replayAgentTranscript, requiresToolApproval, resolveFeishuEndpointCredentials, resolveLangfuseTelemetryConfig, resolveRivusAgentDefinition, restoreAgentHistory, restoreConfiguredRivusDaemonBootstrap, restrictMemoryScopesForAudience, runRivusDaemonCli, shouldAcceptFeishuEndpointMessage, transitionHumanInteraction, validateRivusDeploymentManifest };
|