xiaozuoassistant 0.2.46 → 0.2.47
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.
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReadLarkDocSkill } from './lark-doc.js';
|
|
2
|
+
const plugin = {
|
|
3
|
+
metadata: {
|
|
4
|
+
name: 'lark-skills',
|
|
5
|
+
version: '1.0.0',
|
|
6
|
+
description: 'Lark suite integration skills (Docs, Sheets, etc.)',
|
|
7
|
+
author: 'XiaoZuoClaw Team'
|
|
8
|
+
},
|
|
9
|
+
onLoad: (context) => {
|
|
10
|
+
context.registerSkill(new ReadLarkDocSkill());
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default plugin;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BaseSkill } from '../../../skills/base-skill.js';
|
|
2
|
+
import * as lark from '@larksuiteoapi/node-sdk';
|
|
3
|
+
export class ReadLarkDocSkill extends BaseSkill {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = 'read_lark_doc';
|
|
7
|
+
this.description = 'Read text content from a Lark/Feishu document using its URL or token';
|
|
8
|
+
this.parameters = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
document_url: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: 'The URL or token of the Lark/Feishu document to read'
|
|
14
|
+
},
|
|
15
|
+
app_id: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'The Lark App ID to use for authentication (optional, defaults to the first configured Feishu bot)'
|
|
18
|
+
},
|
|
19
|
+
app_secret: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'The Lark App Secret to use for authentication (optional, defaults to the first configured Feishu bot)'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ['document_url']
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async execute(args, ctx) {
|
|
28
|
+
try {
|
|
29
|
+
// Extract document token from URL
|
|
30
|
+
// Typical Lark doc URL formats:
|
|
31
|
+
// https://domain.feishu.cn/docx/TOKEN
|
|
32
|
+
// https://domain.feishu.cn/wiki/WIKITOKEN
|
|
33
|
+
let documentToken = args.document_url;
|
|
34
|
+
// Basic extraction logic
|
|
35
|
+
if (args.document_url.includes('/docx/')) {
|
|
36
|
+
documentToken = args.document_url.split('/docx/')[1].split(/[?#]/)[0];
|
|
37
|
+
}
|
|
38
|
+
else if (args.document_url.includes('/doc/')) {
|
|
39
|
+
documentToken = args.document_url.split('/doc/')[1].split(/[?#]/)[0];
|
|
40
|
+
}
|
|
41
|
+
// Fetch config to get app_id and app_secret if not provided
|
|
42
|
+
const configLoader = require('../../../config/loader.js').config;
|
|
43
|
+
let appId = args.app_id;
|
|
44
|
+
let appSecret = args.app_secret;
|
|
45
|
+
if (!appId || !appSecret) {
|
|
46
|
+
const feishuBots = configLoader.channels?.feishu;
|
|
47
|
+
if (feishuBots && Array.isArray(feishuBots) && feishuBots.length > 0) {
|
|
48
|
+
// If context has botName, try to find that specific bot
|
|
49
|
+
if (ctx?.metadata?.botName) {
|
|
50
|
+
const specificBot = feishuBots.find((b) => b.name === ctx.metadata.botName);
|
|
51
|
+
if (specificBot) {
|
|
52
|
+
appId = specificBot.appId;
|
|
53
|
+
appSecret = specificBot.appSecret;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Fallback to first bot
|
|
57
|
+
if (!appId || !appSecret) {
|
|
58
|
+
appId = feishuBots[0].appId;
|
|
59
|
+
appSecret = feishuBots[0].appSecret;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return { error: 'Lark App ID and Secret are required to read documents. Please configure a Feishu bot or provide them in the arguments.' };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const client = new lark.Client({
|
|
67
|
+
appId: appId,
|
|
68
|
+
appSecret: appSecret,
|
|
69
|
+
});
|
|
70
|
+
// We use the drive/v1/export API or docx/v1/documents API to read content
|
|
71
|
+
// Let's try the newer DOCX API first to get raw content
|
|
72
|
+
const res = await client.docx.document.rawContent({
|
|
73
|
+
path: {
|
|
74
|
+
document_id: documentToken,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (res.code !== 0) {
|
|
78
|
+
return { error: `Failed to read Lark document. Code: ${res.code}, Msg: ${res.msg}. Make sure the App has the "docs:doc:readonly" permission and has been added as a collaborator to the document.` };
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
success: true,
|
|
82
|
+
content: res.data?.content || "No content returned."
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { error: `Failed to read Lark document: ${error.message}. Ensure the token is correct and the App has appropriate permissions.` };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|