larkway 0.3.21 → 0.3.22

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 CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  You @ the bot in a Feishu thread. It runs on your machine — reading your real codebase, executing commands, opening MRs — and posts the result back. You define what the agent knows and what it can do. Larkway just carries the messages.
10
10
 
11
- **Current release: v0.3.21**
11
+ **Current release: v0.3.22**
12
12
 
13
13
  ---
14
14
 
package/README.zh.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  你在飞书话题里 @ bot,它在你的机器上运行——读真实代码库、执行命令、开 MR——把结果贴回飞书。你定义 agent 知道什么、能做什么。Larkway 只负责传递消息。
10
10
 
11
- **当前版本:v0.3.21**
11
+ **当前版本:v0.3.22**
12
12
 
13
13
  ---
14
14
 
package/dist/cli/index.js CHANGED
@@ -20506,7 +20506,7 @@ var require_websocket = __commonJS({
20506
20506
  var http2 = __require("http");
20507
20507
  var net = __require("net");
20508
20508
  var tls = __require("tls");
20509
- var { randomBytes: randomBytes2, createHash } = __require("crypto");
20509
+ var { randomBytes: randomBytes2, createHash: createHash2 } = __require("crypto");
20510
20510
  var { Duplex, Readable } = __require("stream");
20511
20511
  var { URL: URL2 } = __require("url");
20512
20512
  var PerMessageDeflate = require_permessage_deflate();
@@ -21174,7 +21174,7 @@ var require_websocket = __commonJS({
21174
21174
  abortHandshake(websocket, socket, "Invalid Upgrade header");
21175
21175
  return;
21176
21176
  }
21177
- const digest = createHash("sha1").update(key + GUID).digest("base64");
21177
+ const digest = createHash2("sha1").update(key + GUID).digest("base64");
21178
21178
  if (res.headers["sec-websocket-accept"] !== digest) {
21179
21179
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
21180
21180
  return;
@@ -21543,7 +21543,7 @@ var require_websocket_server = __commonJS({
21543
21543
  var EventEmitter = __require("events");
21544
21544
  var http2 = __require("http");
21545
21545
  var { Duplex } = __require("stream");
21546
- var { createHash } = __require("crypto");
21546
+ var { createHash: createHash2 } = __require("crypto");
21547
21547
  var extension = require_extension();
21548
21548
  var PerMessageDeflate = require_permessage_deflate();
21549
21549
  var subprotocol = require_subprotocol();
@@ -21850,7 +21850,7 @@ var require_websocket_server = __commonJS({
21850
21850
  );
21851
21851
  }
21852
21852
  if (this._state > RUNNING) return abortHandshake(socket, 503);
21853
- const digest = createHash("sha1").update(key + GUID).digest("base64");
21853
+ const digest = createHash2("sha1").update(key + GUID).digest("base64");
21854
21854
  const headers = [
21855
21855
  "HTTP/1.1 101 Switching Protocols",
21856
21856
  "Upgrade: websocket",
@@ -108741,7 +108741,7 @@ ${block}
108741
108741
  const raw = err2;
108742
108742
  return ((_b = (_a = raw === null || raw === void 0 ? void 0 : raw.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg) || ((_d = (_c = raw === null || raw === void 0 ? void 0 : raw.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) || (raw === null || raw === void 0 ? void 0 : raw.message) || String(err2);
108743
108743
  }
108744
- function isRetryable2(err2) {
108744
+ function isRetryable3(err2) {
108745
108745
  return err2.code === "rate_limited" || err2.code === "unknown";
108746
108746
  }
108747
108747
  function isFormatError(err2) {
@@ -108762,7 +108762,7 @@ ${block}
108762
108762
  } catch (raw) {
108763
108763
  const err2 = classifyError(raw, { attempt });
108764
108764
  lastErr = err2;
108765
- if (attempt >= max || !isRetryable2(err2)) {
108765
+ if (attempt >= max || !isRetryable3(err2)) {
108766
108766
  throw err2;
108767
108767
  }
108768
108768
  const delay = base * Math.pow(3, attempt - 1);
@@ -111182,6 +111182,240 @@ var init_channelCardClient = __esm({
111182
111182
  }
111183
111183
  });
111184
111184
 
111185
+ // src/lark/channelCardKitClient.ts
111186
+ import { createHash } from "node:crypto";
111187
+ function isRetryable2(err2) {
111188
+ if (!(err2 instanceof Error)) return false;
111189
+ const msg = err2.message.toLowerCase();
111190
+ if (msg.includes("200810")) return true;
111191
+ if (msg.includes("user callback")) return true;
111192
+ if (msg.includes("interaction")) return true;
111193
+ if (msg.includes("socket hang up")) return true;
111194
+ if (msg.includes("econnreset")) return true;
111195
+ if (msg.includes("etimedout")) return true;
111196
+ if (msg.includes("econnrefused")) return true;
111197
+ if (msg.includes("connect timeout")) return true;
111198
+ const anyErr = err2;
111199
+ const status = anyErr["status"];
111200
+ if (typeof status === "number" && status >= 500) return true;
111201
+ const code = anyErr["code"];
111202
+ if (code === 200810 || code === "200810") return true;
111203
+ const response = anyErr["response"];
111204
+ if (response && typeof response === "object") {
111205
+ const data = response["data"];
111206
+ if (data && typeof data === "object") {
111207
+ const responseCode = data["code"];
111208
+ if (responseCode === 200810 || responseCode === "200810") return true;
111209
+ }
111210
+ }
111211
+ return code === "ECONNRESET" || code === "ETIMEDOUT";
111212
+ }
111213
+ async function withCardKitRetry(label, fn, opts) {
111214
+ let lastErr;
111215
+ for (let attempt = 1; attempt <= opts.maxAttempts; attempt++) {
111216
+ try {
111217
+ return await fn();
111218
+ } catch (err2) {
111219
+ lastErr = err2;
111220
+ if (attempt === opts.maxAttempts || !isRetryable2(err2)) throw err2;
111221
+ const delay = opts.baseDelayMs * Math.pow(2, attempt - 1);
111222
+ console.warn(
111223
+ `[channel.cardkit] ${label} attempt ${attempt} failed (${err2.message}), retrying in ${delay}ms`
111224
+ );
111225
+ await new Promise((r) => setTimeout(r, delay));
111226
+ }
111227
+ }
111228
+ throw lastErr;
111229
+ }
111230
+ var ChannelCardKitClient;
111231
+ var init_channelCardKitClient = __esm({
111232
+ "src/lark/channelCardKitClient.ts"() {
111233
+ "use strict";
111234
+ ChannelCardKitClient = class {
111235
+ resolveChannel;
111236
+ cardThreads;
111237
+ maxAttempts;
111238
+ baseDelayMs;
111239
+ constructor(opts) {
111240
+ this.resolveChannel = opts.resolveChannel;
111241
+ this.cardThreads = opts.cardThreads;
111242
+ this.maxAttempts = opts.maxAttempts ?? 3;
111243
+ this.baseDelayMs = opts.baseDelayMs ?? 300;
111244
+ }
111245
+ channel() {
111246
+ const ch = this.resolveChannel();
111247
+ if (!ch) {
111248
+ throw new Error("[channel.cardkit] outbound called before the Channel SDK connected");
111249
+ }
111250
+ return ch;
111251
+ }
111252
+ async createCardEntity(card) {
111253
+ const res = await withCardKitRetry(
111254
+ "createCardEntity",
111255
+ () => this.channel().rawClient.cardkit.v1.card.create({
111256
+ data: { type: "card_json", data: JSON.stringify(card) }
111257
+ }),
111258
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111259
+ );
111260
+ const cardId = res.data?.card_id;
111261
+ if (!cardId) throw new Error("[channel.cardkit] card.create returned no card_id");
111262
+ return { cardId };
111263
+ }
111264
+ async createCardReply(replyToMessageId, card, opts) {
111265
+ const res = await withCardKitRetry(
111266
+ "createCardReply",
111267
+ () => this.channel().rawClient.im.v1.message.reply({
111268
+ path: { message_id: replyToMessageId },
111269
+ data: {
111270
+ content: JSON.stringify(card),
111271
+ msg_type: "interactive",
111272
+ reply_in_thread: opts.replyInThread,
111273
+ uuid: opts.idempotencyKey
111274
+ }
111275
+ }),
111276
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111277
+ );
111278
+ const messageId = res.data?.message_id;
111279
+ if (!messageId) {
111280
+ throw new Error(
111281
+ `[channel.cardkit] im.v1.message.reply returned no message_id (replyTo=${replyToMessageId})`
111282
+ );
111283
+ }
111284
+ const converted = await withCardKitRetry(
111285
+ "idConvert",
111286
+ () => this.channel().rawClient.cardkit.v1.card.idConvert({
111287
+ data: { message_id: messageId }
111288
+ }),
111289
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111290
+ );
111291
+ const cardId = converted.data?.card_id;
111292
+ if (!cardId) {
111293
+ throw new Error(
111294
+ `[channel.cardkit] card.idConvert returned no card_id (messageId=${messageId})`
111295
+ );
111296
+ }
111297
+ this.cardThreads.set(messageId, opts.threadId ?? replyToMessageId);
111298
+ return { cardId, messageId };
111299
+ }
111300
+ async replyCardEntity(replyToMessageId, cardId, opts) {
111301
+ const res = await withCardKitRetry(
111302
+ "replyCardEntity",
111303
+ () => this.channel().rawClient.im.v1.message.reply({
111304
+ path: { message_id: replyToMessageId },
111305
+ data: {
111306
+ content: JSON.stringify({ type: "card", data: { card_id: cardId } }),
111307
+ msg_type: "interactive",
111308
+ reply_in_thread: opts.replyInThread,
111309
+ uuid: opts.idempotencyKey
111310
+ }
111311
+ }),
111312
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111313
+ );
111314
+ const messageId = res.data?.message_id;
111315
+ if (!messageId) {
111316
+ throw new Error(
111317
+ `[channel.cardkit] im.v1.message.reply returned no message_id (replyTo=${replyToMessageId})`
111318
+ );
111319
+ }
111320
+ this.cardThreads.set(messageId, opts.threadId ?? replyToMessageId);
111321
+ return { messageId };
111322
+ }
111323
+ async updateCardEntity(cardId, card, opts) {
111324
+ await withCardKitRetry(
111325
+ "updateCardEntity",
111326
+ () => this.channel().rawClient.cardkit.v1.card.update({
111327
+ path: { card_id: cardId },
111328
+ data: {
111329
+ card: { type: "card_json", data: JSON.stringify(card) },
111330
+ sequence: opts.sequence,
111331
+ uuid: opts.uuid
111332
+ }
111333
+ }),
111334
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111335
+ );
111336
+ }
111337
+ async streamElementContent(cardId, elementId, content, opts) {
111338
+ await withCardKitRetry(
111339
+ "streamElementContent",
111340
+ () => this.channel().rawClient.cardkit.v1.cardElement.content({
111341
+ path: { card_id: cardId, element_id: elementId },
111342
+ data: { content, sequence: opts.sequence, uuid: opts.uuid }
111343
+ }),
111344
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111345
+ );
111346
+ }
111347
+ async createElements(cardId, elements, opts) {
111348
+ await withCardKitRetry(
111349
+ "createElements",
111350
+ () => this.channel().rawClient.cardkit.v1.cardElement.create({
111351
+ path: { card_id: cardId },
111352
+ data: {
111353
+ type: opts.type ?? "append",
111354
+ target_element_id: opts.targetElementId,
111355
+ elements: JSON.stringify(elements),
111356
+ sequence: opts.sequence,
111357
+ uuid: opts.uuid
111358
+ }
111359
+ }),
111360
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111361
+ );
111362
+ }
111363
+ async deleteElement(cardId, elementId, opts) {
111364
+ await withCardKitRetry(
111365
+ "deleteElement",
111366
+ () => this.channel().rawClient.cardkit.v1.cardElement.delete({
111367
+ path: { card_id: cardId, element_id: elementId },
111368
+ data: { sequence: opts.sequence, uuid: opts.uuid }
111369
+ }),
111370
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111371
+ );
111372
+ }
111373
+ async patchElement(cardId, elementId, partialElement, opts) {
111374
+ await withCardKitRetry(
111375
+ "patchElement",
111376
+ () => this.channel().rawClient.cardkit.v1.cardElement.patch({
111377
+ path: { card_id: cardId, element_id: elementId },
111378
+ data: {
111379
+ partial_element: JSON.stringify(partialElement),
111380
+ sequence: opts.sequence,
111381
+ uuid: opts.uuid
111382
+ }
111383
+ }),
111384
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111385
+ );
111386
+ }
111387
+ async updateElement(cardId, elementId, element, opts) {
111388
+ await withCardKitRetry(
111389
+ "updateElement",
111390
+ () => this.channel().rawClient.cardkit.v1.cardElement.update({
111391
+ path: { card_id: cardId, element_id: elementId },
111392
+ data: {
111393
+ element: JSON.stringify(element),
111394
+ sequence: opts.sequence,
111395
+ uuid: opts.uuid
111396
+ }
111397
+ }),
111398
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111399
+ );
111400
+ }
111401
+ async updateCardSettings(cardId, settings, opts) {
111402
+ await withCardKitRetry(
111403
+ "updateCardSettings",
111404
+ () => this.channel().rawClient.cardkit.v1.card.settings({
111405
+ path: { card_id: cardId },
111406
+ data: {
111407
+ settings: JSON.stringify(settings),
111408
+ sequence: opts.sequence,
111409
+ uuid: opts.uuid
111410
+ }
111411
+ }),
111412
+ { maxAttempts: this.maxAttempts, baseDelayMs: this.baseDelayMs }
111413
+ );
111414
+ }
111415
+ };
111416
+ }
111417
+ });
111418
+
111185
111419
  // src/lark/outboundPostClient.ts
111186
111420
  function numericStatus(err2) {
111187
111421
  if (!err2 || typeof err2 !== "object") return void 0;
@@ -111442,6 +111676,7 @@ var init_channelClient = __esm({
111442
111676
  import_node_sdk = __toESM(require_lib2(), 1);
111443
111677
  init_transport();
111444
111678
  init_channelCardClient();
111679
+ init_channelCardKitClient();
111445
111680
  init_channelPostClient();
111446
111681
  execFile4 = promisify4(execFileCallback);
111447
111682
  LEARNED_CHATS_LIMIT = 100;
@@ -111552,6 +111787,8 @@ var init_channelClient = __esm({
111552
111787
  cardThreads = /* @__PURE__ */ new Map();
111553
111788
  /** Lazily built (after connect) so it can bind the live channel handle. */
111554
111789
  cardClient = null;
111790
+ /** Lazily built CardKit client; shares cardThreads with interactive callbacks. */
111791
+ cardKitClient = null;
111555
111792
  /** Lazily built and only requested by main.ts when post outbound gates are configured. */
111556
111793
  postClient = null;
111557
111794
  constructor(opts) {
@@ -111754,6 +111991,22 @@ var init_channelClient = __esm({
111754
111991
  }
111755
111992
  return this.cardClient;
111756
111993
  }
111994
+ /**
111995
+ * Return an OutboundCardKitClient bound to this client's channel handle.
111996
+ *
111997
+ * CardKit messages share the same messageId -> threadId map as legacy cards,
111998
+ * so final-area choice buttons synthesize normal turns in the originating
111999
+ * Feishu topic.
112000
+ */
112001
+ outboundCardKitClient() {
112002
+ if (!this.cardKitClient) {
112003
+ this.cardKitClient = new ChannelCardKitClient({
112004
+ resolveChannel: () => this.channel,
112005
+ cardThreads: this.cardThreads
112006
+ });
112007
+ }
112008
+ return this.cardKitClient;
112009
+ }
111757
112010
  /**
111758
112011
  * Return an OutboundPostClient bound to this client's channel handle.
111759
112012
  *
@@ -123697,6 +123950,7 @@ function defaultResponseSurfacePrototypeConfig() {
123697
123950
  lazy_card_creation: true,
123698
123951
  kill_switch: false,
123699
123952
  post_outbound_enabled: true,
123953
+ cardkit_streaming_enabled: true,
123700
123954
  allow_agent_mentions: true,
123701
123955
  allowed_mention_open_ids: [],
123702
123956
  max_posts_per_turn: 1,
@@ -123714,6 +123968,7 @@ var responseSurfacePrototypeConfigDefaults = () => ({
123714
123968
  lazy_card_creation: true,
123715
123969
  kill_switch: false,
123716
123970
  post_outbound_enabled: true,
123971
+ cardkit_streaming_enabled: true,
123717
123972
  allow_agent_mentions: true,
123718
123973
  allowed_mention_open_ids: [],
123719
123974
  max_posts_per_turn: 1,
@@ -123794,6 +124049,13 @@ var ResponseSurfacePrototypeConfigSchema = external_exports.object({
123794
124049
  * an injected post client and all safety gates before any post path.
123795
124050
  */
123796
124051
  post_outbound_enabled: external_exports.boolean().default(true),
124052
+ /**
124053
+ * CardKit streaming response surface gate. Defaults on: normal turns use a
124054
+ * streaming CardKit card during execution and finalize that same card into
124055
+ * a clean answer + interaction surface. Disabling this gate rolls back to
124056
+ * the legacy visible card path, not post in-place editing.
124057
+ */
124058
+ cardkit_streaming_enabled: external_exports.boolean().default(true),
123797
124059
  /**
123798
124060
  * Allows Agent-authored post mentions. This powers handoff to peer bots.
123799
124061
  * Keep this false only when the operator wants to suppress every real @.