- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation
🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
import { Transform } from "node:stream";
|
|
export class EventSigningTransformStream extends Transform {
|
|
priorSignature;
|
|
messageSigner;
|
|
eventStreamCodec;
|
|
systemClockOffsetProvider;
|
|
constructor(options) {
|
|
super({
|
|
autoDestroy: true,
|
|
readableObjectMode: true,
|
|
writableObjectMode: true,
|
|
...options,
|
|
});
|
|
this.priorSignature = options.priorSignature;
|
|
this.eventStreamCodec = options.eventStreamCodec;
|
|
this.messageSigner = options.messageSigner;
|
|
this.systemClockOffsetProvider = options.systemClockOffsetProvider;
|
|
}
|
|
async _transform(chunk, encoding, callback) {
|
|
try {
|
|
const now = new Date(Date.now() + (await this.systemClockOffsetProvider()));
|
|
const dateHeader = {
|
|
":date": { type: "timestamp", value: now },
|
|
};
|
|
const signedMessage = await this.messageSigner.sign({
|
|
message: {
|
|
body: chunk,
|
|
headers: dateHeader,
|
|
},
|
|
priorSignature: this.priorSignature,
|
|
}, {
|
|
signingDate: now,
|
|
});
|
|
this.priorSignature = signedMessage.signature;
|
|
const serializedSigned = this.eventStreamCodec.encode({
|
|
headers: {
|
|
...dateHeader,
|
|
":chunk-signature": {
|
|
type: "binary",
|
|
value: getSignatureBinary(signedMessage.signature),
|
|
},
|
|
},
|
|
body: chunk,
|
|
});
|
|
this.push(serializedSigned);
|
|
return callback();
|
|
}
|
|
catch (err) {
|
|
callback(err);
|
|
}
|
|
}
|
|
}
|
|
function getSignatureBinary(signature) {
|
|
const buf = Buffer.from(signature, "hex");
|
|
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
}
|