Files
zCode-CLI-X/~/.npm-cache/hono@4.12.9@@@1/dist/middleware/jsx-renderer/index.js
admin 875c7f9b91 feat: Complete zCode CLI X with Telegram bot integration
- 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
2026-05-05 09:01:26 +00:00

59 lines
1.7 KiB
JavaScript

// src/middleware/jsx-renderer/index.ts
import { html, raw } from "../../helper/html/index.js";
import { Fragment, createContext, jsx, useContext } from "../../jsx/index.js";
import { renderToReadableStream } from "../../jsx/streaming.js";
var RequestContext = createContext(null);
var createRenderer = (c, Layout, component, options) => (children, props) => {
options = typeof options === "function" ? options(c) : options;
const docType = typeof options?.docType === "string" ? options.docType : options?.docType === false ? "" : "<!DOCTYPE html>";
const currentLayout = component ? jsx(
(props2) => component(props2, c),
{
Layout,
...props
},
children
) : children;
const body = html`${raw(docType)}${jsx(
RequestContext.Provider,
{ value: c },
currentLayout
)}`;
if (options?.stream) {
if (options.stream === true) {
c.header("Transfer-Encoding", "chunked");
c.header("Content-Type", "text/html; charset=UTF-8");
c.header("Content-Encoding", "Identity");
} else {
for (const [key, value] of Object.entries(options.stream)) {
c.header(key, value);
}
}
return c.body(renderToReadableStream(body));
} else {
return c.html(body);
}
};
var jsxRenderer = (component, options) => function jsxRenderer2(c, next) {
const Layout = c.getLayout() ?? Fragment;
if (component) {
c.setLayout((props) => {
return component({ ...props, Layout }, c);
});
}
c.setRenderer(createRenderer(c, Layout, component, options));
return next();
};
var useRequestContext = () => {
const c = useContext(RequestContext);
if (!c) {
throw new Error("RequestContext is not provided.");
}
return c;
};
export {
RequestContext,
jsxRenderer,
useRequestContext
};