- 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
41 lines
1.7 KiB
JavaScript
41 lines
1.7 KiB
JavaScript
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
import { EventSigningTransformStream } from "./EventSigningTransformStream";
|
|
export class EventStreamPayloadHandler {
|
|
messageSigner;
|
|
eventStreamCodec;
|
|
systemClockOffsetProvider;
|
|
constructor(options) {
|
|
this.messageSigner = options.messageSigner;
|
|
this.eventStreamCodec = new EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
|
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
|
}
|
|
async handle(next, args, context = {}) {
|
|
const request = args.request;
|
|
const { body: payload, headers, query } = request;
|
|
if (!(payload instanceof ReadableStream)) {
|
|
throw new Error("Eventstream payload must be a ReadableStream.");
|
|
}
|
|
const placeHolderStream = new TransformStream();
|
|
request.body = placeHolderStream.readable;
|
|
const match = (headers?.authorization ?? "").match(/Signature=(\w+)$/);
|
|
let priorSignature = (match ?? [])[1] ?? (query && query["X-Amz-Signature"]) ?? "";
|
|
if (context.__staticSignature) {
|
|
priorSignature = "";
|
|
}
|
|
const signingStream = new EventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
|
|
payload.pipeThrough(signingStream).pipeThrough(placeHolderStream);
|
|
let result;
|
|
try {
|
|
result = await next(args);
|
|
}
|
|
catch (e) {
|
|
const p = payload.cancel?.();
|
|
if (p instanceof Promise) {
|
|
p.catch(() => { });
|
|
}
|
|
throw e;
|
|
}
|
|
return result;
|
|
}
|
|
}
|