diff --git a/.gitignore b/.gitignore index 3f32964..ed93436 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.venv __pycache__ +/client/web/dist diff --git a/client/web/dist/main.js b/client/web/dist/main.js deleted file mode 100644 index 733f2cd..0000000 --- a/client/web/dist/main.js +++ /dev/null @@ -1,118 +0,0 @@ -var __defProp = Object.defineProperty; -var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); - -// https://jsr.io/@char/aftercare/0.2.0/src/elem.ts -function elem(tag, attrs = {}, children = [], extras = {}) { - const element = typeof tag === "string" ? document.createElement(tag) : new tag(); - Object.assign( - element, - Object.fromEntries(Object.entries(attrs).filter(([_k, v]) => v !== void 0)) - ); - if (extras.classList) extras.classList.forEach((c) => element.classList.add(c)); - if (extras.dataset && (element instanceof HTMLElement || element instanceof SVGElement)) - Object.entries(extras.dataset).filter(([_k, v]) => v !== void 0).forEach(([k, v]) => element.dataset[k] = v); - const childNodes = children.map( - (e) => typeof e === "string" ? document.createTextNode(e) : e - ); - element.append(...childNodes); - if (extras._tap) extras._tap(element); - return element; -} -__name(elem, "elem"); - -// https://jsr.io/@char/aftercare/0.2.0/src/jsx.ts -function jsx(tag, props, _key) { - if (tag === void 0) { - throw new Error("fragments are not supported"); - } - const { children = [], classList, dataset, _tap, ...attrs } = props; - const childrenArray = Array.isArray(children) ? children : [children]; - const extras = { classList, dataset, _tap }; - return elem(tag, attrs, childrenArray, extras); -} -__name(jsx, "jsx"); - -// client/main.tsx -var main = document.querySelector("main"); -async function nav() { - const nav2 = /* @__PURE__ */ jsx("nav", {}); - const conversations = await fetch("/api/conversation").then((r) => r.json()); - for (const conversation of conversations) { - const button = /* @__PURE__ */ jsx("button", { type: "button", children: conversation.name }); - button.addEventListener("click", (e) => { - e.preventDefault(); - main.append(conversationUI(conversation.id)); - nav2.remove(); - }); - nav2.append(button); - } - nav2.append( - /* @__PURE__ */ jsx( - "button", - { - type: "button", - _tap: (b) => b.addEventListener("click", (e) => { - e.preventDefault(); - main.append(conversationUI("new")); - nav2.remove(); - }), - children: "new" - } - ) - ); - return nav2; -} -__name(nav, "nav"); -function conversationUI(id) { - window.location.hash = `#${id}`; - const socket = new WebSocket(`/api/conversation/${id}/connect`); - const chatlog = /* @__PURE__ */ jsx("section", { className: "chatlog" }); - const inFlightMessages = /* @__PURE__ */ new Map(); - socket.addEventListener("message", (event) => { - if (typeof event.data !== "string") return; - const message = JSON.parse(event.data); - const scrolledToBottom = chatlog.scrollTop + 16 >= chatlog.scrollHeight - chatlog.clientHeight; - if ("i" in message) { - window.history.replaceState(null, "", "#" + message.i); - } else if ("u" in message) { - chatlog.append(/* @__PURE__ */ jsx("article", { className: "user", children: message.u })); - } else if ("f" in message) { - chatlog.append(/* @__PURE__ */ jsx("article", { className: "assistant", children: message.f })); - } else if ("s" in message) { - const article = /* @__PURE__ */ jsx("article", { className: "assistant" }); - inFlightMessages.set(message.s, article); - chatlog.append(article); - } else if ("r" in message && "c" in message) { - const article = inFlightMessages.get(message.r); - article.append(message.c); - } else if ("d" in message) { - inFlightMessages.delete(message.d); - } - if (scrolledToBottom) chatlog.scrollTop = chatlog.scrollHeight - chatlog.clientHeight; - }); - const form = /* @__PURE__ */ jsx("form", { children: /* @__PURE__ */ jsx("input", { type: "text", placeholder: "Enter a prompt\u2026", required: true }) }); - const input = form.querySelector("input"); - form.addEventListener("submit", (e) => { - e.preventDefault(); - socket.send(input.value); - input.value = ""; - }); - return /* @__PURE__ */ jsx("section", { className: "conversation", children: [ - chatlog, - form - ] }); -} -__name(conversationUI, "conversationUI"); -var showUI = /* @__PURE__ */ __name(async () => { - main.innerHTML = ""; - if (window.location.hash) { - main.append(conversationUI(window.location.hash.substring(1))); - } else { - main.append(await nav()); - } -}, "showUI"); -await showUI(); -window.addEventListener("hashchange", async () => { - await showUI(); -}); -//# sourceMappingURL=main.js.map diff --git a/client/web/dist/main.js.map b/client/web/dist/main.js.map deleted file mode 100644 index d2d6b79..0000000 --- a/client/web/dist/main.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["https://jsr.io/@char/aftercare/0.2.0/src/elem.ts", "https://jsr.io/@char/aftercare/0.2.0/src/jsx.ts", "../../main.tsx"], - "sourcesContent": ["type GenericElement = HTMLElement | SVGElement;\n\ntype IsNullish = [T] extends [null] ? true : [T] extends [undefined] ? true : false;\ntype IsFunctionIsh =\n IsNullish extends true\n ? false\n : // deno-lint-ignore ban-types\n T extends Function | null | undefined\n ? true\n : false;\n\nexport type ElementProps = {\n [K in keyof E as IsFunctionIsh extends true ? never : K]?: E[K];\n};\n\nexport interface ElementExtras {\n classList?: string[];\n dataset?: Partial>;\n /** extra function to run on the element */\n _tap?: (elem: E) => void;\n}\n\nexport type TagName = keyof HTMLElementTagNameMap;\nexport type CustomTagType = new () => T;\nexport type ElementType = T extends TagName\n ? HTMLElementTagNameMap[T]\n : T extends CustomTagType\n ? E\n : never;\n\nexport function elem(\n tag: T,\n attrs: ElementProps> = {},\n children: (Element | string | Text)[] = [],\n extras: ElementExtras> = {},\n): ElementType {\n const element = typeof tag === \"string\" ? document.createElement(tag) : new tag();\n\n Object.assign(\n element,\n Object.fromEntries(Object.entries(attrs).filter(([_k, v]) => v !== undefined)),\n );\n\n if (extras.classList) extras.classList.forEach(c => element.classList.add(c));\n if (extras.dataset && (element instanceof HTMLElement || element instanceof SVGElement))\n Object.entries(extras.dataset)\n .filter(([_k, v]) => v !== undefined)\n .forEach(([k, v]) => (element.dataset[k] = v));\n\n const childNodes = children.map(e =>\n typeof e === \"string\" ? document.createTextNode(e) : e,\n );\n element.append(...childNodes);\n\n if (extras._tap) extras._tap(element as ElementType);\n\n return element as ElementType;\n}\n\nexport function rewrite(element: Element, children: (Element | string | Text)[] = []) {\n element.innerHTML = \"\";\n const nodes = children.map(e => (typeof e === \"string\" ? document.createTextNode(e) : e));\n element.append(...nodes);\n}\n", "import {\n type CustomTagType,\n elem,\n type ElementExtras,\n type ElementProps,\n type ElementType,\n type TagName,\n} from \"./elem.ts\";\n\n// deno-lint-ignore no-namespace\nnamespace JSX {\n export type Element = HTMLElement | SVGElement;\n export type IntrinsicElements = {\n [K in TagName]: Omit>, \"children\"> & {\n children?: JSX.Element | JSX.Element[] | undefined;\n } & Partial>>;\n };\n}\n\nfunction Fragment(props: Record, _key?: string): never {\n return jsx(undefined, props, _key) as never;\n}\n\nfunction jsx(\n tag: T | undefined,\n props: Record,\n _key?: string,\n): ElementType {\n if (tag === undefined) {\n throw new Error(\"fragments are not supported\");\n }\n\n const { children = [], classList, dataset, _tap, ...attrs } = props;\n const childrenArray = Array.isArray(children) ? children : [children];\n const extras = { classList, dataset, _tap } as ElementExtras>;\n return elem(tag, attrs as ElementProps>, childrenArray, extras);\n}\n\nexport { Fragment, jsx, jsx as jsxDEV, jsx as jsxs };\nexport type { JSX };\n", "const main = document.querySelector(\"main\")!;\n\nasync function nav() {\n const nav =