@rivus/gateway 0.22.1 → 0.22.3

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.
@@ -8422,7 +8422,7 @@ function deliveryUuid$1(idempotencyKey) {
8422
8422
  return `rivus-${createHash("sha256").update(idempotencyKey).digest("hex").slice(0, 32)}`;
8423
8423
  }
8424
8424
  function escapeMarkdown(value) {
8425
- return value.replace(/([\\`*_{}[\]|])/g, "\\$1");
8425
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/([\\`*_{}[\]|])/g, "\\$1");
8426
8426
  }
8427
8427
  function renderDigestItem(item, listStyle, index) {
8428
8428
  const sources = item.sources.map((source) => `[${escapeMarkdown(source.label)} ↗](${source.url})`).join(" ");
@@ -8453,7 +8453,7 @@ function renderTable(table, trendColors) {
8453
8453
  width: column.width === void 0 ? "auto" : `${column.width}%`
8454
8454
  })),
8455
8455
  rows: table.rows.map((row) => Object.fromEntries(row.map((cell, index) => {
8456
- const text = escapeMarkdown(cell.text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
8456
+ const text = escapeMarkdown(cell.text);
8457
8457
  const color = cell.trend === void 0 || cell.trend === "flat" ? void 0 : cell.trend === "up" === (trendColors === "red-up") ? "red" : "green";
8458
8458
  return [`c${index}`, color === void 0 ? text : `<font color='${color}'>${text}</font>`];
8459
8459
  })))
@@ -12210,14 +12210,58 @@ function createFeishuCardDeliveryReconciler(options) {
12210
12210
  }) };
12211
12211
  }
12212
12212
  //#endregion
12213
+ //#region src/feishu/infra/adapters/delivery/feishu-steering-reactions.ts
12214
+ const CLEANUP_REQUEST_TIMEOUT = "5 seconds";
12215
+ function createFeishuSteeringReactions(options) {
12216
+ const activeRuns = /* @__PURE__ */ new Map();
12217
+ const remove = (receipt) => options.sender.remove(receipt.messageId, receipt.reactionId).pipe(Effect.interruptible, Effect.timeout(CLEANUP_REQUEST_TIMEOUT), Effect.catchCause((cause) => options.onCleanupError(Cause.squash(cause))));
12218
+ return {
12219
+ acknowledgeSteering: (messageId, runId) => Effect.gen(function* () {
12220
+ const run = activeRuns.get(runId);
12221
+ const receipt = {
12222
+ messageId,
12223
+ reactionId: yield* options.sender.add(messageId)
12224
+ };
12225
+ if (run === void 0 || run.closed) yield* remove(receipt);
12226
+ else run.reactions.push(receipt);
12227
+ }),
12228
+ beginRun: (runId) => Effect.sync(() => {
12229
+ if (!activeRuns.has(runId)) activeRuns.set(runId, {
12230
+ closed: false,
12231
+ reactions: []
12232
+ });
12233
+ }),
12234
+ finalizeRun: (runId) => Effect.gen(function* () {
12235
+ const run = activeRuns.get(runId);
12236
+ if (run === void 0) return;
12237
+ run.closed = true;
12238
+ activeRuns.delete(runId);
12239
+ yield* Effect.forEach(run.reactions.splice(0), remove, { discard: true });
12240
+ })
12241
+ };
12242
+ }
12243
+ //#endregion
12213
12244
  //#region src/feishu/infra/adapters/delivery/feishu-message-reaction.ts
12245
+ const decodeCreatedReaction = Schema.decodeUnknownOption(Schema.Struct({ reaction_id: Schema.String.check(Schema.makeFilter((value) => value.trim() !== "")) }));
12214
12246
  function createConfiguredFeishuMessageReactionSender(options) {
12215
12247
  const baseUrl = options.config.feishu.baseUrl.replace(/\/$/, "");
12216
- return { add: (messageId, emojiType = "OK") => options.client.request({
12217
- body: { reaction_type: { emoji_type: emojiType } },
12218
- method: "POST",
12219
- url: `${baseUrl}/open-apis/im/v1/messages/${encodeURIComponent(messageId)}/reactions`
12220
- }, "Feishu message reaction failed").pipe(Effect.asVoid) };
12248
+ return {
12249
+ add: (messageId, emojiType = "OK") => Effect.gen(function* () {
12250
+ const response = yield* options.client.request({
12251
+ body: { reaction_type: { emoji_type: emojiType } },
12252
+ method: "POST",
12253
+ url: `${baseUrl}/open-apis/im/v1/messages/${encodeURIComponent(messageId)}/reactions`
12254
+ }, "Feishu message reaction failed");
12255
+ return yield* Option.match(decodeCreatedReaction(response.body.data), {
12256
+ onNone: () => Effect.fail(new FeishuOpenApiError(response.status, response.body.code, "Feishu message reaction response missing data.reaction_id")),
12257
+ onSome: ({ reaction_id }) => Effect.succeed(reaction_id)
12258
+ });
12259
+ }),
12260
+ remove: (messageId, reactionId) => options.client.request({
12261
+ method: "DELETE",
12262
+ url: `${baseUrl}/open-apis/im/v1/messages/${encodeURIComponent(messageId)}/reactions/${encodeURIComponent(reactionId)}`
12263
+ }, "Feishu message reaction deletion failed").pipe(Effect.asVoid)
12264
+ };
12221
12265
  }
12222
12266
  //#endregion
12223
12267
  //#region src/feishu/infra/adapters/delivery/feishu-text-reply.ts
@@ -12587,6 +12631,14 @@ function createMessageGateway(options) {
12587
12631
  };
12588
12632
  });
12589
12633
  const replyToCancellation = (reply, action, cancelled) => action.silent === true || !reply ? Effect.void : reply.replyCancelled(action.messageId, cancelled);
12634
+ const replyToSteering = (reply, messageId, runId) => Effect.gen(function* () {
12635
+ if (reply) yield* reply.replySteered(messageId, runId);
12636
+ return {
12637
+ messageId,
12638
+ runId,
12639
+ steered: true
12640
+ };
12641
+ });
12590
12642
  const resetSession = (execution, reply, action) => Effect.gen(function* () {
12591
12643
  const cancelledRunId = yield* execution.cancelActiveRun({
12592
12644
  reason: action.reason,
@@ -12609,16 +12661,6 @@ function createMessageGateway(options) {
12609
12661
  sessionKey: action.sessionKey,
12610
12662
  text: action.text
12611
12663
  });
12612
- const steerPrompt = (execution, reply, action) => Effect.gen(function* () {
12613
- const steered = yield* steerExecution(execution, action);
12614
- if (!steered) return;
12615
- if (reply) yield* reply.replySteered(action.messageId);
12616
- return {
12617
- messageId: action.messageId,
12618
- runId: steered.runId,
12619
- steered: true
12620
- };
12621
- });
12622
12664
  const executePrompt = (execution, observation, presentation, action) => {
12623
12665
  const acceptedRunIds = /* @__PURE__ */ new Set();
12624
12666
  const projectors = /* @__PURE__ */ new Map();
@@ -12697,6 +12739,7 @@ function createMessageGateway(options) {
12697
12739
  const id = hasDedupeId ? action.dedupeId : action.messageId;
12698
12740
  const kind = hasDedupeId ? "dedupe" : "message";
12699
12741
  const key = dedupeKeyOf(action.sourceNamespace, id, kind);
12742
+ let acceptedSteering = false;
12700
12743
  return Effect.gen(function* () {
12701
12744
  const duplicate = duplicateResult(action, key);
12702
12745
  if (duplicate) return duplicate;
@@ -12717,12 +12760,8 @@ function createMessageGateway(options) {
12717
12760
  case "prompt": {
12718
12761
  const steered = yield* steerExecution(execution, action);
12719
12762
  if (steered) {
12720
- if (reply) yield* reply.replySteered(action.messageId);
12721
- return {
12722
- messageId: action.messageId,
12723
- runId: steered.runId,
12724
- steered: true
12725
- };
12763
+ acceptedSteering = true;
12764
+ return yield* replyToSteering(reply, action.messageId, steered.runId);
12726
12765
  }
12727
12766
  const prepared = yield* direct.preparePrompt();
12728
12767
  const promptExecution = prepared.execution ?? execution;
@@ -12752,10 +12791,10 @@ function createMessageGateway(options) {
12752
12791
  markSeen(key);
12753
12792
  return yield* resetSession(execution, reply, action);
12754
12793
  case "steer": {
12755
- const steered = yield* steerPrompt(execution, reply, action);
12794
+ const steered = yield* steerExecution(execution, action);
12756
12795
  if (!steered) return;
12757
12796
  markSeen(key);
12758
- return steered;
12797
+ return yield* replyToSteering(reply, action.messageId, steered.runId);
12759
12798
  }
12760
12799
  case "resolve_interaction": return yield* resolveInteraction(action);
12761
12800
  case "prompt":
@@ -12776,7 +12815,7 @@ function createMessageGateway(options) {
12776
12815
  messageId: action.messageId,
12777
12816
  runId: error.runId
12778
12817
  });
12779
- if (direct) {
12818
+ if (direct && !acceptedSteering) {
12780
12819
  unmarkSeen(key);
12781
12820
  return Effect.fail(error);
12782
12821
  }
@@ -13935,9 +13974,9 @@ function createFeishuAgentDaemon(options) {
13935
13974
  reply: {
13936
13975
  replyCancelled: (messageId, hadActiveRun) => sideEffectsDisabled || !options.reply ? Effect.void : options.reply(messageId, hadActiveRun ? CANCELLED_ACK_TEXT : NO_ACTIVE_RUN_ACK_TEXT),
13937
13976
  replyReset: (messageId, hadActiveRun) => sideEffectsDisabled || !options.reply ? Effect.void : options.reply(messageId, hadActiveRun ? "已停止当前任务并开启新会话。请发送下一条指令。" : "已开启新会话。请发送下一条指令。"),
13938
- replySteered: (messageId) => {
13977
+ replySteered: (messageId, runId) => {
13939
13978
  if (sideEffectsDisabled) return Effect.void;
13940
- if (options.acknowledgeSteering) return options.acknowledgeSteering(messageId).pipe(Effect.catch(() => options.reply ? options.reply(messageId, STEERING_ACK_TEXT) : Effect.void));
13979
+ if (options.acknowledgeSteering) return options.acknowledgeSteering(messageId, runId).pipe(Effect.catch(() => options.reply ? options.reply(messageId, STEERING_ACK_TEXT) : Effect.void));
13941
13980
  return options.reply ? options.reply(messageId, STEERING_ACK_TEXT) : Effect.void;
13942
13981
  }
13943
13982
  }
@@ -20281,6 +20320,17 @@ function createFeishuEndpointPort(deps) {
20281
20320
  config
20282
20321
  });
20283
20322
  const prepareCardTarget = (run) => cardRollover.prepareRun(run);
20323
+ const steeringReactions = createFeishuSteeringReactions({
20324
+ sender: reactions,
20325
+ onCleanupError: (error) => Effect.sync(() => {
20326
+ console.error(`Feishu steering reaction cleanup failed for endpoint ${input.endpointId}`, error);
20327
+ })
20328
+ });
20329
+ const preparePresentation = createFeishuPresentationPreparation({
20330
+ ...cotPublisher ? { cotPublisher } : {},
20331
+ prepareCardTarget,
20332
+ reportCotError: (operation, error) => reportCotError(input.endpointId, operation, error)
20333
+ });
20284
20334
  const herdr = deps.herdrRoute !== void 0 && input.endpointId === deps.herdrRoute.endpointId ? deps.herdrRoute : void 0;
20285
20335
  const embedded = herdr ? yield* openEmbeddedHerdrRoute({
20286
20336
  herdr,
@@ -20293,12 +20343,12 @@ function createFeishuEndpointPort(deps) {
20293
20343
  }) : void 0;
20294
20344
  const endpoint = createFeishuDeploymentEndpoint({
20295
20345
  agentId: input.agentId,
20296
- acknowledgeSteering: (messageId) => reactions.add(messageId),
20346
+ acknowledgeSteering: (messageId, runId) => steeringReactions.acknowledgeSteering(messageId, runId),
20297
20347
  attachmentPreparation,
20298
20348
  attachmentRetention,
20299
20349
  botOpenId,
20300
20350
  cardRollover: composeFeishuCardRolloverTransport(cardRollover, reportCardRolloverError),
20301
- finalizeRun: (runId) => cardRollover.rollover.releaseRun(runId),
20351
+ finalizeRun: (runId) => steeringReactions.finalizeRun(runId).pipe(Effect.ensuring(cardRollover.rollover.releaseRun(runId))),
20302
20352
  cancel: input.cancel,
20303
20353
  endpointId: input.endpointId,
20304
20354
  eventDispatcher: embedded ? createLazyFeishuWebSocketEventDispatcher(embedded.routedDispatcher) : createLazyFeishuWebSocketEventDispatcher(() => createFeishuSdkEventDispatcher(new Lark.EventDispatcher({}))),
@@ -20313,11 +20363,7 @@ function createFeishuEndpointPort(deps) {
20313
20363
  messageContextResolver,
20314
20364
  ...input.projectSpaceId ? { projectSpaceId: input.projectSpaceId } : {},
20315
20365
  onCapacityExceeded: (payload) => replies.reply(payload.event.message.message_id, "Rivus is busy. Please retry in a moment."),
20316
- prepareRun: createFeishuPresentationPreparation({
20317
- ...cotPublisher ? { cotPublisher } : {},
20318
- prepareCardTarget,
20319
- reportCotError: (operation, error) => reportCotError(input.endpointId, operation, error)
20320
- }),
20366
+ prepareRun: (run) => steeringReactions.beginRun(run.runId).pipe(Effect.andThen(preparePresentation(run))),
20321
20367
  promptContext,
20322
20368
  publish: (action) => publisher.publish(action),
20323
20369
  reply: (messageId, text) => replies.reply(messageId, text),
@@ -34,7 +34,7 @@ const messageFields = {
34
34
  chat_type: Schema.optional(Schema.String),
35
35
  create_time: Schema.optional(Schema.String),
36
36
  mentions: Schema.optional(Schema.Array(Schema.Struct({
37
- id: Schema.optional(Schema.Record(Schema.String, Schema.String)),
37
+ id: Schema.optional(Schema.Struct({ open_id: Schema.optional(Schema.String) })),
38
38
  key: Schema.optional(Schema.String),
39
39
  name: Schema.optional(Schema.String)
40
40
  }))),
@@ -435,7 +435,10 @@ interface FeishuReceiveMessagePayload {
435
435
  readonly root_id?: string;
436
436
  readonly message_type: string;
437
437
  readonly mentions?: ReadonlyArray<{
438
- readonly id?: Readonly<Record<string, string>>;
438
+ readonly id?: {
439
+ readonly open_id?: string;
440
+ readonly [key: string]: unknown;
441
+ };
439
442
  readonly key?: string;
440
443
  readonly name?: string;
441
444
  }>;
@@ -741,7 +741,7 @@ const gatewayAudioTranscriberAssetDirectory = fileURLToPath(new URL("assets/audi
741
741
  //#endregion
742
742
  //#region src/home/infra/adapters/project/release-descriptor.ts
743
743
  const RIVUS_RELEASE_DESCRIPTOR = Object.freeze({
744
- version: "0.22.1",
744
+ version: "0.22.3",
745
745
  dependencies: Object.freeze({
746
746
  "@earendil-works/pi-coding-agent": "0.84.4",
747
747
  "@larksuiteoapi/node-sdk": "1.74.0",
@@ -11,6 +11,7 @@ import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep
11
11
  import { fileURLToPath, pathToFileURL } from "node:url";
12
12
  import { createNodePlatform } from "@rivus/agent-kit/node";
13
13
  import { access, chmod, constants, copyFile, link, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, rmdir, stat, symlink, unlink, writeFile } from "node:fs/promises";
14
+ import { compare, minVersion, parse, satisfies, valid } from "semver";
14
15
  import { assertPathWithin, isNodeErrorWithCode, isPathWithin } from "@rivus/platform/filesystem";
15
16
  import { createConnection } from "node:net";
16
17
  import { randomUUID } from "node:crypto";
@@ -19,8 +20,7 @@ import { constants as constants$1, realpathSync } from "node:fs";
19
20
  import { spawn } from "node:child_process";
20
21
  import { isDeepStrictEqual } from "node:util";
21
22
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
22
- import { parse, stringify } from "yaml";
23
- import { compare, minVersion, parse as parse$1, satisfies, valid } from "semver";
23
+ import { parse as parse$1, stringify } from "yaml";
24
24
  //#region src/agent-catalog/domain/plugin/value-objects/rivus-plugin.ts
25
25
  const RIVUS_PLUGIN_API_VERSION = "1";
26
26
  var InvalidRivusPlugin = class extends Error {
@@ -1200,16 +1200,13 @@ function loadRivusHome(directoryPath) {
1200
1200
  }
1201
1201
  //#endregion
1202
1202
  //#region src/home/infra/adapters/doctor/rivus-home-doctor.ts
1203
- function checkNode$1(version) {
1204
- const [major, minor] = version.split(".").map(Number);
1205
- return major === 24 && Number.isInteger(minor) && minor >= 11 ? {
1206
- message: `Node.js ${version} satisfies the supported ^24.11 runtime`,
1207
- name: "node",
1208
- status: "pass"
1209
- } : {
1210
- message: `Node.js 24.11 or newer on major 24 is required; current version is ${version}`,
1203
+ function checkNodeRuntime(version) {
1204
+ const range = "^24.11.0 || ^26.13.1";
1205
+ const supported = satisfies(version, range);
1206
+ return {
1211
1207
  name: "node",
1212
- status: "fail"
1208
+ status: supported ? "pass" : "fail",
1209
+ message: supported ? `Node.js ${version} satisfies ${range}` : `Node.js ${range} is required; current version is ${version}`
1213
1210
  };
1214
1211
  }
1215
1212
  function checkWorkspace(home, findMissingWorkspacePaths) {
@@ -1239,7 +1236,7 @@ function report(directory, checks) {
1239
1236
  }
1240
1237
  function diagnoseRivusHome(input, options) {
1241
1238
  return Effect.gen(function* () {
1242
- const checks = [checkNode$1(input.nodeVersion)];
1239
+ const checks = [checkNodeRuntime(input.nodeVersion)];
1243
1240
  const loaded = yield* options.load(input.directory).pipe(Effect.result);
1244
1241
  if (Result.isFailure(loaded)) {
1245
1242
  checks.push({
@@ -2007,19 +2004,6 @@ const REQUIRED_DEPENDENCIES = Object.freeze([
2007
2004
  "@larksuiteoapi/node-sdk",
2008
2005
  "effect"
2009
2006
  ]);
2010
- function checkNode(version) {
2011
- const [major, minor] = version.split(".").map(Number);
2012
- if (major === 24 && Number.isInteger(minor) && minor >= 11) return {
2013
- message: `Node.js ${version} satisfies the supported ^24.11 runtime`,
2014
- name: "node",
2015
- status: "pass"
2016
- };
2017
- return {
2018
- message: `Node.js 24.11 or newer on major 24 is required; current version is ${version}`,
2019
- name: "node",
2020
- status: "fail"
2021
- };
2022
- }
2023
2007
  function checkManifest(directory) {
2024
2008
  return loadRivusDeploymentManifest(join(directory, "rivus.config.json")).pipe(Effect.flatMap((manifest) => Effect.gen(function* () {
2025
2009
  validateRivusDeploymentManifest(manifest);
@@ -2124,7 +2108,7 @@ function toError(error) {
2124
2108
  function diagnoseRivusProject(options) {
2125
2109
  return Effect.gen(function* () {
2126
2110
  const directory = resolve(options.directory);
2127
- const checks = [checkNode(options.nodeVersion)];
2111
+ const checks = [checkNodeRuntime(options.nodeVersion)];
2128
2112
  checks.push(yield* Effect.tryPromise({
2129
2113
  try: () => checkFiles(directory),
2130
2114
  catch: toError
@@ -4532,7 +4516,7 @@ async function optionalRecord(path, yaml = false) {
4532
4516
  throw new Error("The installed consumer configuration cannot be read");
4533
4517
  }
4534
4518
  try {
4535
- return record(yaml ? parse(text) : JSON.parse(text));
4519
+ return record(yaml ? parse$1(text) : JSON.parse(text));
4536
4520
  } catch {
4537
4521
  throw new Error("The installed consumer configuration is invalid");
4538
4522
  }
@@ -4626,7 +4610,7 @@ try { if (image.get_width() !== 1 || image.get_height() !== 1 || !image.get_byte
4626
4610
  finally { image.free(); }
4627
4611
  `;
4628
4612
  function stableVersion(value) {
4629
- const parsed = parse$1(value);
4613
+ const parsed = parse(value);
4630
4614
  return parsed !== null && parsed.version === value && parsed.prerelease.length === 0 && parsed.build.length === 0;
4631
4615
  }
4632
4616
  async function inspectInstalledRelease(command, cwd, env) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/gateway",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "Message gateway, channels, host binding, automation, and daemon assembly for Rivus.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "license": "GPL-3.0-only",
11
11
  "engines": {
12
- "node": "^24.11.0"
12
+ "node": "^24.11.0 || ^26.13.1"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -63,8 +63,8 @@
63
63
  "@resvg/resvg-js": "2.6.2",
64
64
  "@rivus/agent-kit": "0.24.0",
65
65
  "@rivus/agent-kit-collab": "0.24.0",
66
- "@rivus/platform": "0.22.1",
67
- "@rivus/runtime": "0.22.1",
66
+ "@rivus/platform": "0.22.3",
67
+ "@rivus/runtime": "0.22.3",
68
68
  "axios": "1.20.0",
69
69
  "effect": "4.1.1",
70
70
  "get-east-asian-width": "1.7.0",