@vibe-lark/larkpal 0.1.74 → 0.1.76
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/bin/larkpal.js +0 -0
- package/dist/main.mjs +287 -12
- package/package.json +15 -14
package/bin/larkpal.js
CHANGED
|
File without changes
|
package/dist/main.mjs
CHANGED
|
@@ -3464,6 +3464,139 @@ function createChatAuthRouter() {
|
|
|
3464
3464
|
return router;
|
|
3465
3465
|
}
|
|
3466
3466
|
//#endregion
|
|
3467
|
+
//#region src/gateway/runtime-context.ts
|
|
3468
|
+
const CLAUDE_MD_START = "<!-- LARKPAL_RUNTIME_INSTRUCTIONS_START -->";
|
|
3469
|
+
const CLAUDE_MD_END = "<!-- LARKPAL_RUNTIME_INSTRUCTIONS_END -->";
|
|
3470
|
+
function materializeRuntimeContext(params) {
|
|
3471
|
+
const instructions = normalizeRuntimeInstructions(params.instructions);
|
|
3472
|
+
const skills = normalizeRuntimeSkills(params.skills);
|
|
3473
|
+
if (instructions.length === 0 && skills.length === 0) return void 0;
|
|
3474
|
+
return {
|
|
3475
|
+
instructions: instructions.length > 0 ? writeRuntimeInstructions(params.cwd, instructions) : [],
|
|
3476
|
+
skills: skills.map((skill) => writeRuntimeSkill(params.cwd, skill))
|
|
3477
|
+
};
|
|
3478
|
+
}
|
|
3479
|
+
function normalizeRuntimeInstructions(value) {
|
|
3480
|
+
if (!Array.isArray(value)) return [];
|
|
3481
|
+
return value.map((item) => {
|
|
3482
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return null;
|
|
3483
|
+
const record = item;
|
|
3484
|
+
const id = readNonEmptyString(record.id);
|
|
3485
|
+
const content = readNonEmptyString(record.content);
|
|
3486
|
+
if (!id || !content) return null;
|
|
3487
|
+
return {
|
|
3488
|
+
id,
|
|
3489
|
+
content,
|
|
3490
|
+
scope: readScope(record.scope),
|
|
3491
|
+
version: readNonEmptyString(record.version)
|
|
3492
|
+
};
|
|
3493
|
+
}).filter((item) => item != null);
|
|
3494
|
+
}
|
|
3495
|
+
function normalizeRuntimeSkills(value) {
|
|
3496
|
+
if (!Array.isArray(value)) return [];
|
|
3497
|
+
return value.map((item) => {
|
|
3498
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return null;
|
|
3499
|
+
const record = item;
|
|
3500
|
+
const id = readNonEmptyString(record.id);
|
|
3501
|
+
const content = readNonEmptyString(record.content) || readNonEmptyString(record.skillMarkdown);
|
|
3502
|
+
if (!id || !content) return null;
|
|
3503
|
+
return {
|
|
3504
|
+
id,
|
|
3505
|
+
content,
|
|
3506
|
+
scope: readScope(record.scope),
|
|
3507
|
+
version: readNonEmptyString(record.version),
|
|
3508
|
+
name: readNonEmptyString(record.name),
|
|
3509
|
+
description: readNonEmptyString(record.description)
|
|
3510
|
+
};
|
|
3511
|
+
}).filter((item) => item != null);
|
|
3512
|
+
}
|
|
3513
|
+
function writeRuntimeInstructions(cwd, instructions) {
|
|
3514
|
+
const filePath = join(cwd, "CLAUDE.md");
|
|
3515
|
+
const body = [
|
|
3516
|
+
CLAUDE_MD_START,
|
|
3517
|
+
"# LarkPal Runtime Instructions",
|
|
3518
|
+
"",
|
|
3519
|
+
"The following instructions were injected by LarkPal for this agent session. Treat them as runtime context, not as user message content.",
|
|
3520
|
+
"",
|
|
3521
|
+
...instructions.flatMap((instruction) => [
|
|
3522
|
+
`## ${instruction.id}`,
|
|
3523
|
+
"",
|
|
3524
|
+
instruction.content.trim(),
|
|
3525
|
+
""
|
|
3526
|
+
]),
|
|
3527
|
+
CLAUDE_MD_END,
|
|
3528
|
+
""
|
|
3529
|
+
].join("\n");
|
|
3530
|
+
const next = replaceManagedBlock(existsSync(filePath) ? readFileSync(filePath, "utf-8") : "", body);
|
|
3531
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
3532
|
+
writeFileSync(filePath, next, "utf-8");
|
|
3533
|
+
return instructions.map((instruction) => ({
|
|
3534
|
+
id: instruction.id,
|
|
3535
|
+
scope: instruction.scope ?? "request",
|
|
3536
|
+
hash: hashContent(instruction.content),
|
|
3537
|
+
version: instruction.version,
|
|
3538
|
+
path: "CLAUDE.md"
|
|
3539
|
+
}));
|
|
3540
|
+
}
|
|
3541
|
+
function writeRuntimeSkill(cwd, skill) {
|
|
3542
|
+
const relativePath = `.claude/skills/${sanitizePathSegment(skill.id)}/SKILL.md`;
|
|
3543
|
+
const filePath = join(cwd, relativePath);
|
|
3544
|
+
const content = buildSkillContent(skill);
|
|
3545
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
3546
|
+
writeFileSync(filePath, content, "utf-8");
|
|
3547
|
+
return {
|
|
3548
|
+
id: skill.id,
|
|
3549
|
+
scope: skill.scope ?? "request",
|
|
3550
|
+
hash: hashContent(content),
|
|
3551
|
+
version: skill.version,
|
|
3552
|
+
path: relativePath
|
|
3553
|
+
};
|
|
3554
|
+
}
|
|
3555
|
+
function buildSkillContent(skill) {
|
|
3556
|
+
const content = skill.content.trim();
|
|
3557
|
+
if (content.startsWith("---")) return `${content}\n`;
|
|
3558
|
+
const name = skill.name || skill.id;
|
|
3559
|
+
const description = skill.description || `Runtime skill injected by LarkPal: ${skill.id}`;
|
|
3560
|
+
return [
|
|
3561
|
+
"---",
|
|
3562
|
+
`name: ${yamlScalar(name)}`,
|
|
3563
|
+
`description: ${yamlScalar(description)}`,
|
|
3564
|
+
"---",
|
|
3565
|
+
"",
|
|
3566
|
+
content,
|
|
3567
|
+
""
|
|
3568
|
+
].join("\n");
|
|
3569
|
+
}
|
|
3570
|
+
function replaceManagedBlock(current, managedBlock) {
|
|
3571
|
+
const start = current.indexOf(CLAUDE_MD_START);
|
|
3572
|
+
const end = current.indexOf(CLAUDE_MD_END);
|
|
3573
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
3574
|
+
const before = current.slice(0, start).trimEnd();
|
|
3575
|
+
const after = current.slice(end + 41).trimStart();
|
|
3576
|
+
return [
|
|
3577
|
+
before,
|
|
3578
|
+
managedBlock.trimEnd(),
|
|
3579
|
+
after
|
|
3580
|
+
].filter(Boolean).join("\n\n") + "\n";
|
|
3581
|
+
}
|
|
3582
|
+
return [current.trimEnd(), managedBlock.trimEnd()].filter(Boolean).join("\n\n") + "\n";
|
|
3583
|
+
}
|
|
3584
|
+
function hashContent(content) {
|
|
3585
|
+
return `sha256:${createHash("sha256").update(content).digest("hex")}`;
|
|
3586
|
+
}
|
|
3587
|
+
function sanitizePathSegment(value) {
|
|
3588
|
+
return value.replace(/[^A-Za-z0-9._-]/g, "_").replace(/^\.+$/, "skill") || "skill";
|
|
3589
|
+
}
|
|
3590
|
+
function readNonEmptyString(value) {
|
|
3591
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
3592
|
+
}
|
|
3593
|
+
function readScope(value) {
|
|
3594
|
+
return value === "app" || value === "session" || value === "request" ? value : "request";
|
|
3595
|
+
}
|
|
3596
|
+
function yamlScalar(value) {
|
|
3597
|
+
return JSON.stringify(value);
|
|
3598
|
+
}
|
|
3599
|
+
//#endregion
|
|
3467
3600
|
//#region src/gateway/agent-context.ts
|
|
3468
3601
|
const SENSITIVE_KEY_PATTERN = /(authorization|cookie|token|api[-_]?key|secret|password|credential)/i;
|
|
3469
3602
|
const SAFE_KEY_PATTERN = /^(file[-_]?token|drive[-_]?file[-_]?token|doc[-_]?token|sheet[-_]?token|wiki[-_]?token|node[-_]?token)$/i;
|
|
@@ -3505,11 +3638,17 @@ function buildAgentRuntimeConfig(input) {
|
|
|
3505
3638
|
const userId = requireContextField(input.identity?.userId || input.identity?.openId, "userId");
|
|
3506
3639
|
const scenarioId = getScenarioId(input.scenarioId, input.metadata);
|
|
3507
3640
|
const cwd = resolveAgentCwd(sessionId, input.cwd);
|
|
3641
|
+
const runtimeContext = materializeRuntimeContext({
|
|
3642
|
+
cwd,
|
|
3643
|
+
instructions: input.runtimeInstructions,
|
|
3644
|
+
skills: input.runtimeSkills
|
|
3645
|
+
});
|
|
3508
3646
|
const metadata = buildRunMetadata(input.metadata, {
|
|
3509
3647
|
conversationId,
|
|
3510
3648
|
traceId,
|
|
3511
3649
|
entrypoint: input.entrypoint,
|
|
3512
|
-
scenarioId
|
|
3650
|
+
scenarioId,
|
|
3651
|
+
runtimeContext
|
|
3513
3652
|
});
|
|
3514
3653
|
const authHeaders = buildAuthHeaders({
|
|
3515
3654
|
tenantKey,
|
|
@@ -3541,6 +3680,7 @@ function buildAgentRuntimeConfig(input) {
|
|
|
3541
3680
|
authHeaders,
|
|
3542
3681
|
attachments: input.attachments,
|
|
3543
3682
|
sourceArtifacts: input.sourceArtifacts,
|
|
3683
|
+
runtimeContext,
|
|
3544
3684
|
llmConfig: input.llmConfig,
|
|
3545
3685
|
policy,
|
|
3546
3686
|
metadata
|
|
@@ -3559,6 +3699,7 @@ function buildAgentRuntimeConfig(input) {
|
|
|
3559
3699
|
authHeaders,
|
|
3560
3700
|
attachments: input.attachments,
|
|
3561
3701
|
sourceArtifacts: input.sourceArtifacts,
|
|
3702
|
+
runtimeContext,
|
|
3562
3703
|
llmConfig: input.llmConfig,
|
|
3563
3704
|
policy,
|
|
3564
3705
|
requestContext,
|
|
@@ -3644,6 +3785,7 @@ function buildRunInputAuditMetadata(config) {
|
|
|
3644
3785
|
const metadata = {};
|
|
3645
3786
|
if (config.attachments !== void 0) metadata.attachments = summarizeForAudit(config.attachments);
|
|
3646
3787
|
if (config.sourceArtifacts !== void 0) metadata.sourceArtifacts = summarizeForAudit(config.sourceArtifacts);
|
|
3788
|
+
if (config.runtimeContext !== void 0) metadata.runtimeContext = config.runtimeContext;
|
|
3647
3789
|
return metadata;
|
|
3648
3790
|
}
|
|
3649
3791
|
function buildRuntimeEventAuditMetadata(event) {
|
|
@@ -3732,7 +3874,8 @@ function buildRunMetadata(metadata, context) {
|
|
|
3732
3874
|
conversationId: context.conversationId,
|
|
3733
3875
|
traceId: context.traceId,
|
|
3734
3876
|
entrypoint: context.entrypoint,
|
|
3735
|
-
...context.scenarioId ? { scenarioId: context.scenarioId } : {}
|
|
3877
|
+
...context.scenarioId ? { scenarioId: context.scenarioId } : {},
|
|
3878
|
+
...context.runtimeContext ? { runtimeContext: context.runtimeContext } : {}
|
|
3736
3879
|
};
|
|
3737
3880
|
}
|
|
3738
3881
|
function buildAuditMetadata(context, metadata) {
|
|
@@ -3818,6 +3961,7 @@ function serializeChatRun(run) {
|
|
|
3818
3961
|
completedAt: run.completedAt,
|
|
3819
3962
|
finalStatus: run.finalStatus,
|
|
3820
3963
|
error: run.error,
|
|
3964
|
+
runtimeError: run.runtimeError,
|
|
3821
3965
|
textLength: run.text.length,
|
|
3822
3966
|
finalText: run.status === "running" ? void 0 : run.text || void 0,
|
|
3823
3967
|
lastEventAt: run.lastEventAt,
|
|
@@ -3985,6 +4129,7 @@ function appendRunStatusMessage(run, messageStore) {
|
|
|
3985
4129
|
runtimeEventType: "run-status",
|
|
3986
4130
|
finalStatus: run.finalStatus,
|
|
3987
4131
|
errorMessage: run.error,
|
|
4132
|
+
runtimeError: run.runtimeError,
|
|
3988
4133
|
staleReason: run.staleReason
|
|
3989
4134
|
}
|
|
3990
4135
|
}, "[stream] 保存 run status 消息失败");
|
|
@@ -4351,6 +4496,107 @@ function buildToolResultPayload(result, resultSummary) {
|
|
|
4351
4496
|
result: resultSummary
|
|
4352
4497
|
};
|
|
4353
4498
|
}
|
|
4499
|
+
function normalizeRuntimeResult(result) {
|
|
4500
|
+
if (!result.isError) return {
|
|
4501
|
+
status: "completed",
|
|
4502
|
+
finalStatus: result.subtype,
|
|
4503
|
+
isError: false,
|
|
4504
|
+
finalText: result.result
|
|
4505
|
+
};
|
|
4506
|
+
const error = buildRuntimeErrorSummary(result.subtype, result.result);
|
|
4507
|
+
return {
|
|
4508
|
+
status: "failed",
|
|
4509
|
+
finalStatus: error.code,
|
|
4510
|
+
isError: true,
|
|
4511
|
+
finalText: result.result || error.message,
|
|
4512
|
+
error
|
|
4513
|
+
};
|
|
4514
|
+
}
|
|
4515
|
+
function buildRuntimeErrorSummary(subtype, result) {
|
|
4516
|
+
const message = normalizeWhitespace(result || `Runtime execution failed: ${subtype}`);
|
|
4517
|
+
const httpStatus = extractHttpStatus(message);
|
|
4518
|
+
const requestId = extractRequestId(message);
|
|
4519
|
+
const providerMessage = extractProviderMessage(message);
|
|
4520
|
+
return {
|
|
4521
|
+
isError: true,
|
|
4522
|
+
code: detectRuntimeErrorCode(subtype, message),
|
|
4523
|
+
subtype,
|
|
4524
|
+
httpStatus,
|
|
4525
|
+
message: truncateRuntimeErrorMessage(message),
|
|
4526
|
+
providerMessage: providerMessage ? truncateRuntimeErrorMessage(providerMessage) : void 0,
|
|
4527
|
+
requestId
|
|
4528
|
+
};
|
|
4529
|
+
}
|
|
4530
|
+
function detectRuntimeErrorCode(subtype, message) {
|
|
4531
|
+
if (/\bprovider_response_error\b/i.test(message)) return "provider_response_error";
|
|
4532
|
+
if (/\bapi_error\b/i.test(message) || /^API Error:/i.test(message)) return "api_error";
|
|
4533
|
+
if (subtype && subtype !== "success") return subtype;
|
|
4534
|
+
return "error_during_execution";
|
|
4535
|
+
}
|
|
4536
|
+
function extractHttpStatus(message) {
|
|
4537
|
+
const match = message.match(/\b(?:API Error:|provider[^:]*:)?\s*(\d{3})\b/i);
|
|
4538
|
+
if (!match?.[1]) return void 0;
|
|
4539
|
+
const status = Number.parseInt(match[1], 10);
|
|
4540
|
+
return Number.isFinite(status) ? status : void 0;
|
|
4541
|
+
}
|
|
4542
|
+
function extractRequestId(message) {
|
|
4543
|
+
return message.match(/\bRequest id:\s*([A-Za-z0-9._:-]+)/i)?.[1];
|
|
4544
|
+
}
|
|
4545
|
+
function extractProviderMessage(message) {
|
|
4546
|
+
const parsedMessage = extractJsonErrorMessage(message);
|
|
4547
|
+
if (parsedMessage) return parsedMessage;
|
|
4548
|
+
const jsonMessage = message.match(/"message"\s*:\s*"([^"]+)"/);
|
|
4549
|
+
if (jsonMessage?.[1]) return unescapeJsonFragment(jsonMessage[1]);
|
|
4550
|
+
const requestIdIndex = message.search(/\bRequest id:/i);
|
|
4551
|
+
if (requestIdIndex > 0) {
|
|
4552
|
+
const prefix = message.slice(0, requestIdIndex).trim();
|
|
4553
|
+
const sentenceStart = Math.max(prefix.lastIndexOf("}"), prefix.lastIndexOf(":"));
|
|
4554
|
+
return prefix.slice(sentenceStart + 1).trim() || void 0;
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4557
|
+
function extractJsonErrorMessage(message) {
|
|
4558
|
+
const start = message.indexOf("{");
|
|
4559
|
+
const end = message.lastIndexOf("}");
|
|
4560
|
+
if (start < 0 || end <= start) return void 0;
|
|
4561
|
+
try {
|
|
4562
|
+
const topMessage = readNestedString(JSON.parse(message.slice(start, end + 1)), ["error", "message"]);
|
|
4563
|
+
if (!topMessage) return void 0;
|
|
4564
|
+
return extractNestedJsonErrorMessage(topMessage) || topMessage;
|
|
4565
|
+
} catch {
|
|
4566
|
+
return;
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
function extractNestedJsonErrorMessage(message) {
|
|
4570
|
+
const start = message.indexOf("{");
|
|
4571
|
+
const end = message.lastIndexOf("}");
|
|
4572
|
+
if (start < 0 || end <= start) return void 0;
|
|
4573
|
+
try {
|
|
4574
|
+
return readNestedString(JSON.parse(message.slice(start, end + 1)), ["error", "message"]);
|
|
4575
|
+
} catch {
|
|
4576
|
+
return;
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
function readNestedString(value, path) {
|
|
4580
|
+
let current = value;
|
|
4581
|
+
for (const key of path) {
|
|
4582
|
+
if (!current || typeof current !== "object" || Array.isArray(current)) return void 0;
|
|
4583
|
+
current = current[key];
|
|
4584
|
+
}
|
|
4585
|
+
return typeof current === "string" ? current : void 0;
|
|
4586
|
+
}
|
|
4587
|
+
function unescapeJsonFragment(value) {
|
|
4588
|
+
try {
|
|
4589
|
+
return JSON.parse(`"${value.replace(/"/g, "\\\"")}"`);
|
|
4590
|
+
} catch {
|
|
4591
|
+
return value.replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
|
|
4592
|
+
}
|
|
4593
|
+
}
|
|
4594
|
+
function normalizeWhitespace(value) {
|
|
4595
|
+
return value.replace(/\s+/g, " ").trim();
|
|
4596
|
+
}
|
|
4597
|
+
function truncateRuntimeErrorMessage(value) {
|
|
4598
|
+
return value.length > 2e3 ? `${value.slice(0, 2e3)}...` : value;
|
|
4599
|
+
}
|
|
4354
4600
|
function readStringField(value, key) {
|
|
4355
4601
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
4356
4602
|
const field = value[key];
|
|
@@ -4470,6 +4716,8 @@ function createChatRouter(config) {
|
|
|
4470
4716
|
const scenarioId = getScenarioId(body.options?.scenarioId, body.options?.metadata);
|
|
4471
4717
|
const attachments = getRunInputValue(body.attachments, body.options?.attachments, body.options?.metadata?.attachments);
|
|
4472
4718
|
const sourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.options?.sourceArtifacts, body.options?.source_artifacts, body.options?.metadata?.sourceArtifacts, body.options?.metadata?.source_artifacts);
|
|
4719
|
+
const runtimeInstructions = getRunInputValue(body.runtimeInstructions, body.runtime_instructions, body.options?.runtimeInstructions, body.options?.runtime_instructions, body.options?.metadata?.runtimeInstructions, body.options?.metadata?.runtime_instructions);
|
|
4720
|
+
const runtimeSkills = getRunInputValue(body.runtimeSkills, body.runtime_skills, body.options?.runtimeSkills, body.options?.runtime_skills, body.options?.metadata?.runtimeSkills, body.options?.metadata?.runtime_skills);
|
|
4473
4721
|
log$30.info("[stream] 收到流式对话请求", {
|
|
4474
4722
|
userId,
|
|
4475
4723
|
sessionId,
|
|
@@ -4478,6 +4726,8 @@ function createChatRouter(config) {
|
|
|
4478
4726
|
scenarioId,
|
|
4479
4727
|
hasAttachments: attachments !== void 0,
|
|
4480
4728
|
hasSourceArtifacts: sourceArtifacts !== void 0,
|
|
4729
|
+
hasRuntimeInstructions: runtimeInstructions !== void 0,
|
|
4730
|
+
hasRuntimeSkills: runtimeSkills !== void 0,
|
|
4481
4731
|
promptLength: body.prompt.length
|
|
4482
4732
|
});
|
|
4483
4733
|
if (!sessionId) {
|
|
@@ -4525,6 +4775,8 @@ function createChatRouter(config) {
|
|
|
4525
4775
|
model: process.env.CLAUDE_MODEL || void 0,
|
|
4526
4776
|
attachments,
|
|
4527
4777
|
sourceArtifacts,
|
|
4778
|
+
runtimeInstructions,
|
|
4779
|
+
runtimeSkills,
|
|
4528
4780
|
policy: body.options?.policy,
|
|
4529
4781
|
metadata: body.options?.metadata,
|
|
4530
4782
|
identity: {
|
|
@@ -4564,10 +4816,7 @@ function createChatRouter(config) {
|
|
|
4564
4816
|
requestId,
|
|
4565
4817
|
traceId,
|
|
4566
4818
|
scenarioId,
|
|
4567
|
-
...buildRunInputAuditMetadata(
|
|
4568
|
-
attachments,
|
|
4569
|
-
sourceArtifacts
|
|
4570
|
-
})
|
|
4819
|
+
...buildRunInputAuditMetadata(runtimeConfig)
|
|
4571
4820
|
}
|
|
4572
4821
|
});
|
|
4573
4822
|
} catch (err) {
|
|
@@ -4782,9 +5031,15 @@ function createChatRouter(config) {
|
|
|
4782
5031
|
onResult: async (result) => {
|
|
4783
5032
|
if (run.status !== "running") return;
|
|
4784
5033
|
recordRunEvent(run, "result");
|
|
4785
|
-
const
|
|
5034
|
+
const normalizedResult = normalizeRuntimeResult(result);
|
|
5035
|
+
const partialText = run.text.trim() ? run.text : void 0;
|
|
5036
|
+
const finalText = normalizedResult.isError ? normalizedResult.finalText || partialText || "" : partialText || normalizedResult.finalText || "";
|
|
4786
5037
|
run.text = finalText;
|
|
4787
|
-
|
|
5038
|
+
run.runtimeError = normalizedResult.error;
|
|
5039
|
+
await markRunTerminal(run, messageStore, normalizedResult.status, {
|
|
5040
|
+
finalStatus: normalizedResult.finalStatus,
|
|
5041
|
+
error: normalizedResult.error?.message
|
|
5042
|
+
});
|
|
4788
5043
|
await cleanupTerminalRunProcess(run, processManager, "result");
|
|
4789
5044
|
await queueRunMessage(run, messageStore, {
|
|
4790
5045
|
sessionId,
|
|
@@ -4799,15 +5054,21 @@ function createChatRouter(config) {
|
|
|
4799
5054
|
traceId,
|
|
4800
5055
|
requestId,
|
|
4801
5056
|
scenarioId,
|
|
4802
|
-
finalStatus:
|
|
4803
|
-
isError:
|
|
5057
|
+
finalStatus: normalizedResult.finalStatus,
|
|
5058
|
+
isError: normalizedResult.isError,
|
|
5059
|
+
runtimeError: normalizedResult.error,
|
|
5060
|
+
partialText
|
|
4804
5061
|
}
|
|
4805
5062
|
}, "[stream] 保存 assistant 消息失败");
|
|
4806
5063
|
broadcastRunEvent(run, "done", {
|
|
4807
5064
|
sessionId,
|
|
4808
5065
|
runId: run.runId,
|
|
4809
|
-
result:
|
|
5066
|
+
result: normalizedResult.finalStatus,
|
|
5067
|
+
finalStatus: normalizedResult.finalStatus,
|
|
5068
|
+
isError: normalizedResult.isError,
|
|
5069
|
+
error: normalizedResult.error,
|
|
4810
5070
|
text: finalText,
|
|
5071
|
+
partialText,
|
|
4811
5072
|
durationMs: result.durationMs,
|
|
4812
5073
|
totalCostUsd: result.totalCostUsd,
|
|
4813
5074
|
numTurns: result.numTurns
|
|
@@ -4817,7 +5078,8 @@ function createChatRouter(config) {
|
|
|
4817
5078
|
log$30.info("[stream] 对话完成", {
|
|
4818
5079
|
sessionId,
|
|
4819
5080
|
runId: run.runId,
|
|
4820
|
-
result:
|
|
5081
|
+
result: normalizedResult.finalStatus,
|
|
5082
|
+
isError: normalizedResult.isError,
|
|
4821
5083
|
textLength: finalText.length,
|
|
4822
5084
|
durationMs: result.durationMs
|
|
4823
5085
|
});
|
|
@@ -4826,6 +5088,9 @@ function createChatRouter(config) {
|
|
|
4826
5088
|
metadata: {
|
|
4827
5089
|
runId: run.runId,
|
|
4828
5090
|
subtype: result.subtype,
|
|
5091
|
+
finalStatus: normalizedResult.finalStatus,
|
|
5092
|
+
isError: normalizedResult.isError,
|
|
5093
|
+
runtimeError: normalizedResult.error,
|
|
4829
5094
|
totalCostUsd: result.totalCostUsd,
|
|
4830
5095
|
numTurns: result.numTurns,
|
|
4831
5096
|
traceId,
|
|
@@ -6110,6 +6375,8 @@ async function handleExecute(req, res, processManager) {
|
|
|
6110
6375
|
const scenarioId = getScenarioId(body.scenarioId || body.scenario_id, body.metadata);
|
|
6111
6376
|
const attachments = getRunInputValue(body.attachments, body.metadata?.attachments);
|
|
6112
6377
|
const sourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.metadata?.sourceArtifacts, body.metadata?.source_artifacts);
|
|
6378
|
+
const runtimeInstructions = getRunInputValue(body.runtimeInstructions, body.runtime_instructions, body.metadata?.runtimeInstructions, body.metadata?.runtime_instructions);
|
|
6379
|
+
const runtimeSkills = getRunInputValue(body.runtimeSkills, body.runtime_skills, body.metadata?.runtimeSkills, body.metadata?.runtime_skills);
|
|
6113
6380
|
const identity = resolveExecuteIdentity(req, body);
|
|
6114
6381
|
const missingIdentityFields = getMissingIdentityFields(identity);
|
|
6115
6382
|
if (missingIdentityFields.length > 0) {
|
|
@@ -6156,6 +6423,8 @@ async function handleExecute(req, res, processManager) {
|
|
|
6156
6423
|
authHeaders: body.auth_headers,
|
|
6157
6424
|
attachments,
|
|
6158
6425
|
sourceArtifacts,
|
|
6426
|
+
runtimeInstructions,
|
|
6427
|
+
runtimeSkills,
|
|
6159
6428
|
policy: body.policy,
|
|
6160
6429
|
metadata: body.metadata,
|
|
6161
6430
|
identity
|
|
@@ -6284,6 +6553,8 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
6284
6553
|
const scenarioId = getScenarioId(body.scenarioId || body.scenario_id, body.metadata);
|
|
6285
6554
|
const batchAttachments = getRunInputValue(body.attachments, body.metadata?.attachments);
|
|
6286
6555
|
const batchSourceArtifacts = getRunInputValue(body.sourceArtifacts, body.source_artifacts, body.metadata?.sourceArtifacts, body.metadata?.source_artifacts);
|
|
6556
|
+
const batchRuntimeInstructions = getRunInputValue(body.runtimeInstructions, body.runtime_instructions, body.metadata?.runtimeInstructions, body.metadata?.runtime_instructions);
|
|
6557
|
+
const batchRuntimeSkills = getRunInputValue(body.runtimeSkills, body.runtime_skills, body.metadata?.runtimeSkills, body.metadata?.runtime_skills);
|
|
6287
6558
|
const concurrency = body.concurrency ?? 3;
|
|
6288
6559
|
const taskIds = [];
|
|
6289
6560
|
const taskConfigs = [];
|
|
@@ -6299,6 +6570,8 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
6299
6570
|
};
|
|
6300
6571
|
const taskAttachments = getRunInputValue(task.attachments, task.metadata?.attachments, batchAttachments);
|
|
6301
6572
|
const taskSourceArtifacts = getRunInputValue(task.sourceArtifacts, task.source_artifacts, task.metadata?.sourceArtifacts, task.metadata?.source_artifacts, batchSourceArtifacts);
|
|
6573
|
+
const taskRuntimeInstructions = getRunInputValue(task.runtimeInstructions, task.runtime_instructions, task.metadata?.runtimeInstructions, task.metadata?.runtime_instructions, batchRuntimeInstructions);
|
|
6574
|
+
const taskRuntimeSkills = getRunInputValue(task.runtimeSkills, task.runtime_skills, task.metadata?.runtimeSkills, task.metadata?.runtime_skills, batchRuntimeSkills);
|
|
6302
6575
|
const config = buildAgentRuntimeConfig({
|
|
6303
6576
|
requestId: `${batchRequestId}:${index}`,
|
|
6304
6577
|
traceId,
|
|
@@ -6311,6 +6584,8 @@ async function handleBatchExecute(req, res, processManager) {
|
|
|
6311
6584
|
authHeaders: body.auth_headers,
|
|
6312
6585
|
attachments: taskAttachments,
|
|
6313
6586
|
sourceArtifacts: taskSourceArtifacts,
|
|
6587
|
+
runtimeInstructions: taskRuntimeInstructions,
|
|
6588
|
+
runtimeSkills: taskRuntimeSkills,
|
|
6314
6589
|
policy: body.policy,
|
|
6315
6590
|
metadata: taskMetadata,
|
|
6316
6591
|
identity
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe-lark/larkpal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.76",
|
|
4
4
|
"description": "LarkPal - Lark/Feishu bot service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.mjs",
|
|
@@ -21,9 +21,22 @@
|
|
|
21
21
|
"registry": "https://registry.npmjs.org",
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
+
"packageManager": "pnpm@10.32.1",
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=22"
|
|
26
27
|
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"start": "node --env-file=.env bin/larkpal.js",
|
|
30
|
+
"build": "tsdown",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"lint": "eslint src/",
|
|
34
|
+
"lint:fix": "eslint src/ --fix",
|
|
35
|
+
"sit:larkpal-agent": "node scripts/sit/larkpal-agent-0.1.9-sit.mjs",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"format": "prettier --write src/**/*.ts",
|
|
38
|
+
"format:check": "prettier --check src/**/*.ts"
|
|
39
|
+
},
|
|
27
40
|
"dependencies": {
|
|
28
41
|
"@larksuiteoapi/node-sdk": "^1.60.0",
|
|
29
42
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
@@ -56,17 +69,5 @@
|
|
|
56
69
|
"typescript": "^5.9.3",
|
|
57
70
|
"typescript-eslint": "^8.32.1",
|
|
58
71
|
"vitest": "^4.1.1"
|
|
59
|
-
},
|
|
60
|
-
"scripts": {
|
|
61
|
-
"start": "node --env-file=.env bin/larkpal.js",
|
|
62
|
-
"build": "tsdown",
|
|
63
|
-
"test": "vitest run",
|
|
64
|
-
"test:watch": "vitest",
|
|
65
|
-
"lint": "eslint src/",
|
|
66
|
-
"lint:fix": "eslint src/ --fix",
|
|
67
|
-
"sit:larkpal-agent": "node scripts/sit/larkpal-agent-0.1.9-sit.mjs",
|
|
68
|
-
"typecheck": "tsc --noEmit",
|
|
69
|
-
"format": "prettier --write src/**/*.ts",
|
|
70
|
-
"format:check": "prettier --check src/**/*.ts"
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
+
}
|