larkmate 0.1.27 → 0.1.29
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/INSTALL.md +2 -0
- package/README.md +1 -1
- package/bin/larkmate.js +3 -0
- package/docs/agent-broker.md +1 -1
- package/docs/ai-install.md +1 -1
- package/package.json +1 -1
- package/skills/larkmate/SKILL.md +2 -1
- package/skills/larkmate/references/auth.md +11 -0
- package/skills/larkmate/references/writes.md +2 -1
- package/skills/larkmate/scripts/chrome-login-macos.mjs +80 -0
- package/src/agent-broker.js +3 -2
- package/src/client.js +1 -0
- package/src/stickers.js +21 -0
package/INSTALL.md
CHANGED
|
@@ -51,6 +51,8 @@ larkmate status
|
|
|
51
51
|
|
|
52
52
|
如果已有可用的凭据文件,直接执行 `larkmate status`,不必覆盖它。Cookie 失效时更新文件后重试。也可以通过 `LARKMATE_HOME` 选择配置目录、`LARKMATE_COOKIE` 提供 Cookie,或使用全局选项 `--credentials-file` 指定同格式文件;读取优先级依次为:指定文件、环境变量、配置目录。
|
|
53
53
|
|
|
54
|
+
macOS Chrome 已登录飞书时,也可以让安装了 LarkMate Skill 的 AI 按 Skill 的登录恢复说明验证账户并更新本机凭据。
|
|
55
|
+
|
|
54
56
|
### 3. 安装 Agent Skill
|
|
55
57
|
|
|
56
58
|
使用 [skills](https://github.com/vercel-labs/skills) 从项目仓库安装 Skill,按提示选择 Agent:
|
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 })));
|
package/docs/agent-broker.md
CHANGED
|
@@ -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/docs/ai-install.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
未使用系统用户委托或受限代理时,LarkMate 默认从 `~/.larkmate/credentials.json` 读取 Cookie,也支持 `LARKMATE_HOME`、`LARKMATE_COOKIE` 和 `--credentials-file`。先保留并检查已有登录态,可用 `larkmate status` 验证;不要读取或打印 Cookie 的值到对话、日志或命令参数中。
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
如果没有可用登录态,在直连模式下读取已安装 Skill 的 `references/auth.md`;macOS Chrome 已登录飞书时,可按其中的脚本验证账号并恢复本机凭据。其他环境可引导用户按 [快速安装](https://github.com/NWYLZW/larkmate/blob/main/INSTALL.md) 在本机安全配置。不要要求用户把 Cookie、密码或验证码发到对话中。不能自动完成登录时,如实说明,不声称已经登录。
|
|
32
32
|
|
|
33
33
|
安装后按需读取已安装 Skill 的 `SKILL.md` 和相关参考文件,依照用户的具体要求使用 CLI。当前能力包括会话与消息、会话管理和标签、群组管理、录制妙记及文字记录;以实际 CLI 帮助和 Skill 说明为准。发送消息、文件、权限申请及其他写操作应有用户指示;对于结果不确定的写入,先核查状态,避免重复提交。
|
|
34
34
|
|
package/package.json
CHANGED
package/skills/larkmate/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: 使用 LarkMate 以当前飞书网页版用户身份管理会话、
|
|
|
5
5
|
|
|
6
6
|
# LarkMate
|
|
7
7
|
|
|
8
|
-
使用 `larkmate` 操作当前用户可访问的飞书数据。它使用自己的网页 Cookie,不依赖 Lark CLI 或应用身份。命令和选项以 `larkmate --help`、`larkmate <命令> --help`
|
|
8
|
+
使用 `larkmate` 操作当前用户可访问的飞书数据。它使用自己的网页 Cookie,不依赖 Lark CLI 或应用身份。命令和选项以 `larkmate --help`、`larkmate <命令> --help` 为准;尚未安装时参照 LarkMate 项目的 `INSTALL.md`。不要输出、索取或粘贴 Cookie。
|
|
9
9
|
|
|
10
10
|
若运行环境提供 `LARKMATE_BROKER` 和 `LARKMATE_BROKER_TOKEN_FILE`,使用受限代理并先执行 `larkmate broker-info`。错误码或导出错误的 `cause` 为 `POLICY_DENIED` 时,不尝试绕过或读取 Cookie;由代理所有者调整授权。账号隔离、策略和可用命令见 [Agent 权限委托指南](https://github.com/NWYLZW/larkmate/blob/main/docs/agent-broker.md)。
|
|
11
11
|
|
|
@@ -15,6 +15,7 @@ description: 使用 LarkMate 以当前飞书网页版用户身份管理会话、
|
|
|
15
15
|
|
|
16
16
|
根据任务读取所需参考:
|
|
17
17
|
|
|
18
|
+
- 登录配置或恢复过期登录态: [登录态与恢复](references/auth.md)。
|
|
18
19
|
- 查找会话、搜索与导出消息、获取链接、下载资源,以及管理会话状态和标签: [会话与消息](references/chats.md)。
|
|
19
20
|
- 全局或按会话监听、本地事件服务及脚本触发规则: [消息监听](references/listen.md)。
|
|
20
21
|
- 配置 API 服务、API key 及受限订阅权限: [API 服务与授权](https://github.com/NWYLZW/larkmate/blob/main/docs/api-service.md)。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# 登录态与恢复
|
|
2
|
+
|
|
3
|
+
先运行 `larkmate status`。受限代理和系统用户委托应先检查各自的授权,不读取浏览器 Cookie、不切换账号,也不把 `POLICY_DENIED` 当成登录过期。仅在当前用户的直连模式下,根据用户的登录或修复请求处理凭据;`authenticate` 返回 401 或 `AUTH_FAILED` 时可尝试恢复。单个资源无权限、网络故障或写入结果不确定不等同于登录过期。
|
|
4
|
+
|
|
5
|
+
macOS 上,如果用户已在 Chrome 登录飞书,可以使用本 Skill 的 `scripts/chrome-login-macos.mjs`。它只读取所选 Chrome 配置中飞书域名的 Cookie,通过系统钥匙串解密,在私有临时目录使用 `larkmate status` 验证,并只输出账户 ID 和名称。脚本需要 `node:sqlite` 支持;旧版 Node、其他浏览器或其他系统可按安装文档手动配置。
|
|
6
|
+
|
|
7
|
+
1. 执行 `node <本 Skill 目录>/scripts/chrome-login-macos.mjs` 验证 Chrome 默认配置。其他 Chrome 配置可加 `--profile 'Profile 2'`,仅检查用户选定的配置。
|
|
8
|
+
2. 对照用户指定的账号或已有上下文确认返回的账户;无法确定时先向用户确认。验证通过且账号匹配后,执行 `node <本 Skill 目录>/scripts/chrome-login-macos.mjs --apply --expect-user-id <返回的用户ID>`;使用其他配置时同样传入 `--profile`。脚本会再次验证账号,再原子更新当前用户的 LarkMate 凭据文件。
|
|
9
|
+
3. 运行 `larkmate status` 检查,随后继续用户原先请求的操作。若此前写操作的结果不确定,先查询实际状态,避免重复发送或修改。
|
|
10
|
+
|
|
11
|
+
不要打印 Cookie、密钥或数据库记录,不把它们放进聊天、命令参数或日志。不要绕过钥匙串、系统账户、浏览器或代理的访问限制;脚本无法读取、解密或验证时,保留现有凭据,说明具体阻碍并引导用户按 [安装文档](https://github.com/NWYLZW/larkmate/blob/main/INSTALL.md) 本地配置。验证时使用的临时凭据正常结束会删除;异常终止后,如有该脚本遗留的私有临时目录,应由当前用户检查并清理。
|
|
@@ -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`
|
|
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
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Imports only the current macOS user's Feishu Chrome cookies. Never prints credentials.
|
|
3
|
+
import { createDecipheriv, createHash, pbkdf2Sync, randomBytes } from 'node:crypto';
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { chmod, lstat, mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
export function decryptChromeCookie(row, key, version) {
|
|
11
|
+
if (row.value) return row.value;
|
|
12
|
+
const encrypted=Buffer.from(row.encrypted_value || []);
|
|
13
|
+
if (!['v10','v11'].includes(encrypted.subarray(0,3).toString('ascii'))) return null;
|
|
14
|
+
try {
|
|
15
|
+
const cipher=createDecipheriv('aes-128-cbc',key,Buffer.alloc(16,32));
|
|
16
|
+
let plain=Buffer.concat([cipher.update(encrypted.subarray(3)),cipher.final()]);
|
|
17
|
+
const digest=createHash('sha256').update(row.host_key).digest();
|
|
18
|
+
if(version>=24) { if(plain.length<32||!plain.subarray(0,32).equals(digest)) return null; plain=plain.subarray(32); }
|
|
19
|
+
return plain.toString('utf8');
|
|
20
|
+
} catch { return null; }
|
|
21
|
+
}
|
|
22
|
+
export function makeCookie(rows,key,version,now=Date.now()) {
|
|
23
|
+
const epoch=BigInt(now)*1000n+11644473600000000n,jar=new Map();
|
|
24
|
+
for(const row of rows) {
|
|
25
|
+
if(!['.feishu.cn','internal-api-lark-api.feishu.cn'].includes(row.host_key))continue;
|
|
26
|
+
let expiry;try{expiry=BigInt(row.expires_utc)}catch{continue}
|
|
27
|
+
if(expiry!==0n && expiry<=epoch)continue;
|
|
28
|
+
const value=decryptChromeCookie(row,key,version);
|
|
29
|
+
if(!/^[!#$%&'*+.^_`|~\w-]+$/.test(row.name)||!value||/[\x00-\x20\x7f-\xff;,]/.test(value))continue;
|
|
30
|
+
jar.set(row.name,value);
|
|
31
|
+
}
|
|
32
|
+
return [...jar].map(([name,value])=>`${name}=${value}`).join('; ');
|
|
33
|
+
}
|
|
34
|
+
function parseArgs(args) {
|
|
35
|
+
let profile='Default', apply=false, expected;
|
|
36
|
+
while(args.length) {const arg=args.shift();if(arg==='--help')return {help:true};
|
|
37
|
+
if(arg==='--apply')apply=true;else if(arg==='--profile')profile=args.shift();else if(arg==='--expect-user-id')expected=args.shift();else throw Error('Invalid option.');}
|
|
38
|
+
if(!/^(Default|Profile [1-9][0-9]*)$/.test(profile||''))throw Error('Use Default or a Chrome profile named Profile N.');
|
|
39
|
+
if(apply&&!/^[1-9][0-9]{0,18}$/.test(expected||''))throw Error('Applying requires --expect-user-id with the intended numeric user ID.');
|
|
40
|
+
if(!apply&&expected)throw Error('--expect-user-id requires --apply.');
|
|
41
|
+
return {profile,apply,expected};
|
|
42
|
+
}
|
|
43
|
+
async function privateDirectory(path) {
|
|
44
|
+
await mkdir(path,{recursive:true,mode:0o700});const st=await lstat(path);
|
|
45
|
+
if(!st.isDirectory()||st.isSymbolicLink()||st.uid!==process.getuid()||(st.mode&0o077))throw Error('The LarkMate directory must be private and owned by the current user.');
|
|
46
|
+
}
|
|
47
|
+
async function main() {
|
|
48
|
+
const options=parseArgs(process.argv.slice(2));
|
|
49
|
+
if(options.help){console.log('Usage: node chrome-login-macos.mjs [--profile "Default|Profile N"] [--apply --expect-user-id ID]');return;}
|
|
50
|
+
if(process.platform!=='darwin')throw Error('This helper supports macOS Chrome only.');
|
|
51
|
+
if(['LARKMATE_BROKER','LARKMATE_BROKER_TOKEN_FILE','LARKMATE_DELEGATE_OWNER','LARKMATE_DELEGATE_LAUNCHER','LARKMATE_COOKIE'].some(key=>process.env[key]))throw Error('Use direct mode without a broker, delegate, or LARKMATE_COOKIE to refresh this account.');
|
|
52
|
+
let sqlite;try{sqlite=await import('node:sqlite')}catch{throw Error('This helper needs Node.js with node:sqlite support.');}
|
|
53
|
+
const root=join(homedir(),'Library/Application Support/Google/Chrome',options.profile);
|
|
54
|
+
let dbPath;for(const path of [join(root,'Cookies'),join(root,'Network','Cookies')]) {try{if((await lstat(path)).isFile()){dbPath=path;break}}catch{}}
|
|
55
|
+
if(!dbPath)throw Error('Chrome cookie database was not found for that profile.');
|
|
56
|
+
let secret;try{secret=execFileSync('security',['find-generic-password','-w','-s','Chrome Safe Storage'],{encoding:'utf8',stdio:['ignore','pipe','ignore'],timeout:10000}).trim()}catch{throw Error('Chrome Keychain access was unavailable or denied.');}
|
|
57
|
+
if(!secret)throw Error('Chrome Keychain access was unavailable or denied.');
|
|
58
|
+
const key=pbkdf2Sync(secret,'saltysalt',1003,16,'sha1');let db,rows,version;
|
|
59
|
+
try {db=new sqlite.DatabaseSync(dbPath,{readOnly:true});version=Number(db.prepare("SELECT value FROM meta WHERE key='version'").get()?.value||0);
|
|
60
|
+
rows=db.prepare("SELECT host_key,name,value,encrypted_value,CAST(expires_utc AS TEXT) AS expires_utc FROM cookies WHERE host_key IN ('.feishu.cn','internal-api-lark-api.feishu.cn') ORDER BY length(host_key)").all();
|
|
61
|
+
}catch{throw Error('Cannot read the selected Chrome cookie database.');}finally{db?.close()}
|
|
62
|
+
const cookie=makeCookie(rows,key,version);if(!cookie)throw Error('No usable Feishu cookies were found in that Chrome profile.');
|
|
63
|
+
const dir=await mkdtemp(join(tmpdir(),'larkmate-auth-check-'));let result;
|
|
64
|
+
try {
|
|
65
|
+
const candidate=join(dir,'credentials.json');await writeFile(candidate,JSON.stringify({cookie}),{mode:0o600,flag:'wx'});
|
|
66
|
+
try {const out=execFileSync('larkmate',['--credentials-file',candidate,'status'],{encoding:'utf8',stdio:['ignore','pipe','pipe'],timeout:30000});result=JSON.parse(out)}
|
|
67
|
+
catch{throw Error('Chrome login could not be validated by LarkMate. Sign in on the selected profile and try again.');}
|
|
68
|
+
const user=result?.user;if(!result?.ok||result?.status!=='ready'||!/^\d+$/.test(user?.id||''))throw Error('LarkMate returned an invalid account identity.');
|
|
69
|
+
if(options.apply){
|
|
70
|
+
if(user.id!==options.expected)throw Error('The Chrome account does not match the expected user ID; no credentials were changed.');
|
|
71
|
+
const base=process.env.LARKMATE_HOME||join(homedir(),'.larkmate');await privateDirectory(base);const path=join(base,'credentials.json');let original={};
|
|
72
|
+
try{const st=await lstat(path);if(!st.isFile()||st.isSymbolicLink()||st.uid!==process.getuid()||(st.mode&0o077))throw Error('unsafe');original=JSON.parse(await readFile(path,'utf8'));if(!original||typeof original!=='object'||Array.isArray(original))throw Error('unsafe')}
|
|
73
|
+
catch(e){if(e.code!=='ENOENT')throw Error('Existing credentials are not a private, owned JSON file; no changes were made.');}
|
|
74
|
+
const next=join(base,`.credentials-${randomBytes(12).toString('hex')}`);
|
|
75
|
+
try{await writeFile(next,JSON.stringify({...original,cookie})+'\n',{mode:0o600,flag:'wx'});await chmod(next,0o600);await rename(next,path)}finally{await rm(next,{force:true})}
|
|
76
|
+
}
|
|
77
|
+
console.log(JSON.stringify({ok:true,status:options.apply?'updated':'verified',user:{id:user.id,name:user.name||null}}));
|
|
78
|
+
} finally {await rm(dir,{recursive:true,force:true})}
|
|
79
|
+
}
|
|
80
|
+
if(process.argv[1]&&fileURLToPath(import.meta.url)===process.argv[1])main().catch(error=>{console.error(JSON.stringify({ok:false,error:error.message}));process.exitCode=1});
|
package/src/agent-broker.js
CHANGED
|
@@ -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&¤t.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.');
|