63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
function writeJson(payload) {
|
|
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
}
|
|
|
|
async function readStdin() {
|
|
const chunks = [];
|
|
for await (const chunk of process.stdin) {
|
|
chunks.push(typeof chunk === "string" ? chunk : chunk.toString("utf8"));
|
|
}
|
|
return chunks.join("").trim();
|
|
}
|
|
|
|
function normalizePayload(raw) {
|
|
try {
|
|
const parsed = JSON.parse(raw);
|
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
return {
|
|
ok: false,
|
|
error: "INVALID_CLAW_PAYLOAD: expected object",
|
|
};
|
|
}
|
|
return {
|
|
ok: true,
|
|
payload: parsed,
|
|
};
|
|
} catch {
|
|
return {
|
|
ok: false,
|
|
error: "INVALID_CLAW_PAYLOAD: invalid json",
|
|
};
|
|
}
|
|
}
|
|
|
|
const raw = await readStdin();
|
|
const normalized = normalizePayload(raw);
|
|
|
|
if (!normalized.ok) {
|
|
writeJson({
|
|
status: "failed",
|
|
error: normalized.error,
|
|
});
|
|
process.exit(0);
|
|
}
|
|
|
|
const payload = normalized.payload;
|
|
const requestKind = typeof payload.requestKind === "string" ? payload.requestKind : "unknown";
|
|
const model = typeof payload.model === "string" && payload.model.trim() ? payload.model.trim() : "default";
|
|
const reasoningEffort =
|
|
typeof payload.reasoningEffort === "string" && payload.reasoningEffort.trim()
|
|
? payload.reasoningEffort.trim()
|
|
: "default";
|
|
const executionPrompt =
|
|
typeof payload.executionPrompt === "string" && payload.executionPrompt.trim()
|
|
? payload.executionPrompt.trim()
|
|
: "链路正常";
|
|
|
|
writeJson({
|
|
status: "completed",
|
|
output: `Claw smoke completed: ${executionPrompt} (kind=${requestKind}, model=${model}, reasoning=${reasoningEffort})`,
|
|
});
|