From b58e6e8b7bb96e9484b131c79ba1dfc14910c538 Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Mon, 30 Dec 2024 21:03:29 +0100 Subject: [PATCH] aiproxy web4 bundle --- examples/aiproxy/.gitignore | 2 ++ examples/aiproxy/rollup.config.js | 28 +++++++++++++++++++++++++ examples/aiproxy/web/index.html | 35 ++++++++++++++++++------------- package.json | 5 +++-- 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 examples/aiproxy/rollup.config.js diff --git a/examples/aiproxy/.gitignore b/examples/aiproxy/.gitignore index b52616b..f06f1de 100644 --- a/examples/aiproxy/.gitignore +++ b/examples/aiproxy/.gitignore @@ -1,2 +1,4 @@ target .spin +dist +web4.js diff --git a/examples/aiproxy/rollup.config.js b/examples/aiproxy/rollup.config.js new file mode 100644 index 0000000..6c24732 --- /dev/null +++ b/examples/aiproxy/rollup.config.js @@ -0,0 +1,28 @@ +import html from '@web/rollup-plugin-html'; +import { terser } from 'rollup-plugin-terser'; +import { readFileSync, readdirSync, unlinkSync, writeFileSync } from 'fs'; + +export default { + input: ['./web/index.html'], + output: { dir: 'dist' }, + plugins: [html({ minify: true }), terser(), { + name: 'inline-js', + closeBundle: () => { + const js = readFileSync('dist/main.js').toString(); + const html = readFileSync('dist/index.html').toString() + .replace(``, ``); + + writeFileSync('web4.js', ` +export function web4_get() { + env.value_return(JSON.stringify({ + contentType: 'text/html; charset=UTF-8', + body: '${Buffer.from(html).toString('base64')}' + }) + ); +} + + `); + + } + }], +}; diff --git a/examples/aiproxy/web/index.html b/examples/aiproxy/web/index.html index f00b0c2..5aa3418 100644 --- a/examples/aiproxy/web/index.html +++ b/examples/aiproxy/web/index.html @@ -1,11 +1,14 @@ + - - - OpenAI Proxy Streaming - + + + OpenAI Proxy Streaming + +
@@ -13,22 +16,24 @@
- +
- - - + + +

-
+      
             
         
- - + - - + + + \ No newline at end of file diff --git a/package.json b/package.json index ff4604b..05ea5a7 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test-quickjslib": "cd quickjslib && ./build.sh && node --test", "examples-nft-web4bundle": "cd examples/nft/web4 && rollup -c rollup.config.js", "serve-examples-nft": "http-server -p 8085 examples/nft/web4", - "test-playwright-aiproxy": "yarn playwright test -c examples/aiproxy/playwright.config.js" + "test-playwright-aiproxy": "yarn playwright test -c examples/aiproxy/playwright.config.js", + "aiproxy:web4bundle": "cd examples/aiproxy && rollup -c rollup.config.js" }, "jest": { "transform": {} @@ -28,7 +29,7 @@ "http-server": "^14.1.1", "near-workspaces": "4.0.0", - "rollup": "^2.79.0", + "rollup": "^4.29.1", "rollup-plugin-terser": "^7.0.2" }, "dependencies": {}