aai-lark-bridge 0.2.13 → 0.2.14
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/dist/cli.js +34 -8
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "aai-lark-bridge",
|
|
7
|
-
version: "0.2.
|
|
7
|
+
version: "0.2.14",
|
|
8
8
|
description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
|
|
9
9
|
type: "module",
|
|
10
10
|
main: "./dist/index.js",
|
|
@@ -7526,7 +7526,7 @@ var PROMPT_TOOL = `## \u7528\u63D0\u95EE\u4EBA\u7684\u8EAB\u4EFD\u53EA\u8BFB\uFF
|
|
|
7526
7526
|
- \`aai-user-read search-docs --query <\u5173\u952E\u8BCD> [--page-size N] [--page-token T]\`\uFF1A\u641C\u4ED6\u80FD\u770B\u7684\u6587\u6863
|
|
7527
7527
|
- \`aai-user-read fetch-doc --doc <\u6587\u6863\u94FE\u63A5\u6216 token>\`\uFF1A\u8BFB\u6587\u6863\u6B63\u6587
|
|
7528
7528
|
|
|
7529
|
-
\u8F93\u51FA\u662F JSON\u3002\u53EA\u5728\u56DE\u7B54\u4ED6\u7684\u95EE\u9898\u9700\u8981\u65F6\u8BFB\uFF0C\u8BFB\u5230\u7684\u5185\u5BB9\u53EA\u7528\u6765\u56DE\u7B54\u8FD9\u4E2A\u4EBA\uFF0C\u522B\u8F6C\u8FF0\u5230\u522B\u5904\u3002\u8FD4\u56DE expired \u8BF4\u660E\u8FD9\u4E00\u8F6E\u7684\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u544A\u8BC9\u4ED6\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002
|
|
7529
|
+
\u8F93\u51FA\u662F JSON\u3002\u53EA\u5728\u56DE\u7B54\u4ED6\u7684\u95EE\u9898\u9700\u8981\u65F6\u8BFB\uFF0C\u8BFB\u5230\u7684\u5185\u5BB9\u53EA\u7528\u6765\u56DE\u7B54\u8FD9\u4E2A\u4EBA\uFF0C\u522B\u8F6C\u8FF0\u5230\u522B\u5904\u3002\u8FD4\u56DE expired \u8BF4\u660E\u8FD9\u4E00\u8F6E\u7684\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u544A\u8BC9\u4ED6\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002\u8FD4\u56DE need_auth \u8BF4\u660E\u4ED6\u7684\u6388\u6743\u5931\u6548\u4E86\uFF08\u592A\u4E45\u6CA1\u7528\u6216\u5728\u98DE\u4E66\u91CC\u64A4\u9500\u8FC7\uFF09\uFF0C\u7CFB\u7EDF\u5DF2\u7ECF\u7ED9\u4ED6\u91CD\u53D1\u4E86\u4E00\u5F20\u6388\u6743\u5361\u7247\uFF1A\u544A\u8BC9\u4ED6\u70B9\u5361\u7247\u91CD\u65B0\u6388\u6743\uFF0C\u6388\u6743\u540E\u518D\u95EE\u4E00\u6B21\u3002\u8FD4\u56DE auth_failed \u8BF4\u660E\u6388\u6743\u5931\u6548\u3001\u800C\u4E14\u5361\u7247\u6CA1\u53D1\u51FA\u53BB\uFF1A\u544A\u8BC9\u4ED6\u7A0D\u540E\u518D\u95EE\u4E00\u6B21\u3002
|
|
7530
7530
|
|
|
7531
7531
|
\u6388\u6743\u72B6\u6001\u4EE5\u8FD9\u4E00\u8F6E\u8FD9\u6BB5\u8BF4\u660E\u4E3A\u51C6\uFF1A\u5BF9\u8BDD\u91CC\u66F4\u65E9\u8BF4\u8FC7\u7684\u300C\u8FD8\u6CA1\u6388\u6743\u300D\u300C\u8BF7\u70B9\u6388\u6743\u5361\u7247\u300D\u90FD\u5DF2\u8FC7\u65F6\u3002\u9700\u8981\u8BFB\u4ED6\u7684\u6570\u636E\u65F6\u76F4\u63A5\u8DD1 \`aai-user-read\`\uFF0C\u4EE5\u5B83\u7684\u8FD4\u56DE\u4E3A\u51C6\uFF0C\u4E0D\u8981\u5148\u7528 \`lark-cli auth status\` \u4E4B\u7C7B\u7684\u547D\u4EE4\u786E\u8BA4\u6388\u6743\u3002`;
|
|
7532
7532
|
var PROMPT_NEED_AUTH = `## \u63D0\u95EE\u4EBA\u8FD8\u6CA1\u6388\u6743\u53EA\u8BFB
|
|
@@ -18883,6 +18883,16 @@ function parseJson4(text) {
|
|
|
18883
18883
|
function firstLine(s) {
|
|
18884
18884
|
return s.trim().split("\n")[0]?.trim().slice(0, 300) ?? "";
|
|
18885
18885
|
}
|
|
18886
|
+
function larkError(r) {
|
|
18887
|
+
const json = parseJson4(r.stdout);
|
|
18888
|
+
const err = isRecord6(json) && isRecord6(json.error) ? json.error : void 0;
|
|
18889
|
+
if (err) {
|
|
18890
|
+
const s = (k) => typeof err[k] === "string" ? err[k] : "";
|
|
18891
|
+
const kind = [s("type"), s("subtype")].filter(Boolean).join("/");
|
|
18892
|
+
return { type: s("type") || void 0, detail: `${kind}${kind && s("message") ? ": " : ""}${s("message")}`.slice(0, 300) };
|
|
18893
|
+
}
|
|
18894
|
+
return { detail: firstLine(r.stderr || r.stdout) };
|
|
18895
|
+
}
|
|
18886
18896
|
var BadRequest = class extends Error {
|
|
18887
18897
|
};
|
|
18888
18898
|
function str2(input, key, re, required = true) {
|
|
@@ -19000,7 +19010,7 @@ function createGateway(opts) {
|
|
|
19000
19010
|
const mjson = parseJson4(msg.stdout);
|
|
19001
19011
|
const item = isRecord6(mjson) && isRecord6(mjson.data) && Array.isArray(mjson.data.items) ? mjson.data.items[0] : void 0;
|
|
19002
19012
|
if (msg.code !== 0 || !isRecord6(item)) {
|
|
19003
|
-
log.warn("user-gateway", "verify.message-unreadable", { messageId, detail:
|
|
19013
|
+
log.warn("user-gateway", "verify.message-unreadable", { messageId, detail: larkError(msg).detail });
|
|
19004
19014
|
return msg.code === 0 ? "not_found" : "lark_error";
|
|
19005
19015
|
}
|
|
19006
19016
|
const sender = isRecord6(item.sender) ? item.sender : {};
|
|
@@ -19015,7 +19025,10 @@ function createGateway(opts) {
|
|
|
19015
19025
|
const chat = await asApp(["api", "GET", `/open-apis/im/v1/chats/${chatId}`, "--as", "bot"]);
|
|
19016
19026
|
const cjson = parseJson4(chat.stdout);
|
|
19017
19027
|
const mode = isRecord6(cjson) && isRecord6(cjson.data) ? cjson.data.chat_mode : void 0;
|
|
19018
|
-
if (chat.code !== 0)
|
|
19028
|
+
if (chat.code !== 0) {
|
|
19029
|
+
log.warn("user-gateway", "verify.chat-unreadable", { messageId, detail: larkError(chat).detail });
|
|
19030
|
+
return "lark_error";
|
|
19031
|
+
}
|
|
19019
19032
|
if (mode !== "p2p") return "not_p2p";
|
|
19020
19033
|
used.set(messageId, t + USED_TTL_MS);
|
|
19021
19034
|
let text;
|
|
@@ -19049,7 +19062,7 @@ function createGateway(opts) {
|
|
|
19049
19062
|
"--data",
|
|
19050
19063
|
JSON.stringify({ receive_id: openId, msg_type: "interactive", content: JSON.stringify(card) })
|
|
19051
19064
|
]);
|
|
19052
|
-
if (r.code !== 0) throw new Error(`\u53D1\u6388\u6743\u5361\u7247\u5931\u8D25\uFF1A${
|
|
19065
|
+
if (r.code !== 0) throw new Error(`\u53D1\u6388\u6743\u5361\u7247\u5931\u8D25\uFF1A${larkError(r).detail}`);
|
|
19053
19066
|
}
|
|
19054
19067
|
async function startAuth(openId) {
|
|
19055
19068
|
if (pendingAuth.has(openId)) return;
|
|
@@ -19085,7 +19098,7 @@ function createGateway(opts) {
|
|
|
19085
19098
|
};
|
|
19086
19099
|
const url = pick(["verification_uri_complete", "verificationUriComplete", "verification_url", "verificationUrl", "verification_uri", "verificationUri"]);
|
|
19087
19100
|
const deviceCode = pick(["device_code", "deviceCode"]);
|
|
19088
|
-
if (start.code !== 0 || !url || !deviceCode) throw new Error(`\u53D1\u8D77\u6388\u6743\u5931\u8D25\uFF1A${
|
|
19101
|
+
if (start.code !== 0 || !url || !deviceCode) throw new Error(`\u53D1\u8D77\u6388\u6743\u5931\u8D25\uFF1A${larkError(start).detail}`);
|
|
19089
19102
|
await sendAuthCard(openId, url);
|
|
19090
19103
|
log.info("user-gateway", "auth.card-sent", { sender: tail6(openId) });
|
|
19091
19104
|
return async () => {
|
|
@@ -19166,8 +19179,21 @@ function createGateway(opts) {
|
|
|
19166
19179
|
}
|
|
19167
19180
|
const r = await opts.exec(args, env(userDir(h.openId)), 6e4);
|
|
19168
19181
|
if (r.code !== 0) {
|
|
19169
|
-
|
|
19170
|
-
|
|
19182
|
+
const e = larkError(r);
|
|
19183
|
+
if (!r.timedOut && e.type === "authentication") {
|
|
19184
|
+
await rm13(authorizedMark(h.openId), { force: true });
|
|
19185
|
+
for (const [k, v] of handles) if (v.openId === h.openId) handles.delete(k);
|
|
19186
|
+
try {
|
|
19187
|
+
await startAuth(h.openId);
|
|
19188
|
+
} catch (err) {
|
|
19189
|
+
log.warn("user-gateway", "read.reauth-failed", { ...fields, detail: String(err) });
|
|
19190
|
+
return { status: "auth_failed" };
|
|
19191
|
+
}
|
|
19192
|
+
log.info("user-gateway", "read.need-auth", { ...fields, detail: e.detail });
|
|
19193
|
+
return { status: "need_auth" };
|
|
19194
|
+
}
|
|
19195
|
+
log.warn("user-gateway", "read.failed", { ...fields, result: "lark_error", detail: e.detail });
|
|
19196
|
+
return { status: "lark_error", detail: r.timedOut ? "\u547D\u4EE4\u8D85\u65F6" : e.detail };
|
|
19171
19197
|
}
|
|
19172
19198
|
log.info("user-gateway", "read.ok", { ...fields, result: "ok" });
|
|
19173
19199
|
return { status: "ok", data: parseJson4(r.stdout) ?? r.stdout };
|