新增飞书GLP只读通信契约、技能包与零点接收器

This commit is contained in:
铸渊 ICE-P-ZY001 2026-10-20 00:22:25 +08:00
commit 89ce465e64
6 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,7 @@
import fs from 'node:fs';import {request} from './contract.mjs';
const [mode,...a]=process.argv.slice(2);
try{
if(mode==='build'){if(a.length<3||a.length>4)throw Error('QUESTION_FILE_SESSION_TASK_REQUIRED');console.log(JSON.stringify(request(fs.readFileSync(a[0],'utf8'),{session:a[1],task:a[2],type:a[3]||'REQUEST'}),null,2));}
else if(mode==='send'){if(a.length!==2||!process.env.GUANGHU_GLP_TOKEN)throw Error('MESSAGE_URL_AND_PRIVATE_TOKEN_REQUIRED');const u=new URL(a[1]);if(u.username||u.password||u.search||u.hash||u.pathname!=='/v1/glp'||!(u.protocol==='https:'||(u.protocol==='http:'&&['127.0.0.1','[::1]'].includes(u.hostname))))throw Error('GLP_ENDPOINT_INVALID');const r=await fetch(u,{method:'POST',redirect:'error',headers:{'content-type':'application/json',authorization:'Bearer '+process.env.GUANGHU_GLP_TOKEN},body:fs.readFileSync(a[0]),signal:AbortSignal.timeout(65000)});console.log(JSON.stringify(await r.json(),null,2));if(!r.ok)process.exitCode=2;}
else throw Error('COMMAND_NOT_SUPPORTED');
}catch(e){console.log(JSON.stringify({error:/^[A-Z_]+$/.test(e.message)?e.message:'GLP_TRANSPORT_FAILED'}));process.exitCode=2;}