xiaozuoassistant 0.2.48 → 0.2.49

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.
@@ -1,5 +1,39 @@
1
1
  import { BaseSkill } from '../../../skills/base-skill.js';
2
2
  import * as lark from '@larksuiteoapi/node-sdk';
3
+ // Helper function to resolve document token, especially handling /wiki/ URLs
4
+ async function resolveDocumentToken(client, urlOrToken) {
5
+ let token = urlOrToken;
6
+ let isWiki = false;
7
+ if (urlOrToken.includes('/docx/')) {
8
+ token = urlOrToken.split('/docx/')[1].split(/[?#]/)[0];
9
+ return { token, type: 'docx' };
10
+ }
11
+ else if (urlOrToken.includes('/doc/')) {
12
+ token = urlOrToken.split('/doc/')[1].split(/[?#]/)[0];
13
+ return { token, type: 'doc' };
14
+ }
15
+ else if (urlOrToken.includes('/wiki/')) {
16
+ token = urlOrToken.split('/wiki/')[1].split(/[?#]/)[0];
17
+ isWiki = true;
18
+ }
19
+ else if (urlOrToken.startsWith('wikcn')) {
20
+ isWiki = true;
21
+ }
22
+ if (isWiki) {
23
+ const res = await client.wiki.space.getNode({
24
+ params: { token }
25
+ });
26
+ if (res.code !== 0) {
27
+ throw new Error(`Failed to resolve wiki token. Code: ${res.code}, Msg: ${res.msg}`);
28
+ }
29
+ return {
30
+ token: res.data?.node?.obj_token || token,
31
+ type: res.data?.node?.obj_type || 'docx'
32
+ };
33
+ }
34
+ // Fallback assuming it's a docx token if not wiki
35
+ return { token, type: 'docx' };
36
+ }
3
37
  export class ReadLarkDocSkill extends BaseSkill {
4
38
  constructor() {
5
39
  super(...arguments);
@@ -26,18 +60,6 @@ export class ReadLarkDocSkill extends BaseSkill {
26
60
  }
27
61
  async execute(args, ctx) {
28
62
  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
63
  // Fetch config to get app_id and app_secret if not provided
42
64
  const configLoader = require('../../../config/loader.js').config;
43
65
  let appId = args.app_id;
@@ -67,6 +89,11 @@ export class ReadLarkDocSkill extends BaseSkill {
67
89
  appId: appId,
68
90
  appSecret: appSecret,
69
91
  });
92
+ // Extract and resolve document token from URL
93
+ const { token: documentToken, type: objType } = await resolveDocumentToken(client, args.document_url);
94
+ if (objType !== 'docx' && objType !== 'doc') {
95
+ return { error: `Unsupported document type: ${objType}. Only docx and doc are supported for reading raw text content.` };
96
+ }
70
97
  // We use the drive/v1/export API or docx/v1/documents API to read content
71
98
  // Let's try the newer DOCX API first to get raw content
72
99
  const res = await client.docx.document.rawContent({
@@ -185,13 +212,6 @@ export class AppendLarkDocSkill extends BaseSkill {
185
212
  }
186
213
  async execute(args, ctx) {
187
214
  try {
188
- let documentToken = args.document_url;
189
- if (args.document_url.includes('/docx/')) {
190
- documentToken = args.document_url.split('/docx/')[1].split(/[?#]/)[0];
191
- }
192
- else if (args.document_url.includes('/doc/')) {
193
- documentToken = args.document_url.split('/doc/')[1].split(/[?#]/)[0];
194
- }
195
215
  const configLoader = require('../../../config/loader.js').config;
196
216
  let appId = args.app_id;
197
217
  let appSecret = args.app_secret;
@@ -215,6 +235,10 @@ export class AppendLarkDocSkill extends BaseSkill {
215
235
  }
216
236
  }
217
237
  const client = new lark.Client({ appId: appId, appSecret: appSecret });
238
+ const { token: documentToken, type: objType } = await resolveDocumentToken(client, args.document_url);
239
+ if (objType !== 'docx') {
240
+ return { error: `Unsupported document type: ${objType}. Append operation currently only supports docx documents.` };
241
+ }
218
242
  // Create blocks from content
219
243
  const lines = args.content.split('\n').filter(l => l.trim() !== '');
220
244
  const children = lines.map(line => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.48",
3
+ "version": "0.2.49",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",