@rivus/gateway 0.22.2 → 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),
@@ -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.2",
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",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/gateway",
3
- "version": "0.22.2",
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": [
@@ -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.2",
67
- "@rivus/runtime": "0.22.2",
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",