larkmate 0.1.27 → 0.1.28

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
@@ -70,7 +70,7 @@ npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill la
70
70
  - [x] 给消息添加和取消表情回应
71
71
  - [x] 查询、发送、添加和移除收藏的单个表情
72
72
  - [x] 下载单个表情或批量导出原文件
73
- - [ ] 调整收藏表情的顺序
73
+ - [x] 调整收藏表情的顺序
74
74
  - [x] 获取消息链接
75
75
  - [x] 全局或按会话监听新消息,支持名称、正则、组合过滤和规则触发脚本
76
76
  - [x] 按 API key 限定消息服务的订阅范围
package/bin/larkmate.js CHANGED
@@ -494,6 +494,9 @@ program.command('sticker-add-file').description('Upload an image as a saved indi
494
494
  program.command('sticker-remove').description('Remove a saved individual sticker.')
495
495
  .requiredOption('--id <id>', 'saved sticker ID or key')
496
496
  .action(async options => output(await (await client()).removeSticker({ stickerId: options.id })));
497
+ program.command('sticker-move').description('Move a saved sticker to a position in the collection.')
498
+ .requiredOption('--id <id>', 'saved sticker ID or key').requiredOption('--position <number>', '1-based position')
499
+ .action(async options => output(await (await client()).moveSticker({ stickerId: options.id, position: Number(options.position) })));
497
500
  program.command('sticker-download').description('Download a saved sticker in its original format.')
498
501
  .requiredOption('--id <id>', 'saved sticker ID or key').requiredOption('--output <path>', 'new output file')
499
502
  .action(async options => output(await (await client()).downloadSticker({ stickerId: options.id, output: options.output })));
@@ -55,7 +55,7 @@ LarkMate 可以由持有 Cookie 的账户启动本地代理,再让 Agent 使
55
55
 
56
56
  `send-file`、`send-image` 与 `download-file` 均可单独加入 `allow` 列表,并受 `chatIds` 约束。发送时,由 Agent 进程读取本地文件并传输内容;下载时,由 Agent 进程创建输出文件。代理不接受 Agent 指定的代理端本地路径,而是在私有临时目录中处理中转文件,并在正常结束或失败时将其删除。若进程异常终止,可能会遗留临时文件,因此部署方应保护并按需清理代理账户的临时目录。
57
57
 
58
- 收藏表情属于账号级资源:`stickers-list`、`sticker-add`、`sticker-add-file`、`sticker-remove` 和 `sticker-download` 均需在 `allow` 中分别授权并开启 `allowGlobal`。`sticker-send` 另按 `chatIds` 限制目标会话。批量导出使用 `stickers-list` 和 `sticker-download`;上传和下载由调用方读写自己的文件,代理校验下载的表情属于当前账号的收藏,并应用 `maxFileBytes`。
58
+ 收藏表情属于账号级资源:`stickers-list`、`sticker-add`、`sticker-add-file`、`sticker-remove`、`sticker-move` 和 `sticker-download` 均需在 `allow` 中分别授权并开启 `allowGlobal`。`sticker-send` 另按 `chatIds` 限制目标会话。批量导出使用 `stickers-list` 和 `sticker-download`;上传和下载由调用方读写自己的文件,代理校验下载的表情属于当前账号的收藏,并应用 `maxFileBytes`。
59
59
 
60
60
  如需限制 Agent 可访问的本地目录,部署方应通过配置 Agent 的系统账户或容器权限来实现。策略文件中的会话与大小限制不会约束 Agent 自身的文件系统,也无法阻止其向代理发送已读取的数据。请仅向 Agent 挂载或开放其业务所需的目录,禁止其读取 Cookie 及其他敏感文件。
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larkmate",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "A small, user-identity Feishu CLI with a modular gateway client",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -33,11 +33,12 @@ larkmate sticker-send --chat "$CHAT_ID" --id "$STICKER_ID"
33
33
  larkmate sticker-add --key "$STICKER_KEY"
34
34
  larkmate sticker-add-file --file ./sticker.gif
35
35
  larkmate sticker-remove --id "$STICKER_ID"
36
+ larkmate sticker-move --id "$STICKER_ID" --position 1
36
37
  larkmate sticker-download --id "$STICKER_ID" --output ./sticker.gif
37
38
  larkmate stickers-export --output ./my-stickers
38
39
  ```
39
40
 
40
- 列表中的 `previewUrl` 可用于识别表情;`history` 的表情消息提供资源键。批量导出要求输出目录不存在,保存原文件并生成带格式和结果的 `manifest.json`;`partial` 表示部分下载失败。受限代理或系统用户委托需要分别授权使用的命令,收藏的查询和管理需要 `allowGlobal`,发送还需要目标会话权限;下载和添加本地文件由调用方读写文件,并受 `maxFileBytes` 限制。批量导出需要同时授权 `stickers-list` 和 `sticker-download`。
41
+ 列表中的 `previewUrl` 可用于识别表情;`history` 的表情消息提供资源键。`sticker-move` 的位置从 1 开始,1 表示置顶;移动前检查收藏是否变化,提交后读回结果。若结果未确认,先查询收藏顺序再决定是否重试。批量导出要求输出目录不存在,保存原文件并生成带格式和结果的 `manifest.json`;`partial` 表示部分下载失败。受限代理或系统用户委托需要分别授权使用的命令,收藏的查询和管理需要 `allowGlobal`,发送还需要目标会话权限;下载和添加本地文件由调用方读写文件,并受 `maxFileBytes` 限制。批量导出需要同时授权 `stickers-list` 和 `sticker-download`。
41
42
 
42
43
  `send-rich` 的 JSON 使用 `segments` 数组,支持文本、链接、用户提及和表情;可选 `title` 用于发送带标题的消息:
43
44
 
@@ -12,7 +12,7 @@ import { handleFileRequest, brokerUpload, brokerDownload, brokerStickerDownload
12
12
  const routes = {
13
13
  status: ['client', 'status', 'global'], search: ['client', 'search', 'global'], 'emoji-list': ['client', 'emojiList', 'global'],
14
14
  'stickers-list': ['client', 'stickerList', 'global'], 'sticker-add': ['client', 'addSticker', 'global'],
15
- 'sticker-remove': ['client', 'removeSticker', 'global'], 'sticker-send': ['client', 'sendSticker', 'chatObject'],
15
+ 'sticker-remove': ['client', 'removeSticker', 'global'], 'sticker-move': ['client', 'moveSticker', 'global'], 'sticker-send': ['client', 'sendSticker', 'chatObject'],
16
16
  'calendars': ['calendar','calendars','global'], 'calendar-search': ['calendar','searchCalendars','global'],
17
17
  'calendar-busy': ['calendar','busy','global'], 'calendar-suggest': ['calendar','suggest','global'],
18
18
  'calendar-events': ['calendar','events','global'], 'event-get': ['calendar','event','global'], 'calendar-rooms': ['calendar','rooms','global'],
@@ -67,7 +67,7 @@ const routes = {
67
67
  'download-file': ['files', 'download', 'file'],
68
68
  'sticker-add-file': ['files', 'upload', 'globalFile'], 'sticker-download': ['files', 'downloadSticker', 'globalFile'],
69
69
  };
70
- const writes = new Set(['send', 'send-rich', 'sticker-add', 'sticker-add-file', 'sticker-remove', 'sticker-send', 'pin', 'unpin', 'mark', 'unmark', 'mute', 'unmute', 'done', 'inbox', 'box', 'unbox', 'read', 'unread', 'chat-preferences-set', 'chat-clear-history', 'contact-alias-set', 'contact-note-set', 'group-nickname-set', 'group-avatar-set',
70
+ const writes = new Set(['send', 'send-rich', 'sticker-add', 'sticker-add-file', 'sticker-remove', 'sticker-move', 'sticker-send', 'pin', 'unpin', 'mark', 'unmark', 'mute', 'unmute', 'done', 'inbox', 'box', 'unbox', 'read', 'unread', 'chat-preferences-set', 'chat-clear-history', 'contact-alias-set', 'contact-note-set', 'group-nickname-set', 'group-avatar-set',
71
71
  'label-create', 'label-rename', 'label-delete', 'label-add', 'label-remove', 'chat-open', 'group-create', 'group-invite',
72
72
  'group-update', 'group-dissolve', 'group-bot-protection', 'group-settings-set', 'group-admin-add', 'group-admin-remove', 'group-remove', 'group-leave', 'group-owner', 'group-post-set', 'group-link', 'group-request-approve', 'group-request-reject', 'message-edit', 'message-forward', 'message-recall', 'favorite-add',
73
73
  'favorite-remove', 'reaction-add', 'reaction-remove', 'minutes-request-access', 'send-file', 'send-image', 'sidebar-set', 'task-create', 'task-update', 'task-complete', 'task-reopen', 'task-delete', 'event-create', 'event-update', 'event-delete', 'event-share', 'event-reply', 'calendar-create', 'calendar-update', 'calendar-delete', 'calendar-subscribe', 'calendar-unsubscribe']);
@@ -149,6 +149,7 @@ export function authorize(policy, request) {
149
149
  if (request.command === 'stickers-list' && args.length !== 0) denied();
150
150
  if (request.command === 'sticker-add' && (args.length !== 1 || !only(args[0], ['key']))) denied();
151
151
  if (request.command === 'sticker-remove' && (args.length !== 1 || !only(args[0], ['stickerId']))) denied();
152
+ if (request.command === 'sticker-move' && (args.length !== 1 || !only(args[0], ['stickerId','position']) || typeof args[0].stickerId !== 'string' || !/^[\w.-]{1,200}$/.test(args[0].stickerId) || !Number.isSafeInteger(args[0].position) || args[0].position < 1)) denied();
152
153
  if (['calendar-subscribe', 'calendar-unsubscribe'].includes(request.command) && (args.length !== 1 || !object(args[0]) || args[0].subscribe !== (request.command === 'calendar-subscribe'))) denied();
153
154
  if (['group-request-approve', 'group-request-reject'].includes(request.command) && (args.length !== 1 || !object(args[0]) || args[0].approve !== (request.command === 'group-request-approve'))) denied();
154
155
  if (['group-admin-add', 'group-admin-remove'].includes(request.command) && (args.length !== 1 || !object(args[0]) || args[0].enabled !== (request.command === 'group-admin-add'))) denied();
package/src/client.js CHANGED
@@ -32,6 +32,7 @@ export class LarkMateClient {
32
32
  async addSticker(options) { return new Stickers(this.gateway).add(options); }
33
33
  async addStickerFile(options) { return new Stickers(this.gateway).addFile(options); }
34
34
  async removeSticker(options) { return new Stickers(this.gateway).remove(options); }
35
+ async moveSticker(options) { return new Stickers(this.gateway).move(options); }
35
36
  async downloadSticker(options) { return new Stickers(this.gateway).download(options); }
36
37
 
37
38
  async emojiList({ query } = {}) {
package/src/stickers.js CHANGED
@@ -62,6 +62,27 @@ export class Stickers {
62
62
  try {const after=await this.rawList();if(!after.stickers.some(x=>x.stickerId===s.stickerId && x.key===s.key))return {status:'removed',stickerId:s.stickerId||null,requestId:response.requestId};}catch{}
63
63
  return {status:'submitted_unconfirmed',stickerId:s.stickerId||null,requestId:response.requestId};
64
64
  }
65
+ async move({stickerId,position}) {
66
+ if (!validKey(stickerId)) invalid();
67
+ if (!Number.isSafeInteger(position) || position < 1) throw new FeishuError('INVALID_ARGUMENT','Position must be a positive integer.');
68
+ const before=await this.rawList(), items=before.stickers;
69
+ if (position>items.length) throw new FeishuError('INVALID_ARGUMENT','Position exceeds the sticker collection size.');
70
+ const matches=items.filter(s=>s.stickerId===stickerId||s.key===stickerId);
71
+ if(matches.length!==1)throw new FeishuError(matches.length?'AMBIGUOUS':'NOT_FOUND',matches.length?'Multiple stickers matched; use their IDs.':'Sticker not found in the current account collection.');
72
+ const ids=items.map(s=>s.stickerId);
73
+ if(ids.some(id=>!validKey(id))||new Set(ids).size!==ids.length)throw new FeishuError('INVALID_RESPONSE','The collection does not have unique sticker IDs; refusing to reorder.');
74
+ if(items.some((s,i)=>!Object.hasOwn(s,'position')||!Number.isInteger(s.position)||s.position<0||(i>0&&items[i-1].position<=s.position))||items.at(-1).position!==0)throw new FeishuError('INVALID_RESPONSE','The complete sticker order could not be established; refusing to reorder.');
75
+ const from=items.indexOf(matches[0]);
76
+ if(from===position-1)return {status:'unchanged',stickerId:matches[0].stickerId,from:from+1,position,total:items.length};
77
+ const desired=[...items];desired.splice(from,1);desired.splice(position-1,0,matches[0]);
78
+ const current=await this.rawList();
79
+ if(JSON.stringify(current.stickers.map(s=>s.stickerId))!==JSON.stringify(ids)||(before.updateTime!==null&&current.updateTime!==before.updateTime))throw new FeishuError('STICKERS_CHANGED','The sticker collection changed; list it again before reordering.');
80
+ // The legacy gateway requires contiguous descending positions and returns the reverse of the submitted order.
81
+ const stickers=[...desired].reverse().map((s,i)=>({...s,position:desired.length-1-i}));
82
+ const response=await this.gateway.call(102,'PatchStickersRequest',{stickers},{version:VERSION,mutating:true,operation:'sticker-move'});
83
+ try {const after=await this.rawList();if(JSON.stringify(after.stickers.map(s=>s.stickerId))===JSON.stringify(desired.map(s=>s.stickerId)))return {status:'moved',stickerId:matches[0].stickerId,from:from+1,position,total:items.length,requestId:response.requestId};}catch{}
84
+ return {status:'submitted_unconfirmed',stickerId:matches[0].stickerId,from:from+1,position,total:items.length,requestId:response.requestId};
85
+ }
65
86
  async download({stickerId,output,maxBytes=100*1024*1024}) {
66
87
  if(typeof output!=='string'||!output.trim())throw new FeishuError('INVALID_ARGUMENT','An output path is required.');
67
88
  if(!Number.isSafeInteger(maxBytes)||maxBytes<1||maxBytes>100*1024*1024)throw new FeishuError('INVALID_ARGUMENT','Invalid download size limit.');