larkmate 0.1.22 → 0.1.24

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
@@ -1,7 +1,17 @@
1
1
  # LarkMate
2
2
 
3
+ 在飞书,AI 帮用户干活是一件很自然的事——前提是这个 AI 叫豆包。
4
+
3
5
  LarkMate 是一个以飞书用户身份工作的 CLI。它使用网页登录 Cookie,帮助 AI 助手和用户操作个人可访问的飞书信息。
4
6
 
7
+ ## 与 Lark CLI 的区别
8
+
9
+ **LarkMate 面向个人本地使用。** 它使用你的飞书网页登录态(Cookie),直接以你的身份调用相关接口和 API,访问你本人权限范围内的信息;无需创建飞书开放平台应用,也无需逐项申请应用权限或进行 OAuth 授权。
10
+
11
+ 官方 [Lark CLI](https://github.com/larksuite/cli) 基于飞书开放平台,通过应用凭据和授权调用 API,适合将飞书能力集成到应用中并向其他用户提供服务,同时也支持以用户身份操作。
12
+
13
+ LarkMate 仍需要有效的网页登录态,且操作范围受本人飞书权限限制;由于依赖网页版接口,接口变化时可能需要适配。涉及云文档和其他开放平台能力时,两者也可以搭配使用。
14
+
5
15
  ## 安装
6
16
 
7
17
  ### 让 AI 安装
package/bin/larkmate.js CHANGED
@@ -24,8 +24,9 @@ import { createApiKey } from '../src/access-policy.js';
24
24
  import { startApiService } from '../src/api-service.js';
25
25
 
26
26
  const defaultTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
27
+ const { version } = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
27
28
  const program = new Command();
28
- program.name('larkmate').description('Operate Feishu as the logged-in user.').version('0.1.22');
29
+ program.name('larkmate').description('Operate Feishu as the logged-in user.').version(version);
29
30
  program.option('--credentials-file <path>', 'read LarkMate credentials.json');
30
31
  program.option('--broker <path>', 'use a restricted local broker socket (or LARKMATE_BROKER)');
31
32
  program.option('--broker-token-file <path>', 'read the agent token (or LARKMATE_BROKER_TOKEN_FILE)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larkmate",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "A small, user-identity Feishu CLI with a modular gateway client",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -17,6 +17,8 @@ larkmate favorite-add --chat "$CHAT_ID" --message "$MESSAGE_ID"
17
17
  larkmate favorite-remove --favorite "$FAVORITE_ID"
18
18
  ```
19
19
 
20
+ 同一用户只需提供一次 `--mention`,正文中所有匹配的提及都会生效。
21
+
20
22
  文件须为非空普通文件且不超过 100 MiB。`accepted` 表示服务器返回相应 ID,`submitted_unconfirmed` 表示未可靠确认接收;不确定时先检查实际状态再决定是否重试。
21
23
 
22
24
  使用受限代理或系统用户委托发送文件或图片时,需要相应命令和目标会话的授权;文件由 Agent 自身读取,且还受策略 `maxFileBytes` 限制。
package/src/client.js CHANGED
@@ -366,7 +366,7 @@ export class LarkMateClient {
366
366
  const response = await this.gateway.call(5, 'PutMessageRequest', {
367
367
  type: 3, chatId, cid, isNotified: true, version: 1,
368
368
  content: { fileKey: file.key, fileName: file.name, fileSize: file.size },
369
- }, { version: '5.7.0', mutating: true, operation: 'send-file' });
369
+ }, { version: '8.5.0', mutating: true, operation: 'send-file' });
370
370
  let id = null;
371
371
  try {
372
372
  if (response.packet.payload?.length) {
@@ -516,32 +516,44 @@ export class LarkMateClient {
516
516
  const elementIds = [];
517
517
  const atIds = [];
518
518
  const dictionary = {};
519
- let remaining = text;
519
+ const markers = new Map();
520
+ for (const mention of mentions) {
521
+ requireNumericId(mention.id, 'mention ID');
522
+ const marker = `@${requireText(mention.name, 'mention name')}`;
523
+ if (markers.has(marker) && markers.get(marker) !== mention.id) throw new FeishuError('INVALID_ARGUMENT', 'A mention name cannot identify multiple users.');
524
+ markers.set(marker, mention.id);
525
+ }
526
+ const found = new Set();
520
527
  const addText = part => {
521
528
  if (!part) return;
522
529
  const id = shortId();
523
530
  elementIds.push(id);
524
531
  dictionary[id] = { tag: 1, property: this.gateway.encode('TextProperty', { content: part }) };
525
532
  };
526
- for (const mention of mentions) {
527
- requireNumericId(mention.id, 'mention ID');
528
- const marker = `@${requireText(mention.name, 'mention name')}`;
529
- const index = remaining.indexOf(marker);
530
- if (index < 0) throw new FeishuError('INVALID_ARGUMENT', 'The mention marker is absent from the text.');
531
- addText(remaining.slice(0, index));
533
+ let position = 0;
534
+ while (position < text.length) {
535
+ let next = null;
536
+ for (const [marker, userId] of markers) {
537
+ const index = text.indexOf(marker, position);
538
+ if (index >= 0 && (!next || index < next.index || index === next.index && marker.length > next.marker.length)) next = { marker, userId, index };
539
+ }
540
+ if (!next) break;
541
+ addText(text.slice(position, next.index));
532
542
  const id = shortId();
533
543
  elementIds.push(id);
534
544
  atIds.push(id);
535
- dictionary[id] = { tag: 5, property: this.gateway.encode('AtProperty', { userId: mention.id, content: marker }) };
536
- remaining = remaining.slice(index + marker.length);
545
+ dictionary[id] = { tag: 5, property: this.gateway.encode('AtProperty', { userId: next.userId, content: next.marker }) };
546
+ found.add(next.marker);
547
+ position = next.index + next.marker.length;
537
548
  }
538
- addText(remaining);
549
+ if (found.size !== markers.size) throw new FeishuError('INVALID_ARGUMENT', 'The mention marker is absent from the text.');
550
+ addText(text.slice(position));
539
551
  const cid = shortId();
540
552
  const response = await this.gateway.call(5, 'PutMessageRequest', {
541
553
  type: 4, chatId, cid, isNotified: true, version: 1,
542
554
  ...(replyTo ? { parentId: replyTo, rootId: replyRoot || replyTo } : {}),
543
555
  content: { richText: { elementIds, innerText: text, elements: { dictionary }, atIds } },
544
- }, { version: '5.7.0', mutating: true, operation: 'send' });
556
+ }, { version: '8.5.0', mutating: true, operation: 'send' });
545
557
  return { status: 'submitted_unconfirmed', chatId, cid, requestId: response.requestId };
546
558
  }
547
559