@vibe-lark/larkpal 0.1.53 → 0.1.55
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/main.mjs +62 -9
- package/package.json +2 -2
package/dist/main.mjs
CHANGED
|
@@ -1942,6 +1942,7 @@ async function loadSystemPrompt() {
|
|
|
1942
1942
|
}
|
|
1943
1943
|
}
|
|
1944
1944
|
const SCENARIO_MANIFEST_API_PATH = "/api/scenario-manifests";
|
|
1945
|
+
const DEFAULT_AGENT_MCP_TIMEOUT_MS = 1e4;
|
|
1945
1946
|
function loadLLMConfig() {
|
|
1946
1947
|
const baseURL = process.env.LARKPAL_AGENT_LLM_BASE_URL;
|
|
1947
1948
|
const apiKey = process.env.LARKPAL_AGENT_LLM_API_KEY;
|
|
@@ -1956,6 +1957,13 @@ function loadLLMConfig() {
|
|
|
1956
1957
|
function loadScenarioManifestDirs() {
|
|
1957
1958
|
return (process.env.LARKPAL_AGENT_SCENARIO_DIRS || "").split(":").map((entry) => entry.trim()).filter(Boolean);
|
|
1958
1959
|
}
|
|
1960
|
+
function loadAgentMcpTimeoutMs(env = process.env) {
|
|
1961
|
+
const raw = env.LARKPAL_AGENT_MCP_TIMEOUT_MS;
|
|
1962
|
+
if (raw == null || raw.trim() === "") return DEFAULT_AGENT_MCP_TIMEOUT_MS;
|
|
1963
|
+
const timeoutMs = Number.parseInt(raw, 10);
|
|
1964
|
+
if (!Number.isFinite(timeoutMs) || !/^\d+$/.test(raw.trim()) || timeoutMs <= 0) throw new Error("LARKPAL_AGENT_MCP_TIMEOUT_MS 必须是正整数毫秒值");
|
|
1965
|
+
return timeoutMs;
|
|
1966
|
+
}
|
|
1959
1967
|
function loadScenarioProviderConfig(manifestDirs) {
|
|
1960
1968
|
const rawConfig = process.env.LARKPAL_AGENT_SCENARIO_PROVIDER_CONFIG;
|
|
1961
1969
|
if (rawConfig) {
|
|
@@ -2044,10 +2052,12 @@ async function createLarkpalAgentAdapter() {
|
|
|
2044
2052
|
const defaultMaxTurns = parseInt(process.env.LARKPAL_AGENT_MAX_TURNS || "25", 10);
|
|
2045
2053
|
const scenarioManifestDirs = loadScenarioManifestDirs();
|
|
2046
2054
|
const scenarioProviderConfig = loadScenarioProviderConfig(scenarioManifestDirs);
|
|
2055
|
+
const mcpTimeoutMs = loadAgentMcpTimeoutMs();
|
|
2047
2056
|
log$28.info("创建 LarkpalAgentAdapter", {
|
|
2048
2057
|
baseURL: llm.baseURL,
|
|
2049
2058
|
model: llm.defaultModel,
|
|
2050
2059
|
maxTurns: defaultMaxTurns,
|
|
2060
|
+
mcpTimeoutMs,
|
|
2051
2061
|
scenarioProvider: summarizeScenarioProviderConfig(scenarioProviderConfig)
|
|
2052
2062
|
});
|
|
2053
2063
|
const { LarkpalAgentAdapter, ToolRegistry } = await import("@vibe-lark/larkpal-agent");
|
|
@@ -2063,11 +2073,12 @@ async function createLarkpalAgentAdapter() {
|
|
|
2063
2073
|
});
|
|
2064
2074
|
const mcpServerUrl = process.env.LARKPAL_AGENT_MCP_SERVER_URL;
|
|
2065
2075
|
if (mcpServerUrl) try {
|
|
2066
|
-
const toolCount = await registry.connectMcpServer(mcpServerUrl, { timeoutMs:
|
|
2076
|
+
const toolCount = await registry.connectMcpServer(mcpServerUrl, { timeoutMs: mcpTimeoutMs });
|
|
2067
2077
|
const tools = registry.getAll();
|
|
2068
2078
|
adapter.registerTools(tools);
|
|
2069
2079
|
log$28.info("MCP 工具注册完成", {
|
|
2070
2080
|
serverUrl: mcpServerUrl,
|
|
2081
|
+
timeoutMs: mcpTimeoutMs,
|
|
2071
2082
|
toolCount,
|
|
2072
2083
|
toolNames: tools.map((t) => t.name)
|
|
2073
2084
|
});
|
|
@@ -2326,6 +2337,8 @@ function buildAgentRuntimeConfig(input) {
|
|
|
2326
2337
|
userName: input.identity?.userName,
|
|
2327
2338
|
cwd,
|
|
2328
2339
|
authHeaders,
|
|
2340
|
+
attachments: input.attachments,
|
|
2341
|
+
sourceArtifacts: input.sourceArtifacts,
|
|
2329
2342
|
llmConfig: input.llmConfig,
|
|
2330
2343
|
policy,
|
|
2331
2344
|
metadata
|
|
@@ -2341,6 +2354,8 @@ function buildAgentRuntimeConfig(input) {
|
|
|
2341
2354
|
userContext,
|
|
2342
2355
|
tenantContext: { tenantKey },
|
|
2343
2356
|
authHeaders,
|
|
2357
|
+
attachments: input.attachments,
|
|
2358
|
+
sourceArtifacts: input.sourceArtifacts,
|
|
2344
2359
|
llmConfig: input.llmConfig,
|
|
2345
2360
|
policy,
|
|
2346
2361
|
requestContext,
|
|
@@ -2359,6 +2374,9 @@ function buildAgentRuntimeConfig(input) {
|
|
|
2359
2374
|
metadata
|
|
2360
2375
|
};
|
|
2361
2376
|
}
|
|
2377
|
+
function getRunInputValue(...values) {
|
|
2378
|
+
return values.find((value) => value !== void 0);
|
|
2379
|
+
}
|
|
2362
2380
|
function summarizeForAudit(value) {
|
|
2363
2381
|
if (value == null) return value;
|
|
2364
2382
|
if (typeof value === "string") return summarizeString(value);
|
|
@@ -2419,6 +2437,12 @@ function buildVerifierAuditMetadata(result) {
|
|
|
2419
2437
|
if (result.missingArtifacts) metadata.missingArtifacts = summarizeForAudit(result.missingArtifacts);
|
|
2420
2438
|
return metadata;
|
|
2421
2439
|
}
|
|
2440
|
+
function buildRunInputAuditMetadata(config) {
|
|
2441
|
+
const metadata = {};
|
|
2442
|
+
if (config.attachments !== void 0) metadata.attachments = summarizeForAudit(config.attachments);
|
|
2443
|
+
if (config.sourceArtifacts !== void 0) metadata.sourceArtifacts = summarizeForAudit(config.sourceArtifacts);
|
|
2444
|
+
return metadata;
|
|
2445
|
+
}
|
|
2422
2446
|
function buildRuntimeEventAuditMetadata(event) {
|
|
2423
2447
|
const metadata = {
|
|
2424
2448
|
runtimeEventType: event.type,
|
|
@@ -2598,6 +2622,8 @@ async function handleExecute(req, res, processManager) {
|
|
|
2598
2622
|
const traceId = body.traceId || body.trace_id || getGatewayTraceId(req.headers, requestId);
|
|
2599
2623
|
const conversationId = body.conversationId || body.conversation_id || body.session_id;
|
|
2600
2624
|
const scenarioId = getScenarioId(body.scenarioId || body.scenario_id, body.metadata);
|
|
2625
|
+
const attachments = getRunInputValue(body.attachments, body.metadata?.attachments);
|
|
2626
|
+
const sourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.metadata?.sourceArtifacts, body.metadata?.source_artifacts);
|
|
2601
2627
|
const identity = resolveExecuteIdentity(req, body);
|
|
2602
2628
|
const missingIdentityFields = getMissingIdentityFields(identity);
|
|
2603
2629
|
if (missingIdentityFields.length > 0) {
|
|
@@ -2642,6 +2668,8 @@ async function handleExecute(req, res, processManager) {
|
|
|
2642
2668
|
model: body.llm_config.model
|
|
2643
2669
|
} : void 0,
|
|
2644
2670
|
authHeaders: body.auth_headers,
|
|
2671
|
+
attachments,
|
|
2672
|
+
sourceArtifacts,
|
|
2645
2673
|
policy: body.policy,
|
|
2646
2674
|
metadata: body.metadata,
|
|
2647
2675
|
identity
|
|
@@ -2768,6 +2796,8 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
2768
2796
|
const batchRequestId = getGatewayRequestId(req.headers);
|
|
2769
2797
|
const traceId = getGatewayTraceId(req.headers, batchRequestId);
|
|
2770
2798
|
const scenarioId = getScenarioId(body.scenarioId || body.scenario_id, body.metadata);
|
|
2799
|
+
const batchAttachments = getRunInputValue(body.attachments, body.metadata?.attachments);
|
|
2800
|
+
const batchSourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.metadata?.sourceArtifacts, body.metadata?.source_artifacts);
|
|
2771
2801
|
const concurrency = body.concurrency ?? 3;
|
|
2772
2802
|
const taskIds = [];
|
|
2773
2803
|
const taskConfigs = [];
|
|
@@ -2775,6 +2805,14 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
2775
2805
|
const taskId = v4();
|
|
2776
2806
|
taskIds.push(taskId);
|
|
2777
2807
|
try {
|
|
2808
|
+
const taskMetadata = {
|
|
2809
|
+
...body.metadata,
|
|
2810
|
+
...task.metadata,
|
|
2811
|
+
batchId,
|
|
2812
|
+
batchTaskIndex: index
|
|
2813
|
+
};
|
|
2814
|
+
const taskAttachments = getRunInputValue(task.attachments, task.metadata?.attachments, batchAttachments);
|
|
2815
|
+
const taskSourceArtifacts = getRunInputValue(task.sourceArtifacts, task.source_artifacts, task.metadata?.sourceArtifacts, task.metadata?.source_artifacts, batchSourceArtifacts);
|
|
2778
2816
|
const config = buildAgentRuntimeConfig({
|
|
2779
2817
|
requestId: `${batchRequestId}:${index}`,
|
|
2780
2818
|
traceId,
|
|
@@ -2785,12 +2823,10 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
2785
2823
|
cwd: task.cwd,
|
|
2786
2824
|
prompt: task.prompt,
|
|
2787
2825
|
authHeaders: body.auth_headers,
|
|
2826
|
+
attachments: taskAttachments,
|
|
2827
|
+
sourceArtifacts: taskSourceArtifacts,
|
|
2788
2828
|
policy: body.policy,
|
|
2789
|
-
metadata:
|
|
2790
|
-
...body.metadata,
|
|
2791
|
-
batchId,
|
|
2792
|
-
batchTaskIndex: index
|
|
2793
|
-
},
|
|
2829
|
+
metadata: taskMetadata,
|
|
2794
2830
|
identity
|
|
2795
2831
|
});
|
|
2796
2832
|
const taskInfo = {
|
|
@@ -2948,7 +2984,8 @@ function logRunStarted(config) {
|
|
|
2948
2984
|
traceId: config.runContext?.traceId,
|
|
2949
2985
|
requestId: config.runContext?.requestId,
|
|
2950
2986
|
entrypoint: config.runContext?.entrypoint,
|
|
2951
|
-
scenarioId: config.runContext?.scenarioId
|
|
2987
|
+
scenarioId: config.runContext?.scenarioId,
|
|
2988
|
+
...buildRunInputAuditMetadata(config)
|
|
2952
2989
|
} }));
|
|
2953
2990
|
}
|
|
2954
2991
|
function logAuditEvent(event) {
|
|
@@ -4934,12 +4971,16 @@ function createChatRouter(config) {
|
|
|
4934
4971
|
const requestId = getGatewayRequestId(req.headers);
|
|
4935
4972
|
const traceId = getGatewayTraceId(req.headers, requestId);
|
|
4936
4973
|
const scenarioId = getScenarioId(body.options?.scenarioId, body.options?.metadata);
|
|
4974
|
+
const attachments = getRunInputValue(body.attachments, body.options?.attachments, body.options?.metadata?.attachments);
|
|
4975
|
+
const sourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.options?.sourceArtifacts, body.options?.source_artifacts, body.options?.metadata?.sourceArtifacts, body.options?.metadata?.source_artifacts);
|
|
4937
4976
|
log$25.info("[stream] 收到流式对话请求", {
|
|
4938
4977
|
userId,
|
|
4939
4978
|
sessionId: body.session_id,
|
|
4940
4979
|
requestId,
|
|
4941
4980
|
traceId,
|
|
4942
4981
|
scenarioId,
|
|
4982
|
+
hasAttachments: attachments !== void 0,
|
|
4983
|
+
hasSourceArtifacts: sourceArtifacts !== void 0,
|
|
4943
4984
|
promptLength: body.prompt.length
|
|
4944
4985
|
});
|
|
4945
4986
|
let sessionId = body.session_id;
|
|
@@ -4977,7 +5018,16 @@ function createChatRouter(config) {
|
|
|
4977
5018
|
sessionId,
|
|
4978
5019
|
role: "user",
|
|
4979
5020
|
content: body.prompt,
|
|
4980
|
-
channel: "web"
|
|
5021
|
+
channel: "web",
|
|
5022
|
+
metadata: {
|
|
5023
|
+
requestId,
|
|
5024
|
+
traceId,
|
|
5025
|
+
scenarioId,
|
|
5026
|
+
...buildRunInputAuditMetadata({
|
|
5027
|
+
attachments,
|
|
5028
|
+
sourceArtifacts
|
|
5029
|
+
})
|
|
5030
|
+
}
|
|
4981
5031
|
});
|
|
4982
5032
|
} catch (err) {
|
|
4983
5033
|
activeStreamSessions.delete(sessionId);
|
|
@@ -5006,6 +5056,8 @@ function createChatRouter(config) {
|
|
|
5006
5056
|
maxTurns: body.options?.maxTurns,
|
|
5007
5057
|
maxBudgetUsd: body.options?.maxBudgetUsd,
|
|
5008
5058
|
model: process.env.CLAUDE_MODEL || void 0,
|
|
5059
|
+
attachments,
|
|
5060
|
+
sourceArtifacts,
|
|
5009
5061
|
policy: body.options?.policy,
|
|
5010
5062
|
metadata: body.options?.metadata,
|
|
5011
5063
|
identity: {
|
|
@@ -5213,7 +5265,8 @@ function createChatRouter(config) {
|
|
|
5213
5265
|
traceId: runtimeConfig.runContext?.traceId,
|
|
5214
5266
|
requestId: runtimeConfig.runContext?.requestId,
|
|
5215
5267
|
entrypoint: runtimeConfig.runContext?.entrypoint,
|
|
5216
|
-
scenarioId: runtimeConfig.runContext?.scenarioId
|
|
5268
|
+
scenarioId: runtimeConfig.runContext?.scenarioId,
|
|
5269
|
+
...buildRunInputAuditMetadata(runtimeConfig)
|
|
5217
5270
|
} }));
|
|
5218
5271
|
log$25.info("[stream] 开始执行 prompt", {
|
|
5219
5272
|
sessionId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe-lark/larkpal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"description": "LarkPal - Lark/Feishu bot service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.mjs",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"zod": "^4.3.6"
|
|
51
51
|
},
|
|
52
52
|
"optionalDependencies": {
|
|
53
|
-
"@vibe-lark/larkpal-agent": "^0.1.
|
|
53
|
+
"@vibe-lark/larkpal-agent": "^0.1.16"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@eslint/js": "^10.0.1",
|