aai-lark-bridge 0.2.12 → 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 +45 -17
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -1
- package/dist/index.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",
|
|
@@ -6363,7 +6363,7 @@ var ClaudeAdapter = class {
|
|
|
6363
6363
|
const bridgePrompt = buildBridgeSystemPrompt(this.botIdentity);
|
|
6364
6364
|
const extraPrompt = opts.extraSystemPromptFile ? readFileSync2(opts.extraSystemPromptFile, "utf8") : "";
|
|
6365
6365
|
const systemPromptFile = writeSystemPromptFile(
|
|
6366
|
-
[bridgePrompt, extraPrompt
|
|
6366
|
+
[bridgePrompt, extraPrompt].filter((p3) => p3.trim()).join("\n\n")
|
|
6367
6367
|
);
|
|
6368
6368
|
const args = [
|
|
6369
6369
|
"-p",
|
|
@@ -7526,7 +7526,9 @@ 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
|
+
|
|
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`;
|
|
7530
7532
|
var PROMPT_NEED_AUTH = `## \u63D0\u95EE\u4EBA\u8FD8\u6CA1\u6388\u6743\u53EA\u8BFB
|
|
7531
7533
|
|
|
7532
7534
|
\u4ED6\u8FD8\u6CA1\u6388\u6743\u4F60\u7528\u4ED6\u7684\u8EAB\u4EFD\u8BFB\u6D88\u606F\u548C\u6587\u6863\u3002\u4F60\u5DF2\u7ECF\u5728\u4ED6\u7684\u79C1\u804A\u91CC\u6536\u5230\u4E00\u5F20\u300C\u6388\u6743 bot \u7528\u4F60\u7684\u8EAB\u4EFD\u53EA\u8BFB\u300D\u7684\u5361\u7247\uFF08\u7531\u7CFB\u7EDF\u53D1\u51FA\uFF09\u3002\u8FD9\u4E00\u8F6E\u7528\u5E94\u7528\u8EAB\u4EFD\u5C3D\u91CF\u56DE\u7B54\uFF1B\u5982\u679C\u95EE\u9898\u9700\u8981\u8BFB\u4ED6\u81EA\u5DF1\u7684\u6D88\u606F\u6216\u6587\u6863\uFF0C\u544A\u8BC9\u4ED6\u70B9\u90A3\u5F20\u5361\u7247\u6388\u6743\uFF0C\u6388\u6743\u540E\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002\u4E0D\u8981\u81EA\u5DF1\u8DD1 \`lark-cli auth login\`\u3002`;
|
|
@@ -10157,7 +10159,6 @@ ${runPolicy.prompt}` } : {}
|
|
|
10157
10159
|
...input.capability.agentId === "claude" ? { maxBudgetUsd: input.task ? input.task.maxBudgetUsd : getMaxRunBudgetUsd(input.profileConfig.preferences) } : {},
|
|
10158
10160
|
...binding ? { settingsFile: binding.settingsFile, extraSystemPromptFile: binding.systemPromptFile, strictMcp: true } : {},
|
|
10159
10161
|
...input.extraEnv ? { extraEnv: input.extraEnv } : {},
|
|
10160
|
-
...input.extraSystemPrompt ? { extraSystemPrompt: input.extraSystemPrompt } : {},
|
|
10161
10162
|
observability: input.observability
|
|
10162
10163
|
});
|
|
10163
10164
|
} catch (err) {
|
|
@@ -13156,8 +13157,7 @@ var RunExecutor = class {
|
|
|
13156
13157
|
...input.settingsFile ? { settingsFile: input.settingsFile } : {},
|
|
13157
13158
|
...input.extraSystemPromptFile ? { extraSystemPromptFile: input.extraSystemPromptFile } : {},
|
|
13158
13159
|
...input.strictMcp ? { strictMcp: true } : {},
|
|
13159
|
-
...input.extraEnv ? { extraEnv: input.extraEnv } : {}
|
|
13160
|
-
...input.extraSystemPrompt ? { extraSystemPrompt: input.extraSystemPrompt } : {}
|
|
13160
|
+
...input.extraEnv ? { extraEnv: input.extraEnv } : {}
|
|
13161
13161
|
};
|
|
13162
13162
|
let run;
|
|
13163
13163
|
try {
|
|
@@ -15546,7 +15546,7 @@ async function runAgentBatch(deps) {
|
|
|
15546
15546
|
await runAgentBatchInner({
|
|
15547
15547
|
...deps,
|
|
15548
15548
|
preBinding,
|
|
15549
|
-
userRead: { ...outcome.kind === "handle" ? { extraEnv: outcome.env } : {},
|
|
15549
|
+
userRead: { ...outcome.kind === "handle" ? { extraEnv: outcome.env } : {}, instruction: outcome.prompt }
|
|
15550
15550
|
});
|
|
15551
15551
|
} finally {
|
|
15552
15552
|
if (outcome.kind === "handle") await dropUserRead(cfg, outcome.gatewayRunId);
|
|
@@ -15634,9 +15634,12 @@ async function runAgentBatchInner(deps) {
|
|
|
15634
15634
|
const prevModel = lastRunModelByScope.get(scope);
|
|
15635
15635
|
const modelSwitched = prevModel !== void 0 && prevModel !== modelSelection;
|
|
15636
15636
|
lastRunModelByScope.set(scope, modelSelection);
|
|
15637
|
-
const extraInstructions =
|
|
15638
|
-
|
|
15639
|
-
|
|
15637
|
+
const extraInstructions = [
|
|
15638
|
+
...modelSwitched ? [
|
|
15639
|
+
`\u7528\u6237\u521A\u628A\u672C\u4F1A\u8BDD\u4F7F\u7528\u7684\u6A21\u578B\u5207\u6362\u4E3A\u300C${modelLabel(agentKind, modelPref)}\u300D\u3002\u4E4B\u524D\u7684\u5BF9\u8BDD\u91CC\u53EF\u80FD\u63D0\u5230\u522B\u7684\u6A21\u578B,\u8BF7\u4EE5\u5F53\u524D\u6A21\u578B\u4E3A\u51C6;\u82E5\u88AB\u95EE\u5230\u4F60\u7528\u7684\u662F\u4EC0\u4E48\u6A21\u578B,\u636E\u6B64\u56DE\u7B54\u3002`
|
|
15640
|
+
] : [],
|
|
15641
|
+
...deps.userRead ? [deps.userRead.instruction] : []
|
|
15642
|
+
];
|
|
15640
15643
|
const prompt = buildPrompt(
|
|
15641
15644
|
batch,
|
|
15642
15645
|
attachments,
|
|
@@ -15692,7 +15695,6 @@ async function runAgentBatchInner(deps) {
|
|
|
15692
15695
|
stopGraceMs: getAgentStopGraceMs(controls.cfg),
|
|
15693
15696
|
...binding && taskPlan?.ok ? { task: { binding, maxBudgetUsd: taskPlan.maxBudgetUsd } } : {},
|
|
15694
15697
|
...deps.userRead?.extraEnv ? { extraEnv: deps.userRead.extraEnv } : {},
|
|
15695
|
-
...deps.userRead ? { extraSystemPrompt: deps.userRead.extraSystemPrompt } : {},
|
|
15696
15698
|
observability: {
|
|
15697
15699
|
profile: controls.profile,
|
|
15698
15700
|
agent: capability.agentId,
|
|
@@ -18881,6 +18883,16 @@ function parseJson4(text) {
|
|
|
18881
18883
|
function firstLine(s) {
|
|
18882
18884
|
return s.trim().split("\n")[0]?.trim().slice(0, 300) ?? "";
|
|
18883
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
|
+
}
|
|
18884
18896
|
var BadRequest = class extends Error {
|
|
18885
18897
|
};
|
|
18886
18898
|
function str2(input, key, re, required = true) {
|
|
@@ -18998,7 +19010,7 @@ function createGateway(opts) {
|
|
|
18998
19010
|
const mjson = parseJson4(msg.stdout);
|
|
18999
19011
|
const item = isRecord6(mjson) && isRecord6(mjson.data) && Array.isArray(mjson.data.items) ? mjson.data.items[0] : void 0;
|
|
19000
19012
|
if (msg.code !== 0 || !isRecord6(item)) {
|
|
19001
|
-
log.warn("user-gateway", "verify.message-unreadable", { messageId, detail:
|
|
19013
|
+
log.warn("user-gateway", "verify.message-unreadable", { messageId, detail: larkError(msg).detail });
|
|
19002
19014
|
return msg.code === 0 ? "not_found" : "lark_error";
|
|
19003
19015
|
}
|
|
19004
19016
|
const sender = isRecord6(item.sender) ? item.sender : {};
|
|
@@ -19013,7 +19025,10 @@ function createGateway(opts) {
|
|
|
19013
19025
|
const chat = await asApp(["api", "GET", `/open-apis/im/v1/chats/${chatId}`, "--as", "bot"]);
|
|
19014
19026
|
const cjson = parseJson4(chat.stdout);
|
|
19015
19027
|
const mode = isRecord6(cjson) && isRecord6(cjson.data) ? cjson.data.chat_mode : void 0;
|
|
19016
|
-
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
|
+
}
|
|
19017
19032
|
if (mode !== "p2p") return "not_p2p";
|
|
19018
19033
|
used.set(messageId, t + USED_TTL_MS);
|
|
19019
19034
|
let text;
|
|
@@ -19047,7 +19062,7 @@ function createGateway(opts) {
|
|
|
19047
19062
|
"--data",
|
|
19048
19063
|
JSON.stringify({ receive_id: openId, msg_type: "interactive", content: JSON.stringify(card) })
|
|
19049
19064
|
]);
|
|
19050
|
-
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}`);
|
|
19051
19066
|
}
|
|
19052
19067
|
async function startAuth(openId) {
|
|
19053
19068
|
if (pendingAuth.has(openId)) return;
|
|
@@ -19083,7 +19098,7 @@ function createGateway(opts) {
|
|
|
19083
19098
|
};
|
|
19084
19099
|
const url = pick(["verification_uri_complete", "verificationUriComplete", "verification_url", "verificationUrl", "verification_uri", "verificationUri"]);
|
|
19085
19100
|
const deviceCode = pick(["device_code", "deviceCode"]);
|
|
19086
|
-
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}`);
|
|
19087
19102
|
await sendAuthCard(openId, url);
|
|
19088
19103
|
log.info("user-gateway", "auth.card-sent", { sender: tail6(openId) });
|
|
19089
19104
|
return async () => {
|
|
@@ -19164,8 +19179,21 @@ function createGateway(opts) {
|
|
|
19164
19179
|
}
|
|
19165
19180
|
const r = await opts.exec(args, env(userDir(h.openId)), 6e4);
|
|
19166
19181
|
if (r.code !== 0) {
|
|
19167
|
-
|
|
19168
|
-
|
|
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 };
|
|
19169
19197
|
}
|
|
19170
19198
|
log.info("user-gateway", "read.ok", { ...fields, result: "ok" });
|
|
19171
19199
|
return { status: "ok", data: parseJson4(r.stdout) ?? r.stdout };
|