diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 6ed174f..e51f28d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,6 +19,8 @@ jobs: - run: pnpm install --frozen-lockfile - run: pnpm run prepare:assets - run: pnpm run check + - run: pnpm run harmony:genui-runtime + - run: pnpm run harmony:genui-runtime:check - run: pnpm run test:harmony - run: pnpm run test:miniapps - run: pnpm run test:brand diff --git a/AGENTS.md b/AGENTS.md index cbd2bc3..87e9f8f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -119,7 +119,7 @@ isolation, run from `shared/` with the Android guide's Java runtime: `./gradlew :core-feature:jvmTest --tests '*promptSuggestion*' --tests '*SessionRecordReplicaTest*'`. These are simulated host streams, not evidence of a live remote connection. -Native mobile surfaces are controllers. Desktop and CLI own execution, files, terminals and SSH credentials. Mobile workspace selection may use only connections already saved on the controlled runtime; it must not create an SSH connection or instantiate another runtime. Carry the selected connection identity through every operation, and report missing identity instead of falling back to local files. +Native mobile remote surfaces are controllers. Desktop and CLI own remote execution, files, terminals and SSH credentials. Mobile workspace selection may use only connections already saved on the controlled runtime; it must not create an SSH connection or instantiate another runtime. Carry the selected connection identity through every operation, and report missing identity instead of falling back to local files. ## Offline Mini Apps diff --git a/package.json b/package.json index 14dc31b..b1de16b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "node": ">=22.12.0" }, "scripts": { + "harmony:genui-runtime": "pnpm run prepare:design && node scripts/build-harmony-genui-runtime.mjs", + "harmony:genui-runtime:check": "node scripts/build-harmony-genui-runtime.mjs --check", "prepare:design": "pnpm --filter @openbitfun/design-tokens run build && pnpm --filter @openbitfun/theme-openbitfun run build", "prepare:assets": "pnpm run prepare:design && node scripts/build-mobile-terminal.mjs --harmony && node src/apps/mobile/miniapps/generate.cjs android && node src/apps/mobile/miniapps/generate.cjs ios", "harmony:architecture": "node scripts/check-harmonyos-architecture.mjs", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e15e35..c975b86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,8 +48,140 @@ importers: design-system/tooling/token-engine: {} + src/apps/mobile/harmonyos/genui-runtime: + dependencies: + '@openbitfun/theme-openbitfun': + specifier: workspace:^ + version: link:../../../../../design-system/packages/theme-openbitfun + '@openuidev/lang-core': + specifier: 1.0.2 + version: 1.0.2(zod@4.6.7) + '@openuidev/react-lang': + specifier: 1.0.2 + version: 1.0.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(zod@4.6.7) + decode-named-character-reference: + specifier: 1.3.0 + version: 1.3.0 + katex: + specifier: ^0.16.25 + version: 0.16.47 + lucide-react: + specifier: ^0.560.0 + version: 0.560.0(react@18.3.1) + maplibre-gl: + specifier: ^6.16.0 + version: 6.19.0(@types/react@19.3.0)(react@18.3.1) + react: + specifier: ^18.3.1 + version: 18.3.1 + react-dom: + specifier: ^18.3.1 + version: 18.3.1(react@18.3.1) + react-markdown: + specifier: ^10.1.0 + version: 10.1.0(@types/react@19.3.0)(react@18.3.1) + remark-gfm: + specifier: ^4.0.1 + version: 4.0.1 + zod: + specifier: ^4.6.7 + version: 4.6.7 + devDependencies: + '@vitejs/plugin-react': + specifier: ^4.6.0 + version: 4.7.0(vite@7.3.8(@types/node@26.6.6)(sass@1.108.2)(yaml@2.8.1)) + sass: + specifier: ^1.93.2 + version: 1.108.2 + vite: + specifier: ^7.0.4 + version: 7.3.8(@types/node@26.6.6)(sass@1.108.2)(yaml@2.8.1) + packages: + '@babel/code-frame@7.29.7': + resolution: {integrity: sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==} + engines: {node: '>=6.9.0'} + + '@babel/compat-data@7.29.7': + resolution: {integrity: sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg==} + engines: {node: '>=6.9.0'} + + '@babel/core@7.29.13': + resolution: {integrity: sha512-j1nvOQCZYSgp7HLmisnCXFTpVvFODiijQ9QHkORfGKWH6YDtskTEeCJS7eV545GZ9UBzrq0e2xsOd5QQ5PjIqw==} + engines: {node: '>=6.9.0'} + + '@babel/generator@7.29.14': + resolution: {integrity: sha512-qSY56jgW5JnSXzuekLVil6zaOQxOCtOHidr65KkaMBw772IuAY28Qx4ZykAcDn8+FRF15qk80XzKwgSc/RYW6g==} + engines: {node: '>=6.9.0'} + + '@babel/helper-compilation-targets@7.29.13': + resolution: {integrity: sha512-8WxJ4/Vmes3ghacj8VOJy3NW8eyHiFY/4thU/LSBuBE470+igjR/j1ZTNn8fV5VdNrLx6iXUwig526UdOvfP0w==} + engines: {node: '>=6.9.0'} + + '@babel/helper-globals@7.29.7': + resolution: {integrity: sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==} + engines: {node: '>=6.9.0'} + + '@babel/helper-module-imports@7.29.7': + resolution: {integrity: sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==} + engines: {node: '>=6.9.0'} + + '@babel/helper-module-transforms@7.29.14': + resolution: {integrity: sha512-2XDvQVd9JESaOgGc4jT2/jquTAO7ppA5noTZQqH+MmZ89yjCzScLwtCPbWtkPZylL+TLWR49IwWmk+QkRR4GsA==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0 + + '@babel/helper-plugin-utils@7.29.7': + resolution: {integrity: sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==} + engines: {node: '>=6.9.0'} + + '@babel/helper-string-parser@7.29.14': + resolution: {integrity: sha512-CXvKMFvM80ihI7Vox9jb+kQjnyjESQNPM+vB7U0Zz6TWuZA+Z/FL0QPMH300h33qJtIx+REeBhXqWOPW48TcAQ==} + engines: {node: '>=6.9.0'} + + '@babel/helper-validator-identifier@7.29.7': + resolution: {integrity: sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==} + engines: {node: '>=6.9.0'} + + '@babel/helper-validator-option@7.29.7': + resolution: {integrity: sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==} + engines: {node: '>=6.9.0'} + + '@babel/helpers@7.29.14': + resolution: {integrity: sha512-6E3Mi1r0B0umq6vmZa4/78q+64fqO2YY0THUdjDPKUCKhNb0yQy5NQIaPHCSD3ryTgiTss//P4JsWS80AsZ6LQ==} + engines: {node: '>=6.9.0'} + + '@babel/parser@7.29.14': + resolution: {integrity: sha512-VL220vXuyO2z3rNIQwY7ftj9UwpqOt+33sH+sBWkOekbsSR2g7EEMnOx24ZlCH0xOA3DM/33SifVFGbnJD8r/w==} + engines: {node: '>=6.0.0'} + hasBin: true + + '@babel/plugin-transform-react-jsx-self@7.29.7': + resolution: {integrity: sha512-TL0hMc9xzy86VD31nUiwzd5otRAcyEPcsegCxolO0PvcXuH1v0kECe/UIznYFihpkvU5wg/jk4v0TTEFfm53fw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + + '@babel/plugin-transform-react-jsx-source@7.29.7': + resolution: {integrity: sha512-06IyK09H3wi4cGbhDBwp5gUGo0IKtnYa8tyTiephirPCK6fbobVGiXMMI5zLQ4aKEYP3wZ3ArU44o+8KMrSG/Q==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + + '@babel/template@7.29.7': + resolution: {integrity: sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==} + engines: {node: '>=6.9.0'} + + '@babel/traverse@7.29.14': + resolution: {integrity: sha512-RAdQJrBgmIH1FWvN0X+1hoDxzMzlP4cv/1Zi4dn4tG1H0cTb+rw7CzUxQJhp1f4ANd8j5vH3fy8BAWFGkBDEsA==} + engines: {node: '>=6.9.0'} + + '@babel/types@7.29.14': + resolution: {integrity: sha512-UjI/dKmwJwT9pOszJitq2G6EObZPnsZUfdCr92z2TlF3EZK9J3EdfOKUrCzHl6wFthbzwhzl1Soc/UIwxRiq6w==} + engines: {node: '>=6.9.0'} + '@emnapi/runtime@1.11.3': resolution: {integrity: sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==} @@ -59,156 +191,312 @@ packages: cpu: [ppc64] os: [aix] + '@esbuild/aix-ppc64@0.28.2': + resolution: {integrity: sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [aix] + '@esbuild/android-arm64@0.25.12': resolution: {integrity: sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==} engines: {node: '>=18'} cpu: [arm64] os: [android] + '@esbuild/android-arm64@0.28.2': + resolution: {integrity: sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==} + engines: {node: '>=18'} + cpu: [arm64] + os: [android] + '@esbuild/android-arm@0.25.12': resolution: {integrity: sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==} engines: {node: '>=18'} cpu: [arm] os: [android] + '@esbuild/android-arm@0.28.2': + resolution: {integrity: sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==} + engines: {node: '>=18'} + cpu: [arm] + os: [android] + '@esbuild/android-x64@0.25.12': resolution: {integrity: sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==} engines: {node: '>=18'} cpu: [x64] os: [android] + '@esbuild/android-x64@0.28.2': + resolution: {integrity: sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==} + engines: {node: '>=18'} + cpu: [x64] + os: [android] + '@esbuild/darwin-arm64@0.25.12': resolution: {integrity: sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==} engines: {node: '>=18'} cpu: [arm64] os: [darwin] + '@esbuild/darwin-arm64@0.28.2': + resolution: {integrity: sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + '@esbuild/darwin-x64@0.25.12': resolution: {integrity: sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==} engines: {node: '>=18'} cpu: [x64] os: [darwin] + '@esbuild/darwin-x64@0.28.2': + resolution: {integrity: sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + '@esbuild/freebsd-arm64@0.25.12': resolution: {integrity: sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==} engines: {node: '>=18'} cpu: [arm64] os: [freebsd] + '@esbuild/freebsd-arm64@0.28.2': + resolution: {integrity: sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [freebsd] + '@esbuild/freebsd-x64@0.25.12': resolution: {integrity: sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==} engines: {node: '>=18'} cpu: [x64] os: [freebsd] + '@esbuild/freebsd-x64@0.28.2': + resolution: {integrity: sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==} + engines: {node: '>=18'} + cpu: [x64] + os: [freebsd] + '@esbuild/linux-arm64@0.25.12': resolution: {integrity: sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==} engines: {node: '>=18'} cpu: [arm64] os: [linux] + '@esbuild/linux-arm64@0.28.2': + resolution: {integrity: sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + '@esbuild/linux-arm@0.25.12': resolution: {integrity: sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==} engines: {node: '>=18'} cpu: [arm] os: [linux] + '@esbuild/linux-arm@0.28.2': + resolution: {integrity: sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==} + engines: {node: '>=18'} + cpu: [arm] + os: [linux] + '@esbuild/linux-ia32@0.25.12': resolution: {integrity: sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==} engines: {node: '>=18'} cpu: [ia32] os: [linux] + '@esbuild/linux-ia32@0.28.2': + resolution: {integrity: sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==} + engines: {node: '>=18'} + cpu: [ia32] + os: [linux] + '@esbuild/linux-loong64@0.25.12': resolution: {integrity: sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==} engines: {node: '>=18'} cpu: [loong64] os: [linux] + '@esbuild/linux-loong64@0.28.2': + resolution: {integrity: sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==} + engines: {node: '>=18'} + cpu: [loong64] + os: [linux] + '@esbuild/linux-mips64el@0.25.12': resolution: {integrity: sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==} engines: {node: '>=18'} cpu: [mips64el] os: [linux] + '@esbuild/linux-mips64el@0.28.2': + resolution: {integrity: sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==} + engines: {node: '>=18'} + cpu: [mips64el] + os: [linux] + '@esbuild/linux-ppc64@0.25.12': resolution: {integrity: sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==} engines: {node: '>=18'} cpu: [ppc64] os: [linux] + '@esbuild/linux-ppc64@0.28.2': + resolution: {integrity: sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [linux] + '@esbuild/linux-riscv64@0.25.12': resolution: {integrity: sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==} engines: {node: '>=18'} cpu: [riscv64] os: [linux] + '@esbuild/linux-riscv64@0.28.2': + resolution: {integrity: sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==} + engines: {node: '>=18'} + cpu: [riscv64] + os: [linux] + '@esbuild/linux-s390x@0.25.12': resolution: {integrity: sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==} engines: {node: '>=18'} cpu: [s390x] os: [linux] + '@esbuild/linux-s390x@0.28.2': + resolution: {integrity: sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==} + engines: {node: '>=18'} + cpu: [s390x] + os: [linux] + '@esbuild/linux-x64@0.25.12': resolution: {integrity: sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==} engines: {node: '>=18'} cpu: [x64] os: [linux] + '@esbuild/linux-x64@0.28.2': + resolution: {integrity: sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + '@esbuild/netbsd-arm64@0.25.12': resolution: {integrity: sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==} engines: {node: '>=18'} cpu: [arm64] os: [netbsd] + '@esbuild/netbsd-arm64@0.28.2': + resolution: {integrity: sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [netbsd] + '@esbuild/netbsd-x64@0.25.12': resolution: {integrity: sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==} engines: {node: '>=18'} cpu: [x64] os: [netbsd] + '@esbuild/netbsd-x64@0.28.2': + resolution: {integrity: sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==} + engines: {node: '>=18'} + cpu: [x64] + os: [netbsd] + '@esbuild/openbsd-arm64@0.25.12': resolution: {integrity: sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==} engines: {node: '>=18'} cpu: [arm64] os: [openbsd] + '@esbuild/openbsd-arm64@0.28.2': + resolution: {integrity: sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openbsd] + '@esbuild/openbsd-x64@0.25.12': resolution: {integrity: sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==} engines: {node: '>=18'} cpu: [x64] os: [openbsd] + '@esbuild/openbsd-x64@0.28.2': + resolution: {integrity: sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==} + engines: {node: '>=18'} + cpu: [x64] + os: [openbsd] + '@esbuild/openharmony-arm64@0.25.12': resolution: {integrity: sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==} engines: {node: '>=18'} cpu: [arm64] os: [openharmony] + '@esbuild/openharmony-arm64@0.28.2': + resolution: {integrity: sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openharmony] + '@esbuild/sunos-x64@0.25.12': resolution: {integrity: sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==} engines: {node: '>=18'} cpu: [x64] os: [sunos] + '@esbuild/sunos-x64@0.28.2': + resolution: {integrity: sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==} + engines: {node: '>=18'} + cpu: [x64] + os: [sunos] + '@esbuild/win32-arm64@0.25.12': resolution: {integrity: sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==} engines: {node: '>=18'} cpu: [arm64] os: [win32] + '@esbuild/win32-arm64@0.28.2': + resolution: {integrity: sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [win32] + '@esbuild/win32-ia32@0.25.12': resolution: {integrity: sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==} engines: {node: '>=18'} cpu: [ia32] os: [win32] + '@esbuild/win32-ia32@0.28.2': + resolution: {integrity: sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==} + engines: {node: '>=18'} + cpu: [ia32] + os: [win32] + '@esbuild/win32-x64@0.25.12': resolution: {integrity: sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==} engines: {node: '>=18'} cpu: [x64] os: [win32] + '@esbuild/win32-x64@0.28.2': + resolution: {integrity: sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + '@img/colour@1.1.0': resolution: {integrity: sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==} engines: {node: '>=18'} @@ -346,149 +634,564 @@ packages: cpu: [x64] os: [win32] - '@puppeteer/browsers@1.9.1': - resolution: {integrity: sha512-PuvK6xZzGhKPvlx3fpfdM2kYY3P/hB1URtK8wA7XUJ6prn6pp22zvJHu48th0SGcHL9SutbPHrFuQgfXTFobWA==} - engines: {node: '>=16.3.0'} - hasBin: true + '@jridgewell/gen-mapping@0.3.13': + resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==} - '@tootallnate/quickjs-emscripten@0.23.0': - resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==} + '@jridgewell/remapping@2.3.5': + resolution: {integrity: sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==} - '@types/node@26.6.6': - resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==} + '@jridgewell/resolve-uri@3.1.3': + resolution: {integrity: sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==} + engines: {node: '>=6.0.0'} - '@types/yauzl@2.10.3': - resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==} + '@jridgewell/sourcemap-codec@1.6.0': + resolution: {integrity: sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==} - '@xterm/addon-fit@0.12.0-beta.141': - resolution: {integrity: sha512-VwmjkK5JxfQOr7RLNKMrJz0j/m3fjW+iqw3/GHqlH0r+rBQUyuBbiV9vuHNfEFtNe6H9DcyjWLwOuyqTN00PJg==} - peerDependencies: - '@xterm/xterm': ^6.1.0-beta.141 + '@jridgewell/trace-mapping@0.3.31': + resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} - '@xterm/xterm@6.1.0-beta.141': - resolution: {integrity: sha512-dwcmHvdFfekzNkb6lirSZnkSET21LKBwlwyRENTsIeU2U+4u0MFztUjO44e+MpDR0y+Mv/eeQza0mvhnkmC1Mg==} + '@mapbox/jsonlint-lines-primitives@2.0.3': + resolution: {integrity: sha512-0SElaV0uMxEnxzBhhX9WTuPyUeMsAN/SS0i16tjuba4/mio63MG9khjC1a0JAiPGXAwvwm4UfHJURCN7nyudQg==} + engines: {node: '>= 22'} - agent-base@7.1.4: - resolution: {integrity: sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==} - engines: {node: '>= 14'} + '@mapbox/point-geometry@1.1.0': + resolution: {integrity: sha512-YGcBz1cg4ATXDCM/71L9xveh4dynfGmcLDqufR+nQQy3fKwsAZsWd/x4621/6uJaeB9mwOHE6hPeDgXz9uViUQ==} - ansi-regex@5.0.1: - resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} - engines: {node: '>=8'} + '@mapbox/tiny-sdf@2.3.0': + resolution: {integrity: sha512-gBvcNDBBB66bgQYvnaJ6Jk+VCaMmVq5+IZR2kWPisT88Z8s0kBQt6hfVi8QgRW8Vpg0UWZzBA4ZSyzHHC+VeRA==} - ansi-styles@4.3.0: - resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} - engines: {node: '>=8'} + '@mapbox/unitbezier@1.0.0': + resolution: {integrity: sha512-fqd515fjBmANKGGsQ286E2Wvj/XvDFpGzwJxq4CI6jMQue6Oy04uCKp+JWKF00xRTmk6cEu1jPJ9p3xqH8YWqQ==} - ast-types@0.13.4: - resolution: {integrity: sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==} - engines: {node: '>=4'} + '@mapbox/vector-tile@3.0.0': + resolution: {integrity: sha512-Qf10S1uIHMk20ri/IVBnpS+esUEkVaR5Hftmz88jTInrpmWgPGJfPe3LVjjlE77trLx8tH6qjTG7uWH9hIq/0Q==} - b4a@1.9.0: - resolution: {integrity: sha512-dpfcF9fDNR6++cthXR67iyhgqWy9CBouAvIWhIntzBG6cvK/cnIPiZQjBwi/ZqjjBEDGfoNDtmB0kTjroOJ3pQ==} - peerDependencies: - react-native-b4a: '*' - peerDependenciesMeta: - react-native-b4a: - optional: true + '@maplibre/geojson-vt@6.3.3': + resolution: {integrity: sha512-sfftN4326foT7uex0aN0jqr+vq/lfgeTfASOd+kvdUd0uMMIgXZDPdntCazKFKKcxPH002NPCy4j396peanWCg==} - bare-buffer@3.7.3: - resolution: {integrity: sha512-77owW16RX6YgdOzddHtM0oGz8wsd0/F9k/0coz6TPmjUHnr/9FwWODVMNKwyYWM/a/ESdTum855nfQxnsKUygA==} - engines: {bare: '>=1.20.0'} + '@maplibre/maplibre-gl-style-spec@26.8.0': + resolution: {integrity: sha512-EClj+0m624zGw5gdCOsI5f88bYzkXfgoP2Sj5VGs2AYg9hZaPxvCumX5KDDs6aKFwl2ut+3jAeLhvrSz7hEsBQ==} + hasBin: true - bare-events@2.9.2: - resolution: {integrity: sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==} + '@maplibre/mlt@1.3.0': + resolution: {integrity: sha512-7M2O7ABM80Oi8XPkfkrjKB8mOBIxGoVgkA52Mu4RMWoBvvMdagQ522+WxVYujZsMpqIr3BpzrTbXrm4k8lCzCQ==} + + '@maplibre/vt-pbf@4.3.3': + resolution: {integrity: sha512-dEe5XUd64RQbxNxy2OzIkJnwNDWjVmSXjCd0A7zLirm7QJ/WWbmtDFIkfsiM4yt1cplqzG6oSivRYeWx1SM1yg==} + + '@openuidev/devtools@0.3.1': + resolution: {integrity: sha512-kOCCsRGwY0w6xL1rVL1zOa9CO97ZrG6YGasRZyCv7FXaDAzbFkEgFy+FhYx6EP7sPKhkgr/jBqunADzhevpBDw==} peerDependencies: - bare-abort-controller: '*' + '@openuidev/observability': '>=0.0.4 <0.1.0' + '@openuidev/react-lang': '>=1.0.0 <2.0.0' + react: ^18.3.1 || ^19.0.0 + react-dom: ^18.0.0 || ^19.0.0 peerDependenciesMeta: - bare-abort-controller: + '@openuidev/react-lang': optional: true - bare-fs@4.8.4: - resolution: {integrity: sha512-MPC2eyrpbk3A873sK4y6rk+Iv4o2enxTjHZ8zH3HO0mjrpm5XjnguY2XmfidIsDV6vnjpbMBKUAJpV0ISD2SsQ==} - engines: {bare: '>=1.28.0'} + '@openuidev/lang-core@1.0.2': + resolution: {integrity: sha512-mxrWXgSmGx9N8ZHFiRgvqCmCH8j3x0PTHJVRvtRPlucxDAihthgMR4W6RXJN5KnCl/5fk1SzcT9JHrvGTKcBFw==} peerDependencies: - bare-buffer: '*' + '@modelcontextprotocol/sdk': '>=1.0.0' + zod: ^3.25.0 || ^4.0.0 peerDependenciesMeta: - bare-buffer: + '@modelcontextprotocol/sdk': optional: true - bare-path@3.1.3: - resolution: {integrity: sha512-8r+FVU/o4zcFmpCDqbqAYhHHbtXPP+cyZKo7DRGRWc7OLlNs4TMaSQEpXL/sIdzyEG0M7RHw4B7xYMGrTc+qrg==} + '@openuidev/observability@0.0.4': + resolution: {integrity: sha512-4fjIrWu3TqTlfDE/m7cG10CH1vV7wQk5GPwMOmXeF9vJtkg92dg4Bdk3AjKgud7H7Xypwwjgt52VcLGZCE2CJQ==} - bare-stream@2.13.4: - resolution: {integrity: sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==} + '@openuidev/react-lang@1.0.2': + resolution: {integrity: sha512-nCNALKj71GmKo5x0dR10hr3LKf88MHxlkVgnsbYQdJTxBd3TbD9wqlgJkBcAZNFD4kPHINJ0iTdUAbR871XWBw==} peerDependencies: - bare-abort-controller: '*' - bare-buffer: '*' - bare-events: '*' + '@modelcontextprotocol/sdk': '>=1.0.0' + react: '*' + react-dom: '*' + react-native: '*' + zod: ^3.25.0 || ^4.0.0 peerDependenciesMeta: - bare-abort-controller: + '@modelcontextprotocol/sdk': optional: true - bare-buffer: + react-dom: optional: true - bare-events: + react-native: optional: true - bare-url@2.5.8: - resolution: {integrity: sha512-G5KTe5Bj6z5pqIxcn3lWlIFIv0rkXbccx0T0Xuf7t4RapfSWvFlcVbrwYXxFZ00PC4lp57OCIk6uXP/r3GbpDw==} + '@parcel/watcher-android-arm64@2.6.0': + resolution: {integrity: sha512-trgpLSCKRC/huFjXX/Smh+0sWe4+YtKfktIToiMl59ghz7z+qkH6kMvNnUbLyRs9N11t8l4svSCs1+5B3rOAhA==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [android] - base64-js@1.5.1: - resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + '@parcel/watcher-darwin-arm64@2.6.0': + resolution: {integrity: sha512-Y3QV0gl7Q1zbfueunkWIERICbEojQFCgpyG7YqOGNFLsckXyI1xu9mAIUpKY9QBYzBtSkN8dBPwd3yiAO9ovMw==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [darwin] - basic-ftp@5.3.1: - resolution: {integrity: sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==} - engines: {node: '>=10.0.0'} + '@parcel/watcher-darwin-x64@2.6.0': + resolution: {integrity: sha512-Ohv6OpzhUfKYD7Beb8kDvG0jbIxORCYY1JRdZnaBtnjjkJxgD7ZVL0nw2sCYd0yTMKTvz3nnTnOF3cDifK+kvw==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [darwin] - buffer-crc32@0.2.13: - resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} + '@parcel/watcher-freebsd-x64@2.6.0': + resolution: {integrity: sha512-5HmXvDgs8VK+74jF9y9/2FE3/OnlcKmc56tjmSrEuZjpSZOGL+fvAu+HKJBdPs9uwoP2hE6TlSUpXZ/C5jUFmQ==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [freebsd] - buffer@5.7.1: - resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} + '@parcel/watcher-linux-arm-glibc@2.6.0': + resolution: {integrity: sha512-Ps/hui3A+vMbjdqlqAowK2ZL8+BO8dBjxeWXj6npTBs3jx4wWmbPpaLuqwrQrSqIVMCnpWo238bJ1U37GhQOYg==} + engines: {node: '>= 10.0.0'} + cpu: [arm] + os: [linux] - chromium-bidi@0.5.8: - resolution: {integrity: sha512-blqh+1cEQbHBKmok3rVJkBlBxt9beKBgOsxbFgs7UJcoVbbeZ+K7+6liAsjgpc8l1Xd55cQUy14fXZdGSb4zIw==} - peerDependencies: - devtools-protocol: '*' + '@parcel/watcher-linux-arm-musl@2.6.0': + resolution: {integrity: sha512-9c6AUHgHoG+IY88MRIHupztQiQnrbqHYQjkM2btA+Bf/wQnQMuiD0Wfk1EVv3TlNT3x41uU71rn6E4xh/+zvkw==} + engines: {node: '>= 10.0.0'} + cpu: [arm] + os: [linux] - cliui@8.0.1: - resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} - engines: {node: '>=12'} + '@parcel/watcher-linux-arm64-glibc@2.6.0': + resolution: {integrity: sha512-yHRqS2owEXe6Hic9z6Mh1ECsCd+ODVOGvZDyciqRd21+v+o+DnXMOrw50DSpIG2sb8GPEaPPmfeCAWKPJdq46g==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [linux] - color-convert@2.0.1: - resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} - engines: {node: '>=7.0.0'} + '@parcel/watcher-linux-arm64-musl@2.6.0': + resolution: {integrity: sha512-WhB2e/V7rqdHHWZusBSPuy5Ei8S6lSz6FE5TKKQz5h3a0O+C+mhY7vxU9b/stqvMb8beLnPY82ZrFTLKs+SrKA==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [linux] - color-name@1.1.4: - resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + '@parcel/watcher-linux-x64-glibc@2.6.0': + resolution: {integrity: sha512-ulGE6x6Oz6iAwg75T8YQSoguBWasniIbX+QWpaYPcCnDOpdWX3k+4xbEYPZVLxOuoJI+svJJPD3sEj8G7lrQ3A==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [linux] - cross-fetch@4.0.0: - resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} + '@parcel/watcher-linux-x64-musl@2.6.0': + resolution: {integrity: sha512-tkBYKt7YQrjIJWYDnto2YgO8MRkjlMTSNoRHzsXinBqbLdeOM3L32wPZJvIZxqaLMfSlS/4sUjH/6STVP/XDLw==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [linux] - data-uri-to-buffer@6.0.2: - resolution: {integrity: sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==} - engines: {node: '>= 14'} + '@parcel/watcher-win32-arm64@2.6.0': + resolution: {integrity: sha512-gIZAP23jaHjGWasY/TY6yL7NHFClf0Ga7FN+iINvk+KN94rhm94lYZhFsbYFNcA04/onvGD9kKmiJLJB2HbNwQ==} + engines: {node: '>= 10.0.0'} + cpu: [arm64] + os: [win32] - debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true + '@parcel/watcher-win32-x64@2.6.0': + resolution: {integrity: sha512-cA+/pXV2YkfxlIcXOQ5fSWqAzzPyD78/x5qbK/I0vUkrlYHA8TIz+MXjAbGouguKVSI4bOmkTSJ1/poVSsgt+A==} + engines: {node: '>= 10.0.0'} + cpu: [x64] + os: [win32] - degenerator@5.0.1: - resolution: {integrity: sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==} - engines: {node: '>= 14'} + '@parcel/watcher@2.6.0': + resolution: {integrity: sha512-7FNeNl8NCE7aINx7WXiKQrPYZWC/hvrTsmk6zmxbI7LTXE7hVek/n8AfVgpe2y82zl3w0HvCHN0bVKMBoJcC0w==} + engines: {node: '>= 10.0.0'} - detect-libc@2.1.2: - resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} + '@puppeteer/browsers@1.9.1': + resolution: {integrity: sha512-PuvK6xZzGhKPvlx3fpfdM2kYY3P/hB1URtK8wA7XUJ6prn6pp22zvJHu48th0SGcHL9SutbPHrFuQgfXTFobWA==} + engines: {node: '>=16.3.0'} + hasBin: true + + '@rolldown/pluginutils@1.0.0-beta.27': + resolution: {integrity: sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==} + + '@rollup/rollup-android-arm-eabi@4.68.5': + resolution: {integrity: sha512-4iPGohjhOlA8ovAwOrHcbsLFw2X0lG49y2iWSlyLrRLJMO47D+XNM930CcGVQKPUpCsDfCdK3BV0y1ki6OBdhw==} + cpu: [arm] + os: [android] + + '@rollup/rollup-android-arm64@4.68.5': + resolution: {integrity: sha512-mBK6NsYThYGRkGy8uX7fODOIT0YHz9UyvtYv/fhqdfEZw8Sg2kPiuUsQ8OmzRfq5ve0nHqZVDz2zLOy1xVaVzQ==} + cpu: [arm64] + os: [android] + + '@rollup/rollup-android-x64@4.68.5': + resolution: {integrity: sha512-8D/A3B5bsLlBcVGsUN+IWcA0wreB+Fvmvs3PLBHyEq3itxGefdPsubG/tPHvezUKPTDAh05YoutzsVFDxkcrJQ==} + cpu: [x64] + os: [android] + + '@rollup/rollup-darwin-arm64@4.68.5': + resolution: {integrity: sha512-xJVTzKZnwwQsQ5WA9cV4Q8l1SVYF9UyVa/3ECoCFfgtow4MUt7HcI3AB8Hwa/4790fimHPXzYfsuyMp67ErQ8w==} + cpu: [arm64] + os: [darwin] + + '@rollup/rollup-darwin-x64@4.68.5': + resolution: {integrity: sha512-0Ft351J6xgaXhBtsRtV1qC1iFRSGzOoEpqbfIw5kPA1/R2ldOON8IVHx15XK6X46OI1QvxkETmWT+BIQxfHiOQ==} + cpu: [x64] + os: [darwin] + + '@rollup/rollup-freebsd-arm64@4.68.5': + resolution: {integrity: sha512-crcRf4EJ792/UuuPf8QduPogDOS9t6E7Mlkvgk8KSBQ/r+ZYyL4VKLEg4GmNmz4AUjq/Mr+4fHJ/RqtCFXq47w==} + cpu: [arm64] + os: [freebsd] + + '@rollup/rollup-freebsd-x64@4.68.5': + resolution: {integrity: sha512-6SrbCoHnaFiipnX4TsDnQ74Zd8puOFQma6WdXDvnh0/Oy5Ash2RbNbeOdfbQNQOyNZe65eAg/G/U+EOoaR284w==} + cpu: [x64] + os: [freebsd] + + '@rollup/rollup-linux-arm-gnueabihf@4.68.5': + resolution: {integrity: sha512-Du8EftwTEY5i9H/VmLrvHrv8W4WpnLSvlT4/th5zQR10baXOQM/8Vn+q4MkNZrWwwulUuhuAUItevugalTNCLA==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm-musleabihf@4.68.5': + resolution: {integrity: sha512-eT4t5h+qexha98N75YpiKMY1XDfimwkVL4TCHgQXr3JRFEqRacd38ldXB7dAAi5G62Mkuxlvw7VBHe5UXY2UHw==} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm64-gnu@4.68.5': + resolution: {integrity: sha512-jUsTbXqgd+cJlwgKePc56J8Yie+JZRWl7xiViSR2eQuloZ26PzWCS7ZJrCEZRmY7vrqhnvnbj6fP1ikinE0dfQ==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-arm64-musl@4.68.5': + resolution: {integrity: sha512-HHjSkN3VAI8ZD45xEO4WcV5+yUB04vpR0r5g0ayLX8YfafV61hAIWoh8Qa22HujnxEtOXYDstF4qKbWGicI2RA==} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-loong64-gnu@4.68.5': + resolution: {integrity: sha512-Y//CvF+v/RiwP6ZscB23xFU+x8BtSbRpwEnVb6140X1TBqSjrZwQwdH/hRCG2FKBaUF2sWsOVjdeZ5UmsF5Cqg==} + cpu: [loong64] + os: [linux] + + '@rollup/rollup-linux-loong64-musl@4.68.5': + resolution: {integrity: sha512-O3fyuDSEV+sXQNTfVfZFPCdc5QymYVxS4PT7YXxsouO/LZhmYy8y6xNZJx9tBQCiR96c2sBfRNLRztkhnvahcg==} + cpu: [loong64] + os: [linux] + + '@rollup/rollup-linux-ppc64-gnu@4.68.5': + resolution: {integrity: sha512-xIzFIoRROEVGJZBc/ljGteOcF/sA6Hjuz+x3zHNdcFc24xlVenPm3RPTOJfNvNVF0MZTyfGq1YYIhG4Tj/nYiA==} + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-ppc64-musl@4.68.5': + resolution: {integrity: sha512-srRfsMFnBDxlmpXwlStiwUSQ/4jCbR4u4i52pZg+bV+Anni0V5EmDeHGZ4YbmTIvM+XhcvEecFcjHmZWFWzVpA==} + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-riscv64-gnu@4.68.5': + resolution: {integrity: sha512-hkrVfI5WMnWaZg0vaM8DlJCRlIUhaRa3Z2BT99AuFl739uIcOnnvpYr7kVhUiPuCvHvWEPgExtXtgNRpBDuxbw==} + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-riscv64-musl@4.68.5': + resolution: {integrity: sha512-ZWDUe13obQhNg0qD1pkft3aWBZgDD26TO3ADvuJ2T9SN/T3h632VRVc+GDCjgRzEnd8a8yCOkl9opkkTPxhF0Q==} + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-s390x-gnu@4.68.5': + resolution: {integrity: sha512-9TsAn9NJQv5NsyGS4yOmJZGlM2ASrzQXC6pc6hrjduk5QwtoapONtooLiDSJlPq6+IAwhS2AdJ9+B8tidcdh5w==} + cpu: [s390x] + os: [linux] + + '@rollup/rollup-linux-x64-gnu@4.68.5': + resolution: {integrity: sha512-JK5S9YhArjVwuetZ9nf6/GdpiXLl7DAVTdRUpF40wVMQNq28hkBrQI1+xy9sqjqtPvW08xagGPfBCBj5wLerZA==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-linux-x64-musl@4.68.5': + resolution: {integrity: sha512-pF0UxfDULcfZhdp5azfIvTW5c++AYjYs0Q8iTCzVCVzVH9+9e0Ah0vIZS3MIZbO7GoyPjTuPjAcUgQQvYbM81A==} + cpu: [x64] + os: [linux] + + '@rollup/rollup-openbsd-x64@4.68.5': + resolution: {integrity: sha512-5bkgrD3xTj4pVAaKZ/D+GBWfWaJtorYRdj8i7nHcCsalDaIgiGVmCb/KucTO8P80UXCcPnqMJGcCS4xM94qsbw==} + cpu: [x64] + os: [openbsd] + + '@rollup/rollup-openharmony-arm64@4.68.5': + resolution: {integrity: sha512-Fu+Jd8JWALOrVQdXTBfqUgkDXqWYqWAfjrpvSuvqYOVaSfwwi2wc9TORUEbbyd/8dsAmHLi04K9FnIwnjvWoJQ==} + cpu: [arm64] + os: [openharmony] + + '@rollup/rollup-win32-arm64-msvc@4.68.5': + resolution: {integrity: sha512-WX+jUzphTWxca8eKMPtNSTW58aW6TxScbKQ3Tc0Nagjwrysy1Bu0Wl7BUt5STCPB+WM0EisGFFAyjfZ952f/JA==} + cpu: [arm64] + os: [win32] + + '@rollup/rollup-win32-ia32-msvc@4.68.5': + resolution: {integrity: sha512-z7EKzmD+jJQ3/ISVQSBkLptuUhtYcPf9Vamg8Ovf2jnZMN/Zvf5xCxHPh+TWPoUx9knc1al4EIOi6c9XayVXyQ==} + cpu: [ia32] + os: [win32] + + '@rollup/rollup-win32-x64-gnu@4.68.5': + resolution: {integrity: sha512-VnHYErHaF8wRwdvq0A92NHmE1/u0sbuSgyTgGyOrH1vO14GWhu9aXERntg9SPnZoyK/LM+X4YawBE4g1FNkLBA==} + cpu: [x64] + os: [win32] + + '@rollup/rollup-win32-x64-msvc@4.68.5': + resolution: {integrity: sha512-gVfBrzSqeYl0/QRJegeK9njmGxojS3oiU9cAHNY0wU22AjS44dGzt4WnnuYsTCNO8P40H4Ulykg8cxq2zWWo9Q==} + cpu: [x64] + os: [win32] + + '@tootallnate/quickjs-emscripten@0.23.0': + resolution: {integrity: sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==} + + '@types/babel__core@7.20.5': + resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} + + '@types/babel__generator@7.27.0': + resolution: {integrity: sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg==} + + '@types/babel__template@7.4.4': + resolution: {integrity: sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==} + + '@types/babel__traverse@7.28.0': + resolution: {integrity: sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==} + + '@types/debug@4.1.13': + resolution: {integrity: sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==} + + '@types/estree-jsx@1.0.5': + resolution: {integrity: sha512-52CcUVNFyfb1A2ALocQw/Dd1BQFNmSdkuC3BkZ6iqhdMfQz7JWOFRuJFloOzjk+6WijU56m9oKXFAXc7o3Towg==} + + '@types/estree@1.0.10': + resolution: {integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==} + + '@types/geojson@7946.0.16': + resolution: {integrity: sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==} + + '@types/hast@3.0.5': + resolution: {integrity: sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==} + + '@types/mdast@4.0.4': + resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==} + + '@types/ms@2.1.0': + resolution: {integrity: sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==} + + '@types/node@26.6.6': + resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==} + + '@types/react@19.3.0': + resolution: {integrity: sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==} + + '@types/unist@2.0.11': + resolution: {integrity: sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==} + + '@types/unist@3.0.3': + resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} + + '@types/yauzl@2.10.3': + resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==} + + '@ungap/structured-clone@1.4.0': + resolution: {integrity: sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==} + + '@vitejs/plugin-react@4.7.0': + resolution: {integrity: sha512-gUu9hwfWvvEDBBmgtAowQCojwZmJ5mcLn3aufeCsitijs3+f2NsrPtlAWIR6OPiqljl96GVCUbLe0HyqIpVaoA==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + vite: ^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 + + '@xterm/addon-fit@0.12.0-beta.141': + resolution: {integrity: sha512-VwmjkK5JxfQOr7RLNKMrJz0j/m3fjW+iqw3/GHqlH0r+rBQUyuBbiV9vuHNfEFtNe6H9DcyjWLwOuyqTN00PJg==} + peerDependencies: + '@xterm/xterm': ^6.1.0-beta.141 + + '@xterm/xterm@6.1.0-beta.141': + resolution: {integrity: sha512-dwcmHvdFfekzNkb6lirSZnkSET21LKBwlwyRENTsIeU2U+4u0MFztUjO44e+MpDR0y+Mv/eeQza0mvhnkmC1Mg==} + + agent-base@7.1.4: + resolution: {integrity: sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==} + engines: {node: '>= 14'} + + ansi-regex@5.0.1: + resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} + engines: {node: '>=8'} + + ansi-styles@4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + + ast-types@0.13.4: + resolution: {integrity: sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==} + engines: {node: '>=4'} + + b4a@1.9.0: + resolution: {integrity: sha512-dpfcF9fDNR6++cthXR67iyhgqWy9CBouAvIWhIntzBG6cvK/cnIPiZQjBwi/ZqjjBEDGfoNDtmB0kTjroOJ3pQ==} + peerDependencies: + react-native-b4a: '*' + peerDependenciesMeta: + react-native-b4a: + optional: true + + bail@2.0.2: + resolution: {integrity: sha512-0xO6mYd7JB2YesxDKplafRpsiOzPt9V02ddPCLbY1xYGPOX24NTyN50qnUxgCPcSoYMhKpAuBTjQoRZCAkUDRw==} + + bare-buffer@3.7.3: + resolution: {integrity: sha512-77owW16RX6YgdOzddHtM0oGz8wsd0/F9k/0coz6TPmjUHnr/9FwWODVMNKwyYWM/a/ESdTum855nfQxnsKUygA==} + engines: {bare: '>=1.20.0'} + + bare-events@2.9.2: + resolution: {integrity: sha512-AIPKioV7/Y/8KfZ3AAhjPJxLLbY49S64Ym5DakZlUg75qQiTgUq9hEJoEwa4eUezPUlXRy/i5NpsKvo9jgKmoA==} + peerDependencies: + bare-abort-controller: '*' + peerDependenciesMeta: + bare-abort-controller: + optional: true + + bare-fs@4.8.4: + resolution: {integrity: sha512-MPC2eyrpbk3A873sK4y6rk+Iv4o2enxTjHZ8zH3HO0mjrpm5XjnguY2XmfidIsDV6vnjpbMBKUAJpV0ISD2SsQ==} + engines: {bare: '>=1.28.0'} + peerDependencies: + bare-buffer: '*' + peerDependenciesMeta: + bare-buffer: + optional: true + + bare-path@3.1.3: + resolution: {integrity: sha512-8r+FVU/o4zcFmpCDqbqAYhHHbtXPP+cyZKo7DRGRWc7OLlNs4TMaSQEpXL/sIdzyEG0M7RHw4B7xYMGrTc+qrg==} + + bare-stream@2.13.4: + resolution: {integrity: sha512-PcrQ8lVLbiJscNm1Kez+Yp4Gy4AHGcN1lzwjvf5NybWen7VvEgUfyfnXYJ2zNqWnzOfCb1Abq6lH8ti0syQszA==} + peerDependencies: + bare-abort-controller: '*' + bare-buffer: '*' + bare-events: '*' + peerDependenciesMeta: + bare-abort-controller: + optional: true + bare-buffer: + optional: true + bare-events: + optional: true + + bare-url@2.5.8: + resolution: {integrity: sha512-G5KTe5Bj6z5pqIxcn3lWlIFIv0rkXbccx0T0Xuf7t4RapfSWvFlcVbrwYXxFZ00PC4lp57OCIk6uXP/r3GbpDw==} + + base64-js@1.5.1: + resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + + baseline-browser-mapping@2.11.38: + resolution: {integrity: sha512-rMgy5YW7x28SMfXHLlVZDBqlWzYZ0x2rVR/6FWrNBF0chjigARK1H6nM0hKA1Um3kPOlkQFVtjJs00d2N1ezuw==} + engines: {node: '>=6.0.0'} + hasBin: true + + basic-ftp@5.3.1: + resolution: {integrity: sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==} + engines: {node: '>=10.0.0'} + + bidi-js@1.1.0: + resolution: {integrity: sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg==} + + browserslist@4.29.6: + resolution: {integrity: sha512-CmVVIQ3RVc5HxYEc9X84GvxK/C8C1wH8TlKAiO7uTxF8PDwt7r8t9Qk3J9NkMOVzX5O/HbLv3yzxZg9HPrnI9w==} + engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} + hasBin: true + + buffer-crc32@0.2.13: + resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} + + buffer@5.7.1: + resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} + + caniuse-lite@1.0.30001826: + resolution: {integrity: sha512-wTB+9tIbLro/BCXwLuNV1meHE4L9dS6dArMDwgYfNBPMYScqClHyGunhkCSDtHhe/69Xl0sHlKgBVZ+fNsYtWA==} + + ccount@2.0.1: + resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==} + + character-entities-html4@2.1.0: + resolution: {integrity: sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==} + + character-entities-legacy@3.0.0: + resolution: {integrity: sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==} + + character-entities@2.0.2: + resolution: {integrity: sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==} + + character-reference-invalid@2.0.1: + resolution: {integrity: sha512-iBZ4F4wRbyORVsu0jPV7gXkOsGYjGHPmAyv+HiHG8gi5PtC9KI2j1+v8/tlibRvjoWX027ypmG/n0HtO5t7unw==} + + chokidar@5.0.0: + resolution: {integrity: sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==} + engines: {node: '>= 20.19.0'} + + chromium-bidi@0.5.8: + resolution: {integrity: sha512-blqh+1cEQbHBKmok3rVJkBlBxt9beKBgOsxbFgs7UJcoVbbeZ+K7+6liAsjgpc8l1Xd55cQUy14fXZdGSb4zIw==} + peerDependencies: + devtools-protocol: '*' + + ci-info@4.5.0: + resolution: {integrity: sha512-d1uM8k5UZEyPza1n/MG3ko8nKupKN0KJpFsipgPcgaCCvV+IqIfJ+NzTjetlLM+UcXZx3+cLrNr76+eAO7G1Mw==} + engines: {node: '>=8'} + + cliui@8.0.1: + resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} + engines: {node: '>=12'} + + color-convert@2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + + color-name@1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + + comma-separated-tokens@2.0.3: + resolution: {integrity: sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==} + + commander@8.3.0: + resolution: {integrity: sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==} + engines: {node: '>= 12'} + + convert-source-map@2.0.0: + resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} + + cross-fetch@4.0.0: + resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} + + csstype@3.2.4: + resolution: {integrity: sha512-PoKaoPzQapnEoqUSnHx1u6W6ku8CVEgKsnpmmzU3m1nwkidpPBQ8V/Zq2+bWNrsOKoKLwTGdbx6xF7BXP1zLVQ==} + + data-uri-to-buffer@6.0.2: + resolution: {integrity: sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==} + engines: {node: '>= 14'} + + debug@4.3.4: + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + + decode-named-character-reference@1.3.0: + resolution: {integrity: sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==} + + degenerator@5.0.1: + resolution: {integrity: sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==} + engines: {node: '>= 14'} + + dequal@2.0.3: + resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} + engines: {node: '>=6'} + + detect-libc@2.1.2: + resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} engines: {node: '>=8'} + devlop@1.1.0: + resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==} + devtools-protocol@0.0.1232444: resolution: {integrity: sha512-pM27vqEfxSxRkTMnF+XCmxSEb6duO5R+t8A9DEEJgy4Wz2RVanje2mmj99B6A3zv2r/qGfYlOvYznUhuokizmg==} + earcut@3.2.4: + resolution: {integrity: sha512-FHc6yNpnTORB0tM5kmZ03iD2mDuNakDE2lvf4Hw1XkfxtEHIGVi01B/GqUSwx+NcC1WGjidAfpTXzeALtPtfpg==} + + electron-to-chromium@1.5.488: + resolution: {integrity: sha512-Uox8y5IeRGB/uXNMNSPfWaiI5/8d/2XG125oc+f2C5JniHcoMxsbCXcVFRZnIsdrgPwZQ6/k5SbSxhBirqQPuA==} + emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -500,10 +1203,19 @@ packages: engines: {node: '>=18'} hasBin: true + esbuild@0.28.2: + resolution: {integrity: sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==} + engines: {node: '>=18'} + hasBin: true + escalade@3.2.0: resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==} engines: {node: '>=6'} + escape-string-regexp@5.0.0: + resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==} + engines: {node: '>=12'} + escodegen@2.1.0: resolution: {integrity: sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==} engines: {node: '>=6.0'} @@ -518,6 +1230,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-util-is-identifier-name@3.0.0: + resolution: {integrity: sha512-hFtqIDZTIUZ9BXLb8y4pYGyk6+wekIivNVTcmvk8NoOh+VeRn5y6cEHzbURrWbfp1fIqdVipilzj+lfaadNZmg==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -525,6 +1240,9 @@ packages: events-universal@1.0.1: resolution: {integrity: sha512-LUd5euvbMLpwOF8m6ivPCbhQeSiYVNb8Vs0fQ8QjXo0JTkEHpz8pxdQf0gStltaPpw0Cca8b39KxvK9cfKRiAw==} + extend@3.0.2: + resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + extract-zip@2.0.1: resolution: {integrity: sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==} engines: {node: '>= 10.17.0'} @@ -536,6 +1254,24 @@ packages: fd-slicer@1.1.0: resolution: {integrity: sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==} + fdir@6.5.0: + resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} + engines: {node: '>=12.0.0'} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + + gensync@1.0.0-beta.2: + resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} + engines: {node: '>=6.9.0'} + get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -548,6 +1284,18 @@ packages: resolution: {integrity: sha512-b1O07XYq8eRuVzBNgJLstU6FYc1tS6wnMtF1I1D9lE8LxZSOGZ7LhxN54yPP6mGw5f2CkXY2BQUL9Fx41qvcIg==} engines: {node: '>= 14'} + gl-matrix@3.4.4: + resolution: {integrity: sha512-latSnyDNt/8zYUB6VIJ6PCh2jBjJX6gnDsoCZ7LyW7GkqrD51EWwa9qCoGixj8YqBtETQK/xY7OmpTF8xz1DdQ==} + + hast-util-to-jsx-runtime@2.3.7: + resolution: {integrity: sha512-F7DNV2NMcTxA4GqPVHnXzX+mpoPHAIY9rJAVH3CZ1FdBZOcBUEjUuvMkMpHVs/sicEtznh9tMGj5WUR9S4E2rg==} + + hast-util-whitespace@3.0.0: + resolution: {integrity: sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==} + + html-url-attributes@3.0.1: + resolution: {integrity: sha512-ol6UPyBWqsrO6EJySPz2O7ZSr856WDrEzM5zMqp+FJJLGMW35cLYmmZnl0vztAZxRUoNZJFTCohfjuIJ8I4QBQ==} + http-proxy-agent@7.0.2: resolution: {integrity: sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==} engines: {node: '>= 14'} @@ -559,18 +1307,233 @@ packages: ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + immutable@5.2.1: + resolution: {integrity: sha512-CgXNM1BhKqpMjFHTyqQSk09OWqzHNJ/U4BdeBgXoBdR2DdgBdOSv131cO1/YMgzopqnka3B/i949UaMLEKUxOA==} + + inline-style-parser@0.2.9: + resolution: {integrity: sha512-IttN8BqKLxzUrnTqHI+/hwAJQItBAUjdoHERCDv+oOuX48VP6bzW8+QjOXSfoevzq3YrYAwX1uLHp8TqO9yIeg==} + ip-address@10.7.6: resolution: {integrity: sha512-00LYkM6byILa9eQIx6qoaXCM40xTLd56AZ4vyaPW3YTyb49VZYPo5xsiAq4tuQ54GH4R7gVdYScJ1B7B77PuTg==} engines: {node: '>= 12'} + is-alphabetical@2.0.1: + resolution: {integrity: sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ==} + + is-alphanumerical@2.0.1: + resolution: {integrity: sha512-hmbYhX/9MUMF5uh7tOXyK/n0ZvWpad5caBA17GsC6vyuCqaWliRG5K1qS9inmUhEMaOBIW7/whAnSwveW/LtZw==} + + is-decimal@2.0.1: + resolution: {integrity: sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A==} + + is-extglob@2.1.1: + resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} + engines: {node: '>=0.10.0'} + is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} + is-glob@4.0.3: + resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} + engines: {node: '>=0.10.0'} + + is-hexadecimal@2.0.1: + resolution: {integrity: sha512-DgZQp241c8oO6cA1SbTEWiXeoxV42vlcJxgH+B3hi1AiqqKruZR3ZGF8In3fj4+/y/7rHvlOZLZtgJ/4ttYGZg==} + + is-plain-obj@4.1.0: + resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==} + engines: {node: '>=12'} + + js-tokens@4.0.0: + resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + + jsesc@3.1.0: + resolution: {integrity: sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==} + engines: {node: '>=6'} + hasBin: true + + json-stringify-pretty-compact@4.0.0: + resolution: {integrity: sha512-3CNZ2DnrpByG9Nqj6Xo8vqbjT4F6N+tb4Gb28ESAZjYZ5yqvmc56J+/kuIwkaAMOyblTQhUW7PxMkUb8Q36N3Q==} + + json5@2.2.3: + resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} + engines: {node: '>=6'} + hasBin: true + + katex@0.16.47: + resolution: {integrity: sha512-Eeo8Ys1doU1z+x8AZsPpQu+p/QcZBI5PeOo7QGQdy2x2m0MU/hYagBbGOmXwr5KVbEfVuWv9LpnQWeehogurjg==} + hasBin: true + + kdbush@4.1.0: + resolution: {integrity: sha512-e9vurzrXJQrFX6ckpHP3bvj5l+9CnYzkxDNnNQ1h2QTqdWsUAJgXiKdGNcOa1EY85dU8KbQ+z/FdQdB7P+9yfQ==} + + longest-streak@3.1.0: + resolution: {integrity: sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g==} + + loose-envify@1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + + lru-cache@5.1.1: + resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} + lru-cache@7.18.3: resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} engines: {node: '>=12'} + lucide-react@0.560.0: + resolution: {integrity: sha512-NwKoUA/aBShsdL8WE5lukV2F/tjHzQRlonQs7fkNGI1sCT0Ay4a9Ap3ST2clUUkcY+9eQ0pBe2hybTQd2fmyDA==} + peerDependencies: + react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 + + lucide-react@0.575.0: + resolution: {integrity: sha512-VuXgKZrk0uiDlWjGGXmKV6MSk9Yy4l10qgVvzGn2AWBx1Ylt0iBexKOAoA6I7JO3m+M9oeovJd3yYENfkUbOeg==} + peerDependencies: + react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 + + maplibre-gl@6.19.0: + resolution: {integrity: sha512-3bOrnfddggUYudLGJFsYFvqulUyvSxy4iQzd/uURI7ZhgYEZifdSrECujRSghaCpc+v/ZsFI0Y6ZsGSilEtE+w==} + engines: {node: '>=16.14.0', npm: '>=8.1.0'} + + markdown-table@3.1.0: + resolution: {integrity: sha512-xpeSCdM+B+6P3ncfgaB7FoDbtJ30xAe6Z18TGT7AgXJsHqCElCICZovQqdRMm7kHgpTyYv36EupqewoFFSB8vw==} + + mdast-util-find-and-replace@3.0.4: + resolution: {integrity: sha512-z4B5c6jrnJ1ltOQemhWYPBSAo6y42Z8Gt2yEgfgNTMcLSU59B8bfj8Z8AnAlJrBGLnqkdAUZ7jdDEqQw3KuipQ==} + + mdast-util-from-markdown@2.1.0: + resolution: {integrity: sha512-KRLgmPaP2H1ul2bpoJkOS+9pAcDAAj9Nu1mqLnh8NLeJG5tlvj42TH80PIGBpROWlRXLk0lDrWNuZCFy/tsB4A==} + + mdast-util-gfm-autolink-literal@2.1.0: + resolution: {integrity: sha512-Jx6QSK8wDo558Bcf7q+1pe0v81g2PVs09Hlvu9xJHmCFRF3sAPW7vXFVIAwBncs3sde92WbsVqNxwdqViA2XnQ==} + + mdast-util-gfm-footnote@2.1.0: + resolution: {integrity: sha512-sqpDWlsHn7Ac9GNZQMeUzPQSMzR6Wv0WKRNvQRg0KqHh02fpTz69Qc1QSseNX29bhz1ROIyNyxExfawVKTm1GQ==} + + mdast-util-gfm-strikethrough@2.0.1: + resolution: {integrity: sha512-OuJHqvr455pwu2OaOrir7dbzqs4jlWKOtlu9L6GjcIjjQwNyw02VntQsr/Ek6/A13vgnXfUhBekWRUP1OkNivw==} + + mdast-util-gfm-table@2.0.1: + resolution: {integrity: sha512-fiIjPrAy4kz68/eFbPHhsiWDGHhqUSVoU1XsfLM5DsEPXw7MxgiVVyulUggFRckVWeT1KXQXkg5vm3kv4oMSOA==} + + mdast-util-gfm-task-list-item@2.0.1: + resolution: {integrity: sha512-jXVO1hvB2hs82g1esi7I9nIJDqiijbQLIyH2jDUb5s7jIAZMr/79h0VHSq7XHKTqpLARRm+DDNjduB7S9+6XZA==} + + mdast-util-gfm@3.1.0: + resolution: {integrity: sha512-0ulfdQOM3ysHhCJ1p06l0b0VKlhU0wuQs3thxZQagjcjPrlFRqY215uZGHHJan9GEAXd9MbfPjFJz+qMkVR6zQ==} + + mdast-util-mdx-expression@2.0.1: + resolution: {integrity: sha512-J6f+9hUp+ldTZqKRSg7Vw5V6MqjATc+3E4gf3CFNcuZNWD8XdyI6zQ8GqH7f8169MM6P7hMBRDVGnn7oHB9kXQ==} + + mdast-util-mdx-jsx@3.2.1: + resolution: {integrity: sha512-oXp1GIa+E9IwIs3a106+tr3Bz2MlTTBvlXjOZMoIat11kk7vjqgmBnksB9WHmWv+gZh7k3IUgpAHlwHB7DH4GQ==} + + mdast-util-mdxjs-esm@2.0.1: + resolution: {integrity: sha512-EcmOpxsZ96CvlP03NghtH1EsLtr0n9Tm4lPUJUBccV9RwUOneqSycg19n5HGzCf+10LozMRSObtVr3ee1WoHtg==} + + mdast-util-phrasing@4.1.0: + resolution: {integrity: sha512-TqICwyvJJpBwvGAMZjj4J2n0X8QWp21b9l0o7eXyVJ25YNWYbJDVIyD1bZXE6WtV6RmKJVYmQAKWa0zWOABz2w==} + + mdast-util-to-hast@13.2.2: + resolution: {integrity: sha512-l2pnmOuqs+SGLVpTVXnRLQu5v1AzvDe181404fbXzzqObVxrAnnVxapAP27pUwzLBL/ABIkgUhGlPVU7QSvIFg==} + + mdast-util-to-markdown@2.2.3: + resolution: {integrity: sha512-dImdB6VZRMRac1SwAW6o1c0ESk/7pFFAMCMuKM+9v7LpTSthMM5nzXpqKw4Mjo66aXVKhNkyrP4bMB9MurPyWg==} + + mdast-util-to-string@4.0.0: + resolution: {integrity: sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==} + + micromark-core-commonmark@2.0.4: + resolution: {integrity: sha512-wxEeE8v8XVvOrxn1TZj74qYhAtTQsSqufHVS3uNVyT1MupXxhyaHk8/9xDNPh9BmL77QNDgWTkZ3RsYHB2ry7w==} + + micromark-extension-gfm-autolink-literal@2.1.0: + resolution: {integrity: sha512-oOg7knzhicgQ3t4QCjCWgTmfNhvQbDDnJeVu9v81r7NltNCVmhPy1fJRX27pISafdjL+SVc4d3l48Gb6pbRypw==} + + micromark-extension-gfm-footnote@2.1.0: + resolution: {integrity: sha512-/yPhxI1ntnDNsiHtzLKYnE3vf9JZ6cAisqVDauhp4CEHxlb4uoOTxOCJ+9s51bIB8U1N1FJ1RXOKTIlD5B/gqw==} + + micromark-extension-gfm-strikethrough@2.1.0: + resolution: {integrity: sha512-ADVjpOOkjz1hhkZLlBiYA9cR2Anf8F4HqZUO6e5eDcPQd0Txw5fxLzzxnEkSkfnD0wziSGiv7sYhk/ktvbf1uw==} + + micromark-extension-gfm-table@2.1.2: + resolution: {integrity: sha512-pRzm4kDTu0MjlmBkxmS9yYhw60nncfcEwu9NNdPFSQEFXS95ZKyIIyTSHu/o3ReBUrLKYEq+7YaXCRn/bPB4MA==} + + micromark-extension-gfm-tagfilter@2.0.0: + resolution: {integrity: sha512-xHlTOmuCSotIA8TW1mDIM6X2O1SiX5P9IuDtqGonFhEK0qgRI4yeC6vMxEV2dgyr2TiD+2PQ10o+cOhdVAcwfg==} + + micromark-extension-gfm-task-list-item@2.1.0: + resolution: {integrity: sha512-qIBZhqxqI6fjLDYFTBIa4eivDMnP+OZqsNwmQ3xNLE4Cxwc+zfQEfbs6tzAo2Hjq+bh6q5F+Z8/cksrLFYWQQw==} + + micromark-extension-gfm@3.0.0: + resolution: {integrity: sha512-vsKArQsicm7t0z2GugkCKtZehqUm31oeGBV/KVSorWSy8ZlNAv7ytjFhvaryUiCUJYqs+NoE6AFhpQvBTM6Q4w==} + + micromark-factory-destination@2.0.1: + resolution: {integrity: sha512-Xe6rDdJlkmbFRExpTOmRj9N3MaWmbAgdpSrBQvCFqhezUn4AHqJHbaEnfbVYYiexVSs//tqOdY/DxhjdCiJnIA==} + + micromark-factory-label@2.0.1: + resolution: {integrity: sha512-VFMekyQExqIW7xIChcXn4ok29YE3rnuyveW3wZQWWqF4Nv9Wk5rgJ99KzPvHjkmPXF93FXIbBp6YdW3t71/7Vg==} + + micromark-factory-space@2.1.0: + resolution: {integrity: sha512-fS8hnLIjnjvdQIj39Geug8wWsR0HrYZ43KShKxNfwT7t2LOHo/LbWZEzEaSOjwtjdCsjoE6syHhonEzW0zv0+Q==} + + micromark-factory-title@2.0.1: + resolution: {integrity: sha512-5bZ+3CjhAd9eChYTHsjy6TGxpOFSKgKKJPJxr293jTbfry2KDoWkhBb6TcPVB4NmzaPhMs1Frm9AZH7OD4Cjzw==} + + micromark-factory-whitespace@2.0.1: + resolution: {integrity: sha512-Ob0nuZ3PKt/n0hORHyvoD9uZhr+Za8sFoP+OnMcnWK5lngSzALgQYKMr9RJVOWLqQYuyn6ulqGWSXdwf6F80lQ==} + + micromark-util-character@2.1.1: + resolution: {integrity: sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==} + + micromark-util-chunked@2.0.1: + resolution: {integrity: sha512-QUNFEOPELfmvv+4xiNg2sRYeS/P84pTW0TCgP5zc9FpXetHY0ab7SxKyAQCNCc1eK0459uoLI1y5oO5Vc1dbhA==} + + micromark-util-classify-character@2.0.1: + resolution: {integrity: sha512-K0kHzM6afW/MbeWYWLjoHQv1sgg2Q9EccHEDzSkxiP/EaagNzCm7T/WMKZ3rjMbvIpvBiZgwR3dKMygtA4mG1Q==} + + micromark-util-combine-extensions@2.0.1: + resolution: {integrity: sha512-OnAnH8Ujmy59JcyZw8JSbK9cGpdVY44NKgSM7E9Eh7DiLS2E9RNQf0dONaGDzEG9yjEl5hcqeIsj4hfRkLH/Bg==} + + micromark-util-decode-numeric-character-reference@2.0.2: + resolution: {integrity: sha512-ccUbYk6CwVdkmCQMyr64dXz42EfHGkPQlBj5p7YVGzq8I7CtjXZJrubAYezf7Rp+bjPseiROqe7G6foFd+lEuw==} + + micromark-util-decode-string@2.0.1: + resolution: {integrity: sha512-nDV/77Fj6eH1ynwscYTOsbK7rR//Uj0bZXBwJZRfaLEJ1iGBR6kIfNmlNqaqJf649EP0F3NWNdeJi03elllNUQ==} + + micromark-util-edit-map@1.0.0: + resolution: {integrity: sha512-Pa2ljlsEL6sVwFaYeyrOLSYbQt73JvGbPOYFq+9AElXiSnfI5Q4465RRZ1sHv7lDjDOnGRDDaqPXqClqWK/q1Q==} + + micromark-util-encode@2.0.1: + resolution: {integrity: sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==} + + micromark-util-html-tag-name@2.0.1: + resolution: {integrity: sha512-2cNEiYDhCWKI+Gs9T0Tiysk136SnR13hhO8yW6BGNyhOC4qYFnwF1nKfD3HFAIXA5c45RrIG1ub11GiXeYd1xA==} + + micromark-util-normalize-identifier@2.0.1: + resolution: {integrity: sha512-sxPqmo70LyARJs0w2UclACPUUEqltCkJ6PhKdMIDuJ3gSf/Q+/GIe3WKl0Ijb/GyH9lOpUkRAO2wp0GVkLvS9Q==} + + micromark-util-resolve-all@2.0.1: + resolution: {integrity: sha512-VdQyxFWFT2/FGJgwQnJYbe1jjQoNTS4RjglmSjTUlpUMa95Htx9NHeYW4rGDJzbjvCsl9eLjMQwGeElsqmzcHg==} + + micromark-util-sanitize-uri@2.0.1: + resolution: {integrity: sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==} + + micromark-util-subtokenize@2.1.0: + resolution: {integrity: sha512-XQLu552iSctvnEcgXw6+Sx75GflAPNED1qx7eBJ+wydBb2KCbRZe+NwvIEEMM83uml1+2WSXpBAcp9IUCgCYWA==} + + micromark-util-symbol@2.0.1: + resolution: {integrity: sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==} + + micromark-util-types@2.0.3: + resolution: {integrity: sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==} + + micromark@4.0.3: + resolution: {integrity: sha512-oGYfQzHSG5dOMovQcJ3fyTmZlWAWpi0XA0sJwJs+i6OT88o1+Jtw/8z0CmdowSLxGhhFK89rQ/oXph/wN02PNw==} + + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + mitt@3.0.1: resolution: {integrity: sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==} @@ -580,10 +1543,21 @@ packages: ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} + murmurhash-js@1.0.0: + resolution: {integrity: sha512-TvmkNhkv8yct0SVBSy+o8wYzXjE4Zz3PCesbfs8HiCXXdcTuocApFv11UWlNFWKYsP2okqrhb7JNlSm9InBhIw==} + + nanoid@3.3.20: + resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + netmask@2.1.1: resolution: {integrity: sha512-eonl3sLUha+S1GzTPxychyhnUzKyeQkZ7jLjKrBagJgPla13F+uQ71HgpFefyHgqrjEbCPkDArxYsjY8/+gLKA==} engines: {node: '>= 0.4.0'} + node-addon-api@7.1.1: + resolution: {integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==} + node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -593,6 +1567,10 @@ packages: encoding: optional: true + node-releases@2.0.65: + resolution: {integrity: sha512-PfvofsGQ+MiOQIPkX9fU8ELUWmy5zL74CdQaph/ismKszfFkfwXaw0cGiwbwym2hT9k5+mdyl8O5WQ1MD8EHmA==} + engines: {node: '>=18'} + once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} @@ -604,13 +1582,40 @@ packages: resolution: {integrity: sha512-5NPgf87AT2STgwa2ntRMr45jTKrYBGkVU36yT0ig/n/GMAa3oPqhZfIQ2kMEimReg0+t9kZViDVZ83qfVUlckg==} engines: {node: '>= 14'} + parse-entities@4.0.2: + resolution: {integrity: sha512-GG2AQYWoLgL877gQIKeRPGO1xF9+eG1ujIb5soS5gPvLQ1y2o8FL90w2QWNdf9I361Mpp7726c+lj3U0qK1uGw==} + + pbf@5.1.2: + resolution: {integrity: sha512-mnvGdvOrIvJOBGUEdGkrVXjN8E/VkIJCkf2eS1DH2yv82ORUlLttmDt0rWY38yYZmVwciZwBUvHM20qxBZf40w==} + hasBin: true + pend@1.2.0: resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==} + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} + + picomatch@4.0.7: + resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} + engines: {node: '>=12'} + + postcss@8.5.33: + resolution: {integrity: sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==} + engines: {node: ^10 || ^12 || >=14} + + potpack@2.1.0: + resolution: {integrity: sha512-pcaShQc1Shq0y+E7GqJqvZj8DTthWV1KeHGdi0Z6IAin2Oi3JnLCOfwnCo84qc+HAp52wT9nK9H7FAJp5a44GQ==} + progress@2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} engines: {node: '>=0.4.0'} + property-information@7.2.0: + resolution: {integrity: sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==} + + protocol-buffers-schema@3.6.1: + resolution: {integrity: sha512-VG2K63Igkiv9p76tk1lilczEK1cT+kCjKtkdhw1dQZV3k3IXJbd3o6Ho8b9zJZaHSnT2hKe4I+ObmX9w6m5SmQ==} + proxy-agent@6.3.1: resolution: {integrity: sha512-Rb5RVBy1iyqOtNl15Cw/llpeLH8bsb37gM1FUfKQ+Wck6xHlbAhWGUFiTRHtkjqGTA5pSHz6+0hrPW/oECihPQ==} engines: {node: '>= 14'} @@ -625,10 +1630,72 @@ packages: resolution: {integrity: sha512-ArbnyA3U5SGHokEvkfWjW+O8hOxV1RSJxOgriX/3A4xZRqixt9ZFHD0yPgZQF05Qj0oAqi8H/7stDorjoHY90Q==} engines: {node: '>=16.13.2'} + quickselect@3.0.0: + resolution: {integrity: sha512-XdjUArbK4Bm5fLLvlm5KpTFOiOThgfWWI4axAZDWg4E/0mKdZyI9tNEfds27qCi1ze/vwTR16kvmmGhRra3c2g==} + + react-dom@18.3.1: + resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==} + peerDependencies: + react: ^18.3.1 + + react-markdown@10.1.0: + resolution: {integrity: sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==} + peerDependencies: + '@types/react': '>=18' + react: '>=18' + + react-refresh@0.17.0: + resolution: {integrity: sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==} + engines: {node: '>=0.10.0'} + + react@18.3.1: + resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} + engines: {node: '>=0.10.0'} + + readdirp@5.1.1: + resolution: {integrity: sha512-Kko+Y5XQ6fM+Ce3dq3m9YGxnacYZYl9cA1wZjaF3Vbry2L3i1qVg8+CAgNPsXRArPMUMCaOR7oa9Nqntc43JKA==} + engines: {node: '>= 20.19.0'} + + remark-gfm@4.0.1: + resolution: {integrity: sha512-1quofZ2RQ9EWdeN34S79+KExV1764+wCUGop5CPL1WGdD0ocPpu91lzPGbwWMECpEpd42kJGQwzRfyov9j4yNg==} + + remark-parse@11.0.0: + resolution: {integrity: sha512-FCxlKLNGknS5ba/1lmpYijMUzX2esxW5xQqjWxw2eHFfS2MSdaHVINFmhjo+qN1WhZhNimq0dZATN9pH0IDrpA==} + + remark-rehype@11.1.2: + resolution: {integrity: sha512-Dh7l57ianaEoIpzbp0PC9UKAdCSVklD8E5Rpw7ETfbTl3FqcOOgq5q2LVDhgGCkaBv7p24JXikPdvhhmHvKMsw==} + + remark-stringify@11.0.0: + resolution: {integrity: sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw==} + require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} + require-from-string@2.0.2: + resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} + engines: {node: '>=0.10.0'} + + resolve-protobuf-schema@2.1.0: + resolution: {integrity: sha512-kI5ffTiZWmJaS/huM8wZfEMer1eRd7oJQhDuxeCLe3t7N7mX3z94CN0xPxBQxFYQTSNz9T0i+v6inKqSdK8xrQ==} + + rollup@4.68.5: + resolution: {integrity: sha512-m6toRYCueVCY+5aEIriX7Dc36g3EHzn3Wk7xCW5aGgCQtTo4uXLZiZPNhDFMmPfVSvC92y3wEwIP2DCUp/ukXg==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + + sass@1.108.2: + resolution: {integrity: sha512-kugK8djotnG9HQRPTOf36asKYlxg8rWWsNLYHOgWDIVOiZQqlRfKBgF4XXM6kfw146kIDMvm57B4GIkvDSyTzA==} + engines: {node: '>=20.19.0'} + hasBin: true + + scheduler@0.23.2: + resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} + + semver@6.3.2: + resolution: {integrity: sha512-GYrCADwpu6yV5OAvchkQ27Z5wwMxWAEMg5NNWjyHh/5DboFFqbdbvYNIvZouQpxXyeMPoTOh0vdPYKlf0ZswdQ==} + hasBin: true + semver@7.8.6: resolution: {integrity: sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==} engines: {node: '>=10'} @@ -650,10 +1717,17 @@ packages: resolution: {integrity: sha512-e0VyvkVTwVYViNovRkZ9aodhxVlyoMn7eJhVUPxZ+eK9P/7CBkxvvsBOHqFPEH416726W8tLXXXjKwqgTErrCQ==} engines: {node: '>= 10.0.0', npm: '>= 3.0.0'} + source-map-js@1.2.2: + resolution: {integrity: sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==} + engines: {node: '>=0.10.0'} + source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} + space-separated-tokens@2.0.2: + resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==} + streamx@2.28.1: resolution: {integrity: sha512-zEzXb0s5Cds7tqMH6rhZ05lcJydCWiQPEwiNngVqzsxCc962vLY4Uw+mW7od8kDH258k2Uz/JrOkdIAAhSh9VA==} @@ -661,10 +1735,16 @@ packages: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} + stringify-entities@4.0.4: + resolution: {integrity: sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==} + strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} + style-to-object@2.0.2: + resolution: {integrity: sha512-QmbXPUylqU80HAgTOJeEOdbA40W9KtxmjMhQy+tq+b8F2aoh3aQLuy82hh2jm2qsC9hR9eI0+eQidTMydKcqRA==} + tar-fs@3.0.4: resolution: {integrity: sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==} @@ -680,9 +1760,22 @@ packages: through@2.3.8: resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==} + tinyglobby@0.2.17: + resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} + engines: {node: '>=12.0.0'} + + tinyqueue@3.0.0: + resolution: {integrity: sha512-gRa9gwYU3ECmQYv3lslts5hxuIa90veaEcxDYuu3QGOIAEM2mOZkVHp48ANJuu1CURtRdHKUBY5Lm1tHV+sD4g==} + tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} + trim-lines@3.0.1: + resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==} + + trough@2.2.0: + resolution: {integrity: sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw==} + tslib@2.9.1: resolution: {integrity: sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==} @@ -697,55 +1790,264 @@ packages: undici-types@8.9.0: resolution: {integrity: sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==} + unified@11.0.5: + resolution: {integrity: sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==} + + unist-util-is@6.0.1: + resolution: {integrity: sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==} + + unist-util-position@5.0.0: + resolution: {integrity: sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==} + + unist-util-stringify-position@4.0.0: + resolution: {integrity: sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==} + + unist-util-visit-parents@6.1.0: + resolution: {integrity: sha512-vKXxz6O38sKDj1mtx/k2cWvkkFBuYGx6uGrlzBkVeWCRF/F8sdI0j3Wbkz/5rVNRRuVc8UrgRdbCxNhmYXgP3w==} + + unist-util-visit@5.2.0: + resolution: {integrity: sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ==} + + update-browserslist-db@1.4.0: + resolution: {integrity: sha512-WPJuOnjI9FWDct4fB+ej4Mz8opLaw5CDcZ2t44tFZ0vIQVYWzBhWR3mkixuUj/A7+vY4V9+ApOZ2YYLwdgq46w==} + hasBin: true + peerDependencies: + browserslist: '>= 4.21.0' + urlpattern-polyfill@10.0.0: resolution: {integrity: sha512-H/A06tKD7sS1O1X2SshBVeA5FLycRpjqiBeqGKmBwBDBy28EnRjORxTNe269KSSr5un5qyWi1iL61wLxpd+ZOg==} + vfile-message@4.0.4: + resolution: {integrity: sha512-66ycRswIkNmHH9PHku7ADtv5RVwgIrOcuv3J8Svz6h4qgGRrKVa+9/neuKyJZUXyOpYwLTvS+whZ4R2urHHgQg==} + + vfile@6.0.3: + resolution: {integrity: sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==} + + vite@7.3.8: + resolution: {integrity: sha512-3tTi78MAKhVk9h+YZVXMQ8POmneJuE97QUPAWtJghHzhH7BAyiqQOC2KZh1DWOsu/USB2cRXhznPByaabvYXfw==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + jiti: '>=1.21.0' + less: ^4.0.0 + lightningcss: ^1.21.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + jiti: + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - whatwg-url@5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} + whatwg-url@5.0.0: + resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} + + wrap-ansi@7.0.0: + resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} + engines: {node: '>=10'} + + wrappy@1.0.2: + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + + ws@8.16.0: + resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + + y18n@5.0.8: + resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} + engines: {node: '>=10'} + + yallist@3.1.1: + resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} + + yaml@2.8.1: + resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==} + engines: {node: '>= 14.6'} + hasBin: true + + yargs-parser@21.1.1: + resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} + engines: {node: '>=12'} + + yargs@17.7.2: + resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} + engines: {node: '>=12'} + + yauzl@2.10.0: + resolution: {integrity: sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==} + + zod@4.6.7: + resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==} + + zustand@5.1.0: + resolution: {integrity: sha512-ciJZlP48M1PTQbVQq81CGVFxHTLpZNrFjKqwjtCU34AWuXTZT/jrF3p9+fI84Cf1eSCMLapxqBy/SNTfwOBuqA==} + engines: {node: '>=12.20.0'} + peerDependencies: + '@types/react': '>=18.0.0' + immer: '>=9.0.6' + react: '>=18.0.0' + use-sync-external-store: '>=1.2.0' + peerDependenciesMeta: + '@types/react': + optional: true + immer: + optional: true + react: + optional: true + use-sync-external-store: + optional: true + + zwitch@2.0.4: + resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} + +snapshots: + + '@babel/code-frame@7.29.7': + dependencies: + '@babel/helper-validator-identifier': 7.29.7 + js-tokens: 4.0.0 + picocolors: 1.1.1 + + '@babel/compat-data@7.29.7': {} + + '@babel/core@7.29.13': + dependencies: + '@babel/code-frame': 7.29.7 + '@babel/generator': 7.29.14 + '@babel/helper-compilation-targets': 7.29.13 + '@babel/helper-module-transforms': 7.29.14(@babel/core@7.29.13) + '@babel/helpers': 7.29.14 + '@babel/parser': 7.29.14 + '@babel/template': 7.29.7 + '@babel/traverse': 7.29.14 + '@babel/types': 7.29.14 + '@jridgewell/remapping': 2.3.5 + convert-source-map: 2.0.0 + debug: 4.3.4 + gensync: 1.0.0-beta.2 + json5: 2.2.3 + semver: 6.3.2 + transitivePeerDependencies: + - supports-color + + '@babel/generator@7.29.14': + dependencies: + '@babel/parser': 7.29.14 + '@babel/types': 7.29.14 + '@jridgewell/gen-mapping': 0.3.13 + '@jridgewell/trace-mapping': 0.3.31 + jsesc: 3.1.0 + + '@babel/helper-compilation-targets@7.29.13': + dependencies: + '@babel/compat-data': 7.29.7 + '@babel/helper-validator-option': 7.29.7 + browserslist: 4.29.6 + lru-cache: 5.1.1 + semver: 6.3.2 + + '@babel/helper-globals@7.29.7': {} + + '@babel/helper-module-imports@7.29.7': + dependencies: + '@babel/traverse': 7.29.14 + '@babel/types': 7.29.14 + transitivePeerDependencies: + - supports-color + + '@babel/helper-module-transforms@7.29.14(@babel/core@7.29.13)': + dependencies: + '@babel/core': 7.29.13 + '@babel/helper-module-imports': 7.29.7 + '@babel/helper-validator-identifier': 7.29.7 + '@babel/traverse': 7.29.14 + transitivePeerDependencies: + - supports-color + + '@babel/helper-plugin-utils@7.29.7': {} + + '@babel/helper-string-parser@7.29.14': {} - wrap-ansi@7.0.0: - resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} - engines: {node: '>=10'} + '@babel/helper-validator-identifier@7.29.7': {} - wrappy@1.0.2: - resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + '@babel/helper-validator-option@7.29.7': {} - ws@8.16.0: - resolution: {integrity: sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==} - engines: {node: '>=10.0.0'} - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: '>=5.0.2' - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true + '@babel/helpers@7.29.14': + dependencies: + '@babel/template': 7.29.7 + '@babel/types': 7.29.14 - y18n@5.0.8: - resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} - engines: {node: '>=10'} + '@babel/parser@7.29.14': + dependencies: + '@babel/types': 7.29.14 - yaml@2.8.1: - resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==} - engines: {node: '>= 14.6'} - hasBin: true + '@babel/plugin-transform-react-jsx-self@7.29.7(@babel/core@7.29.13)': + dependencies: + '@babel/core': 7.29.13 + '@babel/helper-plugin-utils': 7.29.7 - yargs-parser@21.1.1: - resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} - engines: {node: '>=12'} + '@babel/plugin-transform-react-jsx-source@7.29.7(@babel/core@7.29.13)': + dependencies: + '@babel/core': 7.29.13 + '@babel/helper-plugin-utils': 7.29.7 - yargs@17.7.2: - resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} - engines: {node: '>=12'} + '@babel/template@7.29.7': + dependencies: + '@babel/code-frame': 7.29.7 + '@babel/parser': 7.29.14 + '@babel/types': 7.29.14 - yauzl@2.10.0: - resolution: {integrity: sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==} + '@babel/traverse@7.29.14': + dependencies: + '@babel/code-frame': 7.29.7 + '@babel/generator': 7.29.14 + '@babel/helper-globals': 7.29.7 + '@babel/parser': 7.29.14 + '@babel/template': 7.29.7 + '@babel/types': 7.29.14 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color -snapshots: + '@babel/types@7.29.14': + dependencies: + '@babel/helper-string-parser': 7.29.14 + '@babel/helper-validator-identifier': 7.29.7 '@emnapi/runtime@1.11.3': dependencies: @@ -755,81 +2057,159 @@ snapshots: '@esbuild/aix-ppc64@0.25.12': optional: true + '@esbuild/aix-ppc64@0.28.2': + optional: true + '@esbuild/android-arm64@0.25.12': optional: true + '@esbuild/android-arm64@0.28.2': + optional: true + '@esbuild/android-arm@0.25.12': optional: true + '@esbuild/android-arm@0.28.2': + optional: true + '@esbuild/android-x64@0.25.12': optional: true + '@esbuild/android-x64@0.28.2': + optional: true + '@esbuild/darwin-arm64@0.25.12': optional: true + '@esbuild/darwin-arm64@0.28.2': + optional: true + '@esbuild/darwin-x64@0.25.12': optional: true + '@esbuild/darwin-x64@0.28.2': + optional: true + '@esbuild/freebsd-arm64@0.25.12': optional: true + '@esbuild/freebsd-arm64@0.28.2': + optional: true + '@esbuild/freebsd-x64@0.25.12': optional: true + '@esbuild/freebsd-x64@0.28.2': + optional: true + '@esbuild/linux-arm64@0.25.12': optional: true + '@esbuild/linux-arm64@0.28.2': + optional: true + '@esbuild/linux-arm@0.25.12': optional: true + '@esbuild/linux-arm@0.28.2': + optional: true + '@esbuild/linux-ia32@0.25.12': optional: true + '@esbuild/linux-ia32@0.28.2': + optional: true + '@esbuild/linux-loong64@0.25.12': optional: true + '@esbuild/linux-loong64@0.28.2': + optional: true + '@esbuild/linux-mips64el@0.25.12': optional: true + '@esbuild/linux-mips64el@0.28.2': + optional: true + '@esbuild/linux-ppc64@0.25.12': optional: true + '@esbuild/linux-ppc64@0.28.2': + optional: true + '@esbuild/linux-riscv64@0.25.12': optional: true + '@esbuild/linux-riscv64@0.28.2': + optional: true + '@esbuild/linux-s390x@0.25.12': optional: true + '@esbuild/linux-s390x@0.28.2': + optional: true + '@esbuild/linux-x64@0.25.12': optional: true + '@esbuild/linux-x64@0.28.2': + optional: true + '@esbuild/netbsd-arm64@0.25.12': optional: true + '@esbuild/netbsd-arm64@0.28.2': + optional: true + '@esbuild/netbsd-x64@0.25.12': optional: true + '@esbuild/netbsd-x64@0.28.2': + optional: true + '@esbuild/openbsd-arm64@0.25.12': optional: true + '@esbuild/openbsd-arm64@0.28.2': + optional: true + '@esbuild/openbsd-x64@0.25.12': optional: true + '@esbuild/openbsd-x64@0.28.2': + optional: true + '@esbuild/openharmony-arm64@0.25.12': optional: true + '@esbuild/openharmony-arm64@0.28.2': + optional: true + '@esbuild/sunos-x64@0.25.12': optional: true + '@esbuild/sunos-x64@0.28.2': + optional: true + '@esbuild/win32-arm64@0.25.12': optional: true + '@esbuild/win32-arm64@0.28.2': + optional: true + '@esbuild/win32-ia32@0.25.12': optional: true + '@esbuild/win32-ia32@0.28.2': + optional: true + '@esbuild/win32-x64@0.25.12': optional: true + '@esbuild/win32-x64@0.28.2': + optional: true + '@img/colour@1.1.0': {} '@img/sharp-darwin-arm64@0.34.5': @@ -926,6 +2306,145 @@ snapshots: '@img/sharp-win32-x64@0.34.5': optional: true + '@jridgewell/gen-mapping@0.3.13': + dependencies: + '@jridgewell/sourcemap-codec': 1.6.0 + '@jridgewell/trace-mapping': 0.3.31 + + '@jridgewell/remapping@2.3.5': + dependencies: + '@jridgewell/gen-mapping': 0.3.13 + '@jridgewell/trace-mapping': 0.3.31 + + '@jridgewell/resolve-uri@3.1.3': {} + + '@jridgewell/sourcemap-codec@1.6.0': {} + + '@jridgewell/trace-mapping@0.3.31': + dependencies: + '@jridgewell/resolve-uri': 3.1.3 + '@jridgewell/sourcemap-codec': 1.6.0 + + '@mapbox/jsonlint-lines-primitives@2.0.3': {} + + '@mapbox/point-geometry@1.1.0': {} + + '@mapbox/tiny-sdf@2.3.0': {} + + '@mapbox/unitbezier@1.0.0': {} + + '@mapbox/vector-tile@3.0.0': + dependencies: + '@mapbox/point-geometry': 1.1.0 + '@types/geojson': 7946.0.16 + pbf: 5.1.2 + + '@maplibre/geojson-vt@6.3.3': + dependencies: + kdbush: 4.1.0 + + '@maplibre/maplibre-gl-style-spec@26.8.0': + dependencies: + '@mapbox/jsonlint-lines-primitives': 2.0.3 + '@mapbox/unitbezier': 1.0.0 + json-stringify-pretty-compact: 4.0.0 + minimist: 1.2.8 + quickselect: 3.0.0 + tinyqueue: 3.0.0 + + '@maplibre/mlt@1.3.0': + dependencies: + '@mapbox/point-geometry': 1.1.0 + + '@maplibre/vt-pbf@4.3.3': + dependencies: + '@mapbox/point-geometry': 1.1.0 + '@types/geojson': 7946.0.16 + pbf: 5.1.2 + + '@openuidev/devtools@0.3.1(@openuidev/observability@0.0.4)(@openuidev/react-lang@1.0.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(zod@4.6.7))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@openuidev/observability': 0.0.4 + lucide-react: 0.575.0(react@18.3.1) + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + optionalDependencies: + '@openuidev/react-lang': 1.0.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(zod@4.6.7) + + '@openuidev/lang-core@1.0.2(zod@4.6.7)': + dependencies: + ci-info: 4.5.0 + zod: 4.6.7 + + '@openuidev/observability@0.0.4': {} + + '@openuidev/react-lang@1.0.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(zod@4.6.7)': + dependencies: + '@openuidev/devtools': 0.3.1(@openuidev/observability@0.0.4)(@openuidev/react-lang@1.0.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(zod@4.6.7))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@openuidev/lang-core': 1.0.2(zod@4.6.7) + '@openuidev/observability': 0.0.4 + react: 18.3.1 + zod: 4.6.7 + optionalDependencies: + react-dom: 18.3.1(react@18.3.1) + + '@parcel/watcher-android-arm64@2.6.0': + optional: true + + '@parcel/watcher-darwin-arm64@2.6.0': + optional: true + + '@parcel/watcher-darwin-x64@2.6.0': + optional: true + + '@parcel/watcher-freebsd-x64@2.6.0': + optional: true + + '@parcel/watcher-linux-arm-glibc@2.6.0': + optional: true + + '@parcel/watcher-linux-arm-musl@2.6.0': + optional: true + + '@parcel/watcher-linux-arm64-glibc@2.6.0': + optional: true + + '@parcel/watcher-linux-arm64-musl@2.6.0': + optional: true + + '@parcel/watcher-linux-x64-glibc@2.6.0': + optional: true + + '@parcel/watcher-linux-x64-musl@2.6.0': + optional: true + + '@parcel/watcher-win32-arm64@2.6.0': + optional: true + + '@parcel/watcher-win32-x64@2.6.0': + optional: true + + '@parcel/watcher@2.6.0': + dependencies: + detect-libc: 2.1.2 + is-glob: 4.0.3 + node-addon-api: 7.1.1 + picomatch: 4.0.7 + optionalDependencies: + '@parcel/watcher-android-arm64': 2.6.0 + '@parcel/watcher-darwin-arm64': 2.6.0 + '@parcel/watcher-darwin-x64': 2.6.0 + '@parcel/watcher-freebsd-x64': 2.6.0 + '@parcel/watcher-linux-arm-glibc': 2.6.0 + '@parcel/watcher-linux-arm-musl': 2.6.0 + '@parcel/watcher-linux-arm64-glibc': 2.6.0 + '@parcel/watcher-linux-arm64-musl': 2.6.0 + '@parcel/watcher-linux-x64-glibc': 2.6.0 + '@parcel/watcher-linux-x64-musl': 2.6.0 + '@parcel/watcher-win32-arm64': 2.6.0 + '@parcel/watcher-win32-x64': 2.6.0 + optional: true + '@puppeteer/browsers@1.9.1(bare-buffer@3.7.3)': dependencies: debug: 4.3.4 @@ -941,18 +2460,163 @@ snapshots: - react-native-b4a - supports-color + '@rolldown/pluginutils@1.0.0-beta.27': {} + + '@rollup/rollup-android-arm-eabi@4.68.5': + optional: true + + '@rollup/rollup-android-arm64@4.68.5': + optional: true + + '@rollup/rollup-android-x64@4.68.5': + optional: true + + '@rollup/rollup-darwin-arm64@4.68.5': + optional: true + + '@rollup/rollup-darwin-x64@4.68.5': + optional: true + + '@rollup/rollup-freebsd-arm64@4.68.5': + optional: true + + '@rollup/rollup-freebsd-x64@4.68.5': + optional: true + + '@rollup/rollup-linux-arm-gnueabihf@4.68.5': + optional: true + + '@rollup/rollup-linux-arm-musleabihf@4.68.5': + optional: true + + '@rollup/rollup-linux-arm64-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-arm64-musl@4.68.5': + optional: true + + '@rollup/rollup-linux-loong64-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-loong64-musl@4.68.5': + optional: true + + '@rollup/rollup-linux-ppc64-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-ppc64-musl@4.68.5': + optional: true + + '@rollup/rollup-linux-riscv64-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-riscv64-musl@4.68.5': + optional: true + + '@rollup/rollup-linux-s390x-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-x64-gnu@4.68.5': + optional: true + + '@rollup/rollup-linux-x64-musl@4.68.5': + optional: true + + '@rollup/rollup-openbsd-x64@4.68.5': + optional: true + + '@rollup/rollup-openharmony-arm64@4.68.5': + optional: true + + '@rollup/rollup-win32-arm64-msvc@4.68.5': + optional: true + + '@rollup/rollup-win32-ia32-msvc@4.68.5': + optional: true + + '@rollup/rollup-win32-x64-gnu@4.68.5': + optional: true + + '@rollup/rollup-win32-x64-msvc@4.68.5': + optional: true + '@tootallnate/quickjs-emscripten@0.23.0': {} + '@types/babel__core@7.20.5': + dependencies: + '@babel/parser': 7.29.14 + '@babel/types': 7.29.14 + '@types/babel__generator': 7.27.0 + '@types/babel__template': 7.4.4 + '@types/babel__traverse': 7.28.0 + + '@types/babel__generator@7.27.0': + dependencies: + '@babel/types': 7.29.14 + + '@types/babel__template@7.4.4': + dependencies: + '@babel/parser': 7.29.14 + '@babel/types': 7.29.14 + + '@types/babel__traverse@7.28.0': + dependencies: + '@babel/types': 7.29.14 + + '@types/debug@4.1.13': + dependencies: + '@types/ms': 2.1.0 + + '@types/estree-jsx@1.0.5': + dependencies: + '@types/estree': 1.0.10 + + '@types/estree@1.0.10': {} + + '@types/geojson@7946.0.16': {} + + '@types/hast@3.0.5': + dependencies: + '@types/unist': 3.0.3 + + '@types/mdast@4.0.4': + dependencies: + '@types/unist': 3.0.3 + + '@types/ms@2.1.0': {} + '@types/node@26.6.6': dependencies: undici-types: 8.9.0 optional: true + '@types/react@19.3.0': + dependencies: + csstype: 3.2.4 + + '@types/unist@2.0.11': {} + + '@types/unist@3.0.3': {} + '@types/yauzl@2.10.3': dependencies: '@types/node': 26.6.6 optional: true + '@ungap/structured-clone@1.4.0': {} + + '@vitejs/plugin-react@4.7.0(vite@7.3.8(@types/node@26.6.6)(sass@1.108.2)(yaml@2.8.1))': + dependencies: + '@babel/core': 7.29.13 + '@babel/plugin-transform-react-jsx-self': 7.29.7(@babel/core@7.29.13) + '@babel/plugin-transform-react-jsx-source': 7.29.7(@babel/core@7.29.13) + '@rolldown/pluginutils': 1.0.0-beta.27 + '@types/babel__core': 7.20.5 + react-refresh: 0.17.0 + vite: 7.3.8(@types/node@26.6.6)(sass@1.108.2)(yaml@2.8.1) + transitivePeerDependencies: + - supports-color + '@xterm/addon-fit@0.12.0-beta.141(@xterm/xterm@6.1.0-beta.141)': dependencies: '@xterm/xterm': 6.1.0-beta.141 @@ -973,6 +2637,8 @@ snapshots: b4a@1.9.0: {} + bail@2.0.2: {} + bare-buffer@3.7.3: {} bare-events@2.9.2: {} @@ -1008,16 +2674,46 @@ snapshots: bare-buffer: 3.7.3 bare-path: 3.1.3 - base64-js@1.5.1: {} + base64-js@1.5.1: {} + + baseline-browser-mapping@2.11.38: {} + + basic-ftp@5.3.1: {} + + bidi-js@1.1.0: + dependencies: + require-from-string: 2.0.2 + + browserslist@4.29.6: + dependencies: + baseline-browser-mapping: 2.11.38 + caniuse-lite: 1.0.30001826 + electron-to-chromium: 1.5.488 + node-releases: 2.0.65 + update-browserslist-db: 1.4.0(browserslist@4.29.6) + + buffer-crc32@0.2.13: {} + + buffer@5.7.1: + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + + caniuse-lite@1.0.30001826: {} + + ccount@2.0.1: {} + + character-entities-html4@2.1.0: {} + + character-entities-legacy@3.0.0: {} - basic-ftp@5.3.1: {} + character-entities@2.0.2: {} - buffer-crc32@0.2.13: {} + character-reference-invalid@2.0.1: {} - buffer@5.7.1: + chokidar@5.0.0: dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 + readdirp: 5.1.1 chromium-bidi@0.5.8(devtools-protocol@0.0.1232444): dependencies: @@ -1025,6 +2721,8 @@ snapshots: mitt: 3.0.1 urlpattern-polyfill: 10.0.0 + ci-info@4.5.0: {} + cliui@8.0.1: dependencies: string-width: 4.2.3 @@ -1037,28 +2735,50 @@ snapshots: color-name@1.1.4: {} + comma-separated-tokens@2.0.3: {} + + commander@8.3.0: {} + + convert-source-map@2.0.0: {} + cross-fetch@4.0.0: dependencies: node-fetch: 2.7.0 transitivePeerDependencies: - encoding + csstype@3.2.4: {} + data-uri-to-buffer@6.0.2: {} debug@4.3.4: dependencies: ms: 2.1.2 + decode-named-character-reference@1.3.0: + dependencies: + character-entities: 2.0.2 + degenerator@5.0.1: dependencies: ast-types: 0.13.4 escodegen: 2.1.0 esprima: 4.0.1 + dequal@2.0.3: {} + detect-libc@2.1.2: {} + devlop@1.1.0: + dependencies: + dequal: 2.0.3 + devtools-protocol@0.0.1232444: {} + earcut@3.2.4: {} + + electron-to-chromium@1.5.488: {} + emoji-regex@8.0.0: {} end-of-stream@1.4.5: @@ -1094,8 +2814,39 @@ snapshots: '@esbuild/win32-ia32': 0.25.12 '@esbuild/win32-x64': 0.25.12 + esbuild@0.28.2: + optionalDependencies: + '@esbuild/aix-ppc64': 0.28.2 + '@esbuild/android-arm': 0.28.2 + '@esbuild/android-arm64': 0.28.2 + '@esbuild/android-x64': 0.28.2 + '@esbuild/darwin-arm64': 0.28.2 + '@esbuild/darwin-x64': 0.28.2 + '@esbuild/freebsd-arm64': 0.28.2 + '@esbuild/freebsd-x64': 0.28.2 + '@esbuild/linux-arm': 0.28.2 + '@esbuild/linux-arm64': 0.28.2 + '@esbuild/linux-ia32': 0.28.2 + '@esbuild/linux-loong64': 0.28.2 + '@esbuild/linux-mips64el': 0.28.2 + '@esbuild/linux-ppc64': 0.28.2 + '@esbuild/linux-riscv64': 0.28.2 + '@esbuild/linux-s390x': 0.28.2 + '@esbuild/linux-x64': 0.28.2 + '@esbuild/netbsd-arm64': 0.28.2 + '@esbuild/netbsd-x64': 0.28.2 + '@esbuild/openbsd-arm64': 0.28.2 + '@esbuild/openbsd-x64': 0.28.2 + '@esbuild/openharmony-arm64': 0.28.2 + '@esbuild/sunos-x64': 0.28.2 + '@esbuild/win32-arm64': 0.28.2 + '@esbuild/win32-ia32': 0.28.2 + '@esbuild/win32-x64': 0.28.2 + escalade@3.2.0: {} + escape-string-regexp@5.0.0: {} + escodegen@2.1.0: dependencies: esprima: 4.0.1 @@ -1108,6 +2859,8 @@ snapshots: estraverse@5.3.0: {} + estree-util-is-identifier-name@3.0.0: {} + esutils@2.0.3: {} events-universal@1.0.1: @@ -1116,6 +2869,8 @@ snapshots: transitivePeerDependencies: - bare-abort-controller + extend@3.0.2: {} + extract-zip@2.0.1: dependencies: debug: 4.3.4 @@ -1132,6 +2887,15 @@ snapshots: dependencies: pend: 1.2.0 + fdir@6.5.0(picomatch@4.0.7): + optionalDependencies: + picomatch: 4.0.7 + + fsevents@2.3.3: + optional: true + + gensync@1.0.0-beta.2: {} + get-caller-file@2.0.5: {} get-stream@5.2.0: @@ -1146,6 +2910,34 @@ snapshots: transitivePeerDependencies: - supports-color + gl-matrix@3.4.4: {} + + hast-util-to-jsx-runtime@2.3.7: + dependencies: + '@types/estree': 1.0.10 + '@types/hast': 3.0.5 + '@types/unist': 3.0.3 + comma-separated-tokens: 2.0.3 + devlop: 1.1.0 + estree-util-is-identifier-name: 3.0.0 + hast-util-whitespace: 3.0.0 + mdast-util-mdx-expression: 2.0.1 + mdast-util-mdx-jsx: 3.2.1 + mdast-util-mdxjs-esm: 2.0.1 + property-information: 7.2.0 + space-separated-tokens: 2.0.2 + style-to-object: 2.0.2 + unist-util-position: 5.0.0 + vfile-message: 4.0.4 + transitivePeerDependencies: + - supports-color + + hast-util-whitespace@3.0.0: + dependencies: + '@types/hast': 3.0.5 + + html-url-attributes@3.0.1: {} + http-proxy-agent@7.0.2: dependencies: agent-base: 7.1.4 @@ -1162,24 +2954,475 @@ snapshots: ieee754@1.2.1: {} + immutable@5.2.1: {} + + inline-style-parser@0.2.9: {} + ip-address@10.7.6: {} + is-alphabetical@2.0.1: {} + + is-alphanumerical@2.0.1: + dependencies: + is-alphabetical: 2.0.1 + is-decimal: 2.0.1 + + is-decimal@2.0.1: {} + + is-extglob@2.1.1: + optional: true + is-fullwidth-code-point@3.0.0: {} + is-glob@4.0.3: + dependencies: + is-extglob: 2.1.1 + optional: true + + is-hexadecimal@2.0.1: {} + + is-plain-obj@4.1.0: {} + + js-tokens@4.0.0: {} + + jsesc@3.1.0: {} + + json-stringify-pretty-compact@4.0.0: {} + + json5@2.2.3: {} + + katex@0.16.47: + dependencies: + commander: 8.3.0 + + kdbush@4.1.0: {} + + longest-streak@3.1.0: {} + + loose-envify@1.4.0: + dependencies: + js-tokens: 4.0.0 + + lru-cache@5.1.1: + dependencies: + yallist: 3.1.1 + lru-cache@7.18.3: {} + lucide-react@0.560.0(react@18.3.1): + dependencies: + react: 18.3.1 + + lucide-react@0.575.0(react@18.3.1): + dependencies: + react: 18.3.1 + + maplibre-gl@6.19.0(@types/react@19.3.0)(react@18.3.1): + dependencies: + '@mapbox/point-geometry': 1.1.0 + '@mapbox/tiny-sdf': 2.3.0 + '@mapbox/unitbezier': 1.0.0 + '@mapbox/vector-tile': 3.0.0 + '@maplibre/geojson-vt': 6.3.3 + '@maplibre/maplibre-gl-style-spec': 26.8.0 + '@maplibre/mlt': 1.3.0 + '@maplibre/vt-pbf': 4.3.3 + '@types/geojson': 7946.0.16 + bidi-js: 1.1.0 + earcut: 3.2.4 + gl-matrix: 3.4.4 + kdbush: 4.1.0 + murmurhash-js: 1.0.0 + pbf: 5.1.2 + potpack: 2.1.0 + quickselect: 3.0.0 + tinyqueue: 3.0.0 + zustand: 5.1.0(@types/react@19.3.0)(react@18.3.1) + transitivePeerDependencies: + - '@types/react' + - immer + - react + - use-sync-external-store + + markdown-table@3.1.0: {} + + mdast-util-find-and-replace@3.0.4: + dependencies: + '@types/mdast': 4.0.4 + escape-string-regexp: 5.0.0 + unist-util-is: 6.0.1 + unist-util-visit-parents: 6.1.0 + + mdast-util-from-markdown@2.1.0: + dependencies: + '@types/mdast': 4.0.4 + '@types/unist': 3.0.3 + decode-named-character-reference: 1.3.0 + devlop: 1.1.0 + mdast-util-to-string: 4.0.0 + micromark: 4.0.3 + micromark-util-decode-numeric-character-reference: 2.0.2 + micromark-util-decode-string: 2.0.1 + micromark-util-normalize-identifier: 2.0.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + unist-util-stringify-position: 4.0.0 + transitivePeerDependencies: + - supports-color + + mdast-util-gfm-autolink-literal@2.1.0: + dependencies: + '@types/mdast': 4.0.4 + ccount: 2.0.1 + devlop: 1.1.0 + mdast-util-find-and-replace: 3.0.4 + micromark-util-character: 2.1.1 + + mdast-util-gfm-footnote@2.1.0: + dependencies: + '@types/mdast': 4.0.4 + devlop: 1.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + micromark-util-normalize-identifier: 2.0.1 + transitivePeerDependencies: + - supports-color + + mdast-util-gfm-strikethrough@2.0.1: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + transitivePeerDependencies: + - supports-color + + mdast-util-gfm-table@2.0.1: + dependencies: + '@types/mdast': 4.0.4 + devlop: 1.1.0 + markdown-table: 3.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + mdast-util-to-string: 4.0.0 + unist-util-visit: 5.2.0 + transitivePeerDependencies: + - supports-color + + mdast-util-gfm-task-list-item@2.0.1: + dependencies: + '@types/mdast': 4.0.4 + devlop: 1.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + transitivePeerDependencies: + - supports-color + + mdast-util-gfm@3.1.0: + dependencies: + mdast-util-from-markdown: 2.1.0 + mdast-util-gfm-autolink-literal: 2.1.0 + mdast-util-gfm-footnote: 2.1.0 + mdast-util-gfm-strikethrough: 2.0.1 + mdast-util-gfm-table: 2.0.1 + mdast-util-gfm-task-list-item: 2.0.1 + mdast-util-to-markdown: 2.2.3 + transitivePeerDependencies: + - supports-color + + mdast-util-mdx-expression@2.0.1: + dependencies: + '@types/estree-jsx': 1.0.5 + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + devlop: 1.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + transitivePeerDependencies: + - supports-color + + mdast-util-mdx-jsx@3.2.1: + dependencies: + '@types/estree-jsx': 1.0.5 + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + '@types/unist': 3.0.3 + ccount: 2.0.1 + devlop: 1.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + parse-entities: 4.0.2 + stringify-entities: 4.0.4 + unist-util-stringify-position: 4.0.0 + vfile-message: 4.0.4 + transitivePeerDependencies: + - supports-color + + mdast-util-mdxjs-esm@2.0.1: + dependencies: + '@types/estree-jsx': 1.0.5 + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + devlop: 1.1.0 + mdast-util-from-markdown: 2.1.0 + mdast-util-to-markdown: 2.2.3 + transitivePeerDependencies: + - supports-color + + mdast-util-phrasing@4.1.0: + dependencies: + '@types/mdast': 4.0.4 + unist-util-is: 6.0.1 + + mdast-util-to-hast@13.2.2: + dependencies: + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + '@ungap/structured-clone': 1.4.0 + devlop: 1.1.0 + micromark-util-sanitize-uri: 2.0.1 + trim-lines: 3.0.1 + unist-util-position: 5.0.0 + unist-util-visit: 5.2.0 + vfile: 6.0.3 + + mdast-util-to-markdown@2.2.3: + dependencies: + '@types/mdast': 4.0.4 + '@types/unist': 3.0.3 + longest-streak: 3.1.0 + mdast-util-phrasing: 4.1.0 + mdast-util-to-string: 4.0.0 + micromark-util-character: 2.1.1 + micromark-util-classify-character: 2.0.1 + micromark-util-decode-string: 2.0.1 + micromark-util-html-tag-name: 2.0.1 + unist-util-visit: 5.2.0 + zwitch: 2.0.4 + + mdast-util-to-string@4.0.0: + dependencies: + '@types/mdast': 4.0.4 + + micromark-core-commonmark@2.0.4: + dependencies: + decode-named-character-reference: 1.3.0 + devlop: 1.1.0 + micromark-factory-destination: 2.0.1 + micromark-factory-label: 2.0.1 + micromark-factory-space: 2.1.0 + micromark-factory-title: 2.0.1 + micromark-factory-whitespace: 2.0.1 + micromark-util-character: 2.1.1 + micromark-util-chunked: 2.0.1 + micromark-util-classify-character: 2.0.1 + micromark-util-edit-map: 1.0.0 + micromark-util-html-tag-name: 2.0.1 + micromark-util-normalize-identifier: 2.0.1 + micromark-util-resolve-all: 2.0.1 + micromark-util-subtokenize: 2.1.0 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm-autolink-literal@2.1.0: + dependencies: + micromark-util-character: 2.1.1 + micromark-util-sanitize-uri: 2.0.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm-footnote@2.1.0: + dependencies: + devlop: 1.1.0 + micromark-core-commonmark: 2.0.4 + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-normalize-identifier: 2.0.1 + micromark-util-sanitize-uri: 2.0.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm-strikethrough@2.1.0: + dependencies: + devlop: 1.1.0 + micromark-util-chunked: 2.0.1 + micromark-util-classify-character: 2.0.1 + micromark-util-resolve-all: 2.0.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm-table@2.1.2: + dependencies: + devlop: 1.1.0 + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm-tagfilter@2.0.0: + dependencies: + micromark-util-types: 2.0.3 + + micromark-extension-gfm-task-list-item@2.1.0: + dependencies: + devlop: 1.1.0 + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-extension-gfm@3.0.0: + dependencies: + micromark-extension-gfm-autolink-literal: 2.1.0 + micromark-extension-gfm-footnote: 2.1.0 + micromark-extension-gfm-strikethrough: 2.1.0 + micromark-extension-gfm-table: 2.1.2 + micromark-extension-gfm-tagfilter: 2.0.0 + micromark-extension-gfm-task-list-item: 2.1.0 + micromark-util-combine-extensions: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-factory-destination@2.0.1: + dependencies: + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-factory-label@2.0.1: + dependencies: + devlop: 1.1.0 + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-factory-space@2.1.0: + dependencies: + micromark-util-character: 2.1.1 + micromark-util-types: 2.0.3 + + micromark-factory-title@2.0.1: + dependencies: + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-factory-whitespace@2.0.1: + dependencies: + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-util-character@2.1.1: + dependencies: + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-util-chunked@2.0.1: + dependencies: + micromark-util-symbol: 2.0.1 + + micromark-util-classify-character@2.0.1: + dependencies: + micromark-util-character: 2.1.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-util-combine-extensions@2.0.1: + dependencies: + micromark-util-chunked: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-util-decode-numeric-character-reference@2.0.2: + dependencies: + micromark-util-symbol: 2.0.1 + + micromark-util-decode-string@2.0.1: + dependencies: + decode-named-character-reference: 1.3.0 + micromark-util-character: 2.1.1 + micromark-util-decode-numeric-character-reference: 2.0.2 + micromark-util-symbol: 2.0.1 + + micromark-util-edit-map@1.0.0: + dependencies: + micromark-util-types: 2.0.3 + + micromark-util-encode@2.0.1: {} + + micromark-util-html-tag-name@2.0.1: {} + + micromark-util-normalize-identifier@2.0.1: + dependencies: + micromark-util-symbol: 2.0.1 + + micromark-util-resolve-all@2.0.1: + dependencies: + micromark-util-types: 2.0.3 + + micromark-util-sanitize-uri@2.0.1: + dependencies: + micromark-util-character: 2.1.1 + micromark-util-encode: 2.0.1 + micromark-util-symbol: 2.0.1 + + micromark-util-subtokenize@2.1.0: + dependencies: + devlop: 1.1.0 + micromark-util-chunked: 2.0.1 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + + micromark-util-symbol@2.0.1: {} + + micromark-util-types@2.0.3: {} + + micromark@4.0.3: + dependencies: + '@types/debug': 4.1.13 + debug: 4.3.4 + decode-named-character-reference: 1.3.0 + devlop: 1.1.0 + micromark-core-commonmark: 2.0.4 + micromark-factory-space: 2.1.0 + micromark-util-character: 2.1.1 + micromark-util-chunked: 2.0.1 + micromark-util-combine-extensions: 2.0.1 + micromark-util-decode-numeric-character-reference: 2.0.2 + micromark-util-edit-map: 1.0.0 + micromark-util-encode: 2.0.1 + micromark-util-normalize-identifier: 2.0.1 + micromark-util-resolve-all: 2.0.1 + micromark-util-sanitize-uri: 2.0.1 + micromark-util-subtokenize: 2.1.0 + micromark-util-symbol: 2.0.1 + micromark-util-types: 2.0.3 + transitivePeerDependencies: + - supports-color + + minimist@1.2.8: {} + mitt@3.0.1: {} mkdirp-classic@0.5.3: {} ms@2.1.2: {} + murmurhash-js@1.0.0: {} + + nanoid@3.3.20: {} + netmask@2.1.1: {} + node-addon-api@7.1.1: + optional: true + node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 + node-releases@2.0.65: {} + once@1.4.0: dependencies: wrappy: 1.0.2 @@ -1202,10 +3445,40 @@ snapshots: degenerator: 5.0.1 netmask: 2.1.1 + parse-entities@4.0.2: + dependencies: + '@types/unist': 2.0.11 + character-entities-legacy: 3.0.0 + character-reference-invalid: 2.0.1 + decode-named-character-reference: 1.3.0 + is-alphanumerical: 2.0.1 + is-decimal: 2.0.1 + is-hexadecimal: 2.0.1 + + pbf@5.1.2: + dependencies: + resolve-protobuf-schema: 2.1.0 + pend@1.2.0: {} + picocolors@1.1.1: {} + + picomatch@4.0.7: {} + + postcss@8.5.33: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.2 + + potpack@2.1.0: {} + progress@2.0.3: {} + property-information@7.2.0: {} + + protocol-buffers-schema@3.6.1: {} + proxy-agent@6.3.1: dependencies: agent-base: 7.1.4 @@ -1243,8 +3516,128 @@ snapshots: - supports-color - utf-8-validate + quickselect@3.0.0: {} + + react-dom@18.3.1(react@18.3.1): + dependencies: + loose-envify: 1.4.0 + react: 18.3.1 + scheduler: 0.23.2 + + react-markdown@10.1.0(@types/react@19.3.0)(react@18.3.1): + dependencies: + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + '@types/react': 19.3.0 + devlop: 1.1.0 + hast-util-to-jsx-runtime: 2.3.7 + html-url-attributes: 3.0.1 + mdast-util-to-hast: 13.2.2 + react: 18.3.1 + remark-parse: 11.0.0 + remark-rehype: 11.1.2 + unified: 11.0.5 + unist-util-visit: 5.2.0 + vfile: 6.0.3 + transitivePeerDependencies: + - supports-color + + react-refresh@0.17.0: {} + + react@18.3.1: + dependencies: + loose-envify: 1.4.0 + + readdirp@5.1.1: {} + + remark-gfm@4.0.1: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-gfm: 3.1.0 + micromark-extension-gfm: 3.0.0 + remark-parse: 11.0.0 + remark-stringify: 11.0.0 + unified: 11.0.5 + transitivePeerDependencies: + - supports-color + + remark-parse@11.0.0: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-from-markdown: 2.1.0 + micromark-util-types: 2.0.3 + unified: 11.0.5 + transitivePeerDependencies: + - supports-color + + remark-rehype@11.1.2: + dependencies: + '@types/hast': 3.0.5 + '@types/mdast': 4.0.4 + mdast-util-to-hast: 13.2.2 + unified: 11.0.5 + vfile: 6.0.3 + + remark-stringify@11.0.0: + dependencies: + '@types/mdast': 4.0.4 + mdast-util-to-markdown: 2.2.3 + unified: 11.0.5 + require-directory@2.1.1: {} + require-from-string@2.0.2: {} + + resolve-protobuf-schema@2.1.0: + dependencies: + protocol-buffers-schema: 3.6.1 + + rollup@4.68.5: + dependencies: + '@types/estree': 1.0.10 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.68.5 + '@rollup/rollup-android-arm64': 4.68.5 + '@rollup/rollup-android-x64': 4.68.5 + '@rollup/rollup-darwin-arm64': 4.68.5 + '@rollup/rollup-darwin-x64': 4.68.5 + '@rollup/rollup-freebsd-arm64': 4.68.5 + '@rollup/rollup-freebsd-x64': 4.68.5 + '@rollup/rollup-linux-arm-gnueabihf': 4.68.5 + '@rollup/rollup-linux-arm-musleabihf': 4.68.5 + '@rollup/rollup-linux-arm64-gnu': 4.68.5 + '@rollup/rollup-linux-arm64-musl': 4.68.5 + '@rollup/rollup-linux-loong64-gnu': 4.68.5 + '@rollup/rollup-linux-loong64-musl': 4.68.5 + '@rollup/rollup-linux-ppc64-gnu': 4.68.5 + '@rollup/rollup-linux-ppc64-musl': 4.68.5 + '@rollup/rollup-linux-riscv64-gnu': 4.68.5 + '@rollup/rollup-linux-riscv64-musl': 4.68.5 + '@rollup/rollup-linux-s390x-gnu': 4.68.5 + '@rollup/rollup-linux-x64-gnu': 4.68.5 + '@rollup/rollup-linux-x64-musl': 4.68.5 + '@rollup/rollup-openbsd-x64': 4.68.5 + '@rollup/rollup-openharmony-arm64': 4.68.5 + '@rollup/rollup-win32-arm64-msvc': 4.68.5 + '@rollup/rollup-win32-ia32-msvc': 4.68.5 + '@rollup/rollup-win32-x64-gnu': 4.68.5 + '@rollup/rollup-win32-x64-msvc': 4.68.5 + fsevents: 2.3.3 + + sass@1.108.2: + dependencies: + chokidar: 5.0.0 + immutable: 5.2.1 + source-map-js: 1.2.2 + optionalDependencies: + '@parcel/watcher': 2.6.0 + + scheduler@0.23.2: + dependencies: + loose-envify: 1.4.0 + + semver@6.3.2: {} + semver@7.8.6: {} sharp@0.34.5: @@ -1293,9 +3686,13 @@ snapshots: ip-address: 10.7.6 smart-buffer: 4.2.0 + source-map-js@1.2.2: {} + source-map@0.6.1: optional: true + space-separated-tokens@2.0.2: {} + streamx@2.28.1: dependencies: events-universal: 1.0.1 @@ -1311,10 +3708,19 @@ snapshots: is-fullwidth-code-point: 3.0.0 strip-ansi: 6.0.1 + stringify-entities@4.0.4: + dependencies: + character-entities-html4: 2.1.0 + character-entities-legacy: 3.0.0 + strip-ansi@6.0.1: dependencies: ansi-regex: 5.0.1 + style-to-object@2.0.2: + dependencies: + inline-style-parser: 0.2.9 + tar-fs@3.0.4(bare-buffer@3.7.3): dependencies: mkdirp-classic: 0.5.3 @@ -1351,8 +3757,19 @@ snapshots: through@2.3.8: {} + tinyglobby@0.2.17: + dependencies: + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 + + tinyqueue@3.0.0: {} + tr46@0.0.3: {} + trim-lines@3.0.1: {} + + trough@2.2.0: {} + tslib@2.9.1: {} typescript@5.9.3: {} @@ -1365,8 +3782,71 @@ snapshots: undici-types@8.9.0: optional: true + unified@11.0.5: + dependencies: + '@types/unist': 3.0.3 + bail: 2.0.2 + devlop: 1.1.0 + extend: 3.0.2 + is-plain-obj: 4.1.0 + trough: 2.2.0 + vfile: 6.0.3 + + unist-util-is@6.0.1: + dependencies: + '@types/unist': 3.0.3 + + unist-util-position@5.0.0: + dependencies: + '@types/unist': 3.0.3 + + unist-util-stringify-position@4.0.0: + dependencies: + '@types/unist': 3.0.3 + + unist-util-visit-parents@6.1.0: + dependencies: + '@types/unist': 3.0.3 + unist-util-is: 6.0.1 + + unist-util-visit@5.2.0: + dependencies: + '@types/unist': 3.0.3 + unist-util-is: 6.0.1 + unist-util-visit-parents: 6.1.0 + + update-browserslist-db@1.4.0(browserslist@4.29.6): + dependencies: + browserslist: 4.29.6 + escalade: 3.2.0 + picocolors: 1.1.1 + urlpattern-polyfill@10.0.0: {} + vfile-message@4.0.4: + dependencies: + '@types/unist': 3.0.3 + unist-util-stringify-position: 4.0.0 + + vfile@6.0.3: + dependencies: + '@types/unist': 3.0.3 + vfile-message: 4.0.4 + + vite@7.3.8(@types/node@26.6.6)(sass@1.108.2)(yaml@2.8.1): + dependencies: + esbuild: 0.28.2 + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 + postcss: 8.5.33 + rollup: 4.68.5 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.6.6 + fsevents: 2.3.3 + sass: 1.108.2 + yaml: 2.8.1 + webidl-conversions@3.0.1: {} whatwg-url@5.0.0: @@ -1386,6 +3866,8 @@ snapshots: y18n@5.0.8: {} + yallist@3.1.1: {} + yaml@2.8.1: {} yargs-parser@21.1.1: {} @@ -1404,3 +3886,12 @@ snapshots: dependencies: buffer-crc32: 0.2.13 fd-slicer: 1.1.0 + + zod@4.6.7: {} + + zustand@5.1.0(@types/react@19.3.0)(react@18.3.1): + optionalDependencies: + '@types/react': 19.3.0 + react: 18.3.1 + + zwitch@2.0.4: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a51417c..472296f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,5 @@ packages: + - src/apps/mobile/harmonyos/genui-runtime - design-system/packages/design-tokens - design-system/packages/theme-openbitfun - design-system/tooling/token-engine diff --git a/scripts/build-harmony-genui-runtime.mjs b/scripts/build-harmony-genui-runtime.mjs new file mode 100644 index 0000000..c253382 --- /dev/null +++ b/scripts/build-harmony-genui-runtime.mjs @@ -0,0 +1,57 @@ +#!/usr/bin/env node +/** + * Build the Harmony Local GenUI contract projection and ArkWeb runtime bundle. + * + * node scripts/build-harmony-genui-runtime.mjs # regenerate + build + * node scripts/build-harmony-genui-runtime.mjs --check # verify freshness only + * + * The contract files under rawfile/genui are checked in; the runtime bundle + * under rawfile/genui/runtime is generated and verified by the HAP build. + */ +import { execFileSync } from 'node:child_process'; +import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { createRequire } from 'node:module'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const genuiDir = path.join(root, 'src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui'); +const runtimeDir = path.join(genuiDir, 'runtime'); +const manifestPath = path.join(genuiDir, 'runtime-manifest.json'); +const buildInfoPath = path.join(runtimeDir, 'build.json'); +const { runtimeFreshnessError } = createRequire(import.meta.url)('../src/apps/mobile/harmonyos/tools/genui-runtime-freshness.cjs'); + +function run(command, args, cwd = root) { + execFileSync(command, args, { cwd, stdio: 'inherit', windowsHide: true, shell: process.platform === 'win32' && command === 'pnpm', env: process.env }); +} + +const HTML = ` + + + + + + +Local GenUI + +
+ +`; + +if (process.argv.includes('--check')) { + run(process.execPath, ['scripts/generate-genui-contract.mjs', '--check']); + const error = runtimeFreshnessError(); + if (error) { console.error(`${error}; run pnpm run harmony:genui-runtime`); process.exit(1); } + console.log('Harmony Local GenUI runtime is fresh'); +} else { + run(process.execPath, ['scripts/generate-genui-contract.mjs']); + run('pnpm', ['exec', 'vite', 'build', '--logLevel', 'warn'], path.join(root, 'src/apps/mobile/harmonyos/genui-runtime')); + writeFileSync(path.join(runtimeDir, 'index.html'), HTML); + // HM Symbol icons; the license travels with the font. + const fontDir = path.join(runtimeDir, 'fonts/hm-symbol'); + mkdirSync(fontDir, { recursive: true }); + for (const file of ['HMSymbolVF.ttf', 'LICENSE.txt']) copyFileSync(path.join(root, 'src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol', file), path.join(fontDir, file)); + const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')); + writeFileSync(buildInfoPath, JSON.stringify({ catalogHash: manifest.catalogHash, rendererRevision: manifest.rendererRevision }, null, 2) + '\n'); + console.log('Built Harmony Local GenUI runtime for ' + manifest.rendererRevision); +} diff --git a/scripts/generate-genui-contract.mjs b/scripts/generate-genui-contract.mjs new file mode 100644 index 0000000..501ee86 --- /dev/null +++ b/scripts/generate-genui-contract.mjs @@ -0,0 +1,25 @@ +import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs'; +import { compileCatalog } from '../src/shared/generative-ui/library.mjs'; +import { projectHarmonyLocalContract } from '../src/shared/generative-ui/harmony-local.mjs'; +const path = new URL('../src/shared/generative-ui/', import.meta.url); +const catalog = compileCatalog(JSON.parse(readFileSync(new URL('library.json', path), 'utf8'))); +const output = JSON.stringify(catalog, null, 2) + '\n'; +const target = new URL('catalog.json', path); +// Harmony Local GenUI consumes a projection of the same catalog. Keep it next +// to the HAP resources so the phone never hand-writes prompts or schemas. +const harmonyDir = new URL('../src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/', import.meta.url); +const harmony = projectHarmonyLocalContract(catalog).files; +const check = process.argv.includes('--check'); +const stale = []; +if (check) { + if (readFileSync(target, 'utf8') !== output) stale.push('src/shared/generative-ui/catalog.json'); + for (const [name, text] of Object.entries(harmony)) { + const file = new URL(name, harmonyDir); + if (!existsSync(file) || readFileSync(file, 'utf8') !== text) stale.push('rawfile/genui/' + name); + } + if (stale.length) throw new Error('GenUI contract is stale (' + stale.join(', ') + '); run node scripts/generate-genui-contract.mjs'); +} else { + writeFileSync(target, output); + mkdirSync(harmonyDir, { recursive: true }); + for (const [name, text] of Object.entries(harmony)) writeFileSync(new URL(name, harmonyDir), text); +} diff --git a/scripts/vendor-fluent-emoji-animated-index.mjs b/scripts/vendor-fluent-emoji-animated-index.mjs new file mode 100644 index 0000000..51d2eae --- /dev/null +++ b/scripts/vendor-fluent-emoji-animated-index.mjs @@ -0,0 +1,45 @@ +#!/usr/bin/env node +/** + * Pin the Microsoft Fluent Emoji animated set (MIT) for Harmony Local GenUI. + * + * node scripts/vendor-fluent-emoji-animated-index.mjs [commit] + * + * The animated repository keeps one folder per emoji, named like the static + * Fluent Emoji folders. Each animated asset is keyed by the code point key the + * static 3D index already uses for that folder, so a cover only animates the + * exact emoji it already shows. Skin-tone variants keep the Default tone, as + * the static index does. The host fetches these files at the pinned commit. + */ +import { readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const vendor = path.join(root, 'src/apps/mobile/harmonyos/genui-runtime/src/components/vendor'); +const staticIndex = JSON.parse(readFileSync(path.join(vendor, 'fluent-emoji-3d-index.json'), 'utf8')); +const repo = 'microsoft/fluentui-emoji-animated'; + +async function json(url) { + const response = await fetch(url, { headers: { Accept: 'application/vnd.github+json' } }); + if (!response.ok) throw new Error(`${url}: ${response.status}`); + return response.json(); +} + +const sha = process.argv[2] ?? (await json(`https://api.github.com/repos/${repo}/commits/main`)).sha; +const tree = await json(`https://api.github.com/repos/${repo}/git/trees/${sha}?recursive=1`); +if (tree.truncated) throw new Error('GitHub tree listing was truncated'); + +const animatedByFolder = new Map(); +for (const entry of tree.tree) { + const match = /^assets\/(.+?)\/(Default\/)?animated\/([^/]+_animated(_default)?\.png)$/.exec(entry.path); + if (entry.type === 'blob' && match) animatedByFolder.set(match[1], entry.path.slice('assets/'.length)); +} + +const icons = {}; +for (const [key, asset] of Object.entries(staticIndex.icons)) { + const animated = animatedByFolder.get(asset.split('/')[0]); + if (animated) icons[key] = animated; +} +const sorted = Object.fromEntries(Object.entries(icons).sort(([a], [b]) => a.localeCompare(b))); +writeFileSync(path.join(vendor, 'fluent-emoji-animated-index.json'), JSON.stringify({ sha, icons: sorted }) + '\n'); +console.log(`Pinned ${Object.keys(sorted).length} of ${animatedByFolder.size} animated Fluent Emoji at ${sha}`); diff --git a/src/apps/mobile/AGENTS.md b/src/apps/mobile/AGENTS.md index f810939..7d53571 100644 --- a/src/apps/mobile/AGENTS.md +++ b/src/apps/mobile/AGENTS.md @@ -119,7 +119,7 @@ isolation, run from `shared/` with the Android guide's Java runtime: `./gradlew :core-feature:jvmTest --tests '*promptSuggestion*' --tests '*SessionRecordReplicaTest*'`. These are simulated host streams, not evidence of a live remote connection. -Native mobile surfaces are controllers. Desktop and CLI own execution, files, terminals and SSH credentials. Mobile workspace selection may use only connections already saved on the controlled runtime; it must not create an SSH connection or instantiate another runtime. Carry the selected connection identity through every operation, and report missing identity instead of falling back to local files. +Native mobile remote surfaces are controllers. Desktop and CLI own remote execution, files, terminals and SSH credentials. Mobile workspace selection may use only connections already saved on the controlled runtime; it must not create an SSH connection or instantiate another runtime. Carry the selected connection identity through every operation, and report missing identity instead of falling back to local files. ## Offline Mini Apps diff --git a/src/apps/mobile/harmonyos/.gitignore b/src/apps/mobile/harmonyos/.gitignore index 63b8fc7..eefa650 100644 --- a/src/apps/mobile/harmonyos/.gitignore +++ b/src/apps/mobile/harmonyos/.gitignore @@ -35,3 +35,4 @@ # Generated from en_US/zh_CN element string catalogs by entry/hvigorfile.ts /entry/src/main/resources/rawfile/string.json +entry/src/main/resources/rawfile/genui/runtime/ diff --git a/src/apps/mobile/harmonyos/AGENTS.md b/src/apps/mobile/harmonyos/AGENTS.md index 0766797..21ffca5 100644 --- a/src/apps/mobile/harmonyos/AGENTS.md +++ b/src/apps/mobile/harmonyos/AGENTS.md @@ -2,14 +2,28 @@ These rules apply to all changes under `src/apps/mobile/harmonyos`. -## Controller product boundary - -Phone, tablet, and foldable entrypoints are remote controllers. They must not -instantiate a local Agent Runtime, model provider, local chat command owner, or -model configuration store. OpenBitFun account identity and the authenticated device directory -are the authority for selection and reconnect; QR data supplies only a device id. -Keep old persisted records readable and retained without activating legacy room -credentials or local execution. Compact and wide hosts enforce the same boundary. +## Product modes + +Remote Chat remains a controller in compact and wide layouts. OpenBitFun account +identity and the authenticated device directory control selection and reconnect. +QR data supplies only a device ID. Keep legacy records readable and inert. + +The sidebar's Create mini apps entry opens Local GenUI. Only `services/local-genui/` owns its session +controller, model provider, app owner and persistence. Local sessions use +`local-genui:` IDs and separate storage tables. They use neither remote session +IDs nor workspace identities, RemoteCommand, HostStream or the remote permission +mailbox. The retired General Chat routes stay inert. Its saved model +configuration can be imported into the encrypted Local GenUI model store. + +The ArkWeb bundle only parses and renders the pinned local contract. Keep +calendar, camera gestures, haptics and cross-device images behind the typed +local action host and platform permission checks. Device preview fixtures do +not substitute for a real provider or permission test. + +From the repository root, run `pnpm run harmony:genui-runtime` before building a +HAP and `pnpm run harmony:genui-runtime:check` to verify the generated contract. +Run `node --test src/apps/mobile/harmonyos/tools/tests/local-genui-*.test.cjs` +for focused host tests. ## MVVM Refactor Boundaries diff --git a/src/apps/mobile/harmonyos/README.md b/src/apps/mobile/harmonyos/README.md index 9f5dc6a..6001155 100644 --- a/src/apps/mobile/harmonyos/README.md +++ b/src/apps/mobile/harmonyos/README.md @@ -48,6 +48,20 @@ can still produce an unsigned HAP. The current project targets HarmonyOS `6.1.1(24)` and supports `6.0.1(21)` or newer on phone and tablet devices. +## Local GenUI + +Open the left sidebar and choose **Create mini apps** to see your saved creation +sessions. Select a session or start a new one. Back returns to the list. +The composer includes **Manage +models** for adding an API endpoint and model. Conversation history, generated +app source and app state are stored on the phone. Generation uses the selected +model API directly from the phone and does not require a desktop connection. + +Before building the HAP, run `pnpm run harmony:genui-runtime` from the +repository root. The contract comes from `src/shared/generative-ui/library.json`. +The source and build configuration for the bundled ArkWeb renderer live in +`genui-runtime/`. + ## Built-in MiniApps Choose **MiniApps** from the sidebar to open Gomoku, Regex Playground, diff --git a/src/apps/mobile/harmonyos/entry/hvigorfile.ts b/src/apps/mobile/harmonyos/entry/hvigorfile.ts index 88474b5..afbe5fa 100644 --- a/src/apps/mobile/harmonyos/entry/hvigorfile.ts +++ b/src/apps/mobile/harmonyos/entry/hvigorfile.ts @@ -4,8 +4,9 @@ import { hapTasks } from '@ohos/hvigor-ohos-plugin'; require('../miniapps/generate.cjs').generate(); // Regenerate the HostTextRetranslator i18n rawfile catalog on every build. require('../i18n/generate.cjs').generate(); +require('../tools/genui-runtime-freshness.cjs').assertRuntimeFresh(); export default { system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ -} \ No newline at end of file +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets index aff034e..d120a85 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets @@ -3,6 +3,8 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { display, window } from '@kit.ArkUI'; import { WindowOrientationService } from '../services/WindowOrientationService'; import { MobileDesignColors, MobileTextScale } from '../generated/MobileDesignTokens'; +import { LocalGenUIDesktopCards } from '../services/local-genui/LocalGenUIDesktopCards'; +import { LocalGenUILaunchInbox } from '../services/local-genui/LocalGenUILaunchInbox'; const DOMAIN = 0x0000; const TAG = 'OpenBitFunRemote'; @@ -36,7 +38,7 @@ export default class EntryAbility extends UIAbility { scenarioId === 'copy-rollback-busy' || scenarioId === 'copy-rollback-unsupported' || scenarioId === 'interaction-mailbox' || scenarioId === 'interaction-mailbox-dark' || scenarioId.startsWith('command-palette') || - deviceModelScenario) { + scenarioId.startsWith('collaboration') || deviceModelScenario) { this.initialPage = 'pages/preview/MobileDesignGallery'; this.previewStorage = new LocalStorage(); this.previewStorage.setOrCreate('scenarioId', scenarioId); @@ -51,10 +53,11 @@ export default class EntryAbility extends UIAbility { const previewDark = this.previewStorage !== undefined && want.parameters?.['openbitfunDesignAppearance'] === 'dark'; const colorMode = previewDark || scenarioId === 'cold-start-home-dark' || scenarioId === 'catalog-refresh-dark' || scenarioId === 'model-role-selector-dark' || scenarioId === 'subagent-process-dark' || scenarioId === 'subagent-swarm-dark' || scenarioId === 'file-visibility-dark' || scenarioId === 'immersive-bottom-dark' || scenarioId === 'immersive-bottom-drawer-dark' || scenarioId === 'immersive-bottom-settings-dark' || scenarioId === 'composer-overflow-dark' || scenarioId === 'composer-overflow-expanded-dark' || scenarioId === 'device-selector-dark' || scenarioId === 'streaming-dark' || scenarioId === 'interaction-mailbox-dark' || scenarioId === 'copy-selection-dark' || scenarioId === 'copy-rollback-dark' || scenarioId === 'copy-rollback-send-dark' || scenarioId === 'copy-rollback-fail-dark' || (scenarioId.startsWith('command-palette') && scenarioId.endsWith('-dark')) || - (deviceModelScenario && scenarioId.endsWith('-dark')) + (deviceModelScenario && scenarioId.endsWith('-dark')) || + (scenarioId.startsWith('collaboration') && scenarioId.endsWith('-dark')) ? ConfigurationConstant.ColorMode.COLOR_MODE_DARK : scenarioId === 'cold-start-home' || scenarioId === 'catalog-refresh' || scenarioId === 'model-role-selector' || scenarioId === 'model-role-selector-wide' || scenarioId === 'subagent-process' || scenarioId === 'subagent-swarm' || scenarioId === 'file-visibility' || scenarioId === 'immersive-bottom' || scenarioId === 'immersive-bottom-wide' || scenarioId === 'immersive-bottom-drawer' || scenarioId === 'immersive-bottom-settings' || scenarioId === 'immersive-bottom-cover' || scenarioId === 'immersive-bottom-miniapps' || scenarioId === 'immersive-bottom-wide-shell' || scenarioId === 'immersive-bottom-tools' || scenarioId === 'immersive-bottom-tools-editor' || scenarioId === 'immersive-bottom-tools-file-action' || scenarioId === 'immersive-bottom-view-settings' || scenarioId === 'immersive-bottom-connect' || scenarioId === 'composer-overflow' || scenarioId === 'composer-overflow-empty' || scenarioId === 'composer-overflow-wide' || scenarioId === 'composer-overflow-expanded' || scenarioId === 'device-selector' || scenarioId === 'connected-conversation' || scenarioId === 'reconnecting-wide' || scenarioId === 'copy-selection' || scenarioId === 'copy-selection-nav' || scenarioId === 'copy-selection-wide' || scenarioId === 'copy-rollback' || scenarioId === 'copy-rollback-send' || scenarioId === 'copy-rollback-send-fail' || scenarioId === 'copy-rollback-fail' || scenarioId === 'copy-rollback-stale' || scenarioId === 'copy-rollback-busy' || scenarioId === 'copy-rollback-unsupported' || (scenarioId.startsWith('command-palette') && !scenarioId.endsWith('-dark')) || - (deviceModelScenario && !scenarioId.endsWith('-dark')) + ((deviceModelScenario || scenarioId.startsWith('collaboration')) && !scenarioId.endsWith('-dark')) ? ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT : ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET; this.context.getApplicationContext().setColorMode(colorMode); @@ -62,9 +65,27 @@ export default class EntryAbility extends UIAbility { hilog.error(DOMAIN, TAG, 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); } this.applyTextScale(); + if (!this.previewStorage) { + this.deliverCardLaunch(want); + } hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); } + onNewWant(want: Want, _launchParam: AbilityConstant.LaunchParam): void { + if (!this.previewStorage) { + this.deliverCardLaunch(want); + } + } + + /** A tap on a generated app's home-screen card opens that app. */ + private deliverCardLaunch(want: Want): void { + const appId = LocalGenUIDesktopCards.launchAppId(want.parameters as Record | undefined); + if (appId.length > 0) { + hilog.info(DOMAIN, TAG, '%{public}s', 'Opening a generated app from its desktop card'); + LocalGenUILaunchInbox.deliver(appId); + } + } + // The type ramp is read through getters, so this has to land before the first // page module loads; onCreate runs ahead of loadContent. A fold changing // screens keeps the same pixel pitch on the devices we ship to, so one read at diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/LocalGenUIFormAbility.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/LocalGenUIFormAbility.ets new file mode 100644 index 0000000..d68d5da --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/LocalGenUIFormAbility.ets @@ -0,0 +1,67 @@ +import { Want } from '@kit.AbilityKit'; +import { formBindingData, FormExtensionAbility } from '@kit.FormKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { LocalGenUIDesktopCardStore } from '../services/local-genui/LocalGenUIDesktopCardStore'; +import { + FORM_IDENTITY_PARAM, + LocalGenUIDesktopCards +} from '../services/local-genui/LocalGenUIDesktopCards'; + +const DOMAIN = 0x0000; +const TAG = 'OpenBitFunGenUICard'; + +/** + * Card host of generated-app desktop cards. It runs in its own process and + * only reads and writes the shared card files; it never opens the Local GenUI + * database, model provider, or runtime. The UI process owns app content and + * pushes it with `formProvider.updateForm`. + */ +export default class LocalGenUIFormAbility extends FormExtensionAbility { + private store(): LocalGenUIDesktopCardStore { + return new LocalGenUIDesktopCardStore(this.context.filesDir); + } + + onAddForm(want: Want): formBindingData.FormBindingData { + const parameters = want.parameters as Record | undefined; + const formIdValue = parameters ? parameters[FORM_IDENTITY_PARAM] : undefined; + const formId = typeof formIdValue === 'string' ? formIdValue : ''; + const store = this.store(); + // The launcher may forward the app id; otherwise the app staged it when + // its "Add to desktop" menu opened. The add callback binds again when the + // launcher calls it. + const forwarded = LocalGenUIDesktopCards.appIdOfAddWant(parameters); + const appId = forwarded.length > 0 ? forwarded : store.claimPendingAdd(); + if (forwarded.length > 0) { + store.claimPendingAdd(); + } + if (formId.length > 0 && appId.length > 0) { + store.bind(formId, appId); + } + hilog.info(DOMAIN, TAG, 'Card added bound=%{public}s source=%{public}s', String(appId.length > 0), + forwarded.length > 0 ? 'want' : (appId.length > 0 ? 'pending' : 'none')); + if (formId.length > 0) { + // The preview needs a file descriptor that must outlive this call. + setTimeout(() => { void store.refresh(formId); }, 0); + } + return formBindingData.createFormBindingData(store.textData(formId)); + } + + onUpdateForm(formId: string): void { + void this.store().refresh(formId); + } + + onCastToNormalForm(formId: string): void { + void this.store().refresh(formId); + } + + onChangeFormVisibility(_newStatus: Record): void { + } + + onFormEvent(_formId: string, _message: string): void { + } + + onRemoveForm(formId: string): void { + this.store().unbind(formId); + hilog.info(DOMAIN, TAG, '%{public}s', 'Card removed'); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/pages/LocalGenUIAppCard.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/pages/LocalGenUIAppCard.ets new file mode 100644 index 0000000..d85d487 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/genuiform/pages/LocalGenUIAppCard.ets @@ -0,0 +1,71 @@ +/** + * 2x2 desktop card of one generated app. Service widgets bind data through + * `@LocalStorageProp`, which only V1 `@Entry @Component` pages support, so + * this page is V1 by platform requirement; it lives outside `pages/` and holds + * no app logic. Keys mirror `LocalGenUIDesktopCardData`. + */ +const storage: LocalStorage = new LocalStorage(); + +@Entry(storage) +@Component +struct LocalGenUIAppCard { + @LocalStorageProp('appId') appId: string = ''; + @LocalStorageProp('state') cardState: string = 'pending'; + @LocalStorageProp('title') title: string = ''; + @LocalStorageProp('initial') initial: string = 'AI'; + @LocalStorageProp('imageName') imageName: string = ''; + + private open(): void { + const params: Record = {}; + if (this.appId.length > 0) { + params['openbitfunLocalGenUIApp'] = this.appId; + } + postCardAction(this, { action: 'router', abilityName: 'EntryAbility', params: params }); + } + + build() { + Stack({ alignContent: Alignment.BottomStart }) { + if (this.cardState === 'ready' && this.imageName.length > 0) { + Image(`memory://${this.imageName}`) + .width('100%').height('100%').objectFit(ImageFit.Cover) + } else { + Column({ space: 4 }) { + if (this.cardState === 'pending' && this.title.length === 0) { + Image($r('app.media.openbitfun_app_icon')).width(40).height(40).borderRadius(10) + } else { + Text(this.initial) + .fontSize(36).fontWeight(FontWeight.Bold) + .fontColor($r('app.color.connect_hero_accent')) + .opacity(this.cardState === 'missing' ? 0.4 : 1) + } + } + .width('100%').height('100%').justifyContent(FlexAlign.Center) + .linearGradient({ + angle: 145, + colors: [[$r('app.color.connect_hero_surface'), 0], [$r('app.color.connect_hero_bg'), 1]] + }) + } + Column({ space: 2 }) { + Text(this.title.length > 0 ? this.title : $r('app.string.genui_card_name')) + .fontSize(13).fontWeight(FontWeight.Medium) + .fontColor($r('app.color.content_on_action')) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + if (this.cardState === 'missing') { + Text($r('app.string.genui_card_missing')) + .fontSize(10).fontColor($r('app.color.content_on_action')).opacity(0.85) + .maxLines(1) + } else if (this.cardState === 'pending') { + Text($r('app.string.genui_card_pending')) + .fontSize(10).fontColor($r('app.color.content_on_action')).opacity(0.85) + .maxLines(1) + } + } + .width('100%').alignItems(HorizontalAlign.Start) + .padding({ left: 10, right: 10, top: 6, bottom: 8 }) + .backgroundColor($r('app.color.toast_background')) + } + .width('100%').height('100%').clip(true) + .backgroundColor($r('app.color.card')) + .onClick(() => this.open()) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets index ddb6f85..aa7baf9 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets @@ -210,8 +210,7 @@ export const EN_US_MESSAGES: [string, string][] = [ ['sidebar.tasks', 'Scheduled'], ['sidebar.tools', 'Apps'], ['sidebar.more', 'More'], - ['sidebar.bot', 'Bot'], - ['sidebar.botComingSoon', 'In development. Stay tuned.'], + ['localGenui.entry', 'Create mini apps'], ['sidebar.newChat', 'Chat'], ['sidebar.generalChat', 'General chat'], ['sidebar.conversations', 'Recent chats'], diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets index 52d47f9..3c92358 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets @@ -210,8 +210,7 @@ export const ZH_CN_MESSAGES: [string, string][] = [ ['sidebar.tasks', '已计划'], ['sidebar.tools', '应用'], ['sidebar.more', '更多'], - ['sidebar.bot', 'Bot'], - ['sidebar.botComingSoon', '开发中,敬请期待'], + ['localGenui.entry', '创建小应用'], ['sidebar.newChat', '聊天'], ['sidebar.generalChat', '普通对话'], ['sidebar.conversations', '最近对话'], diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets index c16a4e6..01905ec 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/model/ChatTimelineModels.ets @@ -60,7 +60,8 @@ export class ObservableChatTimelineItem implements ChatTimelineItem { thinking: message.thinking, tools: message.tools ? message.tools.slice() : undefined, items: message.items ? message.items.slice() : undefined, - images: message.images ? message.images.slice() : undefined + images: message.images ? message.images.slice() : undefined, + appCard: message.appCard }; } } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/model/RemoteModels.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/model/RemoteModels.ets index 15eb301..cfea086 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/model/RemoteModels.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/model/RemoteModels.ets @@ -70,6 +70,21 @@ export interface RemoteSession { deviceId?: string; } +/** + * A generated mini app attached to an assistant message. Only Local GenUI + * produces it; remote hosts never send this field. + */ +export interface ChatMessageAppCard { + appId: string; + title: string; + /** Localized status line. */ + status: string; + /** Preview image on this phone, or '' for the drawn fallback. */ + thumbnailPath: string; + /** Reference handed back through the existing open-link intent. */ + link: string; +} + export interface ChatMessage { id: string; role: string; @@ -84,6 +99,7 @@ export interface ChatMessage { tools?: RemoteToolStatusResponse[]; items?: ChatMessageItemResponse[]; images?: ImageAttachment[]; + appCard?: ChatMessageAppCard; } export interface SessionSummary { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/AppRoot.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/AppRoot.ets index 27c1fa9..bc304a3 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/AppRoot.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/AppRoot.ets @@ -5,6 +5,7 @@ import { ColdStartHomeTransition } from './components/ColdStartHomeTransition'; import { AppRootPresentation } from './components/AppRootPresentation'; import { WatchProvisionCard } from './components/WatchProvisionCard'; import { ArkUiAppRootHostAdapter } from './host/AppRootHostAdapter'; +import { LocalGenUIPresentation } from '../services/local-genui/LocalGenUIModels'; import { AppRootRuntime } from './runtime/AppRootRuntime'; @Entry @@ -52,6 +53,9 @@ struct AppRoot { } onBackPress(): boolean { + if (this.runtime.localGenUIViewModel.back()) { + return true; + } if (this.runtime.miniAppViewModel.state.visible) { if (this.runtime.miniAppViewModel.state.appId) this.runtime.miniAppViewModel.actions.back(); else this.runtime.miniAppViewModel.close(); @@ -66,6 +70,10 @@ struct AppRoot { shellState: this.runtime.appShellState, miniAppState: this.runtime.miniAppViewModel.state, miniAppActions: this.runtime.miniAppViewModel.actions, + localGenUIState: this.runtime.localGenUIViewModel.state, + localGenUIActions: this.runtime.localGenUIViewModel.actions, + localGenUIBridge: this.runtime.localGenUIViewModel.bridge, + onLocalGenUIPresentation: (report: LocalGenUIPresentation) => this.runtime.localGenUIViewModel.updatePresentation(report), navigationStack: this.runtime.navigationStack, remotePageState: this.runtime.remotePageState, deviceDirectoryState: this.runtime.deviceDirectoryState, diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/actions/ConversationIntent.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/actions/ConversationIntent.ets index 32b9696..5c4a141 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/actions/ConversationIntent.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/actions/ConversationIntent.ets @@ -7,6 +7,7 @@ export enum ConversationIntentType { MessageQueue = 'message_queue', Mailbox = 'mailbox', OpenSidebar = 'open_sidebar', + OpenBotHistory = 'open_bot_history', Back = 'back', NewSession = 'new_session', TogglePin = 'toggle_pin', @@ -23,6 +24,7 @@ export enum ConversationIntentType { CopyMessage = 'copy_message', RetryMessage = 'retry_message', SelectModel = 'select_model', + ManageModels = 'manage_models', PickImages = 'pick_images', RemoveImage = 'remove_image', OpenFilePreview = 'open_file_preview', diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets index 53e63cd..e83ace7 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets @@ -4,6 +4,10 @@ import { RemoteCompactHomePolicy } from '../policy/RemoteCompactHomePolicy'; import { MiniAppActions, emptyMiniAppActions } from '../../model/MiniAppModels'; import { MiniAppState } from '../state/MiniAppState'; import { MiniAppSurface } from './MiniAppSurface'; +import { LocalGenUIActions, LocalGenUIState, emptyLocalGenUIActions } from '../state/LocalGenUIState'; +import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; +import { LocalGenUISurface } from './LocalGenUISurface'; +import { LocalGenUIPresentation } from '../../services/local-genui/LocalGenUIModels'; import display from '@ohos.display'; import mediaQuery from '@ohos.mediaquery'; import { RemoteUiState } from '../../services/RemoteUiState'; @@ -68,6 +72,10 @@ enum WideWorkspacePresentationMode { export struct AppRootPresentation { @Param miniAppState: MiniAppState = new MiniAppState(); @Param miniAppActions: MiniAppActions = emptyMiniAppActions(); + @Param localGenUIState: LocalGenUIState = new LocalGenUIState(); + @Param localGenUIActions: LocalGenUIActions = emptyLocalGenUIActions(); + @Param localGenUIBridge: LocalGenUIRuntimeBridge = new LocalGenUIRuntimeBridge(); + @Event onLocalGenUIPresentation: (report: LocalGenUIPresentation) => void = () => {}; @Param shellState: AppShellState = new AppShellState(); @Param navigationStack: NavPathStack = new NavPathStack(); @Param remotePageState: RemotePageState = new RemotePageState(); @@ -145,7 +153,7 @@ export struct AppRootPresentation { AppShell({ shellState: this.shellState, useWideLayout: this.isWideLayout(), - allowSidebar: !this.showWelcomeHome(), + allowSidebar: true, settingsPlacement: this.settingsPlacement, compactAccountLogin: this.shellState.settingsMode === 'account' && this.remotePageState.accountUserId.trim().length === 0, @@ -205,7 +213,26 @@ export struct AppRootPresentation { // Sidebar destinations belong to the moving content pane. A root-level // overlay would cover the drawer before its closing animation can run. if (this.miniAppState.visible) { - MiniAppSurface({ state: this.miniAppState, actions: this.miniAppActions }) + MiniAppSurface({ + state: this.miniAppState, + actions: this.miniAppActions, + generatedApps: this.localGenUIState.gallery, + onOpenGenerated: (appId: string) => this.localGenUIActions.openGalleryApp(appId), + onRemoveGenerated: (appId: string) => this.localGenUIActions.removeFromGallery(appId), + generatedState: this.localGenUIState, + onPrepareDesktopCard: (appId: string) => this.localGenUIActions.prepareDesktopCard(appId), + onDesktopCardAdded: (appId: string, formId: string, error: string) => + this.localGenUIActions.desktopCardAdded(appId, formId, error) + }) + } + if (this.localGenUIState.visible) { + LocalGenUISurface({ + state: this.localGenUIState, + actions: this.localGenUIActions, + bridge: this.localGenUIBridge, + locale: RemoteI18n.language(), + onPresentation: (report: LocalGenUIPresentation) => this.onLocalGenUIPresentation(report) + }) } } .width('100%') diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppSidebar.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppSidebar.ets index a983b0f..8249cad 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppSidebar.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppSidebar.ets @@ -126,14 +126,13 @@ export struct AppSidebar { private EmptySlot() { } - /** Reserved for the future on-device assistant, never a remote-session shortcut. */ @Builder - private BotEntryRow() { + private CreateMiniAppEntryRow() { Button({ type: ButtonType.Normal }) { Row({ space: SidebarLayoutPolicy.ROW_GAP }) { - SidebarGlyph({ kind: 'assistant', iconSize: SidebarLayoutPolicy.PROMINENT_ICON_SLOT_SIZE, + SidebarGlyph({ kind: 'create_app', iconSize: SidebarLayoutPolicy.PROMINENT_ICON_SLOT_SIZE, tint: SIDEBAR_MUTED }) - Text(RemoteI18n.t('sidebar.bot')) + Text(RemoteI18n.t('localGenui.entry')) .fontSize(MobileDesignTypography.bodyMedium.size) .fontWeight(FontWeight.Regular) .fontColor(SIDEBAR_MUTED) @@ -141,12 +140,12 @@ export struct AppSidebar { }.width('100%').alignItems(VerticalAlign.Center) } .width('100%') - .height(40) + .height(SidebarLayoutPolicy.ENTRY_ROW_HEIGHT) .padding({ left: SidebarLayoutPolicy.ROW_HORIZONTAL_PADDING, right: SidebarLayoutPolicy.ROW_HORIZONTAL_PADDING }) .backgroundColor(TRANSPARENT) .borderRadius(6) .id('sidebar-local-bot') - .accessibilityText(RemoteI18n.t('sidebar.bot')) + .accessibilityText(RemoteI18n.t('localGenui.entry')) .onClick(() => this.onOpenBot()) } @@ -309,7 +308,7 @@ export struct AppSidebar { private NavigationScroll() { Scroll() { Column() { - this.BotEntryRow() + this.CreateMiniAppEntryRow() this.MiniAppsEntryRow() if (this.showWorkspaceSection) { this.contentSlot() diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/BotSessionList.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/BotSessionList.ets new file mode 100644 index 0000000..1a9c171 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/BotSessionList.ets @@ -0,0 +1,99 @@ +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUISession } from '../../services/local-genui/LocalGenUIModels'; +import { INK, LINE, MUTED, SIDEBAR_SELECTION, TRANSPARENT } from './Theme'; + +/** + * The saved conversations on the Bot sessions page. + */ +@ComponentV2 +export struct BotSessionList { + @Param sessions: LocalGenUISession[] = []; + @Param selectedSessionId: string = ''; + @Param busy: boolean = false; + @Event onOpenSession: (sessionId: string) => void = (_sessionId: string) => {}; + @Event onDeleteSession: (sessionId: string) => void = (_sessionId: string) => {}; + @Local actionSessionId: string = ''; + + build() { + Column() { + if (this.sessions.length === 0) { + Text(RemoteI18n.t('localGenui.noHistory')) + .fontSize(MobileDesignTypography.bodyMedium.size) + .fontColor(MUTED) + .textAlign(TextAlign.Center) + .width('100%').padding({ top: 24, bottom: 24 }) + } + ForEach(this.sessions, (session: LocalGenUISession, index: number) => { + if (index > 0) { + Divider().strokeWidth(0.5).color(LINE).margin({ left: 12, right: 12 }) + } + this.SessionRow(session) + }, (session: LocalGenUISession): string => `${session.id}:${session.title}:${session.updatedAt}`) + }.width('100%') + } + + @Builder + private SessionRow(session: LocalGenUISession) { + Row({ space: 10 }) { + Column({ space: 3 }) { + Text(session.title || RemoteI18n.t('sidebar.untitled')) + .fontSize(MobileDesignTypography.bodyMedium.size) + .fontWeight(session.id === this.selectedSessionId ? FontWeight.Medium : FontWeight.Regular) + .fontColor(INK).maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + if (this.updatedTime(session).length > 0) { + Text(this.updatedTime(session)).fontSize(MobileDesignTypography.labelSmall.size).fontColor(MUTED) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + } + }.layoutWeight(1).alignItems(HorizontalAlign.Start) + if (this.busy && session.id === this.selectedSessionId) { + LoadingProgress().width(16).height(16) + } else if (session.id === this.selectedSessionId) { + SymbolGlyph($r('sys.symbol.checkmark')).fontSize(16).fontColor([INK]) + } else { + SymbolGlyph($r('sys.symbol.chevron_right')).fontSize(12).fontColor([MUTED]) + } + } + .width('100%') + .constraintSize({ minHeight: 56 }) + .padding({ left: 12, right: 12, top: 8, bottom: 8 }) + .alignItems(VerticalAlign.Center) + .backgroundColor(session.id === this.selectedSessionId ? SIDEBAR_SELECTION : TRANSPARENT) + .borderRadius(10) + .accessibilityText(session.title) + .accessibilitySelected(session.id === this.selectedSessionId) + .onClick(() => { + if (!this.busy || session.id === this.selectedSessionId) this.onOpenSession(session.id); + }) + .bindPopup(this.actionSessionId === session.id, { + builder: (): void => this.SessionActions(session), + placement: Placement.Bottom, + enableArrow: false, + onStateChange: (event) => { + if (!event.isVisible && this.actionSessionId === session.id) this.actionSessionId = ''; + } + }) + .gesture(LongPressGesture({ repeat: false }).onAction(() => { + this.actionSessionId = session.id; + })) + } + + private updatedTime(session: LocalGenUISession): string { + const timestamp = Date.parse(session.updatedAt || session.createdAt); + return Number.isFinite(timestamp) ? RemoteI18n.formatMessageTime(timestamp) : ''; + } + + @Builder + private SessionActions(session: LocalGenUISession) { + Column() { + Text(RemoteI18n.t('common.delete')) + .fontSize(MobileDesignTypography.bodyMedium.size) + .fontColor(INK) + .padding({ left: 20, right: 20, top: 12, bottom: 12 }) + .onClick(() => { + this.actionSessionId = ''; + this.onDeleteSession(session.id); + }) + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets index f842939..35c9f1b 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ChatMessageBubble.ets @@ -1,4 +1,5 @@ import { InteractionMailboxState } from '../../model/InteractionMailbox'; +import { MessageAppCard } from './MessageAppCard'; import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; import { ConversationUiImage, ConversationUiMessage, ConversationUiMessageItem, ConversationUiQuestionAnswer, ConversationUiToolStatus } from '../state/ConversationUiModels'; import { MessageCopyScope } from '../actions/ConversationIntent'; @@ -160,6 +161,12 @@ export struct ChatMessageBubble { if (this.item.images && this.item.images.length > 0) { this.MessageImages(this.item.images) } + if (this.item.appCard) { + MessageAppCard({ + card: this.item.appCard, + onOpen: (link: string, title: string) => this.onOpenFilePreview(link, title) + }) + } if (this.isFailedAssistant(this.item) && (this.item.error || '').trim().length > 0) { this.AssistantFailure( this.item.error || '', diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ComposerBar.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ComposerBar.ets index e5b66eb..46f332d 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ComposerBar.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ComposerBar.ets @@ -114,6 +114,7 @@ export struct ComposerBar { @Event onStop: () => void = () => {}; @Event onVoiceInput: () => void = () => {}; @Event onSelectModel: (modelId: string) => void = (_modelId: string) => {}; + @Event onManageModels: () => void = () => {}; @Event onChatInputChange: (value: string) => void = (_value: string) => {}; aboutToAppear(): void { @@ -329,6 +330,11 @@ export struct ComposerBar { } }) .onClick(() => { + // A surface that owns its models opens their manager when none exist yet. + if (this.enabledModels().length === 0 && this.capabilities.supportsModelManagement) { + this.onManageModels(); + return; + } this.toggleModelSelectorPopover(); }) } @@ -361,6 +367,32 @@ export struct ComposerBar { .scrollBar(BarState.Auto) .edgeEffect(EdgeEffect.Spring) .divider(null) + if (this.capabilities.supportsModelManagement) { + Divider() + .strokeWidth(COMPOSER_MODEL_DEFAULTS_DIVIDER_STROKE) + .color(LINE) + .width('100%') + Row({ space: 10 }) { + Stack({ alignContent: Alignment.Center }) { + SymbolGlyph($r('sys.symbol.gearshape')).fontSize(16).fontColor([INK]) + } + .width(20) + .height(20) + Text(RemoteI18n.t('localGenui.manageModels')) + .fontSize(MobileDesignTypography.bodySmall.size) + .fontWeight(FontWeight.Medium) + .fontColor(INK) + .layoutWeight(1) + } + .width('100%') + .constraintSize({ minHeight: MobileDesignGeometry.composerModelSelectorRowHeight }) + .padding({ left: 10, right: 10, top: 8, bottom: 8 }) + .borderRadius(MobileDesignGeometry.composerModelSelectorRowRadius) + .onClick(() => { + this.closeModelSelector(true); + this.onManageModels(); + }) + } } .width(MobileDesignGeometry.composerModelSelectorWidth) .padding({ left: 10, right: 10, top: 10, bottom: 10 }) @@ -880,7 +912,7 @@ export struct ComposerBar { } private shouldShowModelControl(): boolean { - return this.enabledModels().length > 0; + return this.enabledModels().length > 0 || this.capabilities.supportsModelManagement; } private enabledModels(): ConversationUiModel[] { @@ -922,6 +954,9 @@ export struct ComposerBar { return RemoteI18n.t(roleKey); } const selected = this.selectedModel(); + if (!selected && this.enabledModels().length === 0 && this.capabilities.supportsModelManagement) { + return RemoteI18n.t('localGenui.addModel'); + } return selected ? ConversationModelPresentationPolicy.primaryLabel(selected, RemoteI18n.t('chat.model')) : RemoteI18n.t('chat.model'); } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConversationView.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConversationView.ets index fa79790..1bf8044 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConversationView.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConversationView.ets @@ -527,7 +527,7 @@ export struct ConversationView { subtitle: this.headerSubtitle(), titleFallback: this.headerFallback(), allowRename: this.headerAllowRename(), - showActions: this.headerShowActions(), + showActions: this.surface === ChatSurface.Local || this.headerShowActions(), showSidebarButton: this.showSidebarButton, showBackButton: this.showBackButton, showSidebarRestoreButton: this.showSidebarRestoreButton, @@ -707,6 +707,9 @@ export struct ConversationView { onVoiceInput: () => { this.onVoiceInput(); }, + onManageModels: () => { + this.dispatchValue(ConversationIntentType.ManageModels, ''); + }, onSelectModel: (modelId: string) => { this.onSelectModel(modelId); }, @@ -769,15 +772,23 @@ export struct ConversationView { this.isSessionPinned ? RemoteI18n.t('chat.unpin') : RemoteI18n.t('chat.pin'), () => this.onTogglePinSession(), this.isSessionPinned) } - this.RemoteStyleMenuItem('remote_actions_cloud', RemoteI18n.t('chat.uploadedFiles'), - () => this.onShowUploadedFiles()) + if (this.surface === ChatSurface.Local) { + this.RemoteStyleMenuItem('remote_actions_folder', RemoteI18n.t('localGenui.history'), + () => this.dispatchSimple(ConversationIntentType.OpenBotHistory)) + if (this.headerShowActions()) { + this.RemoteStyleMenuItem('delete', RemoteI18n.t('common.delete'), () => this.onDeleteSession()) + } + } else { + this.RemoteStyleMenuItem('remote_actions_cloud', RemoteI18n.t('chat.uploadedFiles'), + () => this.onShowUploadedFiles()) + } if (this.surface === ChatSurface.General) { Divider().strokeWidth(1).color(LINE).margin({ top: 8, bottom: 8 }) this.RemoteStyleMenuItem('remote_actions_folder', RemoteI18n.t('sidebar.archive'), () => this.onArchiveSession()) this.RemoteStyleMenuItem('delete', RemoteI18n.t('common.delete'), () => this.onDeleteSession()) - } else if (this.canStop && this.connectionState === 'connected') { + } else if (this.surface === ChatSurface.Remote && this.canStop && this.connectionState === 'connected') { Divider().strokeWidth(1).color(LINE).margin({ top: 8, bottom: 8 }) this.RemoteStyleMenuItem('stop', RemoteI18n.t('chat.stop'), () => this.onStop()) } @@ -1038,7 +1049,8 @@ export struct ConversationView { } private headerFallback(): string { - return RemoteI18n.t(this.headerPresentation().fallbackKey); + return RemoteI18n.t(this.surface === ChatSurface.Local ? 'localGenui.entry' : + this.headerPresentation().fallbackKey); } private headerAllowRename(): boolean { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICameraPreview.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICameraPreview.ets new file mode 100644 index 0000000..2b67de4 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICameraPreview.ets @@ -0,0 +1,70 @@ +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { + LOCAL_GESTURE_SURFACE_HEIGHT, + LOCAL_GESTURE_SURFACE_WIDTH +} from '../../services/local-genui/LocalGenUIGestureCamera'; +import { CONTENT_ON_ACTION, LINE, MEDIA_BACKGROUND, TOAST_BACKGROUND } from './Theme'; + +/** + * Small live camera preview shown while a Local GenUI app listens for + * gestures, so the person knows the camera is on and can frame themselves. + * Platform leaf: it only owns the surface and reports its id. + */ +@ComponentV2 +export struct LocalGenUICameraPreview { + /** A short (landscape phone) screen gets a smaller preview at the same aspect. */ + @Param compact: boolean = false; + /** Match the floating preview to the current window orientation. */ + @Param landscape: boolean = false; + @Event onSurface: (surfaceId: string) => void = (_surfaceId: string) => {}; + @Event onSurfaceGone: () => void = () => {}; + private controller: XComponentController = new XComponentController(); + + private previewWidth(): number { + return this.landscape ? (this.compact ? 80 : 128) : (this.compact ? 60 : 96); + } + + private previewHeight(): number { + return this.landscape ? (this.compact ? 60 : 96) : (this.compact ? 80 : 128); + } + + aboutToDisappear(): void { + this.onSurfaceGone(); + } + + build() { + Stack({ alignContent: Alignment.Bottom }) { + XComponent({ type: XComponentType.SURFACE, controller: this.controller }) + .onLoad(() => { + this.controller.setXComponentSurfaceSize({ + surfaceWidth: LOCAL_GESTURE_SURFACE_WIDTH, + surfaceHeight: LOCAL_GESTURE_SURFACE_HEIGHT + }); + this.onSurface(this.controller.getXComponentSurfaceId()); + }) + // The front-camera preview arrives rotated in landscape. Rotate the + // child counter-clockwise while swapping its layout dimensions so the + // person remains upright inside the horizontal preview card. + .width(this.landscape ? this.previewHeight() : this.previewWidth()) + .height(this.landscape ? this.previewWidth() : this.previewHeight()) + .rotate({ angle: this.landscape ? -90 : 0 }) + Text(RemoteI18n.t('localGenui.cameraOn')) + .fontSize(MobileDesignTypography.labelSmall.size) + .fontColor(CONTENT_ON_ACTION) + .backgroundColor(TOAST_BACKGROUND) + .padding({ left: this.compact ? 4 : 6, right: this.compact ? 4 : 6, top: 2, bottom: 2 }) + .borderRadius(8) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Clip }) + .margin({ bottom: this.compact ? 4 : 6 }) + } + .width(this.previewWidth()) + .height(this.previewHeight()) + .borderRadius(this.compact ? 12 : 16) + .clip(true) + .backgroundColor(MEDIA_BACKGROUND) + .border({ width: 1, color: LINE }) + .accessibilityText(RemoteI18n.t('localGenui.cameraOn')) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationPicker.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationPicker.ets new file mode 100644 index 0000000..1d84ee6 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationPicker.ets @@ -0,0 +1,114 @@ +import { CollaborationDeviceFilterType, CollaborationServiceFilter, createCollaborationServiceMenuItems, + CollaborationServiceStateDialog } from '@kit.ServiceCollaborationKit'; +import { image } from '@kit.ImageKit'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { HarmonyCollaborationService, HarmonyCollaborationEnvironment } from '../../services/local-genui/HarmonyCollaborationService'; +import { LocalCollaborationKind, LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; +import { INK, MUTED, CARD } from './Theme'; + +/** Platform leaf: the OS owns device discovery, selection and remote consent. */ +@ComponentV2 +export struct LocalGenUICollaborationPicker { + @Param kind: string = ''; + @Param diagnostic: boolean = true; + @Param persist: ((data: ArrayBuffer) => Promise) | undefined = undefined; + @Event onResult: (state: LocalCollaborationSnapshot) => void = () => {}; + @Local environment: HarmonyCollaborationEnvironment = HarmonyCollaborationService.environment(); + @Local status: LocalCollaborationSnapshot = { phase: 'ready', kind: 'photo', received: 0, code: 0, reason: '' }; + @Local picture: image.PixelMap | undefined = undefined; + private service?: HarmonyCollaborationService; + + aboutToAppear(): void { + this.service = new HarmonyCollaborationService((state: LocalCollaborationSnapshot): void => { + this.status = state; + this.onResult(state); + }, (picture: image.PixelMap | undefined): void => { this.picture = picture; }, this.persist); + if (this.environment.unavailable.length > 0) { + this.service.session.begin('photo', this.environment.unavailable); + } + } + + aboutToDisappear(): void { + this.service?.dispose(); + this.service = undefined; + } + + private begin(kind: LocalCollaborationKind): void { + this.service?.session.begin(kind, this.environment.unavailable); + } + + @Builder + private photoMenu() { + Menu() { + if (this.environment.api >= 23) { + createCollaborationServiceMenuItems([CollaborationServiceFilter.TAKE_PHOTO], 1, + [CollaborationDeviceFilterType.PHONE, CollaborationDeviceFilterType.TABLET]) + } + } + } + + @Builder + private scanMenu() { + Menu() { + if (this.environment.api >= 23) { + createCollaborationServiceMenuItems([CollaborationServiceFilter.SCAN_DOCUMENT], 1, + [CollaborationDeviceFilterType.PHONE, CollaborationDeviceFilterType.TABLET]) + } + } + } + + @Builder + private galleryMenu() { + Menu() { + if (this.environment.api >= 23) { + createCollaborationServiceMenuItems([CollaborationServiceFilter.IMAGE_PICKER], 1, + [CollaborationDeviceFilterType.PHONE, CollaborationDeviceFilterType.TABLET, CollaborationDeviceFilterType.PC_2IN1]) + } + } + } + + build() { + Column({ space: 12 }) { + Text(RemoteI18n.t('collaboration.requirements')).fontColor(MUTED) + .fontSize(MobileDesignTypography.bodyMedium.size) + if (this.diagnostic) { + Text(`API ${this.environment.api} · ${this.environment.deviceType} · SysCap ${this.environment.syscap}`) + .id('collaboration-environment').fontColor(MUTED).fontSize(MobileDesignTypography.labelSmall.size) + } + if (this.environment.unavailable.length === 0) { + if (this.kind === '' || this.kind === 'photo') { + Button(RemoteI18n.t('collaboration.photo')).id('collaboration-photo') + .enabled(this.status.phase === 'ready').onClick(() => this.begin('photo')).bindMenu(this.photoMenu) + } + if (this.kind === '' || this.kind === 'scan') { + Button(RemoteI18n.t('collaboration.scan')).id('collaboration-scan') + .enabled(this.status.phase === 'ready').onClick(() => this.begin('scan')).bindMenu(this.scanMenu) + } + if (this.kind === '' || this.kind === 'gallery') { + Button(RemoteI18n.t('collaboration.gallery')).id('collaboration-gallery') + .enabled(this.status.phase === 'ready').onClick(() => this.begin('gallery')).bindMenu(this.galleryMenu) + } + CollaborationServiceStateDialog({ + onState: (code: number, type: string, buffer: ArrayBuffer): void => { + void this.service?.session.accept(code, type, buffer); + } + }) + } + Text(RemoteI18n.t(`collaboration.phase.${this.status.phase}`)) + .id('collaboration-status').fontColor(INK).fontSize(MobileDesignTypography.bodyMedium.size) + if (this.status.reason.length > 0) { + Text(RemoteI18n.t(`collaboration.reason.${this.status.reason}`)) + .id('collaboration-reason').fontColor(MUTED).fontSize(MobileDesignTypography.bodyMedium.size) + } + if (this.diagnostic) { + Text(RemoteI18n.f2('collaboration.result', String(this.status.received), String(this.status.code))) + .id('collaboration-result').fontColor(MUTED).fontSize(MobileDesignTypography.labelSmall.size) + } + if (this.picture) { + Image(this.picture).width('100%').height(240).objectFit(ImageFit.Contain) + .accessibilityText(RemoteI18n.t('collaboration.receivedImage')) + } + }.width('100%').padding(16).backgroundColor(CARD).borderRadius(16) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationSheet.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationSheet.ets new file mode 100644 index 0000000..7c1fbb6 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUICollaborationSheet.ets @@ -0,0 +1,29 @@ +import { LocalCollaborationRequest } from '../../services/local-genui/LocalGenUICollaborationHost'; +import { LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUICollaborationPicker } from './LocalGenUICollaborationPicker'; +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { INK, PAGE_BG } from './Theme'; + +@ComponentV2 +export struct LocalGenUICollaborationSheet { + @Param @Require request: LocalCollaborationRequest; + @Event onClose: (token: number) => void = () => {}; + @Event onResult: (token: number, state: LocalCollaborationSnapshot) => void = () => {}; + @Param @Require receive: (token: number, data: ArrayBuffer) => Promise; + + aboutToDisappear(): void { this.onClose(this.request.token); } + + build() { + Scroll() { + Column({ space: 16 }) { + Text(RemoteI18n.t('collaboration.inputTitle')).fontColor(INK) + .fontSize(MobileDesignTypography.titleLarge.size) + LocalGenUICollaborationPicker({ kind: this.request.kind, diagnostic: false, + persist: (data: ArrayBuffer): Promise => this.receive(this.request.token, data), + onResult: (state: LocalCollaborationSnapshot): void => this.onResult(this.request.token, state) }) + Button(RemoteI18n.t('collaboration.closeInput')).onClick(() => this.onClose(this.request.token)) + }.width('100%').constraintSize({ maxWidth: 760 }).padding(20) + }.width('100%').height('100%').backgroundColor(PAGE_BG) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIModelManager.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIModelManager.ets new file mode 100644 index 0000000..070fe39 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIModelManager.ets @@ -0,0 +1,191 @@ +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUIModelProfile } from '../../services/local-genui/LocalGenUIModelCatalog'; +import { LocalGenUIActions, LocalGenUIState, emptyLocalGenUIActions } from '../state/LocalGenUIState'; +import { CARD, CONTENT_ON_ACTION, INK, LINE, MUTED, PAGE_BG, PRIMARY_ACTION, SHADOW_FAINT, SOFT, STATUS_DANGER, SUBTLE } from './Theme'; +import { SheetCloseHeader } from './SheetCloseHeader'; +import { AppActionButton, AppActionStyle } from './AppActionButton'; + +/** Same field treatment as the model-service settings panel. */ +class LocalFieldStyle implements AttributeModifier { + applyNormalAttribute(instance: TextInputAttribute): void { + instance.width('100%') + .height(52) + .fontSize(MobileDesignTypography.titleSmall.size) + .fontColor(INK) + .placeholderColor(SUBTLE) + .backgroundColor(CARD) + .border({ width: 0.5, color: LINE }) + .borderRadius(12) + .shadow({ radius: 12, color: SHADOW_FAINT, offsetY: 4 }) + .padding({ left: 14, right: 14 }); + } +} + +/** + * Model profiles of Local GenUI Mode: list, add, edit and delete. Keys are + * entered here and stored encrypted on the phone; they are never displayed. + */ +@ComponentV2 +export struct LocalGenUIModelManager { + @Param state: LocalGenUIState = new LocalGenUIState(); + @Param actions: LocalGenUIActions = emptyLocalGenUIActions(); + @Local name: string = ''; + @Local apiUrl: string = ''; + @Local modelName: string = ''; + @Local apiKey: string = ''; + + @Monitor('state.editorOpen', 'state.editingModelId') + onEditorChange(): void { + if (!this.state.editorOpen) return; + const model = this.state.models.find((item: LocalGenUIModelProfile) => item.id === this.state.editingModelId); + this.name = model ? model.name : ''; + this.apiUrl = model ? model.apiUrl : ''; + this.modelName = model ? model.modelName : ''; + this.apiKey = ''; + } + + build() { + Column() { + SheetCloseHeader({ + title: this.state.editorOpen + ? RemoteI18n.t(this.state.editingModelId === 'new' ? 'localGenui.addModel' : 'localGenui.editModel') + : RemoteI18n.t('localGenui.manageModels'), + showDivider: true, + isEnabled: !this.state.editorSaving, + onClose: (): void => { + if (this.state.editorOpen) this.actions.closeEditor(); + else this.actions.closeModelManager(); + } + }) + + if (this.state.editorOpen) { + this.Editor() + } else { + this.ModelList() + } + } + .width('100%').height('100%').backgroundColor(PAGE_BG) + } + + @Builder + ModelList() { + Scroll() { + Column({ space: 10 }) { + if (this.state.models.length === 0) { + Text(RemoteI18n.t('localGenui.noModels')) + .fontSize(MobileDesignTypography.bodyMedium.size).fontColor(MUTED).padding({ top: 8, bottom: 8 }) + } + ForEach(this.state.models, (model: LocalGenUIModelProfile) => { + Row({ space: 10 }) { + Column({ space: 2 }) { + Text(model.name.trim().length > 0 ? model.name : model.modelName) + .fontSize(MobileDesignTypography.bodyMedium.size).fontWeight(FontWeight.Medium).fontColor(INK) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + Text(`${model.modelName} · ${this.host(model.apiUrl)}`) + .fontSize(MobileDesignTypography.labelSmall.size).fontColor(MUTED) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + }.layoutWeight(1).alignItems(HorizontalAlign.Start) + if (model.id === this.state.currentModelId) { + Text(RemoteI18n.t('settings.modelService.currentModel')).fontSize(MobileDesignTypography.labelSmall.size).fontColor(MUTED) + } + SymbolGlyph($r('sys.symbol.chevron_right')).fontSize(14).fontColor([MUTED]) + } + .width('100%').padding(14).borderRadius(16).backgroundColor(CARD).border({ width: 1, color: LINE }) + .onClick(() => this.actions.editModel(model.id)) + }, (model: LocalGenUIModelProfile) => `${model.id}:${model.name}:${model.modelName}:${model.apiUrl}`) + AppActionButton({ + label: RemoteI18n.t('localGenui.addModel'), + style: AppActionStyle.Primary, + actionHeight: 50, + onAction: (): void => this.actions.editModel('new') + }) + } + .width('100%').padding({ left: 16, right: 16, bottom: 24 }) + } + .width('100%').layoutWeight(1).align(Alignment.Top) + } + + @Builder + Editor() { + Scroll() { + Column({ space: 12 }) { + this.Field(RemoteI18n.t('localGenui.modelDisplayName')) + TextInput({ text: this.name, placeholder: RemoteI18n.t('localGenui.modelDisplayNameHint') }) + .attributeModifier(new LocalFieldStyle()) + .onChange((value: string) => { this.name = value; }) + this.Field(RemoteI18n.t('settings.modelService.apiUrl')) + TextInput({ text: this.apiUrl, placeholder: 'https://api.example.com/v1' }) + .attributeModifier(new LocalFieldStyle()) + .type(InputType.URL) + .onChange((value: string) => { this.apiUrl = value; }) + this.Field(RemoteI18n.t('localGenui.apiKey')) + TextInput({ text: this.apiKey, placeholder: this.state.editorHasKey ? RemoteI18n.t('localGenui.apiKeyKept') : RemoteI18n.t('localGenui.apiKey') }) + .attributeModifier(new LocalFieldStyle()) + .type(InputType.Password) + .showPasswordIcon(true) + .onChange((value: string) => { this.apiKey = value; }) + Row({ space: 8 }) { + this.Field(RemoteI18n.t('settings.modelService.modelName')) + Blank() + if (this.state.fetchingModels) { + LoadingProgress().width(18).height(18) + } + Text(RemoteI18n.t('localGenui.fetchModels')) + .fontSize(MobileDesignTypography.labelSmall.size).fontColor(INK) + .padding({ left: 10, right: 10, top: 5, bottom: 5 }).borderRadius(14).backgroundColor(SOFT) + .enabled(!this.state.fetchingModels && this.apiUrl.trim().length > 0) + .onClick(() => this.actions.fetchRemoteModels(this.apiUrl, this.apiKey)) + }.width('100%') + TextInput({ text: this.modelName, placeholder: RemoteI18n.t('settings.modelService.modelName') }) + .attributeModifier(new LocalFieldStyle()) + .onChange((value: string) => { this.modelName = value; }) + if (this.state.remoteModelNames.length > 0) { + Flex({ wrap: FlexWrap.Wrap }) { + ForEach(this.state.remoteModelNames, (name: string) => { + Text(name) + .fontSize(MobileDesignTypography.labelSmall.size) + .fontColor(name === this.modelName ? CONTENT_ON_ACTION : INK) + .backgroundColor(name === this.modelName ? PRIMARY_ACTION : SOFT) + .padding({ left: 10, right: 10, top: 6, bottom: 6 }).borderRadius(14) + .margin({ right: 8, bottom: 8 }) + .onClick(() => { this.modelName = name; }) + }, (name: string) => name) + }.width('100%') + } + if (this.state.editorError.length > 0) { + Text(this.state.editorError).fontSize(MobileDesignTypography.bodySmall.size).fontColor(STATUS_DANGER) + .copyOption(CopyOptions.InApp) + } + AppActionButton({ + label: this.state.editorSaving ? RemoteI18n.t('common.loading') : RemoteI18n.t('common.save'), + style: AppActionStyle.Primary, + actionHeight: 50, + isEnabled: !this.state.editorSaving, + onAction: (): void => this.actions.saveModel({ name: this.name, apiUrl: this.apiUrl, modelName: this.modelName, apiKey: this.apiKey }) + }) + if (this.state.editingModelId !== 'new') { + AppActionButton({ + label: RemoteI18n.t('localGenui.deleteModel'), + style: AppActionStyle.Destructive, + actionHeight: 50, + onAction: (): void => this.actions.removeModel(this.state.editingModelId) + }) + } + } + .width('100%').padding({ left: 16, right: 16, bottom: 24 }).alignItems(HorizontalAlign.Start) + } + .width('100%').layoutWeight(1).align(Alignment.Top) + } + + @Builder + Field(label: string) { + Text(label).fontSize(MobileDesignTypography.bodyMedium.size).fontWeight(FontWeight.Medium).fontColor(INK) + } + + private host(url: string): string { + const withoutScheme = url.replace(/^https?:\/\//, ''); + const slash = withoutScheme.indexOf('/'); + return slash >= 0 ? withoutScheme.slice(0, slash) : withoutScheme; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets new file mode 100644 index 0000000..b9abeee --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets @@ -0,0 +1,357 @@ +import { AddFormMenuItem, KeyboardAvoidMode } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { resourceManager } from '@kit.LocalizationKit'; +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUIPresentation } from '../../services/local-genui/LocalGenUIModels'; +import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; +import { WindowInsetsBinding } from '../../services/WindowSystemBarService'; +import { LocalGenUIActions, LocalGenUIState, emptyLocalGenUIActions } from '../state/LocalGenUIState'; +import { ConversationIntent, ConversationIntentType } from '../actions/ConversationIntent'; +import { ConversationViewState } from '../state/ConversationViewState'; +import { ConversationViewHost } from './ConversationViewHost'; +import { BotSessionList } from './BotSessionList'; +import { AppActionButton, AppActionStyle } from './AppActionButton'; +import { LocalGenUICameraPreview } from './LocalGenUICameraPreview'; +import { LocalGenUICollaborationSheet } from './LocalGenUICollaborationSheet'; +import { LocalCollaborationRequest } from '../../services/local-genui/LocalGenUICollaborationHost'; +import { LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; +import { LocalGenUIModelManager } from './LocalGenUIModelManager'; +import { LocalGenUIWebSurface } from './LocalGenUIWebSurface'; +import { NavigationBackButton } from './NavigationBackButton'; +import { TemplateIcon } from './TemplateIcon'; +import { CONTENT_ON_ACTION, FLOATING_PANEL_BG, INK, PAGE_BG, SHADOW_SUBTLE, TOAST_BACKGROUND } from './Theme'; + +/** Component the launcher snapshots for the add-to-desktop animation. */ +const APP_BODY_ID: string = 'local-genui-app-body'; + +const WIDE_BREAKPOINT: number = 600; + +/** + * Local GenUI page. It lives in the moving content pane like a remote + * conversation: the sidebar opens over it, and remote destinations close it. + */ +@ComponentV2 +export struct LocalGenUISurface { + @Param state: LocalGenUIState = new LocalGenUIState(); + @Param actions: LocalGenUIActions = emptyLocalGenUIActions(); + @Param @Require bridge: LocalGenUIRuntimeBridge; + @Param locale: string = 'zh-CN'; + @Event onPresentation: (report: LocalGenUIPresentation) => void = () => {}; + @Local insets: WindowInsetsBinding = new WindowInsetsBinding(); + @Local scheme: string = 'light'; + @Local bodyWidth: number = 0; + @Local rootWidth: number = 0; + @Local rootHeight: number = 0; + private previousKeyboardAvoidMode: KeyboardAvoidMode = KeyboardAvoidMode.OFFSET; + + aboutToAppear(): void { + // The composer sits at the bottom; resize so the header stays on screen. + this.previousKeyboardAvoidMode = this.getUIContext().getKeyboardAvoidMode(); + this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); + this.actions.appOnScreen(this.showsApp()); + const context = this.getUIContext().getHostContext(); + if (context) { + this.insets.bind(this.getUIContext(), context); + try { + const colorMode = context.resourceManager.getConfigurationSync().colorMode; + this.scheme = colorMode === resourceManager.ColorMode.DARK ? 'dark' : 'light'; + } catch (_err) { + this.scheme = 'light'; + } + } + } + + aboutToDisappear(): void { + this.actions.appOnScreen(false); + this.insets.unbind(); + this.getUIContext().setKeyboardAvoidMode(this.previousKeyboardAvoidMode); + } + + private report(): void { + this.onPresentation({ + posture: this.rootWidth >= WIDE_BREAKPOINT ? 'wide' : 'compact', + deviceWidth: Math.round(this.rootWidth), + deviceHeight: Math.round(this.rootHeight), + safeTop: Math.round(this.insets.top), + safeBottom: Math.round(this.insets.bottom), + // The runtime page fills the device width; it is never scaled. + viewportScale: 1 + }); + } + + /** Device capabilities run only while the app pane is the visible one. */ + @Monitor('state.view', 'state.appId') + onAppVisibilityChanged(): void { + this.actions.appOnScreen(this.showsApp()); + } + + private statusText(status: string): string { + return status.length > 0 ? RemoteI18n.t(`localGenui.status.${status}`) : ''; + } + + /** A missing app (e.g. opened from a stale desktop card) says so, not "unsupported". */ + private statusLine(): string { + if (this.state.appStreaming) return RemoteI18n.t('localGenui.generating'); + if (this.state.appStatus === 'unsupported' && this.state.appTitle.length === 0 && this.state.appDetail.length > 0) { + return this.state.appDetail; + } + return this.statusText(this.state.appStatus); + } + + private showsApp(): boolean { + return this.state.view === 'app' && this.state.appId.length > 0; + } + + /** The conversation pane is the shared remote/general ConversationView. */ + private conversationState(): ConversationViewState { + return ConversationViewState.local(this.state.conversation, ''); + } + + private onConversationIntent(intent: ConversationIntent): void { + if (intent.type === ConversationIntentType.OpenBotHistory) { + this.actions.showSessions(); + return; + } + this.actions.conversation(intent); + } + + /** Floating controls reserve this much below the top inset (vp). */ + private static readonly CONTROL_SIZE: number = 40; + private static readonly CONTROL_TOP: number = 8; + + /** The page runs under the floating controls; tell it how much to keep clear. */ + private syncPageInsets(): void { + const chrome = this.showsApp() ? LocalGenUISurface.CONTROL_TOP + LocalGenUISurface.CONTROL_SIZE : 0; + this.bridge.setInsets(this.insets.top + chrome, this.insets.left, this.insets.right, this.insets.bottom); + } + + @Monitor('insets.top', 'insets.left', 'insets.right', 'insets.bottom', 'state.view', 'state.appId') + onInsetsChanged(): void { + this.syncPageInsets(); + } + + private goBack(): void { + if (this.state.standalone) this.actions.close(); + else this.actions.showChat(); + } + + /** Only states the person must act on or wait for are shown over the app. */ + private floatingStatus(): string { + if (this.state.appStreaming) return RemoteI18n.t('localGenui.generating'); + if (this.state.appStatus === 'failed' || this.state.appStatus === 'unsupported' || this.state.appStatus === 'state_migration_required') { + return this.statusLine(); + } + return ''; + } + + build() { + Stack({ alignContent: Alignment.Top }) { + // Each sheet has its own binding node. + Column() {} + .width(0).height(0) + .bindSheet($$this.state.showCollaboration, this.CollaborationSheet(), { + height: SheetSize.LARGE, showClose: true, backgroundColor: PAGE_BG + }) + // The runtime stays mounted while the page is open so local acceptance + // can probe it even when the conversation is in front. It runs edge to + // edge; the page keeps its content clear of the reported insets. + LocalGenUIWebSurface({ bridge: this.bridge, scheme: this.scheme, locale: this.locale }) + .id(APP_BODY_ID) + .width('100%') + .height('100%') + .onAreaChange((_old: Area, next: Area) => { + this.bodyWidth = Number(next.width); + this.report(); + this.syncPageInsets(); + }) + + if (this.showsApp()) { + this.FloatingControls() + } + + if (this.showsApp() && this.state.cameraWanted) { + LocalGenUICameraPreview({ + compact: this.rootHeight > 0 && this.rootHeight < 480, + landscape: this.rootWidth > this.rootHeight && this.rootWidth > 0, + onSurface: (surfaceId: string) => this.actions.cameraSurface(surfaceId), + onSurfaceGone: () => this.actions.cameraSurfaceGone() + }) + .position({ right: this.insets.rightPadding(12), bottom: this.insets.bottom + 16 }) + } + + if (this.state.view === 'sessions') { + this.SessionsPage() + } else if (!this.showsApp()) { + ConversationViewHost({ + viewState: this.conversationState(), + showSidebarButton: false, + showBackButton: true, + onIntent: (intent: ConversationIntent) => this.onConversationIntent(intent) + }) + .width('100%').height('100%') + } + if (this.state.notice.length > 0) { + Text(this.state.notice) + .fontSize(MobileDesignTypography.bodySmall.size).fontColor(CONTENT_ON_ACTION) + .backgroundColor(TOAST_BACKGROUND).borderRadius(16).padding({ left: 14, right: 14, top: 8, bottom: 8 }) + .margin({ top: 72 + this.insets.top, left: 24, right: 24 }) + .copyOption(CopyOptions.InApp) + } + } + .width('100%').height('100%').backgroundColor(PAGE_BG) + .bindSheet($$this.state.showModelManager, this.ModelManagerSheet(), { + height: SheetSize.LARGE, showClose: false, backgroundColor: PAGE_BG, + onDisappear: () => this.actions.closeModelManager() + }) + .onAreaChange((_old: Area, next: Area) => { + this.rootWidth = Number(next.width); + this.rootHeight = Number(next.height); + this.report(); + }) + } + + @Builder + private SessionsPage() { + Column() { + Row() { + NavigationBackButton({ onBack: () => { this.actions.back(); } }) + Text(RemoteI18n.t('localGenui.entry')) + .fontSize(MobileDesignTypography.conversationHeaderTitle.size) + .fontWeight(FontWeight.Medium).fontColor(INK).textAlign(TextAlign.Center).layoutWeight(1) + Blank().width(48) + }.width('100%').height(56) + .padding({ left: this.insets.leftPadding(8), right: this.insets.rightPadding(8) }) + Scroll() { + Column() { + if (this.state.loading) { + LoadingProgress().width(28).height(28).margin(24) + } else if (this.state.error.length > 0) { + Text(this.state.error).fontSize(MobileDesignTypography.bodyMedium.size).fontColor(INK) + .padding(16) + } else { + BotSessionList({ + sessions: this.state.localSessions, + selectedSessionId: this.state.sessionId, + busy: this.state.conversation.isBusy, + onOpenSession: (id: string): void => this.actions.openSession(id), + onDeleteSession: (id: string): void => this.actions.deleteSession(id) + }) + } + }.width('100%').constraintSize({ maxWidth: 560 }) + }.width('100%').layoutWeight(1).align(Alignment.Top) + .padding({ left: this.insets.leftPadding(12), right: this.insets.rightPadding(12), top: 8 }) + .scrollBar(BarState.Auto) + Column() { + AppActionButton({ + label: RemoteI18n.t('localGenui.newSession'), + style: AppActionStyle.Primary, + elevated: false, + isEnabled: !this.state.loading && !this.state.conversation.isBusy, + onAction: (): void => this.actions.newSession() + }) + }.width('100%').constraintSize({ maxWidth: 560 }) + .padding({ left: this.insets.leftPadding(20), right: this.insets.rightPadding(20), + top: 16, bottom: this.insets.bottomPadding(16) }) + }.id('bot-sessions-page').width('100%').height('100%').padding({ top: this.insets.top }) + .backgroundColor(PAGE_BG) + } + + @Builder + private CollaborationSheet() { + ForEach(this.state.collaborationRequest ? [this.state.collaborationRequest] : [], (request: LocalCollaborationRequest) => { + LocalGenUICollaborationSheet({ request, + receive: (token: number, data: ArrayBuffer): Promise => this.actions.collaborationReceive(token, data), + onClose: (token: number): void => this.actions.collaborationClose(token), + onResult: (token: number, result: LocalCollaborationSnapshot): void => this.actions.collaborationResult(token, result) }) + }, (request: LocalCollaborationRequest): string => String(request.token)) + } + + /** + * The app owns the whole screen: a floating back control at the leading + * edge, the app actions behind a floating menu at the trailing edge, and a + * status pill only while the app is generating or cannot run. + */ + @Builder + FloatingControls() { + Row({ space: 8 }) { + Stack() { + NavigationBackButton({ controlSize: LocalGenUISurface.CONTROL_SIZE, onBack: (): void => this.goBack() }) + } + .width(LocalGenUISurface.CONTROL_SIZE).height(LocalGenUISurface.CONTROL_SIZE) + .borderRadius(LocalGenUISurface.CONTROL_SIZE / 2).clip(true) + .backgroundColor(FLOATING_PANEL_BG).backgroundBlurStyle(BlurStyle.Thin) + .shadow({ radius: 12, color: SHADOW_SUBTLE, offsetY: 2 }) + + Blank().layoutWeight(1) + if (this.floatingStatus().length > 0) { + Row({ space: 6 }) { + if (this.state.appStreaming) { + LoadingProgress().width(14).height(14) + } + Text(this.floatingStatus()) + .fontSize(MobileDesignTypography.labelSmall.size).fontColor(INK) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + } + .height(32).padding({ left: 12, right: 12 }).borderRadius(16) + .backgroundColor(FLOATING_PANEL_BG).backgroundBlurStyle(BlurStyle.Thin) + .constraintSize({ maxWidth: 240 }) + } + Blank().layoutWeight(1) + + if (!this.state.appStreaming && this.state.appStatus !== 'failed' && this.state.appStatus !== 'unsupported') { + Stack({ alignContent: Alignment.Center }) { + TemplateIcon({ src: $r('app.media.remote_ref_more'), iconWidth: 18, iconHeight: 6 }) + } + .width(LocalGenUISurface.CONTROL_SIZE).height(LocalGenUISurface.CONTROL_SIZE) + .borderRadius(LocalGenUISurface.CONTROL_SIZE / 2) + .backgroundColor(FLOATING_PANEL_BG).backgroundBlurStyle(BlurStyle.Thin) + .shadow({ radius: 12, color: SHADOW_SUBTLE, offsetY: 2 }) + .accessibilityText(RemoteI18n.t('localGenui.appActions')) + .bindMenu(this.AppActionsMenu(), { + onAppear: () => this.actions.prepareDesktopCard(this.state.appId) + }) + } else { + Blank().width(LocalGenUISurface.CONTROL_SIZE) + } + } + .width('100%') + .padding({ + left: this.insets.leftPadding(12), right: this.insets.rightPadding(12), + top: this.insets.top + LocalGenUISurface.CONTROL_TOP + }) + .hitTestBehavior(HitTestMode.Transparent) + } + + /** "Add to desktop" places a home-screen card that opens this app. */ + @Builder + AppActionsMenu() { + Menu() { + if (this.state.standalone) { + MenuItem({ content: RemoteI18n.t('localGenui.backToChat') }) + .onClick(() => this.actions.showChat()) + } + if (this.state.inGallery(this.state.appId)) { + MenuItem({ content: RemoteI18n.t('localGenui.removeFromGallery') }) + .onClick(() => this.actions.removeFromGallery(this.state.appId)) + } else { + MenuItem({ content: RemoteI18n.t('localGenui.addToGallery') }) + .onClick(() => this.actions.addToGallery(this.state.appId)) + } + if (this.state.canAddToDesktop(this.state.appId)) { + AddFormMenuItem(this.state.desktopCardWant(this.state.appId), APP_BODY_ID, { + formBindingData: this.state.desktopCardInitialData(this.state.appId, this.state.appTitle), + style: { options: { content: RemoteI18n.t('localGenui.addToDesktop') } }, + callback: (error: BusinessError, formId: string) => { + this.actions.desktopCardAdded(this.state.appId, formId ?? '', error && error.code ? `${error.code}` : ''); + } + }) + } + } + } + + @Builder + ModelManagerSheet() { + LocalGenUIModelManager({ state: this.state, actions: this.actions }) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets new file mode 100644 index 0000000..6387ffd --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets @@ -0,0 +1,155 @@ +import { webview } from '@kit.ArkWeb'; +import { image } from '@kit.ImageKit'; +import BuildProfile from 'BuildProfile'; +import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; +import { LOCAL_GENUI_ICON3D_ROOT } from '../../services/local-genui/LocalGenUIIcon3DStore'; +import { LOCAL_GENUI_COLLABORATION_ROOT } from '../../services/local-genui/LocalGenUICollaborationAssets'; +import { RemoteLogger } from '../../services/RemoteLogger'; + +const LOCAL_GENUI_WEB_ID: string = 'local-genui-runtime-web'; + +/** ArkWeb javaScriptProxy object. Every message is untrusted input. */ +class LocalGenUINativeChannel { + private readonly dispatch: (raw: string) => void; + constructor(dispatch: (raw: string) => void) { this.dispatch = dispatch; } + post(raw: string): void { this.dispatch(raw); } +} + +/** + * Platform leaf for the Local GenUI runtime. It owns only the WebView + * lifecycle and message transport; parsing and rendering stay in the bundle. + */ +@ComponentV2 +export struct LocalGenUIWebSurface { + @Param @Require bridge: LocalGenUIRuntimeBridge; + @Param scheme: string = 'light'; + @Param locale: string = 'zh-CN'; + private controller: webview.WebviewController = new webview.WebviewController(); + private alive: boolean = true; + // Offline documents repeat the same blocked-resource warning on every render. + private loggedConsole: Set = new Set(); + private channel: LocalGenUINativeChannel = new LocalGenUINativeChannel((raw: string): void => { + if (this.alive) this.bridge.receive(raw); + }); + + aboutToAppear(): void { + if (BuildProfile.DEBUG) { + // Debug builds only: lets native acceptance evidence inspect the real DOM. + webview.WebviewController.setWebDebuggingAccess(true); + } + this.bridge.setAppearance(this.scheme, this.locale); + } + + aboutToDisappear(): void { + this.alive = false; + this.bridge.detach(); + } + + @Monitor('scheme', 'locale') + onAppearanceChange(): void { + this.bridge.setAppearance(this.scheme, this.locale); + } + + private send(json: string): void { + if (!this.alive) return; + try { + this.controller.runJavaScript(`window.__genuiHost && window.__genuiHost.receive(${JSON.stringify(json)})`) + .catch((err: Error) => RemoteLogger.warn(`local genui runtime send failed: ${err.message}`)); + } catch (err) { + RemoteLogger.warn(`local genui runtime send failed: ${String(err)}`); + } + } + + private async capture(): Promise { + // Component snapshot of the Web node: what the runtime actually rendered. + try { + const pixels = await this.getUIContext().getComponentSnapshot().get(LOCAL_GENUI_WEB_ID); + if (pixels) { + return pixels; + } + } catch (err) { + RemoteLogger.warn(`local genui component snapshot failed: ${String(err)}`); + } + return new Promise((resolve: (value: image.PixelMap | undefined) => void) => { + try { + this.controller.webPageSnapshot({ id: 'local-genui-thumbnail' }, (err, result) => { + resolve(!err && result && result.status !== false ? result.imagePixelMap : undefined); + }); + } catch (err) { + RemoteLogger.warn(`local genui page snapshot failed: ${String(err)}`); + resolve(undefined); + } + }); + } + + build() { + Web({ src: $rawfile('genui/runtime/index.html'), controller: this.controller }) + .javaScriptAccess(true) + .domStorageAccess(true) + .fileAccess(false) + .imageAccess(true) + // Network images stay closed by the document CSP (img-src data:, blob: and + // the host picture address). The host address is answered below and never + // reaches the network; this switch only lets those requests be issued. + .onlineImageAccess(true) + .geolocationAccess(false) + .mediaPlayGestureAccess(true) + .darkMode(WebDarkMode.Off) + .forceDarkAccess(false) + .overScrollMode(OverScrollMode.NEVER) + .javaScriptProxy({ object: this.channel, name: 'genuiNative', methodList: ['post'], controller: this.controller }) + .onControllerAttached(() => { + this.bridge.attach((json: string): void => this.send(json)); + this.bridge.attachSnapshot((): Promise => this.capture()); + }) + .onInterceptRequest((event: OnInterceptRequestEvent): WebResourceResponse | null => { + // Host-served 3D pictures; nothing else is intercepted. Answers are + // asynchronous: the picture may need one download before the cache has it. + const url = event.request.getRequestUrl(); + const collaborationImage = url.startsWith(LOCAL_GENUI_COLLABORATION_ROOT); + if (!url.startsWith(LOCAL_GENUI_ICON3D_ROOT) && !collaborationImage) { + return null; + } + RemoteLogger.info('local genui host image request'); + const response = new WebResourceResponse(); + response.setResponseIsReady(false); + response.setResponseHeader([ + { headerKey: 'Access-Control-Allow-Origin', headerValue: '*' }, + { headerKey: 'Cache-Control', headerValue: collaborationImage ? 'no-store' : 'max-age=31536000, immutable' } + ]); + void this.bridge.picture(url).then((bytes: ArrayBuffer | undefined) => { + RemoteLogger.info(`local genui host image ${bytes ? `served ${bytes.byteLength} bytes` : 'not found'}`); + if (bytes) { + response.setResponseData(bytes); + response.setResponseMimeType(collaborationImage ? 'image/jpeg' : 'image/png'); + response.setResponseCode(200); + response.setReasonMessage('OK'); + } else { + response.setResponseData(''); + response.setResponseMimeType('text/plain'); + response.setResponseCode(404); + response.setReasonMessage('Not Found'); + } + response.setResponseIsReady(true); + }); + return response; + }) + .onOverrideUrlLoading((request: WebResourceRequest) => { + // The runtime never navigates. Generated content cannot open pages. + return request.getRequestUrl().indexOf('genui/runtime/index.html') < 0; + }) + .onConsole((event) => { + if (event && event.message.getMessageLevel() === MessageLevel.Error) { + const text = event.message.getMessage().slice(0, 300); + if (!this.loggedConsole.has(text) && this.loggedConsole.size < 50) { + this.loggedConsole.add(text); + RemoteLogger.warn(`local genui runtime console: ${text}`); + } + } + return false; + }) + .id(LOCAL_GENUI_WEB_ID) + .width('100%') + .height('100%') + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MessageAppCard.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MessageAppCard.ets new file mode 100644 index 0000000..c6d69f5 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MessageAppCard.ets @@ -0,0 +1,75 @@ +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { ChatMessageAppCard } from '../../model/RemoteModels'; +import { + CARD, CONNECT_HERO_ACCENT, CONNECT_HERO_BG, CONNECT_HERO_SURFACE, CONTENT_ON_ACTION, INK, LINE, MUTED, + PRIMARY_ACTION, SHADOW_FAINT, TOAST_BACKGROUND +} from './Theme'; + +const THUMB_SIZE: number = 76; + +/** + * A generated mini app inside an assistant message: its rendered preview, + * name, status and an open action. Same visual language as the MiniApp + * gallery tile, so the app looks the same wherever it appears. + */ +@ComponentV2 +export struct MessageAppCard { + @Param card: ChatMessageAppCard = { appId: '', title: '', status: '', thumbnailPath: '', link: '' }; + @Event onOpen: (link: string, title: string) => void = (_link: string, _title: string) => {}; + + build() { + Row({ space: 12 }) { + Stack({ alignContent: Alignment.BottomEnd }) { + if (this.card.thumbnailPath.length > 0) { + Image(`file://${this.card.thumbnailPath}`) + .width('100%').height('100%').objectFit(ImageFit.Cover) + .draggable(false).accessibilityLevel('no') + } else { + Text(this.initial()) + .fontSize(MobileDesignTypography.displayLarge.size).fontWeight(FontWeight.Bold) + .fontColor(CONNECT_HERO_ACCENT) + .width('100%').height('100%').textAlign(TextAlign.Center) + .linearGradient({ angle: 145, colors: [[CONNECT_HERO_SURFACE, 0], [CONNECT_HERO_BG, 1]] }) + } + Stack({ alignContent: Alignment.Center }) { + SymbolGlyph($r('sys.symbol.wand_and_stars')).fontSize(11).fontColor([CONTENT_ON_ACTION]) + } + .width(20).height(20).borderRadius(10) + .backgroundColor(TOAST_BACKGROUND).backgroundBlurStyle(BlurStyle.Thin).margin(5) + } + .width(THUMB_SIZE).height(THUMB_SIZE).borderRadius(16).clip(true) + .border({ width: 0.5, color: LINE }) + + Column({ space: 4 }) { + Text(this.card.title) + .fontSize(MobileDesignTypography.titleSmall.size).fontWeight(FontWeight.Medium).fontColor(INK) + .maxLines(2).textOverflow({ overflow: TextOverflow.Ellipsis }) + Text(this.card.status) + .fontSize(MobileDesignTypography.labelSmall.size).fontColor(MUTED) + .maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }) + Text(RemoteI18n.t('common.open')) + .fontSize(MobileDesignTypography.labelMedium.size).fontWeight(FontWeight.Medium) + .fontColor(CONTENT_ON_ACTION).backgroundColor(PRIMARY_ACTION) + .padding({ left: 14, right: 14, top: 6, bottom: 6 }).borderRadius(16) + .margin({ top: 4 }) + } + .layoutWeight(1) + .alignItems(HorizontalAlign.Start) + } + .width('100%') + .padding(12) + .backgroundColor(CARD) + .borderRadius(20) + .border({ width: 0.5, color: LINE }) + .shadow({ radius: 12, color: SHADOW_FAINT, offsetY: 4 }) + .alignItems(VerticalAlign.Center) + .accessibilityText(`${this.card.title}, ${this.card.status}`) + .onClick(() => this.onOpen(this.card.link, this.card.title)) + } + + private initial(): string { + const trimmed = this.card.title.trim(); + return trimmed.length > 0 ? Array.from(trimmed)[0] : 'AI'; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets index 20f6c0d..4fa9474 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets @@ -1,15 +1,32 @@ +import { AddFormMenuItem } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { LocalGenUIState } from '../state/LocalGenUIState'; +import { LocalGenUIGalleryEntry } from '../../services/local-genui/LocalGenUIModels'; import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/MobileDesignTokens'; import { MiniAppSummary } from '../../model/MiniAppModels'; import { RemoteI18n } from '../../i18n/RemoteI18n'; import { MiniAppState } from '../state/MiniAppState'; import { MiniAppGalleryPolicy } from '../policy/MiniAppGalleryPolicy'; -import { CARD, INK, MUTED, LINE, SUBTLE, SHADOW_SUBTLE } from './Theme'; +import { CARD, INK, MUTED, LINE, SUBTLE, SHADOW_SUBTLE, CONNECT_HERO_ACCENT, CONNECT_HERO_SURFACE, TRANSPARENT } from './Theme'; + +interface MiniAppGalleryItem extends MiniAppSummary { + generatedId: string; + thumbnailPath: string; +} @ComponentV2 export struct MiniAppGallery { @Require @Param state: MiniAppState; @Param bottomInset: number = 0; @Event onSelect: (id: string) => void = (_id: string) => {}; + @Param generatedApps: LocalGenUIGalleryEntry[] = []; + @Param generatedState: LocalGenUIState = new LocalGenUIState(); + @Event onOpenGenerated: (id: string) => void = (_id: string) => {}; + @Event onRemoveGenerated: (id: string) => void = (_id: string) => {}; + @Event onPrepareDesktopCard: (id: string) => void = (_id: string) => {}; + @Event onDesktopCardAdded: (id: string, formId: string, error: string) => void = + (_id: string, _formId: string, _error: string) => {}; + @Local failedThumbnails: string[] = []; @Local viewportWidth: number = 360; @Local stackHeight: number = 480; @@ -19,23 +36,23 @@ export struct MiniAppGallery { this.ListView() } else { Stack({ alignContent: Alignment.Center }) { - ForEach(this.state.apps, (app: MiniAppSummary, index: number) => { + ForEach(this.items(), (app: MiniAppGalleryItem, index: number) => { this.SwipeCard(app, index) - }, (app: MiniAppSummary): string => app.id) + }, (app: MiniAppGalleryItem): string => app.id) } .width('100%').layoutWeight(1).clip(true) .onAreaChange((_old: Area, area: Area) => { this.stackHeight = Number(area.height); }) .gesture(PanGesture({ direction: PanDirection.Horizontal, distance: 12 }) .onActionEnd((event: GestureEvent) => { - const index = MiniAppGalleryPolicy.nextIndex(this.currentIndex(), event.offsetX, this.state.apps.length); + const index = MiniAppGalleryPolicy.nextIndex(this.currentIndex(), event.offsetX, this.items().length); this.focus(index); })) Row({ space: 8 }) { - ForEach(this.state.apps, (app: MiniAppSummary, index: number) => { + ForEach(this.items(), (app: MiniAppGalleryItem, index: number) => { Row().width(index === this.currentIndex() ? 24 : 8).height(8) .borderRadius(4).backgroundColor(index === this.currentIndex() ? INK : SUBTLE) .opacity(index === this.currentIndex() ? 1 : 0.4) - }, (app: MiniAppSummary): string => app.id) + }, (app: MiniAppGalleryItem): string => app.id) }.justifyContent(FlexAlign.Center).padding({ top: 20, bottom: 12 }) .accessibilityLevel('no') Text(RemoteI18n.t('miniapp.swipeHint')).fontSize(MobileDesignTypography.labelSmall.size) @@ -46,11 +63,10 @@ export struct MiniAppGallery { } @Builder - private SwipeCard(app: MiniAppSummary, index: number) { + private SwipeCard(app: MiniAppGalleryItem, index: number) { Button({ type: ButtonType.Normal }) { Column() { - Image(this.preview(app.id)).width('100%').height('65%').objectFit(ImageFit.Cover) - .draggable(false).accessibilityLevel('no') + this.Cover(app, '100%', '65%') Column({ space: 8 }) { Text(app.name).fontSize(MobileDesignTypography.titleSmall.size).fontWeight(FontWeight.Bold) .fontColor(INK).maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }).width('100%') @@ -60,7 +76,7 @@ export struct MiniAppGallery { .alignItems(HorizontalAlign.Start) }.width('100%').height('100%') } - .id(`miniapp-card-${app.id}`) + .id(this.elementId(app, true)) .width(MiniAppGalleryPolicy.cardWidth(this.viewportWidth)) .height(MiniAppGalleryPolicy.cardHeight(this.viewportWidth, this.stackHeight)) .padding(0).backgroundColor(CARD).borderRadius(MobileDesignGeometry.miniappCardRadius).clip(true) @@ -73,19 +89,23 @@ export struct MiniAppGallery { .hitTestBehavior(index === this.currentIndex() ? HitTestMode.Default : HitTestMode.None) .accessibilityLevel(index === this.currentIndex() ? 'yes' : 'no-hide-descendants') .accessibilityText(`${app.name}, ${app.description}`) - .onClick(() => { if (index === this.currentIndex()) { this.state.galleryAppId = app.id; this.onSelect(app.id); } }) + .onClick(() => { if (index === this.currentIndex()) this.select(app); }) + .bindContextMenu(this.GeneratedActions(app, true), ResponseType.LongPress, { + onAppear: () => { + if (app.generatedId.length > 0) this.onPrepareDesktopCard(app.generatedId); + } + }) } @Builder private ListView() { Grid() { - ForEach(this.state.apps, (app: MiniAppSummary) => { + ForEach(this.items(), (app: MiniAppGalleryItem) => { GridItem() { Button({ type: ButtonType.Normal }) { Row() { - Image(this.preview(app.id)).width(Math.min(MobileDesignGeometry.miniappListCoverSize, this.viewportWidth * 0.36)) - .height(MobileDesignGeometry.miniappListCoverSize).objectFit(ImageFit.Cover).draggable(false) - .accessibilityLevel('no') + this.Cover(app, Math.min(MobileDesignGeometry.miniappListCoverSize, this.viewportWidth * 0.36), + MobileDesignGeometry.miniappListCoverSize) Column({ space: 8 }) { Text(app.name).fontSize(MobileDesignTypography.titleSmall.size).fontWeight(FontWeight.Bold) .fontColor(INK).maxLines(2).textOverflow({ overflow: TextOverflow.Ellipsis }).width('100%') @@ -93,12 +113,17 @@ export struct MiniAppGallery { .maxLines(3).textOverflow({ overflow: TextOverflow.Ellipsis }).width('100%') }.layoutWeight(1).padding(16).alignItems(HorizontalAlign.Start) }.width('100%') - }.id(`miniapp-list-${app.id}`).width('100%').padding(0).backgroundColor(CARD) + }.id(this.elementId(app, false)).width('100%').padding(0).backgroundColor(CARD) .border({ width: 1, color: LINE, radius: MobileDesignGeometry.miniappListRadius }).clip(true) .accessibilityText(`${app.name}, ${app.description}`) - .onClick(() => { this.state.galleryAppId = app.id; this.onSelect(app.id); }) + .onClick(() => this.select(app)) + .bindContextMenu(this.GeneratedActions(app, false), ResponseType.LongPress, { + onAppear: () => { + if (app.generatedId.length > 0) this.onPrepareDesktopCard(app.generatedId); + } + }) } - }, (app: MiniAppSummary): string => app.id) + }, (app: MiniAppGalleryItem): string => app.id) GridItem() { Row().height(this.bottomInset + 24).hitTestBehavior(HitTestMode.None) } .columnStart(0).columnEnd(MiniAppGalleryPolicy.columns(this.viewportWidth) - 1) }.width('100%').layoutWeight(1).padding({ left: 16, right: 16 }) @@ -107,12 +132,75 @@ export struct MiniAppGallery { .scrollBar(BarState.Off) } + @Builder + private Cover(app: MiniAppGalleryItem, width: Length, height: Length) { + Stack() { + if (app.generatedId.length === 0) { + Image(this.preview(app.id)).width('100%').height('100%').objectFit(ImageFit.Cover) + .draggable(false).accessibilityLevel('no') + } else if (app.thumbnailPath.length > 0 && !this.failedThumbnails.includes(app.thumbnailPath)) { + Image(`file://${app.thumbnailPath}`).width('100%').height('100%').objectFit(ImageFit.Contain) + .draggable(false).accessibilityLevel('no') + .onError(() => { this.failedThumbnails = this.failedThumbnails.concat([app.thumbnailPath]); }) + } else { + SymbolGlyph($r('sys.symbol.square_grid_2x2')) + .fontSize(30).fontColor([CONNECT_HERO_ACCENT]).accessibilityLevel('no') + } + } + .width(width).height(height).clip(true) + .backgroundColor(app.generatedId.length > 0 ? CONNECT_HERO_SURFACE : TRANSPARENT) + } + + @Builder + private GeneratedActions(app: MiniAppGalleryItem, card: boolean) { + if (app.generatedId.length > 0) { + Menu() { + if (this.generatedState.canAddToDesktop(app.generatedId)) { + AddFormMenuItem(this.generatedState.desktopCardWant(app.generatedId), this.elementId(app, card), { + formBindingData: this.generatedState.desktopCardInitialData(app.generatedId, app.name), + style: { options: { content: RemoteI18n.t('localGenui.addToDesktop') } }, + callback: (error: BusinessError, formId: string) => { + this.onDesktopCardAdded(app.generatedId, formId ?? '', error && error.code ? `${error.code}` : ''); + } + }) + } + MenuItem({ content: RemoteI18n.t('localGenui.removeFromGallery') }) + .onClick(() => this.onRemoveGenerated(app.generatedId)) + } + } + } + + private items(): MiniAppGalleryItem[] { + const builtins = this.state.apps.map((app: MiniAppSummary): MiniAppGalleryItem => ({ + id: app.id, name: app.name, description: app.description, generatedId: '', thumbnailPath: '' + })); + const generated = this.generatedApps.map((entry: LocalGenUIGalleryEntry): MiniAppGalleryItem => ({ + id: `generated:${entry.appId}`, + name: entry.title, + description: RemoteI18n.t('localGenui.generatedApps'), + generatedId: entry.appId, + thumbnailPath: entry.thumbnailPath ?? '' + })); + return builtins.concat(generated); + } + + private elementId(app: MiniAppGalleryItem, card: boolean): string { + const id = app.id.replace(/[^A-Za-z0-9_-]/g, '_'); + return card ? `miniapp-card-${id}` : `miniapp-list-${id}`; + } + + private select(app: MiniAppGalleryItem): void { + this.state.galleryAppId = app.id; + if (app.generatedId.length > 0) this.onOpenGenerated(app.generatedId); + else this.onSelect(app.id); + } + private currentIndex(): number { - return Math.max(0, this.state.apps.findIndex((app: MiniAppSummary): boolean => app.id === this.state.galleryAppId)); + return Math.max(0, this.items().findIndex((app: MiniAppGalleryItem): boolean => app.id === this.state.galleryAppId)); } private focus(index: number): void { - const app = this.state.apps[index]; + const app = this.items()[index]; if (!app) return; this.getUIContext().animateTo({ duration: 240, curve: Curve.EaseOut }, () => { this.state.galleryAppId = app.id; }); } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets index c2a77fb..44d2ee0 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets @@ -2,8 +2,10 @@ import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/Mo import { MiniAppActions, emptyMiniAppActions } from '../../model/MiniAppModels'; import { RemoteI18n } from '../../i18n/RemoteI18n'; import { MiniAppState } from '../state/MiniAppState'; -import { TemplateIcon } from './TemplateIcon'; +import { LocalGenUIState } from '../state/LocalGenUIState'; +import { LocalGenUIGalleryEntry } from '../../services/local-genui/LocalGenUIModels'; import { MiniAppGallery } from './MiniAppGallery'; +import { TemplateIcon } from './TemplateIcon'; import { MiniAppWebView } from './MiniAppWebView'; import { NavigationBackButton } from './NavigationBackButton'; import { PAGE_BG, INK, MUTED, SOFT, TRANSPARENT } from './Theme'; @@ -13,6 +15,15 @@ import { WindowInsetsBinding } from '../../services/WindowSystemBarService'; export struct MiniAppSurface { @Param state: MiniAppState = new MiniAppState(); @Param actions: MiniAppActions = emptyMiniAppActions(); + /** Generated apps the user added to the gallery (Local GenUI Mode). */ + @Param generatedApps: LocalGenUIGalleryEntry[] = []; + @Event onOpenGenerated: (appId: string) => void = (_appId: string) => {}; + @Event onRemoveGenerated: (appId: string) => void = (_appId: string) => {}; + /** Local GenUI projection; supplies the add-to-desktop want. */ + @Param generatedState: LocalGenUIState = new LocalGenUIState(); + @Event onPrepareDesktopCard: (appId: string) => void = (_appId: string) => {}; + @Event onDesktopCardAdded: (appId: string, formId: string, error: string) => void = + (_appId: string, _formId: string, _error: string) => {}; @Local insets: WindowInsetsBinding = new WindowInsetsBinding(); aboutToAppear(): void { @@ -47,11 +58,21 @@ export struct MiniAppSurface { .fontColor(MUTED).padding({ top: 16, bottom: 16 }).copyOption(CopyOptions.InApp) Button(RemoteI18n.t('miniapp.refresh')) .fontColor(INK).backgroundColor(SOFT).onClick(() => this.actions.refresh()) - } else if (this.state.apps.length === 0) { + } else if (this.state.apps.length === 0 && this.generatedApps.length === 0) { Text(RemoteI18n.t('miniapp.empty')).fontSize(MobileDesignTypography.bodyMedium.size) .fontColor(MUTED).padding(24) } else { - MiniAppGallery({ state: this.state, bottomInset: this.insets.bottom, onSelect: this.actions.select }) + MiniAppGallery({ + state: this.state, + bottomInset: this.insets.bottom, + onSelect: this.actions.select, + generatedApps: this.generatedApps, + generatedState: this.generatedState, + onOpenGenerated: this.onOpenGenerated, + onRemoveGenerated: this.onRemoveGenerated, + onPrepareDesktopCard: this.onPrepareDesktopCard, + onDesktopCardAdded: this.onDesktopCardAdded + }) .layoutWeight(1) } }.width('100%').constraintSize({ maxWidth: 1000 }).layoutWeight(1) diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SidebarGlyphs.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SidebarGlyphs.ets index 2d9578e..f68e405 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SidebarGlyphs.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SidebarGlyphs.ets @@ -21,6 +21,12 @@ export struct SidebarGlyph { this.Clock() } else if (this.kind === 'apps') { this.Apps() + } else if (this.kind === 'create_app') { + Stack({ alignContent: Alignment.Center }) { + SymbolGlyph($r('sys.symbol.wand_and_stars')) + .fontSize(this.iconSize).fontColor([this.tint]) + } + .width(this.iconSize).height(this.iconSize) } else if (this.kind === 'assistant') { this.Assistant() } else if (this.kind === 'code_flower') { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/WelcomeHome.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/WelcomeHome.ets index 21ba58c..f4dc370 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/WelcomeHome.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/WelcomeHome.ets @@ -1,3 +1,4 @@ +import { SidebarToggleButton } from './SidebarToggleButton'; import { RemoteI18n } from '../../i18n/RemoteI18n'; import { MobileDesignTypography, MobileDesignGeometry as G } from '../../generated/MobileDesignTokens'; import { WelcomePhrase } from './WelcomePhrase'; @@ -18,6 +19,7 @@ import { INK, PAGE_BG, WELCOME_PAGE_BG, MUTED, TRANSPARENT } from './Theme'; export struct WelcomeHome { @Param signedIn: boolean = false; @Event onLogin: () => void = () => {}; + @Event onOpenSidebar: () => void = () => {}; @Event onMiniApps: () => void = () => {}; @Local pageHeight: number = 700; @Local pageWidth: number = 390; @@ -52,6 +54,9 @@ export struct WelcomeHome { Column() { Row() { ForEach('OpenBitFun'.split(''), (letter: string) => { this.Glyph(letter, G.welcomeHeaderWordSize); }) + Blank() + SidebarToggleButton({ restore: true, controlSize: G.controlTouchSize, + onToggle: () => this.onOpenSidebar() }) }.width('100%').height(G.welcomeHeaderHeight) .padding({ left: this.wide() ? 40 : G.welcomeGutter, right: G.welcomeGutter }) if (this.landscape()) { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/remote/RemoteSurfaceHost.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/remote/RemoteSurfaceHost.ets index 5d0ea5b..8e43626 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/remote/RemoteSurfaceHost.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/remote/RemoteSurfaceHost.ets @@ -219,7 +219,8 @@ export struct RemoteSurfaceHost { this.actions.onSettings.openAccount(); } }, - onMiniApps: this.actions.onRemoteHome.openMiniApps + onMiniApps: this.actions.onRemoteHome.openMiniApps, + onOpenSidebar: () => this.onOpenSidebar() }) } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/policy/ConversationMessageRenderPolicy.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/policy/ConversationMessageRenderPolicy.ets index 57d79e5..fc646b9 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/policy/ConversationMessageRenderPolicy.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/policy/ConversationMessageRenderPolicy.ets @@ -36,6 +36,9 @@ export class ConversationMessageRenderPolicy { if (item.images && item.images.length > 0) { return true; } + if (item.appCard) { + return true; + } const status = (item.status || '').toLowerCase(); return status === 'active' || status === 'failed'; } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/CollaborationPreview.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/CollaborationPreview.ets new file mode 100644 index 0000000..6223aa9 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/CollaborationPreview.ets @@ -0,0 +1,32 @@ +import { LocalGenUICollaborationPicker } from '../components/LocalGenUICollaborationPicker'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { INK, MUTED, PAGE_BG } from '../components/Theme'; + +/** Real SDK probe, not simulated devices or a fake transfer. */ +@ComponentV2 +export struct CollaborationPreview { + @Local generation: number = 0; + @Local compact: boolean = false; + + build() { + Scroll() { + Column({ space: 16 }) { + Text(RemoteI18n.t('collaboration.title')).fontColor(INK) + .fontSize(MobileDesignTypography.titleLarge.size) + Text(RemoteI18n.t('collaboration.emulatorNotice')).fontColor(MUTED) + .fontSize(MobileDesignTypography.bodyMedium.size) + ForEach([this.generation], (_generation: number) => { + LocalGenUICollaborationPicker() + }, (generation: number) => String(generation)) + Button(RemoteI18n.t('collaboration.reset')).id('collaboration-reset') + .onClick(() => { this.generation += 1; }) + Button(RemoteI18n.t('collaboration.resize')).id('collaboration-resize') + .onClick(() => { this.compact = !this.compact; }) + Text(RemoteI18n.t('collaboration.resetNotice')).fontColor(MUTED) + .fontSize(MobileDesignTypography.labelSmall.size) + }.padding({ top: 64, left: 20, right: 20, bottom: 40 }) + .width(this.compact ? 340 : '100%').constraintSize({ maxWidth: 840 }) + }.width('100%').height('100%').backgroundColor(PAGE_BG) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/MobileDesignGallery.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/MobileDesignGallery.ets index f44b5e2..67406be 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/MobileDesignGallery.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/preview/MobileDesignGallery.ets @@ -1,3 +1,4 @@ +import { CollaborationPreview } from './CollaborationPreview'; import { HistoryScrollPreview } from './HistoryScrollPreview'; import { ColdStartHomePreview } from './ColdStartHomePreview'; import { ComposerSubmissionPreview } from './ComposerSubmissionPreview'; @@ -48,7 +49,9 @@ struct MobileDesignGallery { } build() { - if ((AppStorage.get('scenarioId') || '').startsWith('cold-start-home')) { + if ((AppStorage.get('scenarioId') || '').startsWith('collaboration')) { + CollaborationPreview() + } else if ((AppStorage.get('scenarioId') || '').startsWith('cold-start-home')) { ColdStartHomePreview() } else if (AppStorage.get('scenarioId') === 'history-scroll') { HistoryScrollPreview() diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets index 90b4627..ff54033 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets @@ -14,6 +14,7 @@ import { stampRemoteSessionsDevice } from '../../services/RemoteSessionIdentity'; import { RemoteUiState } from '../../services/RemoteUiState'; +import { LocalGenUILaunchInbox } from '../../services/local-genui/LocalGenUILaunchInbox'; import { AppRootHostPort } from '../host/AppRootHostAdapter'; import { AppNavigationBackAction, @@ -41,6 +42,11 @@ export class AppRootRuntime extends AppRootRuntimeComposition { } async aboutToAppear(onAccountRestored?: (signedIn: boolean) => void): Promise { + // A generated app opened from its home-screen card is local: it does not + // wait for account, device, or remote restoration below. + LocalGenUILaunchInbox.subscribe((appId: string): void => { + void this.localGenUIViewModel.openGalleryApp(appId); + }); // Account login can be tapped while the rest of the cold-start work is // still running. Initialize its secure store first so the login path never // races the asynchronous cache and onboarding setup below. @@ -85,6 +91,11 @@ export class AppRootRuntime extends AppRootRuntimeComposition { } onPageShow(): void { + this.localGenUIViewModel.setForeground(true); + // Wide layouts keep the local session sidebar mounted from the first + // frame, so there is no sidebar-open callback to trigger its first load. + // Refresh here for both cold starts and returns from the background. + void this.localGenUIViewModel.load(); RemoteLogger.info(`page show state=${(this.remotePageState.connectionState as ConnectionState)} route=${this.appShellViewModel.currentRoute()}`); this.settingsController.setAuthorizationForeground(true); this.taskCompletionNotificationController.onForeground(); @@ -96,6 +107,8 @@ export class AppRootRuntime extends AppRootRuntimeComposition { } onPageHide(): void { + // Background: Local GenUI releases the camera immediately. + this.localGenUIViewModel.setForeground(false); RemoteLogger.info(`page hide state=${(this.remotePageState.connectionState as ConnectionState)} route=${this.appShellViewModel.currentRoute()}`); this.settingsController.setAuthorizationForeground(false); this.settingsController.stopPresencePolling(); @@ -115,7 +128,9 @@ export class AppRootRuntime extends AppRootRuntimeComposition { } aboutToDisappear(): void { + LocalGenUILaunchInbox.unsubscribe(); this.miniAppViewModel.close(); + this.localGenUIViewModel.close(); this.settingsController.stopPresencePolling(); this.watchProvisionController.stop(); this.taskCompletionNotificationController.stop(); @@ -383,6 +398,8 @@ export class AppRootRuntime extends AppRootRuntimeComposition { this.host.animate(230, () => { this.appShellState.setSidebarVisible(true); }); + // Local sessions are read from this phone's own store; no network. + void this.localGenUIViewModel.load(); // The device rows are only on screen from here, and a desktop that came // online since the last look would otherwise stay grey. void this.settingsController.refreshAccountDevicesIfStale(DEVICE_PRESENCE_MAX_AGE_MS).then(() => diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets index f49cb8f..85b60d1 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntimeComposition.ets @@ -9,6 +9,7 @@ import { WorkspaceToolsViewModel } from '../viewmodel/WorkspaceToolsViewModel'; import { WorkspaceToolsIntent } from '../state/WorkspaceToolsState'; import { BuiltinMiniAppHost } from '../../services/BuiltinMiniAppHost'; import { MiniAppViewModel } from '../viewmodel/MiniAppViewModel'; +import { LocalGenUIViewModel } from '../viewmodel/LocalGenUIViewModel'; import { SidebarConnectionActionPolicy } from '../policy/SidebarConnectionActionPolicy'; import { accountDeviceLink } from '../../services/AccountDeviceLink'; import { @@ -157,6 +158,8 @@ export abstract class AppRootRuntimeComposition { readonly sessionManager: RemoteSessionManager = new RemoteSessionManager(); readonly miniAppViewModel: MiniAppViewModel = new MiniAppViewModel(new BuiltinMiniAppHost((): Context => this.host.context())); + // Local GenUI Mode: constructs nothing local until the surface is opened. + readonly localGenUIViewModel: LocalGenUIViewModel = new LocalGenUIViewModel((): Context => this.host.context()); readonly taskCompletionNotificationPort: HarmonyTaskCompletionNotificationPort = new HarmonyTaskCompletionNotificationPort((): Context => this.host.context()); readonly taskCompletionNotificationController: TaskCompletionNotificationController = @@ -978,7 +981,13 @@ export abstract class AppRootRuntimeComposition { onCompactLayoutEntered: (): void => this.enterCompactLayout(), onLayoutModeChanged: (wideLayout: boolean): void => this.appShellState.setWideLayout(wideLayout), onRemoteHome: { - openMiniApps: (): void => { this.closeAppSidebar(); this.miniAppViewModel.actions.open(); }, + openMiniApps: (): void => { + this.closeAppSidebar(); + this.localGenUIViewModel.close(); + this.miniAppViewModel.actions.open(); + // Generated apps the user added appear in the gallery; local data only. + void this.localGenUIViewModel.load(); + }, openSidebar: (): void => this.openAppSidebar(), connectWorkspace: (): void => this.openConnectSheet(), addConnection: (): void => this.openConnectSheet(), @@ -986,6 +995,7 @@ export abstract class AppRootRuntimeComposition { showWorkspaces: (): void => { this.remoteWorkspaceViewModel.toggleRecentWorkspaces(); }, showAssistants: (): void => { this.remoteWorkspaceViewModel.toggleAssistants(); }, selectWorkspace: (path: string, deviceId?: string, connectionId?: string, sshHost?: string, workspaceId?: string): void => { + this.localGenUIViewModel.close(); void this.selectWorkspaceOnDevice(path, deviceId, connectionId, sshHost, workspaceId); }, selectAssistant: (path: string, workspaceId?: string): void => { this.selectAssistant(path, workspaceId); }, @@ -997,14 +1007,18 @@ export abstract class AppRootRuntimeComposition { reconnect: (): void => { this.reconnect(); }, disconnect: (): void => { this.disconnect(false); }, clearPairing: (): void => { this.disconnect(true); }, - create: (agentType: string): void => { this.conversationController.createRemoteSession(agentType); }, + create: (agentType: string): void => { + this.localGenUIViewModel.close(); this.conversationController.createRemoteSession(agentType); }, createInPlace: (agentType: string): void => { + this.localGenUIViewModel.close(); this.conversationController.createRemoteSession(agentType, true); }, createInWorkspace: (path: string, agentType: string, deviceId?: string, connectionId?: string, sshHost?: string, workspaceId?: string): void => { + this.localGenUIViewModel.close(); this.conversationController.createRemoteSessionInWorkspace(path, agentType, false, deviceId, connectionId, sshHost, workspaceId); }, createInWorkspaceInPlace: (path: string, agentType: string, deviceId?: string, connectionId?: string, sshHost?: string, workspaceId?: string): void => { + this.localGenUIViewModel.close(); this.conversationController.createRemoteSessionInWorkspace(path, agentType, true, deviceId, connectionId, sshHost, workspaceId); }, selectDirectoryDevice: (deviceId: string): void => { @@ -1020,17 +1034,25 @@ export abstract class AppRootRuntimeComposition { await this.loadWorkspaceSessionsOnDevice(deviceId, path, remoteConnectionId, remoteSshHost, workspaceId); }, openSession: (session: RemoteSession): void => this.conversationController.openHomeSession(session), - openSessionInPlace: (session: RemoteSession): void => this.conversationController.openHomeSession(session, true), + openSessionInPlace: (session: RemoteSession): void => { + this.localGenUIViewModel.close(); + this.conversationController.openHomeSession(session, true); + }, deleteSession: (session: RemoteSession): void => { this.conversationController.deleteHomeSession(session); } }, onSidebar: { close: (): void => this.closeAppSidebar(), openAssistant: (): void => { void this.assistantNavigationController.open(); }, - openBot: (): void => { this.host.showToast(RemoteI18n.t('sidebar.botComingSoon'), 2200); }, + openBot: (): void => { + this.closeAppSidebar(); + this.miniAppViewModel.actions.close(); + this.localGenUIViewModel.actions.open(); + }, newChat: async (agentType: string = 'code'): Promise => { if (agentType === 'claw') { await this.assistantNavigationController.open(true); return; } if (!SidebarConnectionActionPolicy.canCreateSession(this.remotePageState.connectionState, this.remotePageState.isBusy)) return; this.closeAppSidebar(); + this.localGenUIViewModel.close(); await this.conversationController.createRemoteSession(agentType); }, enterCode: (): void => { this.closeAppSidebar(); this.enterCodeEntry(); }, @@ -1053,6 +1075,7 @@ export abstract class AppRootRuntimeComposition { // The shell supplies the horizontal motion; do not stack a second // NavDestination push animation on top of the closing drawer. this.closeAppSidebar(); + this.localGenUIViewModel.close(); this.conversationController.openHomeSession(session, true); }, deleteSession: (session: RemoteSession): void => { this.conversationController.deleteHomeSession(session); } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatComposerCapabilities.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatComposerCapabilities.ets index 911be61..3dec09a 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatComposerCapabilities.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatComposerCapabilities.ets @@ -11,6 +11,9 @@ export class ChatComposerCapabilities { // turn yield to it, so on that surface the draft outranks the stop button. // Where nothing queues, holding the draft back is the honest behaviour. readonly supportsMidRunSend: boolean; + // The surface owns its model profiles and offers a "manage models" entry in + // the composer's model selector (Local GenUI). Host-owned catalogs do not. + readonly supportsModelManagement: boolean; constructor( surface: ChatSurface, @@ -18,7 +21,8 @@ export class ChatComposerCapabilities { requiresRemoteConnection: boolean, showAddButton: boolean = true, showVoiceInput: boolean = true, - supportsMidRunSend: boolean = false + supportsMidRunSend: boolean = false, + supportsModelManagement: boolean = false ) { this.surface = surface; this.supportsAttachments = supportsAttachments; @@ -26,6 +30,7 @@ export class ChatComposerCapabilities { this.showAddButton = showAddButton; this.showVoiceInput = showVoiceInput; this.supportsMidRunSend = supportsMidRunSend; + this.supportsModelManagement = supportsModelManagement; } } @@ -34,3 +39,7 @@ export const GENERAL_CHAT_COMPOSER_CAPABILITIES: ChatComposerCapabilities = export const REMOTE_CHAT_COMPOSER_CAPABILITIES: ChatComposerCapabilities = new ChatComposerCapabilities(ChatSurface.Remote, true, true, true, true, true); + +/** Local GenUI: phone-owned models, no attachments, voice or remote connection. */ +export const LOCAL_GENUI_COMPOSER_CAPABILITIES: ChatComposerCapabilities = + new ChatComposerCapabilities(ChatSurface.Local, false, false, false, false, false, true); diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatSurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatSurface.ets index 284d69a..cf1bdbe 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatSurface.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ChatSurface.ets @@ -1,4 +1,6 @@ export enum ChatSurface { General = 'general', - Remote = 'remote' + Remote = 'remote', + /** Local GenUI Mode: a phone-owned conversation that produces mini apps. */ + Local = 'local' } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationCoreState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationCoreState.ets index c8b4aa8..bcf8a3a 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationCoreState.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationCoreState.ets @@ -245,7 +245,8 @@ export class ConversationCoreState { thinking: message.thinking, tools: message.tools ? message.tools.slice() : undefined, items: message.items ? message.items.slice() : undefined, - images: message.images ? message.images.slice() : undefined + images: message.images ? message.images.slice() : undefined, + appCard: message.appCard }; } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationUiModels.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationUiModels.ets index 773175e..6dca83b 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationUiModels.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationUiModels.ets @@ -1,6 +1,7 @@ // Presentation-owned structures. Protocol DTOs are mapped at the boundary and // never imported by leaf rendering components. import { + ChatMessageAppCard, ChatMessage, ChatMessageItemResponse, ImageAttachment, @@ -109,6 +110,7 @@ export interface ConversationUiMessage { tools?: ConversationUiToolStatus[]; items?: ConversationUiMessageItem[]; images?: ConversationUiImage[]; + appCard?: ChatMessageAppCard; } /** Stable observable projection consumed by retained/reused message rows. */ @@ -127,6 +129,7 @@ export class ObservableConversationUiMessage implements ConversationUiMessage { @Trace tools: ConversationUiToolStatus[] | undefined = undefined; @Trace items: ConversationUiMessageItem[] | undefined = undefined; @Trace images: ConversationUiImage[] | undefined = undefined; + @Trace appCard: ChatMessageAppCard | undefined = undefined; updateFrom(source: ConversationUiMessage): void { this.id = source.id; @@ -142,6 +145,7 @@ export class ObservableConversationUiMessage implements ConversationUiMessage { this.tools = source.tools; this.items = source.items; this.images = source.images; + this.appCard = source.appCard; } } @@ -267,7 +271,8 @@ export function toConversationUiMessage(source: ChatMessage): ConversationUiMess thinking: source.thinking, tools: source.tools ? source.tools.map((tool: RemoteToolStatusResponse) => toConversationUiToolStatus(tool)) : undefined, items: source.items ? source.items.map((item: ChatMessageItemResponse) => toConversationUiMessageItem(item)) : undefined, - images: source.images ? source.images.map((image: ImageAttachment) => toConversationUiImage(image)) : undefined + images: source.images ? source.images.map((image: ImageAttachment) => toConversationUiImage(image)) : undefined, + appCard: source.appCard }; } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationViewState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationViewState.ets index 59f84d9..5156497 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationViewState.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/ConversationViewState.ets @@ -10,6 +10,7 @@ import { RemoteUiState } from '../../services/RemoteUiState'; import { ChatComposerCapabilities, GENERAL_CHAT_COMPOSER_CAPABILITIES, + LOCAL_GENUI_COMPOSER_CAPABILITIES, REMOTE_CHAT_COMPOSER_CAPABILITIES } from './ChatComposerCapabilities'; import { ChatSurface } from './ChatSurface'; @@ -146,6 +147,17 @@ export class ConversationViewState { return state; } + /** Local GenUI conversation: the same view, phone-owned models and sessions. */ + static local(core: ConversationCoreState, inlineStatus: string): ConversationViewState { + const state = ConversationViewState.fromCore(core); + state.surface = ChatSurface.Local; + state.inlineStatusText = inlineStatus; + state.connectionState = 'connected'; + state.composerCapabilities = LOCAL_GENUI_COMPOSER_CAPABILITIES; + state.showSuggestionsWhenEmpty = false; + return state; + } + private static general(general: GeneralChatPageState, inlineStatus: string): ConversationViewState { const state = ConversationViewState.fromCore(general.conversation); state.inlineStatusText = inlineStatus; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets new file mode 100644 index 0000000..aa6feae --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets @@ -0,0 +1,163 @@ +import { LocalCollaborationRequest } from '../../services/local-genui/LocalGenUICollaborationHost'; +import { LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; +import { LocalGenUIGalleryEntry, LocalGenUISession } from '../../services/local-genui/LocalGenUIModels'; +import { Want } from '@kit.AbilityKit'; +import { formBindingData } from '@kit.FormKit'; +import { LocalGenUIDesktopCards } from '../../services/local-genui/LocalGenUIDesktopCards'; +import { LocalGenUIModelProfile } from '../../services/local-genui/LocalGenUIModelCatalog'; +import { ConversationCoreState } from './ConversationCoreState'; +import { ConversationIntent } from '../actions/ConversationIntent'; + +/** Presentation projection of Local GenUI sessions, conversations and apps. */ +@ObservedV2 +export class LocalGenUIState { + @Trace visible: boolean = false; + /** Opened from the MiniApp gallery: the app alone, without the conversation. */ + @Trace standalone: boolean = false; + /** The conversation pane is the shared ConversationView over this core. */ + @Trace conversation: ConversationCoreState = new ConversationCoreState('chat'); + @Trace loading: boolean = false; + @Trace error: string = ''; + @Trace notice: string = ''; + @Trace localSessions: LocalGenUISession[] = []; + @Trace sessionId: string = ''; + @Trace view: 'sessions' | 'chat' | 'app' = 'sessions'; + @Trace appId: string = ''; + @Trace appTitle: string = ''; + @Trace appStatus: string = ''; + @Trace appDetail: string = ''; + @Trace appUnverified: string[] = []; + @Trace appStreaming: boolean = false; + // Models + @Trace models: LocalGenUIModelProfile[] = []; + @Trace currentModelId: string = ''; + @Trace modelMissing: boolean = false; + @Trace showModelManager: boolean = false; + /** '' = list, 'new' = add form, otherwise the edited model id. */ + @Trace editingModelId: string = ''; + @Trace editorOpen: boolean = false; + @Trace editorSaving: boolean = false; + @Trace editorError: string = ''; + @Trace editorHasKey: boolean = false; + @Trace remoteModelNames: string[] = []; + @Trace fetchingModels: boolean = false; + /** An app on screen holds a gesture subscription: show the camera preview. */ + @Trace showCollaboration: boolean = false; + @Trace collaborationRequest: LocalCollaborationRequest | undefined = undefined; + @Trace cameraWanted: boolean = false; + // Gallery + @Trace gallery: LocalGenUIGalleryEntry[] = []; + /** Bundle of this app; empty until the context is known, which hides "Add to desktop". */ + @Trace bundleName: string = ''; + + currentModelName(): string { + const model = this.models.find((item: LocalGenUIModelProfile) => item.id === this.currentModelId); + if (!model) return ''; + return model.name.trim().length > 0 ? model.name.trim() : model.modelName; + } + + canAddToDesktop(appId: string): boolean { + return this.bundleName.length > 0 && LocalGenUIDesktopCards.isAppId(appId); + } + + /** Want of `AddFormMenuItem` for the app's home-screen card. */ + desktopCardWant(appId: string): Want { + return LocalGenUIDesktopCards.addWant(this.bundleName, appId); + } + + /** + * First content of the new card. It carries the app id itself, so the card + * opens its app even before the card host or the add callback binds it. + */ + desktopCardInitialData(appId: string, title: string): formBindingData.FormBindingData { + const data: Record = {}; + data['appId'] = appId; + data['state'] = title.length > 0 ? 'ready' : 'pending'; + data['title'] = title; + data['initial'] = LocalGenUIDesktopCards.initial(title); + data['imageName'] = ''; + return formBindingData.createFormBindingData(data); + } + + inGallery(appId: string): boolean { + return this.gallery.some((entry: LocalGenUIGalleryEntry) => entry.appId === appId); + } +} + +export interface LocalGenUIModelEditorInput { + name: string; + apiUrl: string; + modelName: string; + apiKey: string; +} + +export interface LocalGenUIActions { + open: () => void; + close: () => void; + back: () => boolean; + newSession: () => void; + openSession: (sessionId: string) => void; + deleteSession: (sessionId: string) => void; + openApp: (appId: string) => void; + showSessions: () => void; + showChat: () => void; + /** Intents from the shared ConversationView. */ + conversation: (intent: ConversationIntent) => void; + // Models + openModelManager: () => void; + closeModelManager: () => void; + editModel: (modelId: string) => void; + closeEditor: () => void; + saveModel: (input: LocalGenUIModelEditorInput) => void; + removeModel: (modelId: string) => void; + fetchRemoteModels: (apiUrl: string, apiKey: string) => void; + // Gallery + addToGallery: (appId: string) => void; + removeFromGallery: (appId: string) => void; + openGalleryApp: (appId: string) => void; + // Desktop cards + /** The add menu is about to show: make sure the card has content to show. */ + prepareDesktopCard: (appId: string) => void; + /** Result of `AddFormMenuItem`; `error` is empty on success. */ + desktopCardAdded: (appId: string, formId: string, error: string) => void; + // Device capabilities (presentation facts from the surface) + appOnScreen: (onScreen: boolean) => void; + cameraSurface: (surfaceId: string) => void; + cameraSurfaceGone: () => void; + collaborationClose: (token: number) => void; + collaborationResult: (token: number, result: LocalCollaborationSnapshot) => void; + collaborationReceive: (token: number, data: ArrayBuffer) => Promise; +} + +export function emptyLocalGenUIActions(): LocalGenUIActions { + return { + open: () => {}, + close: () => {}, + back: (): boolean => false, + newSession: () => {}, + openSession: (_sessionId: string) => {}, + deleteSession: (_sessionId: string) => {}, + openApp: (_appId: string) => {}, + showSessions: () => {}, + showChat: () => {}, + conversation: (_intent: ConversationIntent) => {}, + openModelManager: () => {}, + closeModelManager: () => {}, + editModel: (_modelId: string) => {}, + closeEditor: () => {}, + saveModel: (_input: LocalGenUIModelEditorInput) => {}, + removeModel: (_modelId: string) => {}, + fetchRemoteModels: (_apiUrl: string, _apiKey: string) => {}, + addToGallery: (_appId: string) => {}, + removeFromGallery: (_appId: string) => {}, + openGalleryApp: (_appId: string) => {}, + prepareDesktopCard: (_appId: string) => {}, + desktopCardAdded: (_appId: string, _formId: string, _error: string) => {}, + appOnScreen: (_onScreen: boolean) => {}, + cameraSurface: (_surfaceId: string) => {}, + collaborationClose: (_token: number) => {}, + collaborationResult: (_token: number, _result: LocalCollaborationSnapshot) => {}, + collaborationReceive: async (_token: number, _data: ArrayBuffer): Promise => { throw new Error('collaboration unavailable'); }, + cameraSurfaceGone: () => {} + }; +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIConversationProjection.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIConversationProjection.ets new file mode 100644 index 0000000..c8fadfb --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIConversationProjection.ets @@ -0,0 +1,90 @@ +import { ChatMessage, RemoteModelCatalog, RemoteModelConfig, SessionSummary } from '../../model/RemoteModels'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUIMessage, LocalGenUISession } from '../../services/local-genui/LocalGenUIModels'; +import { LocalGenUIModelProfile } from '../../services/local-genui/LocalGenUIModelCatalog'; + +/** Link scheme the shared timeline renders for a generated app. */ +export const LOCAL_GENUI_APP_LINK: string = 'openbitfun-genui://app/'; +const ACTIVE_TURN_ID: string = 'local-genui-active-turn'; + +/** + * Projects Local GenUI records onto the shapes the shared ConversationView + * already renders, so the local conversation reuses the remote timeline, + * composer and model selector instead of a parallel UI. + */ +export class LocalGenUIConversationProjection { + static session(session: LocalGenUISession): SessionSummary { + return { sessionId: session.id, title: session.title, workspacePath: '', agentType: 'chat' }; + } + + static messages(messages: LocalGenUIMessage[], thumbnailFor: (appId: string) => string): ChatMessage[] { + return messages.map((message: LocalGenUIMessage): ChatMessage => { + const text = message.text.trim(); + const failed = message.error.length > 0; + const projected: ChatMessage = { + id: message.id, + role: message.role, + text, + // The shared bubble draws its own failure block from `error`. + status: failed ? 'failed' : 'completed', + error: failed ? message.error : undefined, + turnId: message.id, + timestamp: message.createdAt, + items: message.role === 'assistant' && text.length > 0 ? [{ type: 'text', content: text }] : undefined + }; + if (message.appId.length > 0) { + projected.appCard = { + appId: message.appId, + title: message.appTitle, + status: message.status.length > 0 ? RemoteI18n.t(`localGenui.status.${message.status}`) : '', + thumbnailPath: thumbnailFor(message.appId), + link: `${LOCAL_GENUI_APP_LINK}${message.appId}` + }; + } + return projected; + }); + } + + static activeTurn(text: string): ChatMessage { + return { + id: ACTIVE_TURN_ID, + role: 'assistant', + text, + status: 'active', + turnId: ACTIVE_TURN_ID, + items: text.length > 0 ? [{ type: 'text', content: text }] : [] + }; + } + + /** Phone-owned model profiles as the composer's model catalog. */ + static catalog(models: LocalGenUIModelProfile[], selectedId: string): RemoteModelCatalog { + return { + version: 1, + models: models.map((model: LocalGenUIModelProfile): RemoteModelConfig => ({ + id: model.id, + name: model.name.trim().length > 0 ? model.name.trim() : model.modelName, + provider: 'local', + base_url: model.apiUrl, + model_name: model.modelName, + enabled: true, + capabilities: ['text_chat'] + })), + // No primary/fast roles: the session pins a concrete model profile. + default_models: {}, + session_model_id: selectedId.length > 0 ? selectedId : undefined + }; + } + + static latestAppId(messages: LocalGenUIMessage[]): string { + for (let i = messages.length - 1; i >= 0; i--) { + if (messages[i].appId.length > 0) { + return messages[i].appId; + } + } + return ''; + } + + static appIdFromLink(reference: string): string { + return reference.startsWith(LOCAL_GENUI_APP_LINK) ? reference.slice(LOCAL_GENUI_APP_LINK.length) : ''; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets new file mode 100644 index 0000000..f4e4d10 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets @@ -0,0 +1,572 @@ +import { LocalGenUICollaborationAssets, LOCAL_GENUI_COLLABORATION_ROOT } from '../../services/local-genui/LocalGenUICollaborationAssets'; +import { LocalGenUICollaborationHost, LocalCollaborationOwner, LocalCollaborationRequest, LocalCollaborationReply } from '../../services/local-genui/LocalGenUICollaborationHost'; +import { LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; +import { HarmonyCollaborationService } from '../../services/local-genui/HarmonyCollaborationService'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { RemoteLogger } from '../../services/RemoteLogger'; +import { GeneralChatConfigStore } from '../../services/general-chat/GeneralChatConfigStore'; +import { LocalGenUIContractLoader } from '../../services/local-genui/LocalGenUIContract'; +import { + HarmonyLocalGenUIStreamTransport, + HttpLocalGenUIModelProvider, + LocalGenUIStreamTransport +} from '../../services/local-genui/LocalGenUIModelProvider'; +import { + LocalGenUIGalleryEntry, + LocalGenUIMessage, + LocalGenUIPresentation, + LocalGenUISession +} from '../../services/local-genui/LocalGenUIModels'; +import { LocalGenUIModelProfile } from '../../services/local-genui/LocalGenUIModelCatalog'; +import { LocalGenUIModelStore } from '../../services/local-genui/LocalGenUIModelStore'; +import { LocalGenUIRepository } from '../../services/local-genui/LocalGenUIRepository'; +import { LocalGenUIThumbnailStore } from '../../services/local-genui/LocalGenUIThumbnailStore'; +import { LocalGenUIDesktopCardStore } from '../../services/local-genui/LocalGenUIDesktopCardStore'; +import { LocalGenUIOrientation } from '../../services/local-genui/LocalGenUIOrientation'; +import { LocalGenUIIcon3DStore } from '../../services/local-genui/LocalGenUIIcon3DStore'; +import { LocalGenUIDeviceCapabilityHost } from '../../services/local-genui/LocalGenUIDeviceCapabilityHost'; +import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; +import { HarmonyCalendarService } from '../../services/local-genui/HarmonyCalendarService'; +import { + LocalGenUIAppView, + LocalGenUIControllerListener, + LocalGenUIPresentationSource, + LocalGenUISessionController +} from '../../services/local-genui/LocalGenUISessionController'; +import { LocalGenUIActions, LocalGenUIModelEditorInput, LocalGenUIState } from '../state/LocalGenUIState'; +import { ConversationIntent, ConversationIntentType, MessageCopyScope } from '../actions/ConversationIntent'; +import { ConversationViewModel } from './ConversationViewModel'; +import { ChatMessage, RemoteModelCatalog, RemoteModelConfig } from '../../model/RemoteModels'; +import { ChatTimelineState } from '../../services/ChatTimelineStore'; +import { RemoteUiState } from '../../services/RemoteUiState'; +import { ClipboardService } from '../../services/ClipboardService'; +import { MarkdownHtmlSerializer } from '../../services/MarkdownHtmlSerializer'; +import { LocalGenUIConversationProjection } from './LocalGenUIConversationProjection'; + +/** + * Local GenUI Mode entry. Local stores are created on first use (surface, + * sidebar section or gallery); Remote Mode never constructs them. + */ +export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalGenUIPresentationSource { + readonly state: LocalGenUIState = new LocalGenUIState(); + readonly bridge: LocalGenUIRuntimeBridge = new LocalGenUIRuntimeBridge(); + private readonly context: () => Context; + private readonly transport: () => LocalGenUIStreamTransport; + private controller?: LocalGenUISessionController; + private initializing?: Promise; + private facts: LocalGenUIPresentation = { posture: 'compact', deviceWidth: 0, deviceHeight: 0, safeTop: 0, safeBottom: 0, viewportScale: 1 }; + private noticeTimer: number = -1; + /** The shared timeline store behind ConversationView. */ + private readonly timeline: ConversationViewModel = new ConversationViewModel(); + private readonly clipboard: ClipboardService = new ClipboardService(); + private messages: LocalGenUIMessage[] = []; + private devices?: LocalGenUIDeviceCapabilityHost; + private collaboration?: LocalGenUICollaborationHost; + private foreground: boolean = true; + private appOnScreen: boolean = false; + private streaming: string = ''; + private readonly orientation: LocalGenUIOrientation; + private preferredOrientation: string = 'auto'; + + readonly actions: LocalGenUIActions = { + open: (): void => { + this.showSessions(); + void this.open(); + }, + close: (): void => this.close(), + back: (): boolean => this.back(), + newSession: (): void => { void this.newSession(); }, + openSession: (sessionId: string): void => { void this.openSession(sessionId); }, + deleteSession: (sessionId: string): void => { void this.withController((c) => c.deleteSession(sessionId)); }, + openApp: (appId: string): void => { + this.state.view = 'app'; + void this.withController((c) => c.openApp(appId)); + }, + showSessions: (): void => this.showSessions(), + showChat: (): void => { + this.state.standalone = false; + this.state.view = 'chat'; + }, + conversation: (intent: ConversationIntent): void => this.dispatch(intent), + openModelManager: (): void => { + this.state.showModelManager = true; + this.state.editorOpen = false; + }, + closeModelManager: (): void => { + this.state.showModelManager = false; + this.state.editorOpen = false; + }, + editModel: (modelId: string): void => this.editModel(modelId), + closeEditor: (): void => { this.state.editorOpen = false; }, + saveModel: (input: LocalGenUIModelEditorInput): void => { void this.saveModel(input); }, + removeModel: (modelId: string): void => { + this.state.editorOpen = false; + void this.withController((c) => c.removeModel(modelId)); + }, + fetchRemoteModels: (apiUrl: string, apiKey: string): void => { void this.fetchRemoteModels(apiUrl, apiKey); }, + addToGallery: (appId: string): void => { + void this.withController(async (c) => { + await c.addToGallery(appId); + this.notice(RemoteI18n.t('localGenui.addedToGallery')); + }); + }, + removeFromGallery: (appId: string): void => { void this.withController((c) => c.removeFromGallery(appId)); }, + openGalleryApp: (appId: string): void => { void this.openGalleryApp(appId); }, + prepareDesktopCard: (appId: string): void => { + void this.withController((c) => c.prepareDesktopCard(appId)); + }, + desktopCardAdded: (appId: string, formId: string, error: string): void => { + if (error.length > 0 || formId.length === 0) { + RemoteLogger.warn(`local genui desktop card not added: ${error}`); + this.notice(RemoteI18n.t('localGenui.addToDesktopFailed')); + return; + } + RemoteLogger.info('local genui desktop card add callback received'); + void this.withController(async (c) => { + await c.desktopCardAdded(appId, formId); + this.notice(RemoteI18n.t('localGenui.addedToDesktop')); + }); + }, + appOnScreen: (onScreen: boolean): void => this.setAppOnScreen(onScreen), + cameraSurface: (surfaceId: string): void => this.attachCameraSurface(surfaceId), + cameraSurfaceGone: (): void => this.detachCameraSurface(), + collaborationClose: (token: number): void => this.collaboration?.close(token), + collaborationResult: (token: number, result: LocalCollaborationSnapshot): void => this.collaboration?.result(token, result), + collaborationReceive: async (token: number, data: ArrayBuffer): Promise => { + if (!this.collaboration) throw new Error('collaboration unavailable'); + await this.collaboration.receive(token, data); + } + }; + + private showSessions(): void { + this.state.standalone = false; + this.state.view = 'sessions'; + } + + constructor(context: () => Context, transport: () => LocalGenUIStreamTransport = () => new HarmonyLocalGenUIStreamTransport()) { + this.context = context; + this.transport = transport; + this.orientation = new LocalGenUIOrientation(context); + } + + /** The add-to-desktop want names this app's card host. */ + private syncBundleName(): void { + if (this.state.bundleName.length > 0) return; + try { + this.state.bundleName = this.context().applicationInfo.name; + } catch (err) { + RemoteLogger.warn(`local genui bundle name unavailable: ${err instanceof Error ? err.message : String(err)}`); + } + } + + /** Read-only local data for the sidebar section and the gallery. */ + async load(): Promise { + this.syncBundleName(); + await this.withController(async (c) => { + await c.refreshSessions(); + await c.refreshGallery(); + }); + } + + async open(): Promise { + this.syncBundleName(); + this.state.visible = true; + this.state.standalone = false; + this.state.error = ''; + try { + await this.ensureController(); + if (this.controller) { + await this.controller.refreshSessions(); + await this.controller.refreshModels(); + await this.controller.refreshGallery(); + } + } catch (err) { + this.state.error = err instanceof Error ? err.message : String(err); + RemoteLogger.warn(`local genui open failed: ${this.state.error}`); + } + } + + async openSession(sessionId: string): Promise { + await this.open(); + this.state.view = 'chat'; + // Opening a session shows its conversation; the app opens from its card. + if (this.controller) await this.controller.openSession(sessionId); + } + + async newSession(): Promise { + await this.open(); + this.state.view = 'chat'; + if (this.controller) this.controller.newSession(); + } + + async openGalleryApp(appId: string): Promise { + await this.open(); + this.state.standalone = true; + this.state.view = 'app'; + if (this.controller) await this.controller.openGalleryApp(appId); + } + + close(): void { + if (this.controller && this.controller.isTurnActive()) { + this.controller.cancel(); + } + this.state.visible = false; + this.state.standalone = false; + this.appOnScreen = false; + this.syncDeviceVisibility(); + this.state.showModelManager = false; + } + + /** Returns true when the back gesture was consumed inside the surface. */ + back(): boolean { + if (!this.state.visible) return false; + if (this.state.editorOpen) { + this.state.editorOpen = false; + return true; + } + if (this.state.showModelManager) { + this.state.showModelManager = false; + return true; + } + if (this.state.view === 'app' && !this.state.standalone) { + this.state.view = 'chat'; + return true; + } + if (this.state.view === 'chat') { + this.showSessions(); + return true; + } + this.close(); + return true; + } + + /** The page reports whether the app pane is on screen. */ + setAppOnScreen(onScreen: boolean): void { + this.appOnScreen = onScreen; + this.syncDeviceVisibility(); + } + + /** The phone app went to the background or came back. */ + setForeground(foreground: boolean): void { + this.foreground = foreground; + this.syncDeviceVisibility(); + } + + /** Camera surface from the preview leaf; recognition starts once it exists. */ + attachCameraSurface(surfaceId: string): void { + if (this.devices) this.devices.attachSurface(surfaceId); + } + + detachCameraSurface(): void { + if (this.devices) this.devices.detachSurface(); + } + + private syncDeviceVisibility(): void { + this.collaboration?.setVisible(this.foreground && this.state.visible && this.appOnScreen); + void this.orientation.sync(this.foreground && this.state.visible && this.appOnScreen, this.preferredOrientation); + if (this.devices) { + const wanted = this.foreground && this.state.visible && this.appOnScreen; + RemoteLogger.info(`local genui device visibility wanted=${wanted} foreground=${this.foreground} visible=${this.state.visible} appOnScreen=${this.appOnScreen} view=${this.state.view}`); + this.devices.setVisible(wanted); + } + } + + updatePresentation(facts: LocalGenUIPresentation): void { + this.facts = facts; + } + + presentation(): LocalGenUIPresentation { + return this.facts; + } + + orientationChanged(orientation: string): void { + this.preferredOrientation = orientation; + this.syncDeviceVisibility(); + } + + // LocalGenUIControllerListener + sessionsChanged(sessions: LocalGenUISession[], activeId: string): void { + this.state.localSessions = sessions; + this.state.sessionId = activeId; + const active = sessions.find((item: LocalGenUISession) => item.id === activeId); + if (active) { + this.state.conversation.setActiveSession(LocalGenUIConversationProjection.session(active)); + } else if (activeId.length === 0) { + this.state.conversation.clearActiveSession(); + } + } + + messagesChanged(sessionId: string, messages: LocalGenUIMessage[]): void { + const switched = sessionId !== this.state.sessionId; + this.state.sessionId = sessionId; + this.messages = messages; + if (switched) { + this.timeline.reset(sessionId); + this.streaming = ''; + } + this.timeline.setPersistedMessages(LocalGenUIConversationProjection.messages(messages, + (appId: string): string => this.controller ? this.controller.thumbnailFor(appId) : '')); + this.syncTimeline(); + } + + streamingText(_sessionId: string, text: string): void { + this.streaming = text; + if (this.state.conversation.isBusy) { + this.timeline.setActiveTurn(LocalGenUIConversationProjection.activeTurn(text)); + } + this.syncTimeline(); + } + + appChanged(app: LocalGenUIAppView | undefined): void { + this.collaboration?.invalidate(app?.appId || '', app?.sourceRevision || 0, app?.streaming || false); + if (!app) { + this.state.appId = ''; + this.state.appTitle = ''; + this.state.appStatus = ''; + this.state.appDetail = ''; + this.state.appUnverified = []; + this.state.appStreaming = false; + if (this.state.view === 'app' && !this.state.standalone) this.state.view = 'chat'; + return; + } + this.state.appId = app.appId; + this.state.appTitle = app.title; + this.state.appStatus = app.status; + this.state.appDetail = app.detail; + this.state.appUnverified = app.unverified; + this.state.appStreaming = app.streaming; + if (app.streaming && this.state.view !== 'sessions') this.state.view = 'app'; + } + + busyChanged(busy: boolean): void { + this.state.conversation.setBusy(busy); + if (busy) { + this.timeline.setActiveTurn(LocalGenUIConversationProjection.activeTurn(this.streaming)); + } else { + this.streaming = ''; + this.timeline.clearActiveTurn(); + } + this.syncTimeline(); + } + + notice(text: string): void { + this.state.notice = text; + if (this.noticeTimer >= 0) clearTimeout(this.noticeTimer); + this.noticeTimer = setTimeout(() => { this.state.notice = ''; this.noticeTimer = -1; }, 5000); + } + + modelsChanged(models: LocalGenUIModelProfile[], currentId: string, missing: boolean): void { + this.state.models = models; + this.state.currentModelId = currentId; + this.state.modelMissing = missing; + // The shared composer's model selector reads the core catalog. + this.state.conversation.setModelCatalog(LocalGenUIConversationProjection.catalog(models, currentId), currentId); + this.state.conversation.setStatusText(missing ? RemoteI18n.t('localGenui.modelMissing') : ''); + } + + galleryChanged(entries: LocalGenUIGalleryEntry[]): void { + this.state.gallery = entries; + } + + private editModel(modelId: string): void { + this.state.editingModelId = modelId; + this.state.editorOpen = true; + this.state.editorError = ''; + this.state.remoteModelNames = []; + this.state.editorHasKey = modelId.length > 0 && modelId !== 'new' && this.controller !== undefined && this.controller.hasStoredKey(modelId); + } + + private async saveModel(input: LocalGenUIModelEditorInput): Promise { + if (!this.controller || this.state.editorSaving) return; + this.state.editorSaving = true; + this.state.editorError = ''; + try { + await this.controller.saveModel({ id: this.state.editingModelId === 'new' ? '' : this.state.editingModelId, name: input.name, apiUrl: input.apiUrl, modelName: input.modelName, apiKey: input.apiKey }); + this.state.editorOpen = false; + this.notice(RemoteI18n.t('localGenui.saved')); + } catch (err) { + this.state.editorError = err instanceof Error ? err.message : String(err); + } finally { + this.state.editorSaving = false; + } + } + + private async fetchRemoteModels(apiUrl: string, apiKey: string): Promise { + if (!this.controller || this.state.fetchingModels) return; + this.state.fetchingModels = true; + this.state.editorError = ''; + try { + const editing = this.state.editingModelId === 'new' ? '' : this.state.editingModelId; + const names = await this.controller.listRemoteModels(apiUrl, apiKey, editing); + this.state.remoteModelNames = names; + if (names.length === 0) this.state.editorError = RemoteI18n.t('localGenui.noRemoteModels'); + } catch (err) { + this.state.editorError = err instanceof Error ? err.message : String(err); + } finally { + this.state.fetchingModels = false; + } + } + + /** Intents of the shared ConversationView. Unsupported ones are explicit. */ + private dispatch(intent: ConversationIntent): void { + switch (intent.type) { + case ConversationIntentType.ChatInputChanged: + this.state.conversation.setChatInput(intent.value); + return; + case ConversationIntentType.Send: + void this.send(this.state.conversation.chatInput); + return; + case ConversationIntentType.RetryMessage: + void this.send(intent.value); + return; + case ConversationIntentType.Stop: + if (this.controller) this.controller.cancel(); + return; + case ConversationIntentType.SelectModel: + void this.withController((c) => c.chooseModel(intent.value)); + return; + case ConversationIntentType.ManageModels: + this.actions.openModelManager(); + return; + case ConversationIntentType.NewSession: + void this.newSession(); + return; + case ConversationIntentType.Back: + this.back(); + return; + case ConversationIntentType.Delete: + if (this.state.sessionId.length > 0) this.actions.deleteSession(this.state.sessionId); + return; + case ConversationIntentType.RenameSession: + void this.withController((c) => c.renameSession(this.state.sessionId, intent.value)); + return; + case ConversationIntentType.CopyMessage: + void this.copy(intent.value, intent.copyScope); + return; + case ConversationIntentType.OpenFilePreview: { + const reference = intent.filePreviewRequest ? intent.filePreviewRequest.reference : ''; + const appId = LocalGenUIConversationProjection.appIdFromLink(reference); + if (appId.length > 0) { + this.actions.openApp(appId); + } else { + this.notice(RemoteI18n.t('localGenui.linkUnsupported')); + } + return; + } + default: + return; + } + } + + private async copy(text: string, scope: MessageCopyScope): Promise { + if (text.trim().length === 0) return; + try { + if (scope === MessageCopyScope.Rich) { + await this.clipboard.copyRich(text, MarkdownHtmlSerializer.toHtml(text)); + } else { + await this.clipboard.writeText(text); + } + this.notice(RemoteI18n.t('status.messageCopied')); + } catch (err) { + this.notice(err instanceof Error ? err.message : String(err)); + } + } + + private syncTimeline(): void { + const snapshot: ChatTimelineState = this.timeline.snapshotState(); + this.state.conversation.setTimelineProjection( + snapshot.persistedMessages, + snapshot.optimisticMessages, + snapshot.activeTurn || RemoteUiState.emptyActiveTurn(), + false, + this.timeline.viewState(false) + ); + } + + /** Follow-up turns in a session refine its latest app. */ + private async send(text: string): Promise { + const prompt = text.trim(); + if (prompt.length === 0 || this.state.conversation.isBusy) return; + await this.withController(async (c) => { + this.state.conversation.setChatInput(''); + await c.send(prompt, LocalGenUIConversationProjection.latestAppId(this.messages)); + }); + } + + private async withController(work: (controller: LocalGenUISessionController) => Promise): Promise { + try { + await this.ensureController(); + if (this.controller) await work(this.controller); + } catch (err) { + this.notice(err instanceof Error ? err.message : String(err)); + } + } + + private async ensureController(): Promise { + if (this.controller) return; + if (!this.initializing) { + this.initializing = this.createController(); + } + try { + await this.initializing; + } catch (err) { + this.initializing = undefined; + throw err instanceof Error ? err : new Error(String(err)); + } + } + + private async createController(): Promise { + this.state.loading = true; + try { + const context = this.context(); + const contract = await LocalGenUIContractLoader.load(context); + const repository = new LocalGenUIRepository(); + await repository.init(context); + const legacy = new GeneralChatConfigStore(); + await legacy.init(context); + const models = new LocalGenUIModelStore(); + await models.init(context, legacy); + const provider = new HttpLocalGenUIModelProvider(models, this.transport()); + const thumbnails = new LocalGenUIThumbnailStore(context.filesDir); + const desktopCards = new LocalGenUIDesktopCardStore(context.filesDir); + const icons = new LocalGenUIIcon3DStore(context.filesDir); + const assets = new LocalGenUICollaborationAssets(context.filesDir); + this.bridge.setPictureSource(async (url: string): Promise => { + if (!url.startsWith(LOCAL_GENUI_COLLABORATION_ROOT)) return icons.picture(url); + const mount = this.bridge.currentMount(); + if (!mount) return undefined; + const bytes = await assets.picture(mount.identity.appId, url); + return this.bridge.currentMount()?.identity.appId === mount.identity.appId ? bytes : undefined; + }); + const collaboration = new LocalGenUICollaborationHost({ + owner: (): LocalCollaborationOwner => { + const mount = this.bridge.currentMount(); + return { appId: mount?.identity.appId || '', sourceRevision: mount?.sourceRevision || 0, + live: !!mount && mount.mode === 'live' && !mount.streaming }; + }, + unavailable: (): string => HarmonyCollaborationService.environment().unavailable, + changed: (request: LocalCollaborationRequest | undefined): void => { + this.state.collaborationRequest = request; + this.state.showCollaboration = request !== undefined; + }, + send: (reply: LocalCollaborationReply): void => this.bridge.sendCollaboration(reply), + save: (appId: string, data: ArrayBuffer): Promise => assets.save(appId, data), + discard: (appId: string, asset: string): Promise => assets.discard(appId, asset) + }); + this.collaboration = collaboration; + const devices = new LocalGenUIDeviceCapabilityHost(context, { + gesture: (subscriptionId: string, gesture: string): void => this.bridge.sendCapabilityEvent(subscriptionId, gesture), + status: (subscriptionId: string, status: string): void => this.bridge.sendCapabilityStatus(subscriptionId, status), + cameraWanted: (wanted: boolean): void => { this.state.cameraWanted = wanted; } + }); + const calendar = new HarmonyCalendarService((): Context => context); + this.devices = devices; + this.syncDeviceVisibility(); + this.controller = new LocalGenUISessionController(repository, provider, contract, this.bridge, this, this, models, thumbnails, devices, desktopCards, calendar, collaboration); + await this.controller.refreshModels(); + RemoteLogger.info(`local genui ready renderer=${contract.manifest.rendererRevision} models=${models.list().length}`); + } finally { + this.state.loading = false; + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets index ef68dca..6aff7f3 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineProjector.ets @@ -126,7 +126,8 @@ export class ChatTimelineProjector { thinking: message.thinking, tools: message.tools, items: message.items, - images: message.images + images: message.images, + appCard: message.appCard }; } } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets index 2b0034e..ca620b6 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/ChatTimelineStore.ets @@ -159,7 +159,8 @@ export class ChatTimelineStore { thinking: message.thinking, tools: message.tools, items: message.items, - images: message.images + images: message.images, + appCard: message.appCard }; }); this.state = { @@ -747,7 +748,8 @@ export class ChatTimelineStore { thinking: message.thinking, tools: message.tools, items: ChatTimelineStore.mergeActiveItems(activeTurn.items || [], message.items || []), - images: message.images + images: message.images, + appCard: message.appCard }; }); } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCalendarService.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCalendarService.ets new file mode 100644 index 0000000..d2bdef4 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCalendarService.ets @@ -0,0 +1,269 @@ +import { abilityAccessCtrl, Context, Permissions } from '@kit.AbilityKit'; +import { calendarManager } from '@kit.CalendarKit'; +import { MobileDesignColors } from '../../generated/MobileDesignTokens'; +import { RemoteLogger } from '../RemoteLogger'; + +const READ_CALENDAR: Permissions = 'ohos.permission.READ_CALENDAR'; +const WRITE_CALENDAR: Permissions = 'ohos.permission.WRITE_CALENDAR'; +const CALENDAR_NAME: string = 'OpenBitFun'; +const MAX_TITLE_LENGTH: number = 256; +const MAX_TEXT_LENGTH: number = 4000; +const MAX_REMINDERS: number = 5; + +export type HarmonyCalendarAction = 'CreateCalendarEvent' | 'UpdateCalendarEvent' | 'DeleteCalendarEvent' | 'ListCalendarEvents'; + +export interface HarmonyCalendarActionResult { + ok: boolean; + kind: 'created' | 'updated' | 'deleted' | 'listed' | 'failed'; + eventId?: number; + count?: number; + error?: string; +} + +interface CalendarActionParams { + id?: Object; + title?: Object; + startTime?: Object; + endTime?: Object; + description?: Object; + location?: Object; + reminderMinutes?: Object; + recurrence?: Object; +} + +interface RecurrenceParams { + frequency?: Object; + interval?: Object; + count?: Object; + expire?: Object; +} + +/** + * Calendar Kit adapter for Local GenUI. + * + * The adapter owns one application-specific local calendar. It does not use + * the Huawei Clock alarm store and it never touches calendars created by other + * applications. Permission is requested only after an explicit GenUI action. + */ +export class HarmonyCalendarService { + private readonly contextProvider: () => Context; + private permissionRequest?: Promise; + private manager?: calendarManager.CalendarManager; + private calendar?: calendarManager.Calendar; + + constructor(contextProvider: () => Context) { + this.contextProvider = contextProvider; + } + + async execute(action: HarmonyCalendarAction, rawParams: Object): Promise { + try { + const params = HarmonyCalendarService.params(rawParams); + if (action === 'CreateCalendarEvent') { + return await this.create(params); + } + if (action === 'UpdateCalendarEvent') { + return await this.update(params); + } + if (action === 'DeleteCalendarEvent') { + return await this.remove(params); + } + if (action === 'ListCalendarEvents') { + return await this.list(params); + } + return this.failure('unsupported calendar action'); + } catch (err) { + const reason = HarmonyCalendarService.errorText(err); + RemoteLogger.warn(`local genui calendar action failed: ${reason}`); + return this.failure(reason); + } + } + + private async create(params: CalendarActionParams): Promise { + const event = this.event(params); + const id = await (await this.ensureCalendar()).addEvent(event); + return { ok: true, kind: 'created', eventId: id }; + } + + private async update(params: CalendarActionParams): Promise { + const id = HarmonyCalendarService.number(params.id, 'id', true); + const event = this.event(params); + event.id = id; + await (await this.ensureCalendar()).updateEvent(event); + return { ok: true, kind: 'updated', eventId: id }; + } + + private async remove(params: CalendarActionParams): Promise { + const id = HarmonyCalendarService.number(params.id, 'id', true); + await (await this.ensureCalendar()).deleteEvent(id); + return { ok: true, kind: 'deleted', eventId: id }; + } + + private async list(params: CalendarActionParams): Promise { + const calendar = await this.ensureCalendar(); + const start = params.startTime === undefined ? undefined : HarmonyCalendarService.time(params.startTime, 'startTime'); + const end = params.endTime === undefined ? undefined : HarmonyCalendarService.time(params.endTime, 'endTime'); + if (start !== undefined && end !== undefined && end <= start) { + return this.failure('endTime must be later than startTime'); + } + const filter = start !== undefined && end !== undefined ? calendarManager.EventFilter.filterByTime(start, end) : undefined; + const events = await calendar.getEvents(filter); + return { ok: true, kind: 'listed', count: events.length }; + } + + private async ensureCalendar(): Promise { + await this.ensurePermission(); + if (this.calendar) { + return this.calendar; + } + if (!this.manager) { + this.manager = calendarManager.getCalendarManager(this.contextProvider()); + } + const account: calendarManager.CalendarAccount = { + name: CALENDAR_NAME, + type: calendarManager.CalendarType.LOCAL, + displayName: CALENDAR_NAME + }; + try { + this.calendar = await this.manager.getCalendar(account); + } catch (_err) { + this.calendar = await this.manager.createCalendar(account); + await this.calendar.setConfig({ enableReminder: true, color: MobileDesignColors.brandDot.light }); + } + return this.calendar; + } + + private async ensurePermission(): Promise { + if (!this.permissionRequest) { + this.permissionRequest = this.requestPermission(); + } + if (!(await this.permissionRequest)) { + throw new Error('calendar permission denied'); + } + } + + private async requestPermission(): Promise { + try { + const atManager = abilityAccessCtrl.createAtManager(); + const result = await atManager.requestPermissionsFromUser(this.contextProvider(), [READ_CALENDAR, WRITE_CALENDAR]); + return result.authResults.length === 2 && + result.authResults[0] === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED && + result.authResults[1] === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; + } catch (err) { + RemoteLogger.warn(`local genui calendar permission request failed: ${HarmonyCalendarService.errorText(err)}`); + return false; + } + } + + private event(params: CalendarActionParams): calendarManager.Event { + const title = HarmonyCalendarService.text(params.title, 'title', MAX_TITLE_LENGTH, true); + const start = HarmonyCalendarService.time(params.startTime, 'startTime', true) as number; + const end = HarmonyCalendarService.time(params.endTime, 'endTime', true) as number; + if (start !== undefined && end !== undefined && end <= start) { + throw new Error('endTime must be later than startTime'); + } + const event: calendarManager.Event = { + title, + startTime: start, + endTime: end, + type: calendarManager.EventType.NORMAL + }; + const description = HarmonyCalendarService.text(params.description, 'description', MAX_TEXT_LENGTH, false); + const location = HarmonyCalendarService.text(params.location, 'location', MAX_TEXT_LENGTH, false); + if (description) event.description = description; + if (location) { + const place: calendarManager.Location = { location }; + event.location = place; + } + const reminders = HarmonyCalendarService.reminders(params.reminderMinutes); + if (reminders.length > 0) event.reminderTime = reminders; + const recurrence = HarmonyCalendarService.recurrence(params.recurrence); + if (recurrence) event.recurrenceRule = recurrence; + return event; + } + + private static params(value: Object): CalendarActionParams { + const raw = value as Record; + if (raw['event'] && typeof raw['event'] === 'object') return raw['event'] as CalendarActionParams; + if (raw['filter'] && typeof raw['filter'] === 'object') return raw['filter'] as CalendarActionParams; + return value as CalendarActionParams; + } + + private static text(value: Object | undefined, name: string, max: number, required: boolean = false): string { + if (value === undefined || value === null) { + if (required) throw new Error(`${name} is required`); + return ''; + } + if (typeof value !== 'string' || value.trim().length === 0) { + if (required) throw new Error(`${name} must be a non-empty string`); + return ''; + } + const result = value.trim(); + if (result.length > max) throw new Error(`${name} is too long`); + return result; + } + + private static number(value: Object | undefined, name: string, required: boolean = false, minimum: number = 1): number { + if (value === undefined || value === null || value === '') { + if (required) throw new Error(`${name} is required`); + return 0; + } + const result = typeof value === 'number' ? value : Number(value); + if (!Number.isInteger(result) || result < minimum) { + throw new Error(`${name} must be an integer greater than or equal to ${minimum}`); + } + return result; + } + + private static time(value: Object | undefined, name: string, required: boolean = false): number | undefined { + if (value === undefined || value === null || value === '') { + if (required) throw new Error(`${name} is required`); + return undefined; + } + const result = typeof value === 'number' ? value : Date.parse(String(value)); + if (!Number.isFinite(result) || result <= 0) throw new Error(`${name} must be an ISO date or epoch milliseconds`); + return Math.trunc(result); + } + + private static reminders(value: Object | undefined): number[] { + if (value === undefined || value === null || value === '') return []; + const raw: Object[] = typeof value === 'object' && value !== null + ? (value as Object[]) + : [value as Object]; + if (raw.length > MAX_REMINDERS) throw new Error('too many reminders'); + const reminders: number[] = raw.map((item: Object): number => + HarmonyCalendarService.number(item, 'reminderMinutes', false, 0)); + if (reminders.some(item => item > 10080)) throw new Error('reminderMinutes is too large'); + return reminders; + } + + private static recurrence(value: Object | undefined): calendarManager.RecurrenceRule | undefined { + if (!value || typeof value !== 'object') return undefined; + const input = value as RecurrenceParams; + const frequency = String(input.frequency || '').toLowerCase(); + let mapped: calendarManager.RecurrenceFrequency; + if (frequency === 'daily') mapped = calendarManager.RecurrenceFrequency.DAILY; + else if (frequency === 'weekly') mapped = calendarManager.RecurrenceFrequency.WEEKLY; + else if (frequency === 'monthly') mapped = calendarManager.RecurrenceFrequency.MONTHLY; + else if (frequency === 'yearly') mapped = calendarManager.RecurrenceFrequency.YEARLY; + else throw new Error('recurrence.frequency must be daily, weekly, monthly or yearly'); + const rule: calendarManager.RecurrenceRule = { recurrenceFrequency: mapped }; + if (input.interval !== undefined) rule.interval = HarmonyCalendarService.number(input.interval, 'recurrence.interval'); + if (input.count !== undefined) rule.count = HarmonyCalendarService.number(input.count, 'recurrence.count'); + if (input.expire !== undefined) rule.expire = HarmonyCalendarService.time(input.expire, 'recurrence.expire', true); + return rule; + } + + private failure(error: string): HarmonyCalendarActionResult { + return { ok: false, kind: 'failed', error }; + } + + private static errorText(err: Object): string { + if (err instanceof Error && err.message.length > 0) return err.message; + try { + const text = JSON.stringify(err); + return text.length > 0 && text !== '{}' ? text : 'unknown error'; + } catch (_jsonErr) { + return `${err}`; + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCollaborationService.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCollaborationService.ets new file mode 100644 index 0000000..e417429 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/HarmonyCollaborationService.ets @@ -0,0 +1,79 @@ +import { deviceInfo } from '@kit.BasicServicesKit'; +import { image } from '@kit.ImageKit'; +import { LocalCollaborationSession, LocalCollaborationSnapshot } from './LocalCollaborationSession'; + +export interface HarmonyCollaborationEnvironment { + api: number; + deviceType: string; + syscap: boolean; + unavailable: string; +} + +/** Native image ownership stays here; no file, account or Remote Mode dependency. */ +export class HarmonyCollaborationService { + readonly session: LocalCollaborationSession; + private picture?: image.PixelMap; + private readonly onPicture: (picture: image.PixelMap | undefined) => void; + private readonly onEncoded?: (data: ArrayBuffer) => Promise; + + constructor(onState: (state: LocalCollaborationSnapshot) => void, + onPicture: (picture: image.PixelMap | undefined) => void, + onEncoded?: (data: ArrayBuffer) => Promise) { + this.onPicture = onPicture; + this.onEncoded = onEncoded; + this.session = new LocalCollaborationSession(onState, + (data: ArrayBuffer, generation: number): Promise => this.decode(data, generation)); + } + + static environment(): HarmonyCollaborationEnvironment { + try { + const api = deviceInfo.sdkApiVersion; + const deviceType = deviceInfo.deviceType; + const syscap = canIUse('SystemCapability.Collaboration.Service'); + return { api, deviceType, syscap, + unavailable: LocalCollaborationSession.unavailableReason(api, deviceType, syscap) }; + } catch (_err) { + return { api: 0, deviceType: '', syscap: false, unavailable: 'probeFailed' }; + } + } + + private async decode(data: ArrayBuffer, generation: number): Promise { + const source = image.createImageSource(data); + let decoded: image.PixelMap | undefined; + try { + const info = await source.getImageInfo(); + if (!this.session.isCurrent(generation)) return; + const scale = Math.min(1, 1600 / Math.max(info.size.width, info.size.height)); + decoded = await source.createPixelMap({ desiredSize: { + width: Math.max(1, Math.round(info.size.width * scale)), + height: Math.max(1, Math.round(info.size.height * scale)) + } }); + if (!this.session.isCurrent(generation)) return; + if (this.onEncoded) { + const packer = image.createImagePacker(); + try { + const bytes = await packer.packToData(decoded, { format: 'image/jpeg', quality: 85 }); + if (!this.session.isCurrent(generation)) return; + await this.onEncoded(bytes); + } finally { await packer.release(); } + if (!this.session.isCurrent(generation)) return; + } + const previous = this.picture; + this.picture = decoded; + decoded = undefined; + this.onPicture(this.picture); + if (previous) void previous.release(); + } finally { + if (decoded) void decoded.release(); + await source.release(); + } + } + + dispose(): void { + this.session.close(); + this.onPicture(undefined); + const previous = this.picture; + this.picture = undefined; + if (previous) void previous.release(); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalCollaborationSession.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalCollaborationSession.ets new file mode 100644 index 0000000..72e89cb --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalCollaborationSession.ets @@ -0,0 +1,122 @@ +export type LocalCollaborationKind = 'photo' | 'scan' | 'gallery'; +export type LocalCollaborationPhase = 'ready' | 'selecting' | 'active' | 'receiving' | + 'completed' | 'cancelled' | 'failed' | 'closed' | 'unavailable'; + +export interface LocalCollaborationSnapshot { + phase: LocalCollaborationPhase; + kind: LocalCollaborationKind; + received: number; + code: number; + reason: string; +} + +/** Published by the SDK; a started service is not a completed transfer. */ +export class LocalCollaborationSession { + private generation: number = 0; + private pending: number = 0; + private ended: boolean = false; + private state: LocalCollaborationSnapshot = { + phase: 'ready', kind: 'photo', received: 0, code: 0, reason: '' + }; + private readonly changed: (state: LocalCollaborationSnapshot) => void; + private readonly receiveImage: (data: ArrayBuffer, generation: number) => Promise; + + constructor(changed: (state: LocalCollaborationSnapshot) => void, + receiveImage: (data: ArrayBuffer, generation: number) => Promise) { + this.changed = changed; + this.receiveImage = receiveImage; + } + + static unavailableReason(api: number, deviceType: string, syscap: boolean): string { + if (!syscap) return 'missingSyscap'; + // The first adapter uses the API 23 device filters on every form factor. + if (api < 23) return 'version'; + if (!['phone', 'tablet', '2in1', 'tv', 'pc'].includes(deviceType)) return 'deviceType'; + return ''; + } + + snapshot(): LocalCollaborationSnapshot { + return { phase: this.state.phase, kind: this.state.kind, received: this.state.received, + code: this.state.code, reason: this.state.reason }; + } + + begin(kind: LocalCollaborationKind, unavailable: string): boolean { + // One native receiver per mount. Retry remounts it so callbacks cannot cross requests. + if (this.state.phase !== 'ready') return false; + this.generation += 1; + this.state = { phase: unavailable ? 'unavailable' : 'selecting', kind, received: 0, + code: 0, reason: unavailable }; + this.publish(); + return !unavailable; + } + + isCurrent(generation: number): boolean { + return generation === this.generation && this.accepting(); + } + + private accepting(): boolean { + return ['selecting', 'active', 'receiving'].includes(this.state.phase); + } + + async accept(code: number, type: string, buffer: ArrayBuffer): Promise { + if (!this.accepting()) return; + this.state.code = code; + if (code === 1001202001 || code === 1001202003) { + this.finish('cancelled', code === 1001202001 ? 'peerCancelled' : 'localCancelled'); + } else if (code === 1001202004) { + this.state.phase = 'active'; + this.publish(); + } else if (code === 1001202006) { + this.state.phase = 'receiving'; + this.publish(); + } else if (code === 1001202005) { + this.ended = true; + this.completeIfReady(); + } else if (code === 0) { + // This first adapter asks for one image, and never accepts video URIs as image bytes. + if (type !== 'general.image' || !buffer || buffer.byteLength === 0) { + this.finish('failed', 'invalidImage'); + return; + } + if (buffer.byteLength > 32 * 1024 * 1024 || this.pending + this.state.received >= 1) { + this.finish('failed', 'imageLimit'); + return; + } + const generation = this.generation; + this.pending += 1; + this.state.phase = 'receiving'; + this.publish(); + try { + await this.receiveImage(buffer, generation); + if (!this.isCurrent(generation)) return; + this.pending -= 1; + this.state.received += 1; + this.publish(); + this.completeIfReady(); + } catch (_err) { + if (this.isCurrent(generation)) this.finish('failed', 'decodeFailed'); + } + } else { + this.finish('failed', 'platformError'); + } + } + + close(): void { + if (this.state.phase === 'closed') return; + this.finish('closed', ''); + } + + private completeIfReady(): void { + if (!this.ended || this.pending > 0 || !this.accepting()) return; + this.finish(this.state.received > 0 ? 'completed' : 'failed', this.state.received > 0 ? '' : 'emptyResult'); + } + + private finish(phase: LocalCollaborationPhase, reason: string): void { + this.generation += 1; + this.state.phase = phase; + this.state.reason = reason; + this.publish(); + } + + private publish(): void { this.changed(this.snapshot()); } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets new file mode 100644 index 0000000..05b178b --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets @@ -0,0 +1,166 @@ +import { LocalGenUIIds } from './LocalGenUIModels'; +import { LocalRuntimeInbound } from './LocalGenUIRuntimeProtocol'; + +/** + * Capability registry for messages coming out of the Local GenUI runtime. + * The document never selects an execution target: the mounted app identity + * comes from the host, and only registered capabilities run. + */ +export interface LocalGenUICapabilityHandlers { + saveState: (appId: string, sourceRevision: number, baseStateRevision: number, stateJson: string) => Promise; + modelTurn: (appId: string, message: string) => Promise; + isTurnActive: () => boolean; + unsupported: (appId: string, capability: string, reason: string) => void; + /** Device capabilities; return '' when accepted or a refusal reason. */ + subscribeGesture: (appId: string, subscriptionId: string, gesture: string) => string; + unsubscribeGesture: (subscriptionId: string) => void; + haptic: (kind: string) => void; + /** Calendar actions; return '' when accepted or a refusal reason. */ + calendar: (appId: string, action: string, params: Object) => Promise; + collaboration?: (message: LocalRuntimeInbound) => string; +} + +interface LocalCapabilityPolicy { + maxPayloadChars: number; + perMinute: number; +} + +const STATE_SAVE: string = 'state.save'; +const MODEL_TURN: string = 'model.turn'; +const DEVICE_GESTURE: string = 'device.gesture'; +const DEVICE_HAPTIC: string = 'device.haptic'; +const CALENDAR_ACTIONS: string[] = [ + 'CreateCalendarEvent', + 'UpdateCalendarEvent', + 'DeleteCalendarEvent', + 'ListCalendarEvents' +]; +const CALENDAR: string = 'calendar.event'; + +export class LocalGenUIActionHost { + private readonly handlers: LocalGenUICapabilityHandlers; + private readonly policies: Map = new Map(); + private readonly usage: Map = new Map(); + private readonly now: () => number; + + constructor(handlers: LocalGenUICapabilityHandlers, now: () => number = () => Date.now()) { + this.handlers = handlers; + this.now = now; + this.policies.set(STATE_SAVE, { maxPayloadChars: 256 * 1024, perMinute: 240 }); + this.policies.set(MODEL_TURN, { maxPayloadChars: 2000, perMinute: 6 }); + this.policies.set(DEVICE_GESTURE, { maxPayloadChars: 64, perMinute: 30 }); + this.policies.set(DEVICE_HAPTIC, { maxPayloadChars: 16, perMinute: 120 }); + this.policies.set(CALENDAR, { maxPayloadChars: 16000, perMinute: 30 }); + this.policies.set('device.collaboration', { maxPayloadChars: 1024, perMinute: 30 }); + } + + /** Returns a short diagnostic when the message was refused. */ + async handle(message: LocalRuntimeInbound, mountedAppId: string, mountedSourceRevision: number): Promise { + const appId = message.appId || ''; + if (!LocalGenUIIds.isLocal(appId) || appId !== mountedAppId) { + return 'message for an app that is not mounted'; + } + if (message.type === 'state') { + const stateJson = JSON.stringify(message.state === undefined ? {} : message.state); + const refused = this.admit(appId, STATE_SAVE, stateJson.length); + if (refused.length > 0) { + return refused; + } + if (message.sourceRevision !== mountedSourceRevision || typeof message.baseStateRevision !== 'number') { + return 'state update for another source revision'; + } + await this.handlers.saveState(appId, mountedSourceRevision, message.baseStateRevision, stateJson); + return ''; + } + if (message.type === 'collaboration') { + if (message.sourceRevision !== mountedSourceRevision) return 'collaboration for another source revision'; + if (!this.handlers.collaboration) return 'collaboration is unavailable'; + if (message.op === 'cancel') return this.handlers.collaboration(message); + const refused = this.admit(appId, 'device.collaboration', JSON.stringify(message).length); + return refused || this.handlers.collaboration(message); + } + if (message.type === 'action') { + if (message.action === 'continue_conversation') { + const text = (message.message || '').trim(); + if (text.length === 0) { + return 'empty model action'; + } + const refused = this.admit(appId, MODEL_TURN, text.length); + if (refused.length > 0) { + this.handlers.unsupported(appId, MODEL_TURN, refused); + return refused; + } + if (this.handlers.isTurnActive()) { + this.handlers.unsupported(appId, MODEL_TURN, 'a local turn is already running'); + return 'a local turn is already running'; + } + await this.handlers.modelTurn(appId, text); + return ''; + } + if (message.sourceRevision !== mountedSourceRevision) return 'action for another source revision'; + if (CALENDAR_ACTIONS.indexOf(message.action || '') >= 0) { + const params: Object = message.params || (JSON.parse('{}') as Object); + const refused = this.admit(appId, CALENDAR, JSON.stringify(params).length); + if (refused.length > 0) { + this.handlers.unsupported(appId, message.action || CALENDAR, refused); + return refused; + } + const result = await this.handlers.calendar(appId, message.action || '', params); + if (result.length > 0) { + this.handlers.unsupported(appId, message.action || CALENDAR, result); + } + return result; + } + const name = message.action || 'unknown'; + this.handlers.unsupported(appId, name, 'not a local phase 1 capability'); + return `unsupported action ${name}`; + } + if (message.type === 'capability') { + const subscriptionId = message.subscriptionId || ''; + if (subscriptionId.length === 0 || subscriptionId.length > 64) { + return 'invalid capability subscription'; + } + if (message.op === 'unsubscribe') { + this.handlers.unsubscribeGesture(subscriptionId); + return ''; + } + const gesture = message.gesture || ''; + const refused = this.admit(appId, DEVICE_GESTURE, gesture.length); + return refused.length > 0 ? refused : this.handlers.subscribeGesture(appId, subscriptionId, gesture); + } + if (message.type === 'haptic') { + const kind = message.kind || ''; + const refused = this.admit(appId, DEVICE_HAPTIC, kind.length); + if (refused.length === 0) { + this.handlers.haptic(kind); + } + return refused; + } + if (message.type === 'query') { + const name = message.capability || 'query'; + this.handlers.unsupported(appId, name, 'not a local phase 1 capability'); + return `unsupported query ${name}`; + } + return ''; + } + + private admit(appId: string, capability: string, payloadChars: number): string { + const policy = this.policies.get(capability); + if (!policy) { + return `capability ${capability} is not registered`; + } + if (payloadChars > policy.maxPayloadChars) { + return `${capability} payload exceeds ${policy.maxPayloadChars} characters`; + } + const key = `${appId}|${capability}`; + const now = this.now(); + const recent = (this.usage.get(key) || []).filter((at: number) => now - at < 60000); + if (recent.length >= policy.perMinute) { + this.usage.set(key, recent); + return `${capability} quota of ${policy.perMinute} per minute reached`; + } + recent.push(now); + this.usage.set(key, recent); + return ''; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICalendarActions.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICalendarActions.ets new file mode 100644 index 0000000..2648a66 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICalendarActions.ets @@ -0,0 +1,39 @@ +export interface LocalGenUICalendarReceiptPort { + calendarReceipts(appId: string): Promise; + saveCalendarReceipt(appId: string, paramsJson: string): Promise; +} + +/** Successful creates belong to the app and event payload, not a button position. */ +export class LocalGenUICalendarActions { + private readonly pending: Map> = new Map>(); + private readonly completed: Set = new Set(); + private readonly receipts: LocalGenUICalendarReceiptPort; + constructor(receipts: LocalGenUICalendarReceiptPort) { + this.receipts = receipts; + } + + create(appId: string, params: Object, execute: () => Promise): Promise { + const payload = JSON.stringify(params); + const key = JSON.stringify([appId, payload]); + const existing = this.pending.get(key); + if (existing) return existing; + const request = this.run(appId, payload, key, execute); + this.pending.set(key, request); + void request.finally(() => { this.pending.delete(key); }); + return request; + } + + private async run(appId: string, payload: string, key: string, execute: () => Promise): Promise { + try { + if (this.completed.has(key) || (await this.receipts.calendarReceipts(appId)).indexOf(payload) >= 0) return ''; + const error = await execute(); + if (error.length > 0) return error; + // Keep the in-process receipt even if durable storage fails after the OS created the event. + this.completed.add(key); + await this.receipts.saveCalendarReceipt(appId, payload); + return ''; + } catch (error) { + return String(error); + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationAssets.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationAssets.ets new file mode 100644 index 0000000..a55ed22 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationAssets.ets @@ -0,0 +1,71 @@ +import { fileIo as fs } from '@kit.CoreFileKit'; +import { util } from '@kit.ArkTS'; +import { LocalGenUIIds } from './LocalGenUIModels'; + +export const LOCAL_GENUI_COLLABORATION_ROOT: string = 'https://genui-assets.openbitfun.invalid/collaboration/'; +const MAX_BYTES: number = 2 * 1024 * 1024; + +/** User media, isolated by generated app. Never treated as a disposable icon cache. */ +export class LocalGenUICollaborationAssets { + private readonly root: string; + constructor(filesDir: string) { this.root = `${filesDir}/local-genui/collaboration`; } + + static prefix(appId: string): string { + LocalGenUIIds.require(appId, 'app'); + return `${LOCAL_GENUI_COLLABORATION_ROOT}${encodeURIComponent(appId)}/`; + } + + static fileName(appId: string, url: string): string { + const prefix = LocalGenUICollaborationAssets.prefix(appId); + if (!url.startsWith(prefix)) return ''; + const name = url.substring(prefix.length); + return /^[a-f0-9]{32}\.jpg$/.test(name) ? name : ''; + } + + private directory(appId: string): string { + LocalGenUIIds.require(appId, 'app'); + return `${this.root}/${encodeURIComponent(appId)}`; + } + + async save(appId: string, bytes: ArrayBuffer): Promise { + if (bytes.byteLength === 0 || bytes.byteLength > MAX_BYTES) throw new Error('collaboration image size unsupported'); + const dir = this.directory(appId); + if (!await fs.access(dir)) await fs.mkdir(dir, true); + const name = `${util.generateRandomUUID(false).replace(/-/g, '')}.jpg`; + const path = `${dir}/${name}`; + const temporary = `${path}.tmp`; + const file = await fs.open(temporary, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + const count = await fs.write(file.fd, bytes); + if (count !== bytes.byteLength) throw new Error('incomplete collaboration image write'); + } catch (err) { + await fs.close(file); + try { await fs.unlink(temporary); } catch (_ignored) { /* incomplete new file only */ } + throw new Error(`collaboration image write failed: ${String(err)}`); + } + await fs.close(file); + await fs.rename(temporary, path); + return LocalGenUICollaborationAssets.prefix(appId) + name; + } + + async picture(appId: string, url: string): Promise { + const name = LocalGenUICollaborationAssets.fileName(appId, url); + if (!name) return undefined; + try { + const file = await fs.open(`${this.directory(appId)}/${name}`, fs.OpenMode.READ_ONLY); + try { + const size = (await fs.stat(file.fd)).size; + if (size <= 0 || size > MAX_BYTES) return undefined; + const bytes = new ArrayBuffer(size); + return await fs.read(file.fd, bytes) === size ? bytes : undefined; + } finally { await fs.close(file); } + } catch (_err) { return undefined; } + } + + /** Only discard a newly received file whose owning request was abandoned. */ + async discard(appId: string, url: string): Promise { + const name = LocalGenUICollaborationAssets.fileName(appId, url); + if (!name) return; + try { await fs.unlink(`${this.directory(appId)}/${name}`); } catch (_err) { /* retain on failure */ } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationHost.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationHost.ets new file mode 100644 index 0000000..4b963d7 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUICollaborationHost.ets @@ -0,0 +1,126 @@ +import { LocalCollaborationKind, LocalCollaborationSnapshot } from './LocalCollaborationSession'; +import { LocalRuntimeInbound } from './LocalGenUIRuntimeProtocol'; + +export interface LocalCollaborationRequest { + appId: string; + sourceRevision: number; + requestId: string; + token: number; + kind: LocalCollaborationKind; +} +export interface LocalCollaborationReply { + type: string; + appId: string; + sourceRevision: number; + requestId: string; + status: string; + reason: string; + asset: string; +} +export interface LocalCollaborationOwner { appId: string; sourceRevision: number; live: boolean; } +export interface LocalCollaborationHostPorts { + owner: () => LocalCollaborationOwner; + unavailable: () => string; + changed: (request: LocalCollaborationRequest | undefined) => void; + send: (reply: LocalCollaborationReply) => void; + save: (appId: string, data: ArrayBuffer) => Promise; + discard: (appId: string, asset: string) => Promise; +} + +/** One native picker, bound to an accepted app/source revision and a request token. */ +export class LocalGenUICollaborationHost { + private active?: LocalCollaborationRequest; + private serial: number = 0; + private visible: boolean = false; + private asset: string = ''; + private receiving: boolean = false; + private readonly ports: LocalCollaborationHostPorts; + constructor(ports: LocalCollaborationHostPorts) { this.ports = ports; } + + setVisible(visible: boolean): void { + this.visible = visible; + if (!visible) this.close(); + } + + invalidate(appId: string, sourceRevision: number, streaming: boolean): void { + if (this.active && (streaming || this.active.appId !== appId || this.active.sourceRevision !== sourceRevision)) this.close(); + } + + handle(message: LocalRuntimeInbound): string { + const owner = this.ports.owner(); + if (!owner.live || message.appId !== owner.appId || message.sourceRevision !== owner.sourceRevision) return 'stale collaboration owner'; + if (!message.requestId || !/^[a-zA-Z0-9_-]{1,64}$/.test(message.requestId)) return 'invalid collaboration request'; + if (message.op === 'cancel') { + if (this.active?.requestId === message.requestId) this.close(); + return ''; + } + if (message.op !== 'start' || !['photo', 'scan', 'gallery'].includes(message.kind || '')) return 'invalid collaboration operation'; + if (this.active && !this.current(this.active)) this.close(); + const request: LocalCollaborationRequest = { appId: owner.appId, sourceRevision: owner.sourceRevision, + requestId: message.requestId, token: ++this.serial, kind: message.kind as LocalCollaborationKind }; + if (this.active) { + if (this.active.requestId !== request.requestId) this.reply(request, 'failed', 'busy'); + return ''; + } + const unavailable = this.ports.unavailable(); + if (!this.visible || unavailable) { + this.reply(request, 'unavailable', unavailable || 'notVisible'); + return ''; + } + this.active = request; + this.asset = ''; + this.receiving = false; + this.reply(request, 'pending', ''); + this.ports.changed(request); + return ''; + } + + async receive(token: number, data: ArrayBuffer): Promise { + const request = this.active; + if (!request || request.token !== token || !this.current(request) || this.receiving || this.asset) throw new Error('inactive collaboration receiver'); + this.receiving = true; + const asset = await this.ports.save(request.appId, data); + if (!this.current(request)) { + await this.ports.discard(request.appId, asset); + throw new Error('collaboration request closed while saving'); + } + this.asset = asset; + } + + result(token: number, snapshot: LocalCollaborationSnapshot): void { + const request = this.active; + if (!request || request.token !== token || !this.current(request)) return; + if (snapshot.phase === 'completed') { + const asset = this.asset; + this.asset = ''; + this.reply(request, asset ? 'completed' : 'failed', asset ? '' : 'emptyResult', asset); + this.clear(); + } else if (['cancelled', 'closed', 'failed', 'unavailable'].includes(snapshot.phase)) { + this.reply(request, snapshot.phase === 'closed' ? 'cancelled' : snapshot.phase, snapshot.reason); + this.clear(); + } + } + + close(token?: number): void { + if (!this.active || (token !== undefined && token !== this.active.token)) return; + this.reply(this.active, 'cancelled', 'localCancelled'); + this.clear(); + } + + private current(request: LocalCollaborationRequest): boolean { + const owner = this.ports.owner(); + return this.visible && this.active?.token === request.token && owner.live && owner.appId === request.appId && owner.sourceRevision === request.sourceRevision; + } + private clear(): void { + const request = this.active; + const asset = this.asset; + this.active = undefined; + this.asset = ''; + if (request && asset) void this.ports.discard(request.appId, asset); + this.ports.changed(undefined); + } + private reply(request: LocalCollaborationRequest, status: string, reason: string, asset: string = ''): void { + this.ports.send({ type: 'collaboration_result', appId: request.appId, sourceRevision: request.sourceRevision, + requestId: request.requestId, status, reason, asset }); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIContract.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIContract.ets new file mode 100644 index 0000000..8d1ae6c --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIContract.ets @@ -0,0 +1,71 @@ +import { util } from '@kit.ArkTS'; +import { OhosError } from '../OhosError'; +import { LocalGenUIManifest } from './LocalGenUIModels'; +import { LocalCanvasSpec } from './LocalGenUIRuntimeProtocol'; + +/** Generated Local GenUI contract read from HAP rawfile. Never hand-written. */ +export interface LocalGenUIContract { + manifest: LocalGenUIManifest; + prompt: string; + /** Raw JSON of `{ name, description, input_schema }`. */ + toolSchemaJson: string; + /** Acceptance checks required by the pinned design specification. */ + requiredChecks: string[]; + canvas: LocalCanvasSpec; +} + +interface LocalCatalogInsets { + left?: number; + right?: number; +} + +interface LocalCatalogShell { + contentInsets?: LocalCatalogInsets; +} + +interface LocalCatalogViewport { + width?: number; +} + +interface LocalCatalogDesignSpec { + acceptance?: LocalCatalogAcceptance; + viewport?: LocalCatalogViewport; + shell?: LocalCatalogShell; +} + +interface LocalCatalogAcceptance { + checks?: string[]; +} + +interface LocalCatalog { + designSpec?: LocalCatalogDesignSpec; +} + +export class LocalGenUIContractLoader { + static async load(context: Context): Promise { + try { + const manifest = JSON.parse(await LocalGenUIContractLoader.read(context, 'genui/runtime-manifest.json')) as LocalGenUIManifest; + const catalog = JSON.parse(await LocalGenUIContractLoader.read(context, 'genui/catalog.json')) as LocalCatalog; + const prompt = await LocalGenUIContractLoader.read(context, 'genui/harmony-prompt.txt'); + const toolSchemaJson = await LocalGenUIContractLoader.read(context, 'genui/local-tool-schema.json'); + const checks = catalog.designSpec && catalog.designSpec.acceptance && catalog.designSpec.acceptance.checks + ? catalog.designSpec.acceptance.checks : []; + const spec = catalog.designSpec; + const width = spec && spec.viewport && spec.viewport.width ? spec.viewport.width : 0; + const insets = spec && spec.shell && spec.shell.contentInsets ? spec.shell.contentInsets : undefined; + if (!manifest.libraryId || !manifest.catalogHash || prompt.length === 0 || checks.length === 0 || width <= 0 || !insets) { + throw new Error('generated Local GenUI contract is incomplete'); + } + const canvas: LocalCanvasSpec = { width, insetLeft: insets.left || 0, insetRight: insets.right || 0 }; + return { manifest, prompt, toolSchemaJson, requiredChecks: checks, canvas }; + } catch (err) { + throw OhosError.wrap('local genui contract load', err); + } + } + + private static async read(context: Context, path: string): Promise { + const bytes = await context.resourceManager.getRawFileContent(path); + const decoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }); + return decoder.decodeToString(bytes); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCardStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCardStore.ets new file mode 100644 index 0000000..c7841d1 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCardStore.ets @@ -0,0 +1,250 @@ +import { BusinessError } from '@kit.BasicServicesKit'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { formBindingData, formProvider } from '@kit.FormKit'; +import { + LocalGenUIDesktopCardApp, + LocalGenUIDesktopCardBinding, + LocalGenUIDesktopCardData, + LocalGenUIDesktopCards +} from './LocalGenUIDesktopCards'; + +const FORM_NOT_EXIST: number = 16501001; +/** + * How long an "Add to desktop" menu stays claimable by the next new card. The + * launcher adds the card within seconds of the tap; a short window keeps a + * card added later from the system widget picker from taking the app. + */ +const PENDING_ADD_TTL_MS: number = 60000; + +interface LocalGenUIDesktopCardPendingAdd { + appId: string; + stagedAt: number; +} + +/** + * Desktop card state shared by the UI process and the card host process + * (`LocalGenUIFormAbility`). Both run in the same app sandbox, so the state is + * small JSON files under `filesDir` instead of the RDB the UI process owns: + * + * - `bindings/
.json`: which app a home-screen card opens. + * - `apps/.json`: what the card shows for that app (title, preview, whether + * the app still exists). + * + * Writes go through a temporary file and a rename, so a reader in the other + * process sees the old file or the new one, never half of one. Everything here + * is derived data: losing it costs a card its content, never the app itself. + */ +export class LocalGenUIDesktopCardStore { + private readonly root: string; + + constructor(filesDir: string) { + this.root = `${filesDir}/local-genui/desktop-cards`; + } + + // Bindings + + bind(formId: string, appId: string): void { + if (formId.length === 0 || !LocalGenUIDesktopCards.isAppId(appId)) { + return; + } + const binding: LocalGenUIDesktopCardBinding = { formId, appId, boundAt: new Date().toISOString() }; + this.writeJson(this.bindingPath(formId), JSON.stringify(binding)); + } + + unbind(formId: string): void { + this.unlink(this.bindingPath(formId)); + } + + appOf(formId: string): string { + const binding = this.readJson(this.bindingPath(formId)); + return binding && LocalGenUIDesktopCards.isAppId(binding.appId) ? binding.appId : ''; + } + + /** Cards on the home screen that open `appId`. */ + formsOf(appId: string): string[] { + const forms: string[] = []; + this.list(`${this.root}/bindings`).forEach((name: string) => { + const binding = this.readJson(`${this.root}/bindings/${name}`); + if (binding && binding.appId === appId && binding.formId.length > 0) { + forms.push(binding.formId); + } + }); + return forms; + } + + // Pending add + + /** + * Some launchers neither forward custom want parameters to `onAddForm` nor + * call the `AddFormMenuItem` callback, so the card host would not know which + * app a new card opens. The UI process stages the app when the add menu + * opens; the card host claims it once, for the card it is adding. + */ + stagePendingAdd(appId: string, now: number = Date.now()): void { + if (!LocalGenUIDesktopCards.isAppId(appId)) { + return; + } + const pending: LocalGenUIDesktopCardPendingAdd = { appId, stagedAt: now }; + this.writeJson(this.pendingPath(), JSON.stringify(pending)); + } + + claimPendingAdd(now: number = Date.now()): string { + const pending = this.readJson(this.pendingPath()); + this.unlink(this.pendingPath()); + if (!pending || !LocalGenUIDesktopCards.isAppId(pending.appId)) { + return ''; + } + const age = now - pending.stagedAt; + return age >= 0 && age <= PENDING_ADD_TTL_MS ? pending.appId : ''; + } + + // App projections + + app(appId: string): LocalGenUIDesktopCardApp | undefined { + return this.readJson(this.appPath(appId)); + } + + /** Record what cards show for an app; no cards are touched. */ + saveApp(app: LocalGenUIDesktopCardApp): void { + if (!LocalGenUIDesktopCards.isAppId(app.appId)) { + return; + } + this.writeJson(this.appPath(app.appId), JSON.stringify(app)); + } + + /** Record the app and repaint every card bound to it. */ + async publish(app: LocalGenUIDesktopCardApp): Promise { + const forms = this.formsOf(app.appId); + if (forms.length === 0 && !this.app(app.appId)) { + // No card has ever shown this app: nothing to keep in step. + return; + } + this.saveApp(app); + for (let i = 0; i < forms.length; i++) { + await this.refresh(forms[i]); + } + } + + // Card content + + /** Text-only content for `onAddForm`; the preview follows through `refresh`. */ + textData(formId: string): LocalGenUIDesktopCardData { + const appId = this.appOf(formId); + return LocalGenUIDesktopCards.cardData(formId, appId, appId.length > 0 ? this.app(appId) : undefined, false); + } + + /** + * Push the card's current content, preview included. A card the launcher + * already removed fails here; its binding is dropped with it. + */ + async refresh(formId: string): Promise { + const appId = this.appOf(formId); + const app = appId.length > 0 ? this.app(appId) : undefined; + const thumbnail = app && app.available ? app.thumbnailPath : ''; + let fd: number = -1; + if (thumbnail.length > 0) { + try { + fd = fs.openSync(thumbnail, fs.OpenMode.READ_ONLY).fd; + } catch (_err) { + fd = -1; + } + } + const data = LocalGenUIDesktopCards.cardData(formId, appId, app, fd >= 0); + const payload: Record = {}; + payload['formId'] = data.formId; + payload['appId'] = data.appId; + payload['state'] = data.state; + payload['title'] = data.title; + payload['initial'] = data.initial; + payload['imageName'] = data.imageName; + if (fd >= 0 && data.imageName.length > 0) { + const images: Record = {}; + images[data.imageName] = fd; + payload['formImages'] = images; + } + try { + await formProvider.updateForm(formId, formBindingData.createFormBindingData(payload)); + return true; + } catch (err) { + // 16501001: the form id does not exist; the card is gone from the screen. + if ((err as BusinessError).code === FORM_NOT_EXIST) { + this.unbind(formId); + } + return false; + } finally { + if (fd >= 0) { + try { + fs.closeSync(fd); + } catch (_err) { + // Already closed by the platform. + } + } + } + } + + // Files + + private pendingPath(): string { + return `${this.root}/pending-add.json`; + } + + private bindingPath(formId: string): string { + return `${this.root}/bindings/${LocalGenUIDesktopCards.fileKey(formId)}.json`; + } + + private appPath(appId: string): string { + return `${this.root}/apps/${LocalGenUIDesktopCards.fileKey(appId)}.json`; + } + + private list(directory: string): string[] { + try { + if (!fs.accessSync(directory)) { + return []; + } + return fs.listFileSync(directory).filter((name: string) => name.endsWith('.json')); + } catch (_err) { + return []; + } + } + + private readJson(path: string): T | undefined { + try { + if (!fs.accessSync(path)) { + return undefined; + } + return JSON.parse(fs.readTextSync(path)) as T; + } catch (_err) { + return undefined; + } + } + + /** Derived data: a failed write leaves the previous file, never half of one. */ + private writeJson(path: string, text: string): void { + const temporary = `${path}.${Date.now()}.tmp`; + try { + const directory = path.substring(0, path.lastIndexOf('/')); + if (!fs.accessSync(directory)) { + fs.mkdirSync(directory, true); + } + const file = fs.openSync(temporary, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + fs.writeSync(file.fd, text); + } finally { + fs.closeSync(file); + } + fs.renameSync(temporary, path); + } catch (_err) { + this.unlink(temporary); + } + } + + private unlink(path: string): void { + try { + if (fs.accessSync(path)) { + fs.unlinkSync(path); + } + } catch (_err) { + // Derived data. + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCards.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCards.ets new file mode 100644 index 0000000..37c1afb --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDesktopCards.ets @@ -0,0 +1,135 @@ +import { Want } from '@kit.AbilityKit'; +import { LOCAL_GENUI_NAMESPACE } from './LocalGenUIModels'; + +/** + * Desktop (home screen) cards of generated apps: pure policy shared by the + * main UI process and `LocalGenUIFormAbility`. Platform kits are used for + * types only. + * + * A card is an entry, not a runtime: service widgets cannot host ArkWeb, so a + * card shows the app's title and preview and opens the app in the phone app. + */ +export const DESKTOP_CARD_ABILITY: string = 'LocalGenUIFormAbility'; +export const DESKTOP_CARD_FORM_NAME: string = 'local_genui_app'; +export const DESKTOP_CARD_MODULE: string = 'entry'; +/** 2x2, `formInfo.FormDimension.Dimension_2_2`. */ +export const DESKTOP_CARD_DIMENSION: number = 2; +/** Want parameter carrying the app id into `onAddForm`. */ +export const DESKTOP_CARD_APP_PARAM: string = 'openbitfunLocalGenUIAppId'; +/** Router parameter carrying the app id from a card tap into `EntryAbility`. */ +export const DESKTOP_CARD_LAUNCH_PARAM: string = 'openbitfunLocalGenUIApp'; +export const FORM_IDENTITY_PARAM: string = 'ohos.extra.param.key.form_identity'; + +export enum LocalGenUIDesktopCardState { + /** The card exists but its app is not known to it yet. */ + Pending = 'pending', + Ready = 'ready', + /** The app was deleted or can no longer run; the card says so. */ + Missing = 'missing' +} + +/** What a card shows for one app; written by the app, read by the card host. */ +export interface LocalGenUIDesktopCardApp { + appId: string; + title: string; + thumbnailPath: string; + available: boolean; + updatedAt: string; +} + +export interface LocalGenUIDesktopCardBinding { + formId: string; + appId: string; + boundAt: string; +} + +/** Binding data of the card page (`LocalStorage` keys of the widget). */ +export interface LocalGenUIDesktopCardData { + formId: string; + appId: string; + state: string; + title: string; + initial: string; + /** `formImages` key; empty when the card shows the fallback tile. */ + imageName: string; +} + +export class LocalGenUIDesktopCards { + static isAppId(appId: string): boolean { + return appId.startsWith(LOCAL_GENUI_NAMESPACE) && appId.length > LOCAL_GENUI_NAMESPACE.length; + } + + /** The want handed to `AddFormMenuItem` for one app. */ + static addWant(bundleName: string, appId: string): Want { + const parameters: Record = {}; + parameters['ohos.extra.param.key.form_dimension'] = DESKTOP_CARD_DIMENSION; + parameters['ohos.extra.param.key.form_name'] = DESKTOP_CARD_FORM_NAME; + parameters['ohos.extra.param.key.module_name'] = DESKTOP_CARD_MODULE; + parameters[DESKTOP_CARD_APP_PARAM] = appId; + return { bundleName, abilityName: DESKTOP_CARD_ABILITY, parameters }; + } + + /** App id carried by `onAddForm`'s want, when the launcher forwarded it. */ + static appIdOfAddWant(parameters: Record | undefined): string { + const value = parameters ? parameters[DESKTOP_CARD_APP_PARAM] : undefined; + const appId = typeof value === 'string' ? value : ''; + return LocalGenUIDesktopCards.isAppId(appId) ? appId : ''; + } + + /** + * App id of a card tap. Router events deliver their params as a JSON string + * under `params`; a direct key is accepted as well. Anything outside the + * local namespace is ignored, so a crafted want cannot open a remote id. + */ + static launchAppId(parameters: Record | undefined): string { + if (!parameters) { + return ''; + } + let value: Object | undefined = parameters[DESKTOP_CARD_LAUNCH_PARAM]; + const params = parameters['params']; + if (value === undefined && typeof params === 'string') { + try { + const parsed = JSON.parse(params) as Record; + value = parsed[DESKTOP_CARD_LAUNCH_PARAM]; + } catch (_err) { + value = undefined; + } + } + const appId = typeof value === 'string' ? value : ''; + return LocalGenUIDesktopCards.isAppId(appId) ? appId : ''; + } + + /** File-name-safe key; ids are namespaced and may contain `:`. */ + static fileKey(id: string): string { + return id.replace(/[^A-Za-z0-9_-]/g, '_'); + } + + /** A versioned image key, so the launcher does not keep a cached preview. */ + static imageName(thumbnailPath: string): string { + if (thumbnailPath.length === 0) { + return ''; + } + const base = thumbnailPath.substring(thumbnailPath.lastIndexOf('/') + 1).replace(/\.[^.]*$/, ''); + return `genui_${LocalGenUIDesktopCards.fileKey(base)}`; + } + + static initial(title: string): string { + const trimmed = title.trim(); + return trimmed.length > 0 ? Array.from(trimmed)[0] : 'AI'; + } + + /** Card content for a form, from its binding and the app projection. */ + static cardData(formId: string, appId: string, app: LocalGenUIDesktopCardApp | undefined, + imageAvailable: boolean): LocalGenUIDesktopCardData { + if (appId.length === 0) { + return { formId, appId: '', state: LocalGenUIDesktopCardState.Pending, title: '', initial: 'AI', imageName: '' }; + } + if (!app) { + // Bound, but nothing written for the app yet: still an entry to it. + return { formId, appId, state: LocalGenUIDesktopCardState.Pending, title: '', initial: 'AI', imageName: '' }; + } + const state = app.available ? LocalGenUIDesktopCardState.Ready : LocalGenUIDesktopCardState.Missing; + const imageName = app.available && imageAvailable ? LocalGenUIDesktopCards.imageName(app.thumbnailPath) : ''; + return { formId, appId, state, title: app.title, initial: LocalGenUIDesktopCards.initial(app.title), imageName }; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDeviceCapabilityHost.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDeviceCapabilityHost.ets new file mode 100644 index 0000000..56625bf --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIDeviceCapabilityHost.ets @@ -0,0 +1,190 @@ +import { RemoteLogger } from '../RemoteLogger'; +import { LocalGenUIGestureCamera, LocalGestureCameraStatus } from './LocalGenUIGestureCamera'; +import { LocalGenUIHaptics } from './LocalGenUIHaptics'; +import { LocalGestureName } from './LocalGestureClassifier'; + +/** Gestures a GenUI app may subscribe to; anything else is refused. */ +const SUPPORTED_GESTURES: string[] = [LocalGestureName.RaiseLeft, LocalGestureName.RaiseRight, LocalGestureName.RaiseBoth]; +const MAX_SUBSCRIPTIONS: number = 4; +/** + * A camera-service failure is usually transient (device released late, another + * app still closing it), so retry before telling the person it cannot work. + */ +const MAX_START_RETRIES: number = 2; +const RETRY_DELAY_MS: number = 1200; + +interface GestureSubscription { + appId: string; + gesture: string; +} + +export interface LocalGenUIDeviceCapabilityEvents { + /** Runtime delivery: one gesture for one subscription. */ + gesture: (subscriptionId: string, gesture: string) => void; + status: (subscriptionId: string, status: string) => void; + /** Presentation: whether the camera preview surface should exist. */ + cameraWanted: (wanted: boolean) => void; +} + +/** + * Device capabilities served to Local GenUI apps. The camera runs only while + * an app holds a subscription, that app is on screen, and the phone app is in + * the foreground; otherwise subscribers see `paused`. + */ +export class LocalGenUIDeviceCapabilityHost { + private readonly events: LocalGenUIDeviceCapabilityEvents; + private readonly camera: LocalGenUIGestureCamera; + private readonly subscriptions: Map = new Map(); + private visible: boolean = false; + private surfaceId: string = ''; + private lastStatus: string = 'starting'; + /** Retries spent in the current visibility episode. */ + private retries: number = 0; + private retryTimer: number = -1; + + // CoreVisionKit labels skeleton points by the person's anatomical sides for + // the front-camera stream. The preview is not mirrored at the classifier + // input, so swapping the sides here would turn right-hand input into left. + constructor(context: Context, events: LocalGenUIDeviceCapabilityEvents, mirrored: boolean = false) { + this.events = events; + this.camera = new LocalGenUIGestureCamera(context, { + onGesture: (gesture: LocalGestureName): void => this.dispatch(gesture), + onStatus: (status: LocalGestureCameraStatus): void => this.onCameraStatus(status) + }, mirrored); + } + + private onCameraStatus(status: LocalGestureCameraStatus): void { + if (status === LocalGestureCameraStatus.Active) { + this.retries = 0; + } + this.broadcast(status); + if (status === LocalGestureCameraStatus.Failed) { + this.scheduleRetry(); + } + } + + /** Bounded, so a genuinely broken camera still settles on a final answer. */ + private scheduleRetry(): void { + if (this.retryTimer >= 0 || this.retries >= MAX_START_RETRIES) { + return; + } + this.retryTimer = setTimeout(() => { + this.retryTimer = -1; + if (!this.visible || this.subscriptions.size === 0) { + return; + } + this.retries += 1; + RemoteLogger.info(`local genui gesture camera retry ${this.retries}/${MAX_START_RETRIES}`); + this.update(); + }, RETRY_DELAY_MS); + } + + private clearRetry(): void { + if (this.retryTimer >= 0) { + clearTimeout(this.retryTimer); + this.retryTimer = -1; + } + this.retries = 0; + } + + /** Returns a refusal reason, or '' when accepted. */ + subscribeGesture(appId: string, subscriptionId: string, gesture: string): string { + if (SUPPORTED_GESTURES.indexOf(gesture) < 0) { + this.events.status(subscriptionId, 'unavailable'); + return `unsupported gesture ${gesture}`; + } + if (!this.subscriptions.has(subscriptionId) && this.subscriptions.size >= MAX_SUBSCRIPTIONS) { + this.events.status(subscriptionId, 'unavailable'); + return 'too many gesture subscriptions'; + } + this.subscriptions.set(subscriptionId, { appId, gesture }); + this.events.status(subscriptionId, this.visible ? this.lastStatus : 'paused'); + this.update(); + return ''; + } + + unsubscribeGesture(subscriptionId: string): void { + if (this.subscriptions.delete(subscriptionId)) { + this.update(); + } + } + + haptic(kind: string): void { + LocalGenUIHaptics.play(kind); + } + + /** A different app is mounted (or none): its subscriptions end. */ + releaseOtherApps(appId: string): void { + const stale: string[] = []; + this.subscriptions.forEach((sub: GestureSubscription, id: string) => { + if (sub.appId !== appId) { + stale.push(id); + } + }); + stale.forEach((id: string) => this.subscriptions.delete(id)); + if (stale.length > 0) { + this.update(); + } + } + + /** App view on screen and phone app in the foreground. */ + setVisible(visible: boolean): void { + if (this.visible === visible) { + return; + } + this.visible = visible; + if (!visible) { + this.clearRetry(); + this.broadcast('paused'); + } + this.update(); + } + + /** The preview surface the camera renders into (from the presentation leaf). */ + attachSurface(surfaceId: string): void { + this.surfaceId = surfaceId; + this.update(); + } + + detachSurface(): void { + this.surfaceId = ''; + this.clearRetry(); + void this.camera.stop(); + } + + shutdown(): void { + this.subscriptions.clear(); + this.surfaceId = ''; + this.clearRetry(); + void this.camera.stop(); + this.events.cameraWanted(false); + } + + private update(): void { + const wanted = this.visible && this.subscriptions.size > 0; + this.events.cameraWanted(wanted); + if (!wanted) { + void this.camera.stop(); + return; + } + if (this.surfaceId.length > 0 && !this.camera.isRunning()) { + void this.camera.start(this.surfaceId); + } + } + + private dispatch(gesture: LocalGestureName): void { + RemoteLogger.info(`local genui gesture ${gesture}`); + this.subscriptions.forEach((sub: GestureSubscription, id: string) => { + if (sub.gesture === gesture) { + this.events.gesture(id, gesture); + } + }); + } + + private broadcast(status: string): void { + if (status !== 'paused') { + this.lastStatus = status; + } + this.subscriptions.forEach((_sub: GestureSubscription, id: string) => this.events.status(id, status)); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIEditMode.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIEditMode.ets new file mode 100644 index 0000000..29ca9a6 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIEditMode.ets @@ -0,0 +1,49 @@ +/** + * OpenUI edit mode for Local GenUI follow-ups and repairs. + * + * The model returns only the statements that change; the runtime merges them + * into the base program with lang-core `mergeStatements` (same name replaces, + * a new name appends, `name = null` deletes, unreachable statements drop). + * `OPENUI_EDIT_MODE_RULES` is lang-core's own edit-mode prompt section, + * copied verbatim; tools/tests/local-genui-edit-mode.test.cjs keeps it in step + * with the bundled lang-core. + */ +export const OPENUI_EDIT_MODE_RULES: string = [ + '## Edit Mode', + '', + 'The runtime merges by statement name: same name = replace, new name = append.', + 'Output ONLY statements that changed or are new. Everything else is kept automatically.', + '', + '### Delete', + 'To remove a component, re-declare its parent without that component in the parent\'s children array. The removed component and any statements only it referenced are automatically garbage-collected.', + '', + '### Patch size guide', + '- Changing a title or label: 1 statement', + '- Adding a component: 2-3 statements (the new component + parent update)', + '- Removing a component: 1 statement (re-declare parent without the removed child)', + '- Adding a filter + wiring to query: 3-5 statements', + '- Restructuring into tabs: 5-10 statements', + '', + '### Rules', + '- Reuse existing statement names exactly — do not rename', + '- Do NOT re-emit unchanged statements — the runtime keeps them', + '- A typical edit patch is 1-10 statements, not 20+', + '- If the existing code already satisfies the request, output only the root statement', + '- NEVER output the entire program as a patch. Only output what actually changes', + '- If you are about to output more than 10 statements, reconsider — most edits need fewer' +].join('\n'); + +export class LocalGenUIEditMode { + /** A follow-up request on an existing app: patch it, or rewrite it when asked. */ + static followUp(request: string, title: string, source: string, stateJson: string): string { + return [ + request, + '', + `This conversation already has the mini app "${title}". If the request changes it, call the tool in edit mode: put only the changed or new statements in source.content, keeping existing statement names. Write the complete program only when the person asks for a new version or a full redesign. If the request does not change the app, answer in text.`, + OPENUI_EDIT_MODE_RULES, + 'Its current OpenUI Lang source is:', + source, + `Current user state: ${stateJson}` + ].join('\n'); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIGestureCamera.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIGestureCamera.ets new file mode 100644 index 0000000..0ff1043 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIGestureCamera.ets @@ -0,0 +1,320 @@ +import { camera } from '@kit.CameraKit'; +import { image } from '@kit.ImageKit'; +import { abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; +import { skeletonDetection } from '@kit.CoreVisionKit'; +import { display } from '@kit.ArkUI'; +import { OhosError } from '../OhosError'; +import { RemoteLogger } from '../RemoteLogger'; +import { LocalGestureClassifier, LocalGestureKeypoint, LocalGestureName } from './LocalGestureClassifier'; + +const CAMERA_PERMISSION: Permissions = 'ohos.permission.CAMERA'; +const FRAME_INTERVAL_MS: number = 200; +/** One diagnostic line every few seconds while running. */ +const DIAGNOSTIC_EVERY: number = 15; +/** Preview surface size the camera profile is matched against (4:3). */ +export const LOCAL_GESTURE_SURFACE_WIDTH: number = 640; +export const LOCAL_GESTURE_SURFACE_HEIGHT: number = 480; + +export enum LocalGestureCameraStatus { + Starting = 'starting', + Active = 'active', + Denied = 'denied', + /** This device cannot serve gestures at all; retrying cannot help. */ + Unavailable = 'unavailable', + /** A transient camera failure; the host retries a bounded number of times. */ + Failed = 'failed' +} + +/** + * The device lacks the capability itself (no front camera, no preview profile, + * no skeleton detector). Distinct from camera-service errors, which are + * transient and worth retrying. + */ +class GestureCapabilityError extends Error { + constructor(message: string) { + super(message); + this.name = 'GestureCapabilityError'; + } +} + +export interface LocalGestureCameraListener { + onGesture: (gesture: LocalGestureName) => void; + onStatus: (status: LocalGestureCameraStatus) => void; +} + +/** + * Front camera + on-device skeleton detection for Local GenUI gestures. + * Frames never leave this object: only gesture names are reported. + */ +export class LocalGenUIGestureCamera { + private readonly context: Context; + private readonly listener: LocalGestureCameraListener; + private readonly classifier: LocalGestureClassifier; + private session?: camera.PhotoSession; + private input?: camera.CameraInput; + private preview?: camera.PreviewOutput; + private detector?: skeletonDetection.SkeletonDetector; + private timer: number = -1; + private busy: boolean = false; + private generation: number = 0; + /** One attempt at a time; set before the first await so callers see it. */ + private starting: boolean = false; + private surfaceId: string = ''; + private frames: number = 0; + /** Sensor mounting angle of the front camera, in degrees. */ + private sensorOrientation: number = 0; + + constructor(context: Context, listener: LocalGestureCameraListener, mirrored: boolean) { + this.context = context; + this.listener = listener; + this.classifier = new LocalGestureClassifier(mirrored); + } + + isRunning(): boolean { + return this.session !== undefined; + } + + /** + * The presenter starts the camera once per subscription, so several calls + * arrive together. Every attempt opens the same physical device, and a + * concurrent attempt tears down the session the previous one is still + * configuring (7400102/7400201/7400103), so only one may run at a time. + */ + async start(surfaceId: string): Promise { + if (this.starting && this.surfaceId === surfaceId) { + return; + } + if (this.session && this.surfaceId === surfaceId) { + return; + } + this.starting = true; + this.surfaceId = surfaceId; + const generation = ++this.generation; + try { + await this.releaseSession(); + if (generation !== this.generation) { + return; + } + this.listener.onStatus(LocalGestureCameraStatus.Starting); + if (!(await this.ensurePermission())) { + if (generation === this.generation) { + this.listener.onStatus(LocalGestureCameraStatus.Denied); + } + return; + } + this.detector = await LocalGenUIGestureCamera.createDetector(); + const manager = camera.getCameraManager(this.context); + const front = manager.getSupportedCameras().find((device: camera.CameraDevice) => + device.cameraPosition === camera.CameraPosition.CAMERA_POSITION_FRONT); + if (!front) { + throw new GestureCapabilityError('no front camera'); + } + const capability = manager.getSupportedOutputCapability(front, camera.SceneMode.NORMAL_PHOTO); + const profile = LocalGenUIGestureCamera.pickProfile(capability.previewProfiles); + if (!profile) { + throw new GestureCapabilityError('no preview profile'); + } + this.sensorOrientation = front.cameraOrientation; + const input = manager.createCameraInput(front); + await input.open(); + if (generation !== this.generation) { + await LocalGenUIGestureCamera.release(undefined, input, undefined); + return; + } + this.input = input; + const preview = manager.createPreviewOutput(profile, surfaceId); + this.preview = preview; + const session = manager.createSession(camera.SceneMode.NORMAL_PHOTO) as camera.PhotoSession; + this.session = session; + session.beginConfig(); + session.addInput(input); + session.addOutput(preview); + await session.commitConfig(); + if (generation !== this.generation) { + return; + } + await session.start(); + if (generation !== this.generation) { + return; + } + this.frames = 0; + this.busy = false; + this.classifier.reset(); + this.timer = setInterval(() => { void this.analyze(generation); }, FRAME_INTERVAL_MS); + RemoteLogger.info(`local genui gesture camera started ${profile.size.width}x${profile.size.height} sensor=${this.sensorOrientation} upright=${this.uprightRotation()}`); + this.listener.onStatus(LocalGestureCameraStatus.Active); + } catch (err) { + const missingCapability = err instanceof GestureCapabilityError; + RemoteLogger.warn(`local genui gesture camera ${missingCapability ? 'unavailable' : 'failed'}: ${OhosError.reason(err).slice(0, 400)}`); + // A newer start owns the fields now; releasing here would kill its session. + if (generation === this.generation) { + await this.releaseSession(); + this.listener.onStatus(missingCapability ? LocalGestureCameraStatus.Unavailable : LocalGestureCameraStatus.Failed); + } + } finally { + if (generation === this.generation) { + this.starting = false; + } + } + } + + async stop(): Promise { + this.generation += 1; + this.starting = false; + this.surfaceId = ''; + await this.releaseSession(); + } + + /** Releases the device objects of the current (or a superseded) attempt. */ + private async releaseSession(): Promise { + if (this.timer >= 0) { + clearInterval(this.timer); + this.timer = -1; + } + const session = this.session; + const input = this.input; + const preview = this.preview; + const detector = this.detector; + this.session = undefined; + this.input = undefined; + this.preview = undefined; + this.detector = undefined; + if (session || input || preview) { + await LocalGenUIGestureCamera.release(session, input, preview); + RemoteLogger.info('local genui gesture camera stopped'); + } + if (detector) { + try { + await detector.destroy(); + } catch (_err) { + // Already released. + } + } + } + + private async analyze(generation: number): Promise { + if (this.busy || !this.detector || generation !== this.generation || this.surfaceId.length === 0) { + return; + } + this.busy = true; + let pixels: image.PixelMap | undefined = undefined; + try { + pixels = await image.createPixelMapFromSurface(this.surfaceId); + // Sensor frames are landscape; the detector needs an upright person. + const rotation = this.uprightRotation(); + if (rotation !== 0) { + await pixels.rotate(rotation); + } + const response = await this.detector.process({ inputData: { pixelMap: pixels } }); + if (generation !== this.generation) { + return; + } + const skeleton = response.skeletons.length > 0 ? response.skeletons[0] : undefined; + const points: LocalGestureKeypoint[] = skeleton ? skeleton.points.map((point: skeletonDetection.SkeletonPoint): LocalGestureKeypoint => ({ + type: point.type, x: point.point.x, y: point.point.y, score: point.score + })) : []; + this.frames += 1; + if (this.frames % DIAGNOSTIC_EVERY === 1) { + this.logFrame(pixels, response.skeletons.length, points); + } + const gesture = this.classifier.accept(points); + if (gesture) { + const frame = LocalGestureClassifier.measure(points); + RemoteLogger.info(`local genui gesture recognized ${gesture} left=${frame.leftLift.toFixed(2)} right=${frame.rightLift.toFixed(2)}`); + this.listener.onGesture(gesture); + } + } catch (_err) { + // A dropped frame is not an error; the next one retries. + } finally { + if (pixels) { + void pixels.release(); + } + this.busy = false; + } + } + + /** + * Clockwise degrees that turn a sensor frame upright for the current + * display rotation. Rotation never mirrors, so left/right labels from the + * detector are unaffected by it. + */ + private uprightRotation(): number { + let displayDegrees = 0; + try { + displayDegrees = display.getDefaultDisplaySync().rotation * 90; + } catch (_err) { + displayDegrees = 0; + } + return ((this.sensorOrientation + displayDegrees) % 360 + 360) % 360; + } + + private logFrame(pixels: image.PixelMap, skeletons: number, points: LocalGestureKeypoint[]): void { + const frame = LocalGestureClassifier.measure(points); + const size = pixels.getImageInfoSync().size; + const score = (type: number): string => { + const point = points.find((item: LocalGestureKeypoint) => item.type === type); + return point ? point.score.toFixed(2) : '-'; + }; + RemoteLogger.info(`local genui gesture frame ${size.width}x${size.height} skeletons=${skeletons} tracked=${frame.tracked} left=${frame.leftLift.toFixed(2)} right=${frame.rightLift.toFixed(2)} score lw=${score(9)} rw=${score(10)} le=${score(7)} re=${score(8)} ls=${score(5)} rs=${score(6)}`); + } + + private async ensurePermission(): Promise { + try { + const manager = abilityAccessCtrl.createAtManager(); + const result = await manager.requestPermissionsFromUser(this.context, [CAMERA_PERMISSION]); + return result.authResults.length > 0 && result.authResults[0] === abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED; + } catch (_err) { + return false; + } + } + + /** The detector belongs to the platform capability, not to a runtime failure. */ + private static async createDetector(): Promise { + try { + return await skeletonDetection.SkeletonDetector.create(); + } catch (err) { + throw new GestureCapabilityError(`no skeleton detector: ${OhosError.reason(err).slice(0, 200)}`); + } + } + + /** The 4:3 profile closest to the preview surface; detection needs little resolution. */ + private static pickProfile(profiles: camera.Profile[]): camera.Profile | undefined { + const ratio = LOCAL_GESTURE_SURFACE_WIDTH / LOCAL_GESTURE_SURFACE_HEIGHT; + let best: camera.Profile | undefined = undefined; + let bestScore = Number.MAX_VALUE; + profiles.forEach((profile: camera.Profile) => { + const width = profile.size.width; + const height = profile.size.height; + if (width <= 0 || height <= 0 || Math.abs(width / height - ratio) > 0.02) { + return; + } + const score = Math.abs(width - LOCAL_GESTURE_SURFACE_WIDTH); + if (score < bestScore) { + best = profile; + bestScore = score; + } + }); + return best; + } + + private static async release(session?: camera.PhotoSession, input?: camera.CameraInput, preview?: camera.PreviewOutput): Promise { + try { + if (session) { + await session.stop(); + await session.release(); + } + } catch (_err) { + // Releasing a stopped session. + } + try { + if (preview) { + await preview.release(); + } + if (input) { + await input.close(); + } + } catch (_err) { + // Releasing a closed input. + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIHaptics.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIHaptics.ets new file mode 100644 index 0000000..edb8607 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIHaptics.ets @@ -0,0 +1,16 @@ +import { vibrator } from '@kit.SensorServiceKit'; + +/** Short vibration feedback for Local GenUI apps; failures are silent by design. */ +export class LocalGenUIHaptics { + static play(kind: string): void { + const duration = kind === 'heavy' ? 60 : kind === 'medium' ? 35 : kind === 'light' ? 18 : 0; + if (duration <= 0) { + return; + } + try { + vibrator.startVibration({ type: 'time', duration }, { id: 0, usage: 'touch' }).catch(() => {}); + } catch (_err) { + // A device without a vibrator simply gives no feedback. + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIIcon3DStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIIcon3DStore.ets new file mode 100644 index 0000000..165d4ae --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIIcon3DStore.ets @@ -0,0 +1,178 @@ +import { http } from '@kit.NetworkKit'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { util } from '@kit.ArkTS'; +import { RemoteLogger } from '../RemoteLogger'; + +/** + * 3D pictures for Local GenUI apps, the phone counterpart of the reference + * app's `/api/icon3d` route: Microsoft Fluent Emoji 3D (MIT) at one pinned + * upstream commit, fetched once and kept on the device. + * + * The runtime asks for `/`; only that commit and + * asset paths of the documented shape are served, so a generated app cannot + * use this address to reach anything else. Pictures are derived data: losing + * the cache only costs a download. + * + * A cover may also ask for the animated picture of the same emoji at + * `animated//`: Microsoft Fluent Emoji animated (MIT), + * animated PNGs pinned the same way. They are larger, so only covers use them + * and the static picture stays on screen until one arrives. + */ +export const LOCAL_GENUI_ICON3D_ROOT: string = 'https://genui-assets.openbitfun.invalid/fluent-emoji/'; +/** Must equal `sha` in web-ui fluent-emoji-3d-index.json (checked by a test). */ +export const LOCAL_GENUI_ICON3D_COMMIT: string = '1ffb34c752ecf5d402f04cfb4b392c77f57c54bc'; +const UPSTREAM: string = `https://cdn.jsdelivr.net/gh/microsoft/fluentui-emoji@${LOCAL_GENUI_ICON3D_COMMIT}/assets/`; +/** `/[Default/]3D/_3d[_default].png`, as in the upstream index. */ +const ASSET_PATH: RegExp = /^[\p{L}\p{N}][\p{L}\p{N} ,.'&()!_-]{0,80}\/(Default\/)?3D\/[\p{Ll}\p{N}][\p{Ll}\p{N}_().!'&,-]{0,100}_3d(_default)?\.png$/u; +const MAX_BYTES: number = 2 * 1024 * 1024; +/** Must equal `sha` in fluent-emoji-animated-index.json (checked by a test). */ +export const LOCAL_GENUI_ICON3D_ANIMATED_COMMIT: string = 'daa0365c09795789ed2bc6e8b228c97736cb6669'; +const ANIMATED_SEGMENT: string = 'animated/'; +// The animated repository stores its files in Git LFS; the CDN serves only the pointers. +const ANIMATED_UPSTREAM: string = `https://media.githubusercontent.com/media/microsoft/fluentui-emoji-animated/${LOCAL_GENUI_ICON3D_ANIMATED_COMMIT}/assets/`; +/** `/[Default/]animated/_animated[_default].png`, as in the animated index. */ +const ANIMATED_PATH: RegExp = /^[\p{L}\p{N}][\p{L}\p{N} ,.'&()!_-]{0,80}\/(Default\/)?animated\/[\p{Ll}\p{N}][\p{Ll}\p{N}_().!'&,-]{0,100}_animated(_default)?\.png$/u; +const ANIMATED_MAX_BYTES: number = 6 * 1024 * 1024; + +/** One served picture: where it comes from upstream and how large it may be. */ +interface PictureAsset { + key: string; + url: string; + maxBytes: number; +} + +export class LocalGenUIIcon3DStore { + private readonly directory: string; + private readonly inflight: Map> = new Map>(); + + constructor(filesDir: string) { + this.directory = `${filesDir}/local-genui/icon3d`; + } + + /** The asset path a runtime URL names, or '' when the URL is not a served picture. */ + static assetPath(url: string): string { + return LocalGenUIIcon3DStore.pinnedPath(url, LOCAL_GENUI_ICON3D_ROOT, LOCAL_GENUI_ICON3D_COMMIT, ASSET_PATH); + } + + /** The animated asset path a runtime URL names, or '' when it is not a served animation. */ + static animatedAssetPath(url: string): string { + return LocalGenUIIcon3DStore.pinnedPath(url, LOCAL_GENUI_ICON3D_ROOT + ANIMATED_SEGMENT, + LOCAL_GENUI_ICON3D_ANIMATED_COMMIT, ANIMATED_PATH); + } + + private static pinnedPath(url: string, root: string, commit: string, shape: RegExp): string { + if (!url.startsWith(root)) { + return ''; + } + const rest = url.substring(root.length); + const slash = rest.indexOf('/'); + if (slash < 0 || rest.substring(0, slash) !== commit || rest.indexOf('?') >= 0 || rest.indexOf('#') >= 0) { + return ''; + } + let path = ''; + try { + path = decodeURIComponent(rest.substring(slash + 1)); + } catch (_err) { + return ''; + } + return shape.test(path) && path.indexOf('..') < 0 ? path : ''; + } + + private static asset(url: string): PictureAsset | undefined { + const encode = (path: string): string => path.split('/').map((part: string) => encodeURIComponent(part)).join('/'); + const still = LocalGenUIIcon3DStore.assetPath(url); + if (still.length > 0) { + return { key: still, url: UPSTREAM + encode(still), maxBytes: MAX_BYTES }; + } + const animated = LocalGenUIIcon3DStore.animatedAssetPath(url); + if (animated.length > 0) { + return { key: ANIMATED_SEGMENT + animated, url: ANIMATED_UPSTREAM + encode(animated), maxBytes: ANIMATED_MAX_BYTES }; + } + return undefined; + } + + /** PNG bytes for a served picture, from the cache or the pinned upstream. */ + async picture(url: string): Promise { + const asset = LocalGenUIIcon3DStore.asset(url); + if (!asset) { + return undefined; + } + const running = this.inflight.get(asset.key); + if (running) { + return running; + } + const work = this.load(asset).finally(() => { this.inflight.delete(asset.key); }); + this.inflight.set(asset.key, work); + return work; + } + + private cacheFile(path: string): string { + const base64 = new util.Base64Helper().encodeToStringSync(new util.TextEncoder().encodeInto(path)); + return `${this.directory}/${base64.replace(/[^A-Za-z0-9]/g, '_')}.png`; + } + + private async load(asset: PictureAsset): Promise { + const file = this.cacheFile(asset.key); + try { + if (fs.accessSync(file)) { + const handle = fs.openSync(file, fs.OpenMode.READ_ONLY); + try { + const size = fs.statSync(file).size; + const buffer = new ArrayBuffer(size); + fs.readSync(handle.fd, buffer); + return buffer; + } finally { + fs.closeSync(handle); + } + } + } catch (_err) { + // A damaged cache entry is fetched again. + } + const bytes = await this.fetch(asset); + if (bytes) { + this.store(file, bytes); + } + return bytes; + } + + private async fetch(asset: PictureAsset): Promise { + const request = http.createHttp(); + try { + const response = await request.request(asset.url, { + method: http.RequestMethod.GET, + expectDataType: http.HttpDataType.ARRAY_BUFFER, + connectTimeout: 8000, + readTimeout: asset.maxBytes > MAX_BYTES ? 30000 : 10000 + }); + const body = response.result; + if (response.responseCode !== 200 || !(body instanceof ArrayBuffer) || body.byteLength === 0 || body.byteLength > asset.maxBytes) { + RemoteLogger.warn(`local genui icon3d unavailable status=${response.responseCode}`); + return undefined; + } + return body; + } catch (err) { + RemoteLogger.warn(`local genui icon3d fetch failed: ${err instanceof Error ? err.message : String(err)}`); + return undefined; + } finally { + request.destroy(); + } + } + + private store(file: string, bytes: ArrayBuffer): void { + const temporary = `${file}.${Date.now()}.tmp`; + try { + if (!fs.accessSync(this.directory)) { + fs.mkdirSync(this.directory, true); + } + const handle = fs.openSync(temporary, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + fs.writeSync(handle.fd, bytes); + } finally { + fs.closeSync(handle); + } + fs.renameSync(temporary, file); + } catch (_err) { + try { fs.unlinkSync(temporary); } catch (_ignored) { /* derived data */ } + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUILaunchInbox.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUILaunchInbox.ets new file mode 100644 index 0000000..550cd86 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUILaunchInbox.ets @@ -0,0 +1,34 @@ +/** + * App ids opened from a home-screen card. `EntryAbility` delivers them before + * or after the page exists: a cold start parks the id until the page + * subscribes, a warm start (`onNewWant`) hands it over right away. + */ +export class LocalGenUILaunchInbox { + private static pending: string = ''; + private static listener?: (appId: string) => void; + + static deliver(appId: string): void { + if (appId.length === 0) { + return; + } + const listener = LocalGenUILaunchInbox.listener; + if (listener) { + listener(appId); + } else { + LocalGenUILaunchInbox.pending = appId; + } + } + + static subscribe(listener: (appId: string) => void): void { + LocalGenUILaunchInbox.listener = listener; + const pending = LocalGenUILaunchInbox.pending; + LocalGenUILaunchInbox.pending = ''; + if (pending.length > 0) { + listener(pending); + } + } + + static unsubscribe(): void { + LocalGenUILaunchInbox.listener = undefined; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelCatalog.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelCatalog.ets new file mode 100644 index 0000000..611ceda --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelCatalog.ets @@ -0,0 +1,60 @@ +/** + * Local GenUI model catalog policy. Pure: selection rules are tested without + * preferences or HUKS. + */ +export interface LocalGenUIModelProfile { + id: string; + /** Display name; defaults to the model name. */ + name: string; + apiUrl: string; + modelName: string; + createdAt: string; +} + +export interface LocalGenUIModelChoice { + /** The model a turn would use, if any. */ + model?: LocalGenUIModelProfile; + /** The session names a model that no longer exists. */ + missing: boolean; +} + +export class LocalGenUIModelCatalog { + /** + * A session keeps the model it was created with. A deleted model is reported + * as missing instead of silently switching the session to another model. + */ + static choose(models: LocalGenUIModelProfile[], sessionModelId: string, lastSelectedId: string): LocalGenUIModelChoice { + if (sessionModelId.length > 0) { + const pinned = models.find((model: LocalGenUIModelProfile) => model.id === sessionModelId); + return pinned ? { model: pinned, missing: false } : { missing: true }; + } + const last = models.find((model: LocalGenUIModelProfile) => model.id === lastSelectedId); + if (last) { + return { model: last, missing: false }; + } + return models.length > 0 ? { model: models[0], missing: false } : { missing: false }; + } + + static displayName(model: LocalGenUIModelProfile): string { + return model.name.trim().length > 0 ? model.name.trim() : model.modelName; + } + + /** Returns an i18n key for the first invalid field, or ''. */ + static validate(apiUrl: string, modelName: string, apiKey: string, hasStoredKey: boolean): string { + const url = apiUrl.trim().toLowerCase(); + if (!(url.startsWith('https://') || url.startsWith('http://')) || url.length <= 8) { + return 'settings.modelService.invalidUrl'; + } + if (modelName.trim().length === 0) { + return 'settings.modelService.modelRequired'; + } + if (apiKey.trim().length === 0 && !hasStoredKey) { + return 'settings.modelService.apiKeyRequired'; + } + return ''; + } + + static normalizeUrl(value: string): string { + return value.trim().replace(/\/+$/, ''); + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelProvider.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelProvider.ets new file mode 100644 index 0000000..a74d77d --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelProvider.ets @@ -0,0 +1,293 @@ +import { http } from '@kit.NetworkKit'; +import { util } from '@kit.ArkTS'; +import { OhosError } from '../OhosError'; +import { RemoteLogger } from '../RemoteLogger'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUIModelStore } from './LocalGenUIModelStore'; +import { ModelProviderGeneralChatAdapter, ModelProviderProtocol } from '../general-chat/ModelProviderGeneralChatAdapter'; +import { LocalProviderFrame, LocalProviderProtocol, LocalProviderSseParser } from './LocalProviderSseParser'; + +/** Transport diagnostics go to the log; the person sees a plain reason. */ +function localTransportError(operation: string, err: Object): Error { + if (err instanceof Error) { + return err; + } + RemoteLogger.warn(`${operation} failed: ${OhosError.reason(err).slice(0, 400)}`); + return new Error(RemoteI18n.t('localGenui.networkUnavailable')); +} + +/** + * Reasoning models count their reasoning toward the output budget; an app + * source after a long reasoning phase does not fit in 8k tokens. + */ +export const LOCAL_GENUI_MAX_OUTPUT_TOKENS: number = 32768; + +export interface LocalGenUIPromptMessage { + role: string; + content: string; +} + +export interface LocalGenUITurnRequest { + /** Model profile of the session; resolved to credentials on the phone. */ + modelId: string; + system: string; + toolSchemaJson: string; + messages: LocalGenUIPromptMessage[]; +} + +/** Receives provider frames in order; the session controller normalizes them. */ +export interface LocalGenUIFrameSink { + onFrames(frames: LocalProviderFrame[]): void; +} + +/** + * Model access for Local GenUI. The same interface is implemented by the + * direct HTTP adapter now and an on-device provider later. + */ +export interface LocalGenUIModelProvider { + isConfigured(modelId: string): Promise; + /** OpenAI-compatible model discovery for the model editor; [] when unsupported. */ + listRemoteModels(apiUrl: string, apiKey: string): Promise; + streamTurn(request: LocalGenUITurnRequest, sink: LocalGenUIFrameSink): Promise; + cancelTurn(): void; +} + +/** Byte-level streaming transport; replaced by fixtures in native previews. */ +export interface LocalGenUIStreamTransport { + postStream(url: string, headers: Record, body: string, onBytes: (bytes: ArrayBuffer) => void): Promise; + cancel(): void; +} + +export class HarmonyLocalGenUIStreamTransport implements LocalGenUIStreamTransport { + private active?: http.HttpRequest; + + async postStream(url: string, headers: Record, body: string, onBytes: (bytes: ArrayBuffer) => void): Promise { + const request = http.createHttp(); + this.active = request; + let bytes = 0; + let ended = false; + let markEnded: () => void = () => {}; + const endedSignal = new Promise((resolve: () => void) => { markEnded = resolve; }); + const callback = (data: ArrayBuffer): void => { + bytes += data.byteLength; + onBytes(data); + }; + const endCallback = (): void => { + ended = true; + markEnded(); + }; + request.on('dataReceive', callback); + request.on('dataEnd', endCallback); + try { + const status = await request.requestInStream(url, { + method: http.RequestMethod.POST, + header: headers, + extraData: body, + connectTimeout: 15000, + readTimeout: 180000 + }); + // The status can resolve before the last body chunks are delivered; + // finishing early would truncate the tool-call arguments. + if (!ended) { + let timer = -1; + await Promise.race([endedSignal, new Promise((resolve: () => void) => { timer = setTimeout(resolve, 10000); })]); + clearTimeout(timer); + } + RemoteLogger.info(`local genui stream bytes=${bytes} dataEnd=${ended}`); + return status; + } catch (err) { + throw localTransportError('local genui stream request', err); + } finally { + request.off('dataReceive', callback); + request.off('dataEnd', endCallback); + request.destroy(); + if (this.active === request) { + this.active = undefined; + } + } + } + + cancel(): void { + const request = this.active; + this.active = undefined; + if (request) { + request.destroy(); + } + } +} + +interface AnthropicTool { + name: string; + description: string; + input_schema: Object; +} + +interface OpenAiFunction { + name: string; + description: string; + parameters: Object; +} + +interface OpenAiTool { + type: string; + function: OpenAiFunction; +} + +interface AnthropicBody { + model: string; + max_tokens: number; + stream: boolean; + system: string; + messages: LocalGenUIPromptMessage[]; + tools: AnthropicTool[]; +} + +interface OpenAiBody { + model: string; + max_tokens: number; + stream: boolean; + messages: LocalGenUIPromptMessage[]; + tools: OpenAiTool[]; +} + +interface OpenAiModelEntry { + id?: string; +} + +interface OpenAiModelList { + data?: OpenAiModelEntry[]; +} + +export class HttpLocalGenUIModelProvider implements LocalGenUIModelProvider { + private readonly models: LocalGenUIModelStore; + private readonly transport: LocalGenUIStreamTransport; + + constructor(models: LocalGenUIModelStore, transport: LocalGenUIStreamTransport = new HarmonyLocalGenUIStreamTransport()) { + this.models = models; + this.transport = transport; + } + + async isConfigured(modelId: string): Promise { + return this.models.hasKey(modelId); + } + + async listRemoteModels(apiUrl: string, apiKey: string): Promise { + const base = apiUrl.trim().replace(/\/+$/, ''); + if (ModelProviderGeneralChatAdapter.resolveProtocol(base) === ModelProviderProtocol.Anthropic) { + return []; + } + const root = base.replace(/\/chat\/completions$/, '').replace(/\/v1$/, ''); + const request = http.createHttp(); + try { + const response = await request.request(`${root}/v1/models`, { + method: http.RequestMethod.GET, + header: { 'Authorization': `Bearer ${apiKey.trim()}`, 'Accept': 'application/json' }, + connectTimeout: 10000, + readTimeout: 15000 + }); + if (response.responseCode < 200 || response.responseCode >= 300) { + throw new Error(HttpLocalGenUIModelProvider.statusError(response.responseCode, '')); + } + const list = JSON.parse(typeof response.result === 'string' ? response.result as string : '{}') as OpenAiModelList; + return (list.data || []).map((entry: OpenAiModelEntry) => entry.id || '').filter((id: string) => id.length > 0); + } catch (err) { + throw localTransportError('local genui list models', err); + } finally { + request.destroy(); + } + } + + async streamTurn(request: LocalGenUITurnRequest, sink: LocalGenUIFrameSink): Promise { + const config = await this.models.credentials(request.modelId); + const apiKey = config ? config.apiKey.trim() : ''; + if (!config || config.apiUrl.length === 0 || config.modelName.length === 0 || apiKey.length === 0) { + throw new Error(RemoteI18n.t('localGenui.modelNotConfigured')); + } + const generalProtocol = ModelProviderGeneralChatAdapter.resolveProtocol(config.apiUrl); + const protocol = generalProtocol === ModelProviderProtocol.Anthropic ? LocalProviderProtocol.Anthropic : LocalProviderProtocol.OpenAi; + const url = ModelProviderGeneralChatAdapter.resolveRequestUrl(config.apiUrl, generalProtocol); + const body = HttpLocalGenUIModelProvider.body(config.modelName, request, protocol); + const headers = HttpLocalGenUIModelProvider.headers(url, apiKey, protocol); + const parser = new LocalProviderSseParser(protocol); + // A multi-byte character can span two network chunks. + const decoder = util.TextDecoder.create('utf-8', { ignoreBOM: true }); + let errorBody = ''; + RemoteLogger.info(`local genui request start protocol=${protocol}`); + const status = await this.transport.postStream(url, headers, body, (bytes: ArrayBuffer): void => { + const text = decoder.decodeToString(new Uint8Array(bytes), { stream: true }); + if (errorBody.length < 4096) { + errorBody += text; + } + const frames = parser.feed(text); + if (frames.length > 0) { + sink.onFrames(frames); + } + }); + const tail = decoder.decodeToString(new Uint8Array(0), { stream: false }); + const frames = parser.feed(tail).concat(parser.finish()); + if (frames.length > 0) { + sink.onFrames(frames); + } + RemoteLogger.info(`local genui response status=${status}`); + if (status < 200 || status >= 300) { + throw new Error(HttpLocalGenUIModelProvider.statusError(status, errorBody)); + } + } + + cancelTurn(): void { + this.transport.cancel(); + } + + static body(model: string, request: LocalGenUITurnRequest, protocol: LocalProviderProtocol): string { + const tool = JSON.parse(request.toolSchemaJson) as AnthropicTool; + if (protocol === LocalProviderProtocol.Anthropic) { + const anthropic: AnthropicBody = { + model, + max_tokens: LOCAL_GENUI_MAX_OUTPUT_TOKENS, + stream: true, + system: request.system, + messages: request.messages, + tools: [tool] + }; + return JSON.stringify(anthropic); + } + const messages: LocalGenUIPromptMessage[] = [{ role: 'system', content: request.system }]; + request.messages.forEach((message: LocalGenUIPromptMessage) => messages.push(message)); + const openAi: OpenAiBody = { + model, + max_tokens: LOCAL_GENUI_MAX_OUTPUT_TOKENS, + stream: true, + messages, + tools: [{ type: 'function', function: { name: tool.name, description: tool.description, parameters: tool.input_schema } }] + }; + return JSON.stringify(openAi); + } + + private static headers(url: string, apiKey: string, protocol: LocalProviderProtocol): Record { + const headers: Record = { 'Content-Type': 'application/json', 'Accept': 'text/event-stream' }; + if (protocol === LocalProviderProtocol.Anthropic) { + headers['x-api-key'] = apiKey; + headers['anthropic-version'] = '2023-06-01'; + if (url.indexOf('openbitfun.com') >= 0) { + headers['X-Verification-Code'] = 'from_openbitfun'; + } + } else { + headers['Authorization'] = `Bearer ${apiKey}`; + } + return headers; + } + + private static statusError(status: number, body: string): string { + if (status === 401 || status === 403) { + return RemoteI18n.t('generalChat.authenticationFailed'); + } + if (status === 429) { + return RemoteI18n.t('generalChat.rateLimited'); + } + if (status >= 500) { + return RemoteI18n.t('generalChat.serviceUnavailable'); + } + const detail = body.replace(/\s+/g, ' ').trim().slice(0, 200); + return `${RemoteI18n.f('generalChat.requestFailed', `${status}`)}${detail.length > 0 ? `: ${detail}` : ''}`; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelStore.ets new file mode 100644 index 0000000..3f7ed3b --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModelStore.ets @@ -0,0 +1,231 @@ +import { preferences } from '@kit.ArkData'; +import { huks } from '@kit.UniversalKeystoreKit'; +import { util } from '@kit.ArkTS'; +import { Encoding } from '../Encoding'; +import { OhosError } from '../OhosError'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { GeneralChatConfigStore } from '../general-chat/GeneralChatConfigStore'; +import { LocalGenUIModelCatalog, LocalGenUIModelProfile } from './LocalGenUIModelCatalog'; + +const STORE_NAME: string = 'openbitfun_local_genui_models'; +const MODELS_KEY: string = 'models'; +const LAST_SELECTED_KEY: string = 'last_selected_model_id'; +const IMPORTED_KEY: string = 'imported_general_chat_config'; +const HUKS_ALIAS: string = 'openbitfun_local_genui_model_keys'; + +/** Stored row. Unknown fields written by newer builds are preserved. */ +interface StoredModel { + id: string; + name: string; + apiUrl: string; + modelName: string; + createdAt: string; + keyCipher: string; + keyIv: string; +} + +export interface LocalGenUIModelUpdate { + /** Empty for a new model. */ + id: string; + name: string; + apiUrl: string; + modelName: string; + /** Empty keeps the stored key of an existing model. */ + apiKey: string; +} + +export interface LocalGenUIModelCredentials { + apiUrl: string; + modelName: string; + apiKey: string; +} + +/** + * Model profiles for Local GenUI Mode only. Keys never leave the phone and are + * encrypted with a HUKS AES key. The legacy single General Chat configuration + * is imported once as the first profile and left untouched. + */ +export class LocalGenUIModelStore { + private store?: preferences.Preferences; + private models: StoredModel[] = []; + + async init(context: Context, legacy: GeneralChatConfigStore): Promise { + try { + this.store = await preferences.getPreferences(context, STORE_NAME); + this.models = this.parse(await this.getString(MODELS_KEY)); + if (!(await this.requireStore().get(IMPORTED_KEY, false))) { + await this.importLegacy(legacy); + } + } catch (err) { + throw OhosError.wrap('local genui model store init', err); + } + } + + list(): LocalGenUIModelProfile[] { + return this.models.map((model: StoredModel): LocalGenUIModelProfile => ({ + id: model.id, name: model.name, apiUrl: model.apiUrl, modelName: model.modelName, createdAt: model.createdAt + })); + } + + hasKey(id: string): boolean { + const model = this.models.find((item: StoredModel) => item.id === id); + return model !== undefined && model.keyCipher.length > 0 && model.keyIv.length > 0; + } + + async lastSelectedId(): Promise { + return await this.getString(LAST_SELECTED_KEY); + } + + async setLastSelected(id: string): Promise { + await this.requireStore().put(LAST_SELECTED_KEY, id); + await this.requireStore().flush(); + } + + async save(update: LocalGenUIModelUpdate): Promise { + const existing = this.models.find((item: StoredModel) => item.id === update.id); + const error = LocalGenUIModelCatalog.validate(update.apiUrl, update.modelName, update.apiKey, + existing !== undefined && existing.keyCipher.length > 0); + if (error.length > 0) { + throw new Error(RemoteI18n.t(error)); + } + const row: StoredModel = existing ? JSON.parse(JSON.stringify(existing)) as StoredModel : { + id: `model-${util.generateRandomUUID(false)}`, + name: '', apiUrl: '', modelName: '', createdAt: new Date().toISOString(), keyCipher: '', keyIv: '' + }; + row.name = update.name.trim(); + row.apiUrl = LocalGenUIModelCatalog.normalizeUrl(update.apiUrl); + row.modelName = update.modelName.trim(); + if (update.apiKey.trim().length > 0) { + const encrypted = await this.encrypt(update.apiKey.trim()); + row.keyCipher = encrypted[0]; + row.keyIv = encrypted[1]; + } + const next = this.models.filter((item: StoredModel) => item.id !== row.id); + next.push(row); + next.sort((a: StoredModel, b: StoredModel) => a.createdAt.localeCompare(b.createdAt)); + await this.persist(next); + if ((await this.lastSelectedId()).length === 0) { + await this.setLastSelected(row.id); + } + return { id: row.id, name: row.name, apiUrl: row.apiUrl, modelName: row.modelName, createdAt: row.createdAt }; + } + + /** Deleting a model is explicit; sessions that used it then report it missing. */ + async remove(id: string): Promise { + await this.persist(this.models.filter((item: StoredModel) => item.id !== id)); + if ((await this.lastSelectedId()) === id) { + await this.setLastSelected(this.models.length > 0 ? this.models[0].id : ''); + } + } + + async credentials(id: string): Promise { + const model = this.models.find((item: StoredModel) => item.id === id); + if (!model || model.keyCipher.length === 0) { + return undefined; + } + return { apiUrl: model.apiUrl, modelName: model.modelName, apiKey: await this.decrypt(model.keyCipher, model.keyIv) }; + } + + private async importLegacy(legacy: GeneralChatConfigStore): Promise { + try { + const snapshot = await legacy.snapshot(); + if (this.models.length === 0 && snapshot.apiUrl.length > 0 && snapshot.modelName.length > 0 && snapshot.hasApiKey) { + const key = (await legacy.accessToken()).trim(); + if (key.length > 0) { + await this.save({ id: '', name: '', apiUrl: snapshot.apiUrl, modelName: snapshot.modelName, apiKey: key }); + } + } + } finally { + // Mark once; a failed import keeps the legacy configuration readable. + await this.requireStore().put(IMPORTED_KEY, true); + await this.requireStore().flush(); + } + } + + private async persist(models: StoredModel[]): Promise { + await this.requireStore().put(MODELS_KEY, JSON.stringify(models)); + await this.requireStore().flush(); + this.models = models; + } + + private parse(json: string): StoredModel[] { + try { + const value = JSON.parse(json.length > 0 ? json : '[]') as Object; + return Array.isArray(value) ? (value as StoredModel[]).filter((item: StoredModel) => typeof item.id === 'string') : []; + } catch (_err) { + return []; + } + } + + private async encrypt(apiKey: string): Promise { + try { + await this.ensureKey(); + const iv = Encoding.randomBytes(16); + const options = LocalGenUIModelStore.options(huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, iv); + const session = await huks.initSession(HUKS_ALIAS, options); + const result = await huks.finishSession(session.handle, { properties: options.properties, inData: Encoding.utf8ToBytes(apiKey) }); + if (!result.outData || result.outData.length === 0) { + throw new Error(RemoteI18n.t('settings.modelService.encryptFailed')); + } + return [Encoding.bytesToBase64(result.outData), Encoding.bytesToBase64(iv)]; + } catch (err) { + throw OhosError.wrap('local genui encrypt model key', err); + } + } + + private async decrypt(cipher: string, ivText: string): Promise { + try { + const options = LocalGenUIModelStore.options(huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, Encoding.base64ToBytes(ivText)); + const session = await huks.initSession(HUKS_ALIAS, options); + const result = await huks.finishSession(session.handle, { properties: options.properties, inData: Encoding.base64ToBytes(cipher) }); + return result.outData ? Encoding.bytesToUtf8(result.outData) : ''; + } catch (err) { + throw OhosError.wrap('local genui decrypt model key', err); + } + } + + private async ensureKey(): Promise { + let exists = false; + try { + exists = await huks.isKeyItemExist(HUKS_ALIAS, {}); + } catch (_err) { + exists = false; + } + if (exists) { + return; + } + await huks.generateKeyItem(HUKS_ALIAS, { + properties: [ + { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES }, + { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 }, + { tag: huks.HuksTag.HUKS_TAG_PURPOSE, value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT }, + { tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, value: huks.HuksCipherMode.HUKS_MODE_CBC }, + { tag: huks.HuksTag.HUKS_TAG_PADDING, value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 } + ] + }); + } + + private static options(purpose: huks.HuksKeyPurpose, iv: Uint8Array): huks.HuksOptions { + return { + properties: [ + { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES }, + { tag: huks.HuksTag.HUKS_TAG_PURPOSE, value: purpose }, + { tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, value: huks.HuksCipherMode.HUKS_MODE_CBC }, + { tag: huks.HuksTag.HUKS_TAG_PADDING, value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 }, + { tag: huks.HuksTag.HUKS_TAG_IV, value: iv } + ] + }; + } + + private async getString(key: string): Promise { + const value = await this.requireStore().get(key, ''); + return typeof value === 'string' ? value : ''; + } + + private requireStore(): preferences.Preferences { + if (!this.store) { + throw new Error('local genui model store is not initialized'); + } + return this.store; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModels.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModels.ets new file mode 100644 index 0000000..fc06557 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIModels.ets @@ -0,0 +1,204 @@ +/** + * Local GenUI types. Local sessions are owned by the phone and live in the + * `local-genui:` namespace; they never carry remote session or workspace ids. + */ +export const LOCAL_GENUI_NAMESPACE: string = 'local-genui:'; +export const LOCAL_GENUI_SOURCE_FORMAT: string = 'openui-lang'; +export const LOCAL_GENUI_SCHEMA_VERSION: number = 1; + +export interface LocalGenUIDesignSpec { + id: string; + revision: number; +} + +/** Generated from library.json; see rawfile/genui/runtime-manifest.json. */ +export interface LocalGenUIManifest { + contractVersion: number; + profile: string; + template: string; + libraryId: string; + libraryRevision: number; + designSpec: LocalGenUIDesignSpec; + sourceKinds: string[]; + ownerFields: string[]; + toolName: string; + catalogHash: string; + promptHash: string; + toolSchemaHash: string; + rendererRevision: string; +} + +/** The identity the owner binds before any source delta. */ +export interface LocalGenUIIdentity { + appId: string; + toolCallId: string; + title: string; + template: string; + libraryId: string; + libraryRevision: number; + designSpec: LocalGenUIDesignSpec; + sourceFormat: string; +} + +export enum LocalGenUIAppStatus { + /** Streaming or terminal-parsed but not verified; displayable, not accepted. */ + Candidate = 'candidate', + /** Displayed, but one or more required checks are unverified. */ + Displayable = 'displayable', + Accepted = 'accepted', + Failed = 'failed', + StateMigrationRequired = 'state_migration_required', + /** Unknown schema/library/format: retained as-is and never executed. */ + Unsupported = 'unsupported' +} + +export interface LocalGenUIVerificationCheck { + name: string; + result: string; + detail: string; +} + +/** Real device presentation recorded with local verification. */ +export interface LocalGenUIPresentation { + posture: string; + deviceWidth: number; + deviceHeight: number; + safeTop: number; + safeBottom: number; + viewportScale: number; +} + +export interface LocalGenUIVerification { + mode: string; + presentation?: LocalGenUIPresentation; + rendererRevision: string; + catalogHash: string; + promptHash: string; + checks: LocalGenUIVerificationCheck[]; + unverified: string[]; + sourceHash: string; + stateHash: string; + verifiedAt: string; +} + +/** One persisted row of `local_genui_apps`. Unknown values are preserved. */ +export interface LocalGenUIAppRecord { + appId: string; + sessionId: string; + messageId: string; + schemaVersion: number; + title: string; + template: string; + libraryId: string; + libraryRevision: number; + designSpecId: string; + designSpecRevision: number; + sourceFormat: string; + sourceContent: string; + stateJson: string; + sourceRevision: number; + stateRevision: number; + ownerRevision: number; + status: string; + /** Last accepted revision kept for fallback while a candidate is pending. */ + acceptedSourceContent: string; + acceptedStateJson: string; + acceptedSourceRevision: number; + acceptedStateRevision: number; + /** + * Last runnable (accepted or displayable) revision before the current + * candidate. Restored when a turn fails or a migration is required. + */ + previousSourceContent: string; + previousStateJson: string; + previousSourceRevision: number; + previousStateRevision: number; + previousStatus: string; + /** Automatic repair budget and the diagnostics already tried (Desktop parity). */ + repairAttempts?: number; + repairErrorKeys?: string[]; + /** Initial values the model supplied with the current candidate source. */ + candidateValuesJson?: string; + /** User edits since the source was created; drives migration rules. */ + userEdited: boolean; + verificationJson: string; + updatedAt: string; +} + +export interface LocalGenUISession { + id: string; + title: string; + createdAt: string; + updatedAt: string; + /** Model profile pinned to the session. Absent in records from older builds. */ + modelId?: string; + /** The title was taken from the first generated app; later apps keep it. */ + titleFromApp?: boolean; +} + +/** A generated app the user explicitly added to the MiniApp gallery. */ +export interface LocalGenUIGalleryEntry { + appId: string; + sessionId: string; + title: string; + addedAt: string; + /** Projection only, never persisted: preview image of the rendered app. */ + thumbnailPath?: string; +} + +export enum LocalGenUIMessageRole { + User = 'user', + Assistant = 'assistant' +} + +/** Chat rows keep only text and a reference; app source/state live in the app table. */ +export interface LocalGenUIMessage { + id: string; + sessionId: string; + role: string; + type: string; + text: string; + appId: string; + appTitle: string; + status: string; + error: string; + createdAt: string; +} + +export enum LocalGenUIEventType { + TurnStarted = 'turn.started', + MessageDelta = 'message.delta', + GenUIStarted = 'genui.started', + GenUISourceDelta = 'genui.source.delta', + TurnCompleted = 'turn.completed', + TurnFailed = 'turn.failed' +} + +export interface LocalGenUISourceDelta { + appId: string; + seq: number; + reset: boolean; + text: string; +} + +export interface LocalGenUIEvent { + type: LocalGenUIEventType; + turnId: string; + text?: string; + identity?: LocalGenUIIdentity; + delta?: LocalGenUISourceDelta; + error?: string; +} + +export class LocalGenUIIds { + static isLocal(id: string): boolean { + return id.startsWith(LOCAL_GENUI_NAMESPACE); + } + + static require(id: string, kind: string): string { + if (!LocalGenUIIds.isLocal(id)) { + throw new Error(`refusing non-local ${kind} id`); + } + return id; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOrientation.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOrientation.ets new file mode 100644 index 0000000..daa1393 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOrientation.ets @@ -0,0 +1,43 @@ +import { window } from '@kit.ArkUI'; +import { RemoteLogger } from '../RemoteLogger'; + +/** Applies a page's preference while visible and restores the host's preference. */ +export class LocalGenUIOrientation { + private readonly context: () => Context; + private original?: window.Orientation; + private applied?: window.Orientation; + private pending: Promise = Promise.resolve(); + private serial: number = 0; + + constructor(context: () => Context) { + this.context = context; + } + + /** Serialize rotations so a late window lookup cannot override a close/remount. */ + sync(visible: boolean, preference: string = 'auto'): Promise { + const serial = ++this.serial; + this.pending = this.pending.then(async (): Promise => { + if (serial !== this.serial) return; + const requested = visible && preference === 'landscape' ? window.Orientation.AUTO_ROTATION_LANDSCAPE : + visible && preference === 'portrait' ? window.Orientation.AUTO_ROTATION_PORTRAIT : undefined; + if (requested === undefined && this.original === undefined) return; + try { + const main = await window.getLastWindow(this.context()); + if (serial !== this.serial) return; + if (this.original === undefined) this.original = main.getPreferredOrientation(); + const next = requested === undefined ? this.original : requested; + if (next !== this.applied) { + await main.setPreferredOrientation(next); + this.applied = next; + } + if (requested === undefined) { + this.original = undefined; + this.applied = undefined; + } + } catch (err) { + RemoteLogger.warn(`local genui orientation failed: ${err instanceof Error ? err.message : String(err)}`); + } + }); + return this.pending; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOwner.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOwner.ets new file mode 100644 index 0000000..ec9f81f --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIOwner.ets @@ -0,0 +1,439 @@ +import { + LOCAL_GENUI_SCHEMA_VERSION, + LocalGenUIAppRecord, + LocalGenUIAppStatus, + LocalGenUIIdentity, + LocalGenUIIds, + LocalGenUIManifest, + LocalGenUIVerification +} from './LocalGenUIModels'; +import { LocalGenUIGeneration } from './LocalGenUIStreamParser'; + +/** Persistence port; the RDB repository implements it. */ +export interface LocalGenUIAppPort { + loadApp(appId: string): Promise; + insertApp(record: LocalGenUIAppRecord): Promise; + /** Writes `record` only when the stored owner revision equals `expectedOwnerRevision`. */ + compareAndSwapApp(record: LocalGenUIAppRecord, expectedOwnerRevision: number): Promise; +} + +export interface LocalGenUIRunnableRevision { + source: string; + stateJson: string; + sourceRevision: number; + stateRevision: number; + status: string; +} + +export enum LocalStateSaveOutcome { + Saved = 'saved', + Conflict = 'conflict', + StaleSource = 'stale_source', + Rejected = 'rejected' +} + +export interface LocalStateSaveResult { + outcome: LocalStateSaveOutcome; + record?: LocalGenUIAppRecord; + error: string; +} + +export interface LocalStateMigration { + ok: boolean; + stateJson: string; + reason: string; +} + +function typeOfValue(value: Object | null): string { + if (value === null) { + return 'null'; + } + return Array.isArray(value) ? 'array' : typeof value; +} + +function parseState(json: string): Record | undefined { + try { + const value = JSON.parse(json.length > 0 ? json : '{}') as Object; + return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record : undefined; + } catch (_err) { + return undefined; + } +} + +/** + * State migration when the model replaces the source of an app. + * The key set is the new source's declared state (reported by the OpenUI + * parser in the runtime, `null` meaning no declared default) plus the + * model's initial values. Untouched state follows the new initial values. + * User-edited state keeps keys that still exist with a compatible type; any + * removal or type change requires an explicit migration and leaves the + * previous revision in place. + */ +export function migrateLocalState(previousJson: string, userEdited: boolean, initialJson: string, declaredTypes: Record = {}): LocalStateMigration { + const initial = parseState(initialJson); + if (!initial) { + return { ok: false, stateJson: previousJson, reason: 'candidate initial values are not an object' }; + } + if (!userEdited) { + return { ok: true, stateJson: JSON.stringify(initial), reason: '' }; + } + const previous = parseState(previousJson); + if (!previous) { + return { ok: false, stateJson: previousJson, reason: 'stored user state is unreadable' }; + } + const schema: Map = new Map(); + Object.keys(declaredTypes).forEach((key: string) => schema.set(key, declaredTypes[key])); + Object.keys(initial).forEach((key: string) => schema.set(key, typeOfValue(initial[key]))); + const next: Record = {}; + const previousKeys = Object.keys(previous); + for (let i = 0; i < previousKeys.length; i++) { + const key = previousKeys[i]; + const declared = schema.get(key); + if (declared === undefined) { + return { ok: false, stateJson: previousJson, reason: `state key ${key} was removed` }; + } + if (declared !== 'null' && previous[key] !== null && typeOfValue(previous[key]) !== declared) { + return { ok: false, stateJson: previousJson, reason: `state key ${key} changed type` }; + } + next[key] = previous[key]; + } + Object.keys(initial).forEach((key: string) => { + if (!previousKeys.includes(key)) { + next[key] = initial[key]; + } + }); + return { ok: true, stateJson: JSON.stringify(next), reason: '' }; +} + +/** Checks the local runtime can execute; required checks come from the design spec. */ +export function requiredChecksSatisfied(verification: LocalGenUIVerification, required: string[]): boolean { + for (let i = 0; i < required.length; i++) { + const check = verification.checks.find((item) => item.name === required[i]); + if (!check || check.result !== 'passed') { + return false; + } + } + return true; +} + +/** + * The single owner of Local GenUI source/state revisions. All durable writes + * go through compare-and-swap on ownerRevision. + */ +export class LocalGenUIOwner { + private readonly port: LocalGenUIAppPort; + private readonly manifest: LocalGenUIManifest; + private readonly now: () => string; + + constructor(port: LocalGenUIAppPort, manifest: LocalGenUIManifest, now: () => string = () => new Date().toISOString()) { + this.port = port; + this.manifest = manifest; + this.now = now; + } + + /** Bind identity for a new app from the generated manifest only. */ + newIdentity(appId: string, toolCallId: string, title: string): LocalGenUIIdentity { + return { + appId: LocalGenUIIds.require(appId, 'app'), + toolCallId, + title, + template: this.manifest.template, + libraryId: this.manifest.libraryId, + libraryRevision: this.manifest.libraryRevision, + designSpec: { id: this.manifest.designSpec.id, revision: this.manifest.designSpec.revision }, + sourceFormat: 'openui-lang' + }; + } + + /** Inherit identity from an existing app; a different contract is unsupported here. */ + inheritedIdentity(record: LocalGenUIAppRecord, toolCallId: string, title: string): LocalGenUIIdentity | undefined { + if (!this.isRunnable(record)) { + return undefined; + } + return { + appId: record.appId, + toolCallId, + title: title.length > 0 ? title : record.title, + template: record.template, + libraryId: record.libraryId, + libraryRevision: record.libraryRevision, + designSpec: { id: record.designSpecId, revision: record.designSpecRevision }, + sourceFormat: record.sourceFormat + }; + } + + /** Unknown schema, library, design spec or format is retained but never executed. */ + isRunnable(record: LocalGenUIAppRecord): boolean { + return record.schemaVersion === LOCAL_GENUI_SCHEMA_VERSION && + record.sourceFormat === 'openui-lang' && + record.template === this.manifest.template && + record.libraryId === this.manifest.libraryId && + record.libraryRevision === this.manifest.libraryRevision && + record.designSpecId === this.manifest.designSpec.id && + record.designSpecRevision === this.manifest.designSpec.revision; + } + + /** + * Persist a terminal-parsed candidate. A new app starts at revision 1; an + * existing app keeps its accepted revision as the fallback. + */ + async commitCandidate(sessionId: string, messageId: string, identity: LocalGenUIIdentity, generation: LocalGenUIGeneration): Promise { + const existing = await this.port.loadApp(identity.appId); + if (!existing) { + const record: LocalGenUIAppRecord = { + appId: identity.appId, + sessionId: LocalGenUIIds.require(sessionId, 'session'), + messageId, + schemaVersion: LOCAL_GENUI_SCHEMA_VERSION, + title: generation.title, + template: identity.template, + libraryId: identity.libraryId, + libraryRevision: identity.libraryRevision, + designSpecId: identity.designSpec.id, + designSpecRevision: identity.designSpec.revision, + sourceFormat: identity.sourceFormat, + sourceContent: generation.source, + stateJson: generation.valuesJson, + sourceRevision: 1, + stateRevision: 1, + ownerRevision: 1, + status: LocalGenUIAppStatus.Candidate, + acceptedSourceContent: '', + acceptedStateJson: '', + acceptedSourceRevision: 0, + acceptedStateRevision: 0, + previousSourceContent: '', + previousStateJson: '', + previousSourceRevision: 0, + previousStateRevision: 0, + previousStatus: '', + userEdited: false, + verificationJson: '', + updatedAt: this.now() + }; + await this.port.insertApp(record); + return record; + } + if (!this.isRunnable(existing) || existing.libraryId !== identity.libraryId || existing.libraryRevision !== identity.libraryRevision || + existing.designSpecId !== identity.designSpec.id || existing.designSpecRevision !== identity.designSpec.revision) { + throw new Error('candidate identity does not match the stored app'); + } + const next: LocalGenUIAppRecord = this.copy(existing); + if (LocalGenUIOwner.isDisplayableStatus(existing.status)) { + next.previousSourceContent = existing.sourceContent; + next.previousStateJson = existing.stateJson; + next.previousSourceRevision = existing.sourceRevision; + next.previousStateRevision = existing.stateRevision; + next.previousStatus = existing.status; + } + next.title = generation.title; + next.messageId = messageId; + next.sourceContent = generation.source; + next.sourceRevision = existing.sourceRevision + 1; + next.ownerRevision = existing.ownerRevision + 1; + next.updatedAt = this.now(); + next.verificationJson = ''; + // The checker runs on an isolated copy of the current state; migration + // is decided with the parser-reported declarations at verification. + next.candidateValuesJson = generation.valuesJson; + next.status = LocalGenUIAppStatus.Candidate; + if (!(await this.port.compareAndSwapApp(next, existing.ownerRevision))) { + throw new Error('app changed while committing the candidate'); + } + return next; + } + + /** Record verification; only a fully verified candidate becomes accepted. */ + async recordVerification(appId: string, sourceRevision: number, verification: LocalGenUIVerification, required: string[], + declaredTypes: Record = {}): Promise { + const current = await this.requireApp(appId); + if (current.sourceRevision !== sourceRevision) { + throw new Error('verification belongs to another source revision'); + } + const next = this.copy(current); + next.verificationJson = JSON.stringify(verification); + next.ownerRevision = current.ownerRevision + 1; + next.updatedAt = this.now(); + if (current.candidateValuesJson !== undefined && current.status === LocalGenUIAppStatus.Candidate) { + const migration = migrateLocalState(current.stateJson, current.userEdited, current.candidateValuesJson, declaredTypes); + next.candidateValuesJson = undefined; + if (migration.ok) { + next.stateJson = migration.stateJson; + next.stateRevision = current.stateRevision + 1; + } else { + next.status = LocalGenUIAppStatus.StateMigrationRequired; + next.verificationJson = JSON.stringify({ migration: migration.reason, checks: verification.checks }); + } + } + if (next.status !== LocalGenUIAppStatus.StateMigrationRequired) { + if (requiredChecksSatisfied(verification, required)) { + next.status = LocalGenUIAppStatus.Accepted; + next.acceptedSourceContent = current.sourceContent; + next.acceptedStateJson = next.stateJson; + next.acceptedSourceRevision = current.sourceRevision; + next.acceptedStateRevision = next.stateRevision; + } else if (verification.checks.some((check) => check.result === 'failed')) { + LocalGenUIOwner.restorePrevious(next); + } else { + next.status = LocalGenUIAppStatus.Displayable; + } + } + if (!(await this.port.compareAndSwapApp(next, current.ownerRevision))) { + throw new Error('app changed while recording verification'); + } + return next; + } + + /** + * A failure recorded by another renderer is not a verdict from this one: + * the checks themselves (or the components they measure) have changed since. + * Such a source returns to candidate so the host verifies it again; nothing + * is discarded. A failure from the current renderer stays failed. + */ + async reconsiderFailure(appId: string): Promise { + const current = await this.port.loadApp(appId); + if (!current || current.status !== LocalGenUIAppStatus.Failed || !this.isRunnable(current) || current.sourceContent.length === 0) { + return undefined; + } + if (LocalGenUIOwner.verifiedBy(current) === this.manifest.rendererRevision) { + return undefined; + } + const next = this.copy(current); + next.status = LocalGenUIAppStatus.Candidate; + next.ownerRevision = current.ownerRevision + 1; + next.updatedAt = this.now(); + if (!(await this.port.compareAndSwapApp(next, current.ownerRevision))) { + return undefined; + } + return next; + } + + /** Renderer revision recorded with the last verification; empty when unknown. */ + static verifiedBy(record: LocalGenUIAppRecord): string { + try { + const parsed = JSON.parse(record.verificationJson) as Record; + const renderer = parsed ? parsed['rendererRevision'] : undefined; + return typeof renderer === 'string' ? renderer : ''; + } catch (_err) { + return ''; + } + } + + /** User state CAS from the runtime. */ + async saveState(appId: string, sourceRevision: number, baseStateRevision: number, stateJson: string): Promise { + const current = await this.port.loadApp(appId); + if (!current || !this.isRunnable(current)) { + return { outcome: LocalStateSaveOutcome.Rejected, error: 'app is not runnable' }; + } + if (current.sourceRevision !== sourceRevision) { + return { outcome: LocalStateSaveOutcome.StaleSource, record: current, error: 'source revision changed' }; + } + if (current.stateRevision !== baseStateRevision) { + return { outcome: LocalStateSaveOutcome.Conflict, record: current, error: 'state revision changed' }; + } + if (!parseState(stateJson)) { + return { outcome: LocalStateSaveOutcome.Rejected, error: 'state must be a JSON object' }; + } + const next = this.copy(current); + next.stateJson = stateJson; + next.stateRevision = current.stateRevision + 1; + next.ownerRevision = current.ownerRevision + 1; + next.userEdited = true; + next.updatedAt = this.now(); + if (current.status === LocalGenUIAppStatus.Accepted && current.acceptedSourceRevision === current.sourceRevision) { + next.acceptedStateJson = stateJson; + next.acceptedStateRevision = next.stateRevision; + } + if (!(await this.port.compareAndSwapApp(next, current.ownerRevision))) { + const latest = await this.port.loadApp(appId); + return { outcome: LocalStateSaveOutcome.Conflict, record: latest, error: 'concurrent owner write' }; + } + return { outcome: LocalStateSaveOutcome.Saved, record: next, error: '' }; + } + + /** Record that an automatic repair turn was started for these diagnostics. */ + async recordRepairAttempt(appId: string, errorKey: string): Promise { + const current = await this.port.loadApp(appId); + if (!current) { + return false; + } + const next = this.copy(current); + next.repairAttempts = (current.repairAttempts || 0) + 1; + next.repairErrorKeys = (current.repairErrorKeys || []).concat([errorKey]); + next.ownerRevision = current.ownerRevision + 1; + next.updatedAt = this.now(); + return await this.port.compareAndSwapApp(next, current.ownerRevision); + } + + /** + * A committed candidate whose verification could not run. Turn failures + * before the terminal commit never reach the owner, so the stored app and + * user data are untouched; this restores the previous runnable revision. + */ + async failCandidate(appId: string, sourceRevision: number, error: string): Promise { + const current = await this.port.loadApp(appId); + if (!current || current.sourceRevision !== sourceRevision || current.status !== LocalGenUIAppStatus.Candidate) { + return current; + } + const next = this.copy(current); + next.ownerRevision = current.ownerRevision + 1; + next.updatedAt = this.now(); + next.verificationJson = JSON.stringify({ error }); + LocalGenUIOwner.restorePrevious(next); + if (!(await this.port.compareAndSwapApp(next, current.ownerRevision))) { + return await this.port.loadApp(appId); + } + return next; + } + + /** + * Restore the previous runnable revision as a new monotonic revision so + * revision numbers never name two different sources. + */ + private static restorePrevious(next: LocalGenUIAppRecord): void { + if (next.previousSourceRevision <= 0) { + next.status = LocalGenUIAppStatus.Failed; + return; + } + next.sourceContent = next.previousSourceContent; + next.stateJson = next.previousStateJson; + next.sourceRevision = next.sourceRevision + 1; + next.stateRevision = next.stateRevision + 1; + next.status = next.previousStatus; + next.previousSourceRevision = next.sourceRevision; + next.previousStateRevision = next.stateRevision; + if (next.status === LocalGenUIAppStatus.Accepted) { + next.acceptedSourceContent = next.sourceContent; + next.acceptedStateJson = next.stateJson; + next.acceptedSourceRevision = next.sourceRevision; + next.acceptedStateRevision = next.stateRevision; + } + } + + static isDisplayableStatus(status: string): boolean { + return status === LocalGenUIAppStatus.Accepted || status === LocalGenUIAppStatus.Displayable; + } + + /** The revision a host should render: never a failed or migration-blocked candidate. */ + static runnableRevision(record: LocalGenUIAppRecord): LocalGenUIRunnableRevision | undefined { + if (LocalGenUIOwner.isDisplayableStatus(record.status) || record.status === LocalGenUIAppStatus.Candidate) { + return { source: record.sourceContent, stateJson: record.stateJson, sourceRevision: record.sourceRevision, stateRevision: record.stateRevision, status: record.status }; + } + if (record.previousSourceRevision > 0) { + return { source: record.previousSourceContent, stateJson: record.previousStateJson, sourceRevision: record.previousSourceRevision, stateRevision: record.previousStateRevision, status: record.previousStatus }; + } + return undefined; + } + + private async requireApp(appId: string): Promise { + const record = await this.port.loadApp(appId); + if (!record) { + throw new Error('unknown local app'); + } + return record; + } + + private copy(record: LocalGenUIAppRecord): LocalGenUIAppRecord { + return JSON.parse(JSON.stringify(record)) as LocalGenUIAppRecord; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepairPolicy.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepairPolicy.ets new file mode 100644 index 0000000..0d0a294 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepairPolicy.ets @@ -0,0 +1,55 @@ +import { LocalGenUIAppRecord, LocalGenUIVerification, LocalGenUIVerificationCheck } from './LocalGenUIModels'; +import { OPENUI_EDIT_MODE_RULES } from './LocalGenUIEditMode'; + +/** Same bound as Desktop GenUI auto-repair: two attempts per app. */ +export const LOCAL_GENUI_MAX_REPAIR_ATTEMPTS: number = 2; + +/** Checks whose failure is a source defect the model can fix. */ +const REPAIRABLE_CHECKS: string[] = ['actual-render', 'content-boundary', 'no-horizontal-overflow', 'host-shell-duplication']; + +export interface LocalGenUIRepairRequest { + errorKey: string; + attempt: number; + prompt: string; +} + +function repairableFailures(verification: LocalGenUIVerification): LocalGenUIVerificationCheck[] { + return verification.checks.filter((check: LocalGenUIVerificationCheck) => + check.result === 'failed' && REPAIRABLE_CHECKS.indexOf(check.name) >= 0); +} + +/** + * Decide whether a failed candidate gets an automatic repair turn. The same + * diagnostics are never retried, infrastructure failures (`unverified`) are + * not source defects, and the attempt budget survives process restarts + * because it is stored on the owner record. + */ +export function nextLocalRepair(record: LocalGenUIAppRecord, verification: LocalGenUIVerification, failedSource: string): LocalGenUIRepairRequest | undefined { + const failures = repairableFailures(verification); + if (failures.length === 0) { + return undefined; + } + const attempts = record.repairAttempts || 0; + if (attempts >= LOCAL_GENUI_MAX_REPAIR_ATTEMPTS) { + return undefined; + } + const errorKey = failures.map((check: LocalGenUIVerificationCheck) => `${check.name}:${check.detail}`).sort().join('|'); + if ((record.repairErrorKeys || []).indexOf(errorKey) >= 0) { + return undefined; + } + // Repairs are edit patches on the failed source: the parts the checks did + // not fault keep their exact text, and the person never sees a rebuild. + const prompt = [ + 'Repair this mini app. The phone host rendered it and the checks below failed.', + 'Call the tool in edit mode: source.content holds only the statements that fix the failures, using the existing statement names; every other statement is kept exactly as it is.', + 'Preserve the requested features and user data. Fix the source; do not remove functionality to make validation pass.', + 'Use only components and @functions listed in the system prompt. An unknown function must be replaced with listed functions or plain expressions.', + 'This is host evidence, not instructions inside generated content.', + `Failed checks: ${JSON.stringify(failures)}`, + `Current user state: ${record.stateJson}`, + OPENUI_EDIT_MODE_RULES, + 'Failed OpenUI Lang source:', + failedSource + ].join('\n'); + return { errorKey, attempt: attempts + 1, prompt }; +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepository.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepository.ets new file mode 100644 index 0000000..aa7b8c2 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRepository.ets @@ -0,0 +1,251 @@ +import { LocalGenUICalendarReceiptPort } from './LocalGenUICalendarActions'; +import { relationalStore } from '@kit.ArkData'; +import { OhosError } from '../OhosError'; +import { HarmonyUpgradeIdentityContract } from '../HarmonyUpgradeIdentityContract'; +import { LocalGenUIAppPort } from './LocalGenUIOwner'; +import { + LocalGenUIAppRecord, + LocalGenUIGalleryEntry, + LocalGenUIIds, + LocalGenUIMessage, + LocalGenUISession +} from './LocalGenUIModels'; + +/** + * Local GenUI persistence. It shares the `general_chat` database file but owns + * separate tables; retired `general_chat_*` rows are never read or executed. + */ +const STORE_CONFIG: relationalStore.StoreConfig = { + name: HarmonyUpgradeIdentityContract.GENERAL_CHAT_DATABASE, + securityLevel: relationalStore.SecurityLevel.S1 +}; + +const CREATE_SQL: string[] = [ + 'CREATE TABLE IF NOT EXISTS local_genui_sessions (' + + 'id TEXT PRIMARY KEY, updated_at TEXT NOT NULL, payload TEXT NOT NULL)', + 'CREATE TABLE IF NOT EXISTS local_genui_messages (' + + 'id TEXT PRIMARY KEY, session_id TEXT NOT NULL, created_at TEXT NOT NULL, payload TEXT NOT NULL)', + 'CREATE INDEX IF NOT EXISTS idx_local_genui_messages_session ON local_genui_messages(session_id, created_at)', + // Columns follow the design document; `payload` keeps the complete record so + // fields added by newer builds survive older readers and writers. + 'CREATE TABLE IF NOT EXISTS local_genui_apps (' + + 'app_id TEXT PRIMARY KEY, session_id TEXT NOT NULL, message_id TEXT NOT NULL, schema_version INTEGER NOT NULL, ' + + 'title TEXT NOT NULL, template TEXT NOT NULL, library_id TEXT NOT NULL, library_revision INTEGER NOT NULL, ' + + 'design_spec TEXT NOT NULL, source_content TEXT NOT NULL, state_json TEXT NOT NULL, ' + + 'source_revision INTEGER NOT NULL, state_revision INTEGER NOT NULL, owner_revision INTEGER NOT NULL, ' + + 'status TEXT NOT NULL, updated_at TEXT NOT NULL, payload TEXT NOT NULL)', + 'CREATE INDEX IF NOT EXISTS idx_local_genui_apps_session ON local_genui_apps(session_id)', + // Gallery membership is a user choice, separate from owner revisions. + 'CREATE TABLE IF NOT EXISTS local_genui_gallery (' + + 'app_id TEXT PRIMARY KEY, added_at TEXT NOT NULL, payload TEXT NOT NULL)', + 'CREATE TABLE IF NOT EXISTS local_genui_calendar_receipts (' + + 'app_id TEXT NOT NULL, payload TEXT NOT NULL, PRIMARY KEY (app_id, payload))' +]; + +export class LocalGenUIRepository implements LocalGenUIAppPort, LocalGenUICalendarReceiptPort { + private store?: relationalStore.RdbStore; + + async init(context: Context): Promise { + try { + this.store = await relationalStore.getRdbStore(context, STORE_CONFIG); + for (let i = 0; i < CREATE_SQL.length; i++) { + await this.store.executeSql(CREATE_SQL[i]); + } + } catch (err) { + throw OhosError.wrap('local genui store init', err); + } + } + + async calendarReceipts(appId: string): Promise { + return this.queryPayloads('SELECT payload FROM local_genui_calendar_receipts WHERE app_id = ?', [appId]); + } + + async saveCalendarReceipt(appId: string, paramsJson: string): Promise { + LocalGenUIIds.require(appId, 'app'); + await this.insert('local_genui_calendar_receipts', { app_id: appId, payload: paramsJson }); + } + + async listSessions(): Promise { + const rows = await this.queryPayloads('SELECT payload FROM local_genui_sessions ORDER BY updated_at DESC', []); + const sessions: LocalGenUISession[] = []; + rows.forEach((payload: string) => { + const session = LocalGenUIRepository.parse(payload); + if (session && LocalGenUIIds.isLocal(session.id)) { + sessions.push(session); + } + }); + return sessions; + } + + async upsertSession(session: LocalGenUISession): Promise { + LocalGenUIIds.require(session.id, 'session'); + await this.insert('local_genui_sessions', { + id: session.id, + updated_at: session.updatedAt, + payload: JSON.stringify(session) + }); + } + + async deleteSession(sessionId: string): Promise { + LocalGenUIIds.require(sessionId, 'session'); + try { + const store = this.requireStore(); + await store.executeSql( + 'DELETE FROM local_genui_gallery WHERE app_id IN (SELECT app_id FROM local_genui_apps WHERE session_id = ?)', [sessionId]); + await store.executeSql('DELETE FROM local_genui_apps WHERE session_id = ?', [sessionId]); + await store.executeSql('DELETE FROM local_genui_messages WHERE session_id = ?', [sessionId]); + await store.executeSql('DELETE FROM local_genui_sessions WHERE id = ?', [sessionId]); + } catch (err) { + throw OhosError.wrap('local genui delete session', err); + } + } + + async loadMessages(sessionId: string): Promise { + LocalGenUIIds.require(sessionId, 'session'); + const rows = await this.queryPayloads( + 'SELECT payload FROM local_genui_messages WHERE session_id = ? ORDER BY created_at ASC, id ASC', [sessionId]); + const messages: LocalGenUIMessage[] = []; + rows.forEach((payload: string) => { + const message = LocalGenUIRepository.parse(payload); + if (message) { + messages.push(message); + } + }); + return messages; + } + + async upsertMessage(message: LocalGenUIMessage): Promise { + LocalGenUIIds.require(message.sessionId, 'session'); + await this.insert('local_genui_messages', { + id: message.id, + session_id: message.sessionId, + created_at: message.createdAt, + payload: JSON.stringify(message) + }); + } + + async appIdsOfSession(sessionId: string): Promise { + const rows = await this.queryPayloads('SELECT payload FROM local_genui_apps WHERE session_id = ?', [sessionId]); + const ids: string[] = []; + rows.forEach((payload: string) => { + const record = LocalGenUIRepository.parse(payload); + if (record) ids.push(record.appId); + }); + return ids; + } + + async listGallery(): Promise { + const rows = await this.queryPayloads('SELECT payload FROM local_genui_gallery ORDER BY added_at DESC', []); + const entries: LocalGenUIGalleryEntry[] = []; + rows.forEach((payload: string) => { + const entry = LocalGenUIRepository.parse(payload); + if (entry && LocalGenUIIds.isLocal(entry.appId)) { + entries.push(entry); + } + }); + return entries; + } + + async addToGallery(entry: LocalGenUIGalleryEntry): Promise { + LocalGenUIIds.require(entry.appId, 'app'); + await this.insert('local_genui_gallery', { app_id: entry.appId, added_at: entry.addedAt, payload: JSON.stringify(entry) }); + } + + async removeFromGallery(appId: string): Promise { + try { + await this.requireStore().executeSql('DELETE FROM local_genui_gallery WHERE app_id = ?', [appId]); + } catch (err) { + throw OhosError.wrap('local genui remove gallery entry', err); + } + } + + async loadApp(appId: string): Promise { + const rows = await this.queryPayloads('SELECT payload FROM local_genui_apps WHERE app_id = ?', [appId]); + return rows.length > 0 ? LocalGenUIRepository.parse(rows[0]) : undefined; + } + + async insertApp(record: LocalGenUIAppRecord): Promise { + LocalGenUIIds.require(record.appId, 'app'); + try { + await this.requireStore().insert('local_genui_apps', LocalGenUIRepository.appValues(record), + relationalStore.ConflictResolution.ON_CONFLICT_ABORT); + } catch (err) { + throw OhosError.wrap('local genui insert app', err); + } + } + + async compareAndSwapApp(record: LocalGenUIAppRecord, expectedOwnerRevision: number): Promise { + try { + const predicates = new relationalStore.RdbPredicates('local_genui_apps'); + predicates.equalTo('app_id', record.appId).and().equalTo('owner_revision', expectedOwnerRevision); + const changed = await this.requireStore().update(LocalGenUIRepository.appValues(record), predicates); + return changed === 1; + } catch (err) { + throw OhosError.wrap('local genui compare-and-swap app', err); + } + } + + private static appValues(record: LocalGenUIAppRecord): relationalStore.ValuesBucket { + return { + app_id: record.appId, + session_id: record.sessionId, + message_id: record.messageId, + schema_version: record.schemaVersion, + title: record.title, + template: record.template, + library_id: record.libraryId, + library_revision: record.libraryRevision, + design_spec: `${record.designSpecId}@${record.designSpecRevision}`, + source_content: record.sourceContent, + state_json: record.stateJson, + source_revision: record.sourceRevision, + state_revision: record.stateRevision, + owner_revision: record.ownerRevision, + status: record.status, + updated_at: record.updatedAt, + payload: JSON.stringify(record) + }; + } + + private async insert(table: string, values: relationalStore.ValuesBucket): Promise { + try { + await this.requireStore().insert(table, values, relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); + } catch (err) { + throw OhosError.wrap(`local genui write ${table}`, err); + } + } + + private async queryPayloads(sql: string, args: relationalStore.ValueType[]): Promise { + try { + const result = await this.requireStore().querySql(sql, args); + const rows: string[] = []; + try { + const column = result.getColumnIndex('payload'); + while (result.goToNextRow()) { + rows.push(result.getString(column)); + } + } finally { + result.close(); + } + return rows; + } catch (err) { + throw OhosError.wrap('local genui query', err); + } + } + + /** Corrupt rows are skipped for display but never deleted. */ + private static parse(payload: string): T | undefined { + try { + return JSON.parse(payload) as T; + } catch (_err) { + return undefined; + } + } + + private requireStore(): relationalStore.RdbStore { + if (!this.store) { + throw new Error('local genui store is not initialized'); + } + return this.store; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets new file mode 100644 index 0000000..26f7e12 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets @@ -0,0 +1,377 @@ +import { image } from '@kit.ImageKit'; +import { LocalCollaborationReply } from './LocalGenUICollaborationHost'; +import { LocalGenUIIdentity, LocalGenUIManifest } from './LocalGenUIModels'; +import { + LocalProbeReport, + LocalRuntimeCalendarResultMessage, + LocalRuntimeCalendarReceiptsMessage, + LocalRuntimeCapabilityEventMessage, + LocalRuntimeCapabilityStatusMessage, + LocalRuntimeInbound, + LocalRuntimeInitMessage, + LocalRuntimeProbeMessage, + LocalRuntimeSourceDeltaMessage, + LocalRuntimeSourceResetMessage, + LocalRuntimeStateMessage, + LocalRuntimeInsetsMessage, + LocalRuntimeMergeMessage, + LocalRuntimeThemeMessage, + runtimeIdentity +} from './LocalGenUIRuntimeProtocol'; + +export interface LocalRuntimeMount { + identity: LocalGenUIIdentity; + mode: string; + source: string; + streaming: boolean; + sourceRevision: number; + stateRevision: number; + stateJson: string; + /** The mounted source is an edit patch over this program while it streams. */ + base?: string; +} + +/** Outcome of an edit merge; `error` is empty on success. */ +export interface LocalRuntimeMergeResult { + source: string; + error: string; +} + +interface PendingMerge { + resolve: (result: LocalRuntimeMergeResult) => void; + timer: number; +} + +interface LocalCollaborationAvailability { + type: string; + appId: string; + sourceRevision: number; + available: boolean; + reason: string; +} + +interface PendingProbe { + resolve: (report: LocalProbeReport | undefined) => void; + timer: number; +} + +/** + * Host side of the ArkWeb runtime channel. The WebView component attaches a + * sender; everything else talks to this object. It owns no product state: + * the mount mirrors what the owner/controller decided to show. + */ +export class LocalGenUIRuntimeBridge { + private sender?: (json: string) => void; + private insetsJson: string = ''; + private pictureSource?: (url: string) => Promise; + private snapshotter?: () => Promise; + private booted: boolean = false; + private ready: boolean = false; + private mount?: LocalRuntimeMount; + private manifest?: LocalGenUIManifest; + private scheme: string = 'light'; + private locale: string = 'zh-CN'; + private seq: number = 0; + private probeSerial: number = 0; + private readonly probes: Map = new Map(); + private readonly merges: Map = new Map(); + private inboundHandler?: (message: LocalRuntimeInbound) => void; + private readyWaiters: (() => void)[] = []; + + setManifest(manifest: LocalGenUIManifest): void { + this.manifest = manifest; + } + + setInboundHandler(handler: (message: LocalRuntimeInbound) => void): void { + this.inboundHandler = handler; + } + + /** Called by the WebView component once its controller is attached. */ + attach(sender: (json: string) => void): void { + this.sender = sender; + this.booted = false; + this.ready = false; + } + + /** The WebView leaf provides a page snapshot of the mounted document. */ + attachSnapshot(snapshotter: () => Promise): void { + this.snapshotter = snapshotter; + } + + async snapshot(): Promise { + if (!this.snapshotter || !this.ready) { + return undefined; + } + try { + return await this.snapshotter(); + } catch (_err) { + return undefined; + } + } + + detach(): void { + this.sender = undefined; + this.snapshotter = undefined; + this.booted = false; + this.ready = false; + this.probes.forEach((probe: PendingProbe) => { + clearTimeout(probe.timer); + probe.resolve(undefined); + }); + this.probes.clear(); + this.merges.forEach((merge: PendingMerge) => { + clearTimeout(merge.timer); + merge.resolve({ source: '', error: 'runtime detached' }); + }); + this.merges.clear(); + } + + isAttached(): boolean { + return this.sender !== undefined; + } + + currentMount(): LocalRuntimeMount | undefined { + return this.mount; + } + + /** Raw string from the `genuiNative.post` proxy. Treated as untrusted. */ + receive(raw: string): void { + let message: LocalRuntimeInbound; + try { + message = JSON.parse(raw) as LocalRuntimeInbound; + } catch (_err) { + return; + } + if (message.type === 'boot') { + this.booted = true; + if (this.insetsJson.length > 0) { + this.post(this.insetsJson); + } + this.sendInit(); + return; + } + if (message.type === 'ready') { + this.ready = true; + const waiters = this.readyWaiters; + this.readyWaiters = []; + waiters.forEach((resolve: () => void) => resolve()); + } + if (message.type === 'merge_result' && message.requestId) { + const pending = this.merges.get(message.requestId); + if (pending) { + clearTimeout(pending.timer); + this.merges.delete(message.requestId); + pending.resolve({ source: message.source || '', error: message.error || (message.source ? '' : 'empty merge result') }); + } + return; + } + if (message.type === 'probe_result' && message.report) { + const pending = this.probes.get(message.report.requestId); + if (pending) { + clearTimeout(pending.timer); + this.probes.delete(message.report.requestId); + pending.resolve(message.report); + } + return; + } + if (this.inboundHandler) { + this.inboundHandler(message); + } + } + + /** Host-served pictures (3D icons) the runtime requests by URL. */ + setPictureSource(source: (url: string) => Promise): void { + this.pictureSource = source; + } + + picture(url: string): Promise { + return this.pictureSource ? this.pictureSource(url) : Promise.resolve(undefined); + } + + /** Host chrome over the page; resent after every boot so a reload keeps it. */ + setInsets(top: number, left: number, right: number, bottom: number): void { + const next: LocalRuntimeInsetsMessage = { type: 'insets', top, left, right, bottom }; + const json = JSON.stringify(next); + if (json === this.insetsJson) { + return; + } + this.insetsJson = json; + this.post(json); + } + + setAppearance(scheme: string, locale: string): void { + const changed = scheme !== this.scheme; + this.scheme = scheme; + this.locale = locale; + if (changed && this.booted) { + const theme: LocalRuntimeThemeMessage = { type: 'theme', scheme }; + this.post(JSON.stringify(theme)); + } + } + + /** Replace the mounted app (new app, revision change, checker/live mode). */ + mountApp(mount: LocalRuntimeMount): Promise { + this.mount = mount; + this.seq = 0; + this.ready = false; + const waiting = new Promise((resolve: () => void) => { + this.readyWaiters.push(resolve); + }); + if (this.booted) { + this.sendInit(); + } + return waiting; + } + + unmount(): void { + this.mount = undefined; + } + + appendSource(appId: string, text: string, reset: boolean): void { + const mount = this.mount; + if (!mount || mount.identity.appId !== appId) { + return; + } + if (reset) { + mount.source = text; + this.seq = 0; + const message: LocalRuntimeSourceResetMessage = { type: 'source_reset', appId, text, streaming: true, sourceRevision: mount.sourceRevision }; + this.post(JSON.stringify(message)); + return; + } + mount.source += text; + const delta: LocalRuntimeSourceDeltaMessage = { type: 'source_delta', appId, seq: this.seq, text }; + this.seq += 1; + this.post(JSON.stringify(delta)); + } + + sendState(appId: string, sourceRevision: number, stateRevision: number, stateJson: string, conflict: boolean): void { + const mount = this.mount; + if (!mount || mount.identity.appId !== appId || mount.sourceRevision !== sourceRevision) { + return; + } + mount.stateRevision = stateRevision; + mount.stateJson = stateJson; + const message: LocalRuntimeStateMessage = { type: 'state', appId, sourceRevision, stateRevision, state: JSON.parse(stateJson) as Object, conflict }; + this.post(JSON.stringify(message)); + } + + sendCalendarResult(appId: string, sourceRevision: number, requestId: string, ok: boolean): void { + const message: LocalRuntimeCalendarResultMessage = { type: 'calendar_result', appId, sourceRevision, requestId, ok }; + this.post(JSON.stringify(message)); + } + + sendCollaboration(reply: LocalCollaborationReply): void { + const mount = this.mount; + if (!mount || mount.mode !== 'live' || mount.streaming || mount.identity.appId !== reply.appId || mount.sourceRevision !== reply.sourceRevision) return; + this.post(JSON.stringify(reply)); + } + + sendCollaborationAvailability(available: boolean, reason: string): void { + const mount = this.mount; + if (!mount || mount.mode !== 'live' || mount.streaming) return; + const message: LocalCollaborationAvailability = { type: 'collaboration_availability', appId: mount.identity.appId, + sourceRevision: mount.sourceRevision, available, reason }; + this.post(JSON.stringify(message)); + } + + sendCalendarReceipts(appId: string, sourceRevision: number, params: Object[]): void { + const message: LocalRuntimeCalendarReceiptsMessage = { type: 'calendar_receipts', appId, sourceRevision, params }; + this.post(JSON.stringify(message)); + } + + sendCapabilityEvent(subscriptionId: string, gesture: string): void { + const message: LocalRuntimeCapabilityEventMessage = { type: 'capability_event', subscriptionId, gesture }; + this.post(JSON.stringify(message)); + } + + sendCapabilityStatus(subscriptionId: string, status: string): void { + const message: LocalRuntimeCapabilityStatusMessage = { type: 'capability_status', subscriptionId, status }; + this.post(JSON.stringify(message)); + } + + /** Read-only geometry probe of the mounted document. */ + probe(timeoutMs: number): Promise { + if (!this.sender) { + return Promise.resolve(undefined); + } + this.probeSerial += 1; + const requestId = `probe-${this.probeSerial}`; + return new Promise((resolve: (report: LocalProbeReport | undefined) => void) => { + const timer = setTimeout(() => { + this.probes.delete(requestId); + resolve(undefined); + }, timeoutMs); + this.probes.set(requestId, { resolve, timer }); + const message: LocalRuntimeProbeMessage = { type: 'probe', requestId }; + this.post(JSON.stringify(message)); + }); + } + + /** + * The program an OpenUI edit patch produces on `base`, computed by the + * runtime's own lang-core so the host and the renderer merge identically. + */ + merge(base: string, patch: string, timeoutMs: number): Promise { + if (!this.sender || !this.booted) { + const detached: LocalRuntimeMergeResult = { source: '', error: 'runtime is not attached' }; + return Promise.resolve(detached); + } + this.probeSerial += 1; + const requestId = `merge-${this.probeSerial}`; + return new Promise((resolve: (result: LocalRuntimeMergeResult) => void) => { + const timer = setTimeout(() => { + this.merges.delete(requestId); + resolve({ source: '', error: 'merge timed out' }); + }, timeoutMs); + this.merges.set(requestId, { resolve, timer }); + const message: LocalRuntimeMergeMessage = { type: 'merge', requestId, base, patch }; + this.post(JSON.stringify(message)); + }); + } + + waitReady(timeoutMs: number): Promise { + if (this.ready) { + return Promise.resolve(true); + } + return new Promise((resolve: (ok: boolean) => void) => { + const timer = setTimeout(() => resolve(false), timeoutMs); + this.readyWaiters.push(() => { + clearTimeout(timer); + resolve(true); + }); + }); + } + + private sendInit(): void { + const mount = this.mount; + const manifest = this.manifest; + if (!mount || !manifest || !this.sender) { + return; + } + this.seq = 0; + const message: LocalRuntimeInitMessage = { + type: 'init', + manifest, + identity: runtimeIdentity(mount.identity), + mode: mount.mode, + source: mount.source, + streaming: mount.streaming, + sourceRevision: mount.sourceRevision, + stateRevision: mount.stateRevision, + state: JSON.parse(mount.stateJson.length > 0 ? mount.stateJson : '{}') as Object, + scheme: this.scheme, + locale: this.locale + }; + if (mount.base !== undefined && mount.base.length > 0) { + message.base = mount.base; + } + this.post(JSON.stringify(message)); + } + + private post(json: string): void { + if (this.sender && this.booted) { + this.sender(json); + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets new file mode 100644 index 0000000..bcb2a01 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets @@ -0,0 +1,274 @@ +/** + * ArkTS mirror of the runtime message contract defined in + * src/web-ui/src/tools/generative-ui/local-runtime/localRuntimeProtocol.ts. + */ +import { LocalGenUIDesignSpec, LocalGenUIIdentity, LocalGenUIManifest, LocalGenUIPresentation, LocalGenUIVerification, LocalGenUIVerificationCheck } from './LocalGenUIModels'; + +export interface LocalRuntimeCalendarResultMessage { + type: string; + appId: string; + sourceRevision: number; + requestId: string; + ok: boolean; +} + +export interface LocalRuntimeCalendarReceiptsMessage { + type: string; + appId: string; + sourceRevision: number; + params: Object[]; +} + +export interface LocalRuntimeIdentityMessage { + appId: string; + title: string; + template: string; + libraryId: string; + libraryRevision: number; + designSpec: LocalGenUIDesignSpec; + sourceFormat: string; +} + +export interface LocalRuntimeInitMessage { + type: string; + manifest: LocalGenUIManifest; + identity: LocalRuntimeIdentityMessage; + mode: string; + source: string; + /** Present while an edit patch streams: the program the patch applies to. */ + base?: string; + streaming: boolean; + sourceRevision: number; + stateRevision: number; + state: Object; + scheme: string; + locale: string; +} + +export interface LocalRuntimeSourceResetMessage { + type: string; + appId: string; + text: string; + streaming: boolean; + sourceRevision: number; +} + +export interface LocalRuntimeSourceDeltaMessage { + type: string; + appId: string; + seq: number; + text: string; +} + +export interface LocalRuntimeStateMessage { + type: string; + appId: string; + sourceRevision: number; + stateRevision: number; + state: Object; + conflict: boolean; +} + +export interface LocalRuntimeThemeMessage { + type: string; + scheme: string; +} + +/** Owner request: apply an OpenUI edit patch to its base program. */ +export interface LocalRuntimeMergeMessage { + type: string; + requestId: string; + base: string; + patch: string; +} + +/** Space the host keeps over the edge-to-edge page, in vp. */ +export interface LocalRuntimeInsetsMessage { + type: string; + top: number; + left: number; + right: number; + bottom: number; +} + +export interface LocalRuntimeProbeMessage { + type: string; + requestId: string; +} + +export interface LocalProbeBounds { + left: number; + right: number; + top: number; + bottom: number; +} + +export interface LocalProbeViewport { + width: number; + height: number; + devicePixelRatio: number; +} + +export interface LocalProbeReport { + requestId: string; + appId: string; + sourceRevision: number; + rendererRevision: string; + viewport: LocalProbeViewport; + canvasWidth: number; + canvasScale: number; + contentBounds: LocalProbeBounds; + scrollWidth: number; + visibleElements: number; + componentCount: number; + renderErrors: string[]; + unsupportedComponents: string[]; + hostPartsInDocument: number; + contractOk: boolean; + stateTypes: Record; + widestElement: string; +} + +/** Inbound runtime message; fields are present according to `type`. */ +export interface LocalRuntimeInbound { + type: string; + rendererRevision?: string; + catalogHash?: string; + contractOk?: boolean; + reason?: string; + appId?: string; + sourceRevision?: number; + baseStateRevision?: number; + state?: Object; + action?: string; + message?: string; + params?: Object; + capability?: string; + code?: string; + report?: LocalProbeReport; + /** merge_result */ + requestId?: string; + source?: string; + error?: string; + /** Device capability requests. */ + op?: string; + subscriptionId?: string; + gesture?: string; + kind?: string; + orientation?: string; +} + +export interface LocalRuntimeCapabilityEventMessage { + type: string; + subscriptionId: string; + gesture: string; +} + +export interface LocalRuntimeCapabilityStatusMessage { + type: string; + subscriptionId: string; + status: string; +} + +export function runtimeIdentity(identity: LocalGenUIIdentity): LocalRuntimeIdentityMessage { + return { + appId: identity.appId, + title: identity.title, + template: identity.template, + libraryId: identity.libraryId, + libraryRevision: identity.libraryRevision, + designSpec: identity.designSpec, + sourceFormat: identity.sourceFormat + }; +} + +/** Geometry the design specification fixes for the logical app canvas. */ +export interface LocalCanvasSpec { + width: number; + insetLeft: number; + insetRight: number; +} + + +export interface LocalAcceptanceInput { + probe?: LocalProbeReport; + reopenProbe?: LocalProbeReport; + readbackMatches: boolean; + readbackDetail: string; + canvas: LocalCanvasSpec; + presentation: LocalGenUIPresentation; + requiredChecks: string[]; +} + +function check(name: string, passed: boolean, detail: string): LocalGenUIVerificationCheck { + return { name, result: passed ? 'passed' : 'failed', detail }; +} + +function renderCheck(name: string, probe: LocalProbeReport | undefined): LocalGenUIVerificationCheck { + if (!probe) { + // Checker infrastructure unavailable is not a source defect. + return { name, result: 'unverified', detail: 'runtime probe did not report' }; + } + if (!probe.contractOk) { + return check(name, false, 'runtime contract mismatch'); + } + if (probe.renderErrors.length > 0) { + return check(name, false, probe.renderErrors.slice(0, 3).join('; ')); + } + const unsupported = probe.unsupportedComponents.length > 0 ? `; unsupported: ${probe.unsupportedComponents.join(',')}` : ''; + return check(name, probe.visibleElements > 0, `${probe.visibleElements} visible elements${unsupported}`); +} + +/** + * Local phase 1 acceptance. Checks the phone cannot execute stay + * `unverified`; they are never reported as passed. + */ +export function evaluateLocalAcceptance(input: LocalAcceptanceInput): LocalGenUIVerificationCheck[] { + const probe = input.probe; + const checks: LocalGenUIVerificationCheck[] = []; + const executable: Map = new Map(); + executable.set('actual-render', renderCheck('actual-render', probe)); + if (probe) { + // The page fills the device viewport at scale 1 (narrow screens stack the + // page blocks, wide ones set them side by side); the design-spec insets + // are the page gutter on either side of whatever width the device has. + const left = input.canvas.insetLeft; + const right = probe.canvasWidth - input.canvas.insetRight; + const bounds = probe.contentBounds; + const fills = Math.abs(probe.canvasWidth - probe.viewport.width) <= 1 && probe.canvasScale === 1; + executable.set('fixed-viewport', check('fixed-viewport', fills, + `canvas ${probe.canvasWidth}px x ${probe.canvasScale.toFixed(3)} in viewport ${probe.viewport.width}px (dpr ${probe.viewport.devicePixelRatio}), ${input.presentation.posture} ${input.presentation.deviceWidth}x${input.presentation.deviceHeight}`)); + executable.set('content-boundary', check('content-boundary', probe.visibleElements > 0 && bounds.left >= left - 1 && bounds.right <= right + 1, + `content ${bounds.left}..${bounds.right}, allowed ${left}..${right}, widest ${probe.widestElement}`)); + executable.set('no-horizontal-overflow', check('no-horizontal-overflow', probe.scrollWidth <= Math.ceil(probe.viewport.width) + 1, + `document ${probe.scrollWidth}px, viewport ${probe.viewport.width}px`)); + executable.set('host-shell-duplication', check('host-shell-duplication', probe.hostPartsInDocument === 0, + `${probe.hostPartsInDocument} emulated host parts in document`)); + } + executable.set('host-shell', check('host-shell', true, + `native ArkUI shell; safe area top ${input.presentation.safeTop}, bottom ${input.presentation.safeBottom}`)); + const reopen = renderCheck('save-reopen', input.reopenProbe); + executable.set('save-reopen', input.readbackMatches + ? { name: 'save-reopen', result: reopen.result, detail: `${input.readbackDetail}; reopen ${reopen.detail}` } + : check('save-reopen', false, input.readbackDetail)); + input.requiredChecks.forEach((name: string) => { + const result = executable.get(name); + checks.push(result ? result : { name, result: 'unverified', detail: 'not executable on the local phone runtime in phase 1' }); + }); + return checks; +} + +export function verificationOf(checks: LocalGenUIVerificationCheck[], manifest: LocalGenUIManifest, presentation: LocalGenUIPresentation, sourceHash: string, stateHash: string, now: string): LocalGenUIVerification { + return { + mode: 'local-runtime', + presentation, + rendererRevision: manifest.rendererRevision, + catalogHash: manifest.catalogHash, + promptHash: manifest.promptHash, + checks, + unverified: checks.filter((item: LocalGenUIVerificationCheck) => item.result === 'unverified').map((item: LocalGenUIVerificationCheck) => item.name), + sourceHash, + stateHash, + verifiedAt: now + }; +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets new file mode 100644 index 0000000..cd393a3 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets @@ -0,0 +1,963 @@ +import { HarmonyCollaborationService } from './HarmonyCollaborationService'; +import { LocalGenUICollaborationHost } from './LocalGenUICollaborationHost'; +import { LocalGenUICalendarActions } from './LocalGenUICalendarActions'; +import { util } from '@kit.ArkTS'; +import { Encoding } from '../Encoding'; +import { RemoteLogger } from '../RemoteLogger'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { LocalGenUIActionHost } from './LocalGenUIActionHost'; +import { LocalGenUIContract } from './LocalGenUIContract'; +import { LocalGenUIFrameSink, LocalGenUIModelProvider, LocalGenUIPromptMessage } from './LocalGenUIModelProvider'; +import { + LOCAL_GENUI_NAMESPACE, + LocalGenUIAppRecord, + LocalGenUIAppStatus, + LocalGenUIEvent, + LocalGenUIEventType, + LocalGenUIGalleryEntry, + LocalGenUIIdentity, + LocalGenUIMessage, + LocalGenUIMessageRole, + LocalGenUIPresentation, + LocalGenUISession, + LocalGenUIVerification +} from './LocalGenUIModels'; +import { LocalGenUIOwner, LocalStateSaveOutcome } from './LocalGenUIOwner'; +import { LocalGenUIRepository } from './LocalGenUIRepository'; +import { LocalGenUIRuntimeBridge } from './LocalGenUIRuntimeBridge'; +import { evaluateLocalAcceptance, LocalProbeReport, LocalRuntimeInbound, verificationOf } from './LocalGenUIRuntimeProtocol'; +import { LOCAL_GENUI_TRUNCATED, LocalGenUITurnNormalizer } from './LocalGenUITurnNormalizer'; +import { nextLocalRepair } from './LocalGenUIRepairPolicy'; +import { LocalGenUIEditMode } from './LocalGenUIEditMode'; +import { LocalGenUIDesktopCardStore } from './LocalGenUIDesktopCardStore'; +import { LocalGenUIDesktopCardApp } from './LocalGenUIDesktopCards'; +import { LocalGenUIThumbnailStore } from './LocalGenUIThumbnailStore'; +import { LocalGenUIDeviceCapabilityHost } from './LocalGenUIDeviceCapabilityHost'; +import { HarmonyCalendarAction, HarmonyCalendarService } from './HarmonyCalendarService'; +import { LocalProviderFrame } from './LocalProviderSseParser'; +import { LocalGenUIModelStore, LocalGenUIModelUpdate } from './LocalGenUIModelStore'; +import { LocalGenUIModelCatalog, LocalGenUIModelChoice, LocalGenUIModelProfile } from './LocalGenUIModelCatalog'; + +/** Projection of one app for the presentation layer. */ +export interface LocalGenUIAppView { + appId: string; + title: string; + status: string; + detail: string; + unverified: string[]; + sourceRevision: number; + streaming: boolean; +} + +/** Presentation callbacks; the ViewModel implements them. */ +export interface LocalGenUIControllerListener { + sessionsChanged(sessions: LocalGenUISession[], activeId: string): void; + messagesChanged(sessionId: string, messages: LocalGenUIMessage[]): void; + streamingText(sessionId: string, text: string): void; + appChanged(app: LocalGenUIAppView | undefined): void; + busyChanged(busy: boolean): void; + notice(text: string): void; + /** Models plus the model the current (or next new) session uses. */ + modelsChanged(models: LocalGenUIModelProfile[], currentId: string, missing: boolean): void; + galleryChanged(entries: LocalGenUIGalleryEntry[]): void; + orientationChanged(orientation: string): void; +} + +export interface LocalGenUIPresentationSource { + presentation(): LocalGenUIPresentation; +} + +const PROBE_TIMEOUT_MS: number = 4000; +const READY_TIMEOUT_MS: number = 8000; +const MERGE_TIMEOUT_MS: number = 4000; +const HISTORY_LIMIT: number = 12; + +/** + * Gives the local model an explicit device-local clock for relative dates. + * The model contract already defines @Today(), but generated calendar payloads + * can otherwise drift when the provider has a stale or different system date. + */ +function localGenUIDateContext(): string { + const now = new Date(); + const pad = (value: number): string => value < 10 ? `0${value}` : `${value}`; + const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`; + const time = `${pad(now.getHours())}:${pad(now.getMinutes())}`; + const offsetMinutes = -now.getTimezoneOffset(); + const offsetSign = offsetMinutes >= 0 ? '+' : '-'; + const offsetHours = Math.floor(Math.abs(offsetMinutes) / 60); + const offsetRemainder = Math.abs(offsetMinutes) % 60; + const offset = `UTC${offsetSign}${pad(offsetHours)}:${pad(offsetRemainder)}`; + return `Device-local date: ${date}; local time: ${time}; time zone: ${offset}. ` + + `For relative dates such as “today” or “今天”, use @Today() and create calendar timestamps on ${date}. ` + + 'Do not substitute a stale or hard-coded date.'; +} + +interface LocalGenUIPendingRepair { + /** The failed candidate the checks measured; the repair patch applies to it. */ + base: string; + appId: string; + prompt: string; +} + +class TurnSink implements LocalGenUIFrameSink { + private readonly onFramesCallback: (frames: LocalProviderFrame[]) => void; + constructor(onFrames: (frames: LocalProviderFrame[]) => void) { + this.onFramesCallback = onFrames; + } + onFrames(frames: LocalProviderFrame[]): void { + this.onFramesCallback(frames); + } +} + +/** + * Local GenUI session controller. Owns sessions and turns on the phone; it + * never touches RemoteCommand, HostStream or remote identities. + */ +export class LocalGenUISessionController { + private readonly repository: LocalGenUIRepository; + private readonly provider: LocalGenUIModelProvider; + private readonly contract: LocalGenUIContract; + private readonly owner: LocalGenUIOwner; + private readonly bridge: LocalGenUIRuntimeBridge; + private readonly listener: LocalGenUIControllerListener; + private readonly presentationSource: LocalGenUIPresentationSource; + private readonly actions: LocalGenUIActionHost; + private readonly modelStore: LocalGenUIModelStore; + private readonly thumbnails: LocalGenUIThumbnailStore; + private readonly devices: LocalGenUIDeviceCapabilityHost; + private readonly calendar: HarmonyCalendarService; + private readonly collaboration: LocalGenUICollaborationHost; + private readonly calendarActions: LocalGenUICalendarActions; + private readonly desktopCards: LocalGenUIDesktopCardStore; + private activeSessionId: string = ''; + private activeSession?: LocalGenUISession; + /** Model for the next new session; follows the last explicit choice. */ + private draftModelId: string = ''; + private messages: LocalGenUIMessage[] = []; + private turnActive: boolean = false; + private turnSerial: number = 0; + private mountedAppId: string = ''; + /** Automatic repair queued by the finished turn; runs after it releases the slot. */ + private pendingRepair?: LocalGenUIPendingRepair; + + constructor( + repository: LocalGenUIRepository, + provider: LocalGenUIModelProvider, + contract: LocalGenUIContract, + bridge: LocalGenUIRuntimeBridge, + listener: LocalGenUIControllerListener, + presentationSource: LocalGenUIPresentationSource, + modelStore: LocalGenUIModelStore, + thumbnails: LocalGenUIThumbnailStore, + devices: LocalGenUIDeviceCapabilityHost, + desktopCards: LocalGenUIDesktopCardStore, + calendar: HarmonyCalendarService, + collaboration: LocalGenUICollaborationHost + ) { + this.devices = devices; + this.calendar = calendar; + this.collaboration = collaboration; + this.calendarActions = new LocalGenUICalendarActions(repository); + this.desktopCards = desktopCards; + this.modelStore = modelStore; + this.thumbnails = thumbnails; + this.repository = repository; + this.provider = provider; + this.contract = contract; + this.owner = new LocalGenUIOwner(repository, contract.manifest); + this.bridge = bridge; + this.listener = listener; + this.presentationSource = presentationSource; + this.bridge.setManifest(contract.manifest); + this.bridge.setInboundHandler((message: LocalRuntimeInbound): void => { + void this.onRuntimeMessage(message); + }); + this.actions = new LocalGenUIActionHost({ + saveState: (appId: string, sourceRevision: number, base: number, stateJson: string): Promise => + this.saveState(appId, sourceRevision, base, stateJson), + modelTurn: (appId: string, message: string): Promise => this.send(message, appId), + isTurnActive: (): boolean => this.turnActive, + unsupported: (_appId: string, capability: string, reason: string): void => + this.listener.notice(RemoteI18n.f2('localGenui.unsupportedAction', capability, reason)), + subscribeGesture: (appId: string, subscriptionId: string, gesture: string): string => + this.devices.subscribeGesture(appId, subscriptionId, gesture), + unsubscribeGesture: (subscriptionId: string): void => this.devices.unsubscribeGesture(subscriptionId), + haptic: (kind: string): void => this.devices.haptic(kind), + collaboration: (message: LocalRuntimeInbound): string => this.collaboration.handle(message), + calendar: async (appId: string, action: string, params: Object): Promise => action === 'CreateCalendarEvent' + ? this.calendarActions.create(appId, params, () => this.runCalendar(action, params)) + : this.runCalendar(action, params) + }); + } + + private async runCalendar(action: string, params: Object): Promise { + const result = await this.calendar.execute(action as HarmonyCalendarAction, params); + if (!result.ok) { + return result.error || 'calendar action failed'; + } + if (result.kind === 'created') { + this.listener.notice(RemoteI18n.f('localGenui.calendarCreated', String(result.eventId || ''))); + } else if (result.kind === 'updated') { + this.listener.notice(RemoteI18n.f('localGenui.calendarUpdated', String(result.eventId || ''))); + } else if (result.kind === 'deleted') { + this.listener.notice(RemoteI18n.f('localGenui.calendarDeleted', String(result.eventId || ''))); + } else if (result.kind === 'listed') { + this.listener.notice(RemoteI18n.f('localGenui.calendarListed', String(result.count || 0))); + } + return ''; + } + + /** Device capabilities belong to the mounted app only. */ + private setMountedApp(appId: string): void { + this.collaboration.close(); + this.listener.orientationChanged('auto'); + this.mountedAppId = appId; + this.devices.releaseOtherApps(appId); + } + + isTurnActive(): boolean { + return this.turnActive; + } + + async refreshSessions(): Promise { + this.listener.sessionsChanged(await this.repository.listSessions(), this.activeSessionId); + } + + newSession(): void { + if (this.turnActive) { + return; + } + this.activeSessionId = ''; + this.activeSession = undefined; + this.messages = []; + this.setMountedApp(''); + this.bridge.unmount(); + this.listener.messagesChanged('', []); + this.listener.appChanged(undefined); + void this.refreshSessions(); + void this.refreshModels(); + } + + async openSession(sessionId: string): Promise { + if (this.turnActive) { + return; + } + this.activeSessionId = sessionId; + this.activeSession = (await this.repository.listSessions()).find((item: LocalGenUISession) => item.id === sessionId); + await this.refreshModels(); + this.messages = await this.repository.loadMessages(sessionId); + this.listener.messagesChanged(sessionId, this.messages.slice()); + await this.refreshSessions(); + // Reopen shows the latest app of the session from the owner. + for (let i = this.messages.length - 1; i >= 0; i--) { + if (this.messages[i].appId.length > 0) { + await this.openApp(this.messages[i].appId); + return; + } + } + this.setMountedApp(''); + this.bridge.unmount(); + this.listener.appChanged(undefined); + } + + async renameSession(sessionId: string, title: string): Promise { + const session = (await this.repository.listSessions()).find((item: LocalGenUISession) => item.id === sessionId); + const next = title.trim(); + if (!session || next.length === 0) { + return; + } + session.title = next.slice(0, 60); + session.titleFromApp = true; + await this.repository.upsertSession(session); + if (this.activeSession && this.activeSession.id === sessionId) { + this.activeSession.title = session.title; + } + await this.refreshSessions(); + } + + async deleteSession(sessionId: string): Promise { + if (this.turnActive) { + return; + } + const appIds = await this.repository.appIdsOfSession(sessionId); + await this.repository.deleteSession(sessionId); + appIds.forEach((appId: string) => this.thumbnails.remove(appId)); + // Home-screen cards stay until the person removes them; they say the app is gone. + for (let i = 0; i < appIds.length; i++) { + await this.syncDesktopCards(appIds[i]); + } + await this.refreshGallery(); + if (sessionId === this.activeSessionId) { + this.newSession(); + } else { + await this.refreshSessions(); + } + } + + /** Mount the runnable revision of an app read from the owner. */ + async openApp(appId: string): Promise { + let record = await this.repository.loadApp(appId); + if (record && record.status === LocalGenUIAppStatus.Failed && !this.turnActive) { + // Checked by an older renderer: verify again with this one before showing it. + const reconsidered = await this.owner.reconsiderFailure(appId); + if (reconsidered) { + RemoteLogger.info(`local genui reverify ${appId} r${reconsidered.sourceRevision}: failure came from another renderer`); + record = await this.verify(reconsidered); + } + } + if (!record) { + this.listener.appChanged({ appId, title: '', status: 'unsupported', detail: RemoteI18n.t('localGenui.appMissing'), unverified: [], sourceRevision: 0, streaming: false }); + return; + } + if (!this.owner.isRunnable(record)) { + this.setMountedApp(''); + this.bridge.unmount(); + this.listener.appChanged(this.viewOf(record, false, RemoteI18n.t('localGenui.appUnsupported'))); + return; + } + const runnable = LocalGenUIOwner.runnableRevision(record); + if (!runnable) { + this.setMountedApp(''); + this.bridge.unmount(); + this.listener.appChanged(this.viewOf(record, false, '')); + return; + } + this.setMountedApp(record.appId); + void this.bridge.mountApp({ + identity: this.identityOf(record), + mode: 'live', + source: runnable.source, + streaming: false, + sourceRevision: runnable.sourceRevision, + stateRevision: runnable.stateRevision, + stateJson: runnable.stateJson + }).then(() => this.backfillThumbnail(appId)); + this.listener.appChanged(this.viewOf(record, false, '')); + } + + // Models + + private async modelChoice(): Promise { + const sessionModel = this.activeSession && this.activeSession.modelId ? this.activeSession.modelId : ''; + const last = this.draftModelId.length > 0 ? this.draftModelId : await this.modelStore.lastSelectedId(); + return LocalGenUIModelCatalog.choose(this.modelStore.list(), sessionModel, last); + } + + async refreshModels(): Promise { + const choice = await this.modelChoice(); + this.listener.modelsChanged(this.modelStore.list(), choice.model ? choice.model.id : '', choice.missing); + } + + /** Pin a model to the active session (or the next new one) and remember it. */ + async chooseModel(modelId: string): Promise { + if (!this.modelStore.list().some((model: LocalGenUIModelProfile) => model.id === modelId)) { + return; + } + this.draftModelId = modelId; + await this.modelStore.setLastSelected(modelId); + if (this.activeSession) { + this.activeSession.modelId = modelId; + await this.repository.upsertSession(this.activeSession); + } + await this.refreshModels(); + } + + async saveModel(update: LocalGenUIModelUpdate): Promise { + const saved = await this.modelStore.save(update); + if (update.id.length === 0) { + await this.chooseModel(saved.id); + } else { + await this.refreshModels(); + } + return saved; + } + + async removeModel(modelId: string): Promise { + await this.modelStore.remove(modelId); + if (this.draftModelId === modelId) { + this.draftModelId = ''; + } + await this.refreshModels(); + } + + /** An edited model may reuse its stored key for discovery. */ + async listRemoteModels(apiUrl: string, apiKey: string, modelId: string): Promise { + let key = apiKey.trim(); + if (key.length === 0 && modelId.length > 0) { + const stored = await this.modelStore.credentials(modelId); + key = stored ? stored.apiKey : ''; + } + return await this.provider.listRemoteModels(apiUrl, key); + } + + hasStoredKey(modelId: string): boolean { + return this.modelStore.hasKey(modelId); + } + + // Gallery + + async refreshGallery(): Promise { + const entries = await this.repository.listGallery(); + entries.forEach((entry: LocalGenUIGalleryEntry) => { + const path = this.thumbnails.existing(entry.appId); + if (path.length > 0) { + entry.thumbnailPath = path; + } + }); + this.listener.galleryChanged(entries); + } + + /** Gallery apps from before previews existed get one the first time they are opened. */ + private async backfillThumbnail(appId: string): Promise { + if (this.thumbnails.existing(appId).length > 0) { + return; + } + const inGallery = (await this.repository.listGallery()).some((entry: LocalGenUIGalleryEntry) => entry.appId === appId); + if (!inGallery) { + return; + } + // Let fonts and the first layout settle before the snapshot. + await new Promise((resolve: () => void) => { setTimeout(resolve, 900); }); + await this.captureThumbnail(appId); + await this.refreshGallery(); + } + + thumbnailFor(appId: string): string { + return this.thumbnails.existing(appId); + } + + /** Preview of the app as it is rendered now; only for the mounted live app. */ + private async captureThumbnail(appId: string): Promise { + const mount = this.bridge.currentMount(); + if (!mount || mount.identity.appId !== appId || mount.mode !== 'live' || mount.streaming) { + RemoteLogger.info('local genui thumbnail skipped: app is not the mounted live app'); + return; + } + const pixels = await this.bridge.snapshot(); + const path = pixels ? await this.thumbnails.save(appId, pixels) : ''; + RemoteLogger.info(`local genui thumbnail ${path.length > 0 ? 'saved' : 'unavailable'}`); + // A new preview follows every accepted revision; cards on the home screen + // pick up its title and image here. + await this.syncDesktopCards(appId); + // Repaint the conversation's app card with the new preview. + if (path.length > 0 && this.messages.some((item: LocalGenUIMessage) => item.appId === appId)) { + this.listener.messagesChanged(this.activeSessionId, this.messages.slice()); + } + } + + async addToGallery(appId: string): Promise { + const record = await this.repository.loadApp(appId); + if (!record || !this.owner.isRunnable(record)) { + return; + } + await this.repository.addToGallery({ appId, sessionId: record.sessionId, title: record.title, addedAt: new Date().toISOString() }); + if (this.thumbnails.existing(appId).length === 0) { + await this.captureThumbnail(appId); + } + await this.refreshGallery(); + } + + async removeFromGallery(appId: string): Promise { + await this.repository.removeFromGallery(appId); + await this.refreshGallery(); + } + + // Desktop cards + + /** What a home-screen card shows for an app, from the owner's record. */ + private async desktopCardApp(appId: string): Promise { + const record = await this.repository.loadApp(appId); + const available = record !== undefined && this.owner.isRunnable(record) && + LocalGenUIOwner.runnableRevision(record) !== undefined; + return { + appId, + title: record ? record.title : '', + thumbnailPath: available ? this.thumbnails.existing(appId) : '', + available, + updatedAt: new Date().toISOString() + }; + } + + /** Called before the add menu is shown, so a new card has content at once. */ + async prepareDesktopCard(appId: string): Promise { + // First, before any await: the launcher may add the card right away. + this.desktopCards.stagePendingAdd(appId); + if (this.thumbnails.existing(appId).length === 0) { + await this.captureThumbnail(appId); + } + this.desktopCards.saveApp(await this.desktopCardApp(appId)); + } + + /** The launcher placed a card; bind it even if `onAddForm` lost the app id. */ + async desktopCardAdded(appId: string, formId: string): Promise { + this.desktopCards.bind(formId, appId); + this.desktopCards.saveApp(await this.desktopCardApp(appId)); + await this.desktopCards.refresh(formId); + } + + private async syncDesktopCards(appId: string): Promise { + try { + await this.desktopCards.publish(await this.desktopCardApp(appId)); + } catch (err) { + RemoteLogger.warn(`local genui desktop card sync failed: ${err instanceof Error ? err.message : String(err)}`); + } + } + + /** Open an app from the gallery together with the session that produced it. */ + async openGalleryApp(appId: string): Promise { + const record = await this.repository.loadApp(appId); + if (record && record.sessionId !== this.activeSessionId && !this.turnActive) { + await this.openSession(record.sessionId); + } + await this.openApp(appId); + } + + cancel(): void { + if (this.turnActive) { + this.turnSerial += 1; + this.provider.cancelTurn(); + } + } + + /** + * Send a user turn. `targetAppId` updates an existing app in place. + * `modelPrompt` replaces the visible text for host-generated turns. + * `repairBase` is the failed source a repair patch applies to. + */ + async send(text: string, targetAppId: string = '', modelPrompt: string = '', repairBase: string = ''): Promise { + const prompt = text.trim(); + if (prompt.length === 0 || this.turnActive) { + return; + } + const choice = await this.modelChoice(); + if (choice.missing) { + this.listener.notice(RemoteI18n.t('localGenui.modelMissing')); + return; + } + if (!choice.model || !(await this.provider.isConfigured(choice.model.id))) { + this.listener.notice(RemoteI18n.t('localGenui.modelNotConfigured')); + return; + } + const modelId = choice.model.id; + this.turnActive = true; + const serial = ++this.turnSerial; + this.listener.busyChanged(true); + try { + const sessionId = await this.ensureSession(prompt, modelId); + const now = new Date().toISOString(); + const userMessage: LocalGenUIMessage = this.message(sessionId, LocalGenUIMessageRole.User, prompt, now); + await this.appendMessage(userMessage); + const target = targetAppId.length > 0 ? await this.repository.loadApp(targetAppId) : undefined; + const assistant = this.message(sessionId, LocalGenUIMessageRole.Assistant, '', new Date(Date.now() + 1).toISOString()); + assistant.status = 'streaming'; + // A change to an existing app is an edit patch over the program it changes: + // the failed candidate for a repair, the running revision for a follow-up. + const runnable = target && this.owner.isRunnable(target) ? LocalGenUIOwner.runnableRevision(target) : undefined; + const editBase = repairBase.length > 0 ? repairBase : (runnable ? runnable.source : ''); + await this.runTurn(serial, sessionId, modelPrompt.length > 0 ? modelPrompt : prompt, assistant, target, modelPrompt.length > 0, modelId, editBase); + } catch (err) { + RemoteLogger.warn(`local genui turn failed: ${String(err)}`); + this.listener.notice(String(err instanceof Error ? err.message : err)); + } finally { + this.turnActive = false; + this.listener.busyChanged(false); + } + const repair = this.pendingRepair; + this.pendingRepair = undefined; + if (repair && serial === this.turnSerial) { + await this.send(RemoteI18n.t('localGenui.autoRepair'), repair.appId, repair.prompt, repair.base); + } + } + + private async runTurn(serial: number, sessionId: string, prompt: string, assistant: LocalGenUIMessage, + target: LocalGenUIAppRecord | undefined, hostPrompt: boolean, modelId: string, editBase: string = ''): Promise { + const turnId = Encoding.randomId('turn'); + const owner = this.owner; + const normalizer = new LocalGenUITurnNormalizer(turnId, this.contract.manifest.toolName, { + bind: (toolCallId: string, title: string): LocalGenUIIdentity => { + if (target) { + const inherited = owner.inheritedIdentity(target, toolCallId, title); + if (inherited) { + return inherited; + } + } + return owner.newIdentity(`${LOCAL_GENUI_NAMESPACE}app-${util.generateRandomUUID(false)}`, toolCallId, title); + } + }); + let streamingText = ''; + let identity: LocalGenUIIdentity | undefined = undefined; + const handle = (events: LocalGenUIEvent[]): void => { + if (serial !== this.turnSerial) { + return; + } + events.forEach((event: LocalGenUIEvent) => { + if (event.type === LocalGenUIEventType.MessageDelta && event.text) { + streamingText += event.text; + this.listener.streamingText(sessionId, streamingText); + } else if (event.type === LocalGenUIEventType.GenUIStarted && event.identity) { + identity = event.identity; + // An inherited identity edits the target; a new app has no base. + this.mountStreaming(event.identity, target, target && event.identity.appId === target.appId ? editBase : ''); + } else if (event.type === LocalGenUIEventType.GenUISourceDelta && event.delta) { + this.bridge.appendSource(event.delta.appId, event.delta.text, event.delta.reset); + } + }); + }; + handle([normalizer.started()]); + let providerError = ''; + try { + await this.provider.streamTurn({ + modelId, + system: `${this.contract.prompt}\n\nRuntime date context:\n${localGenUIDateContext()}\n\nCross-device capability context:\n${JSON.stringify(HarmonyCollaborationService.environment())}\nThe environment reports local prerequisites only, not peer discovery. A nonempty unavailable field means CrossDeviceImage cannot start on this device.`, + toolSchemaJson: this.contract.toolSchemaJson, + messages: await this.history(sessionId, prompt, hostPrompt ? undefined : target) + }, new TurnSink((frames: LocalProviderFrame[]): void => handle(normalizer.accept(frames)))); + } catch (err) { + providerError = err instanceof Error ? err.message : String(err); + } + if (serial !== this.turnSerial) { + providerError = RemoteI18n.t('localGenui.cancelled'); + } + const result = normalizer.finish(this.contract.manifest.ownerFields); + RemoteLogger.info(`local genui turn finished stop=${result.stopReason || 'none'} text=${result.assistantText.length} generation=${result.generation ? (result.generation.ok ? 'ok' : `rejected: ${result.generation.error.slice(0, 200)}`) : 'none'}`); + result.warnings.forEach((warning: string) => RemoteLogger.warn(`local genui: ${warning}`)); + assistant.text = result.assistantText.trim(); + this.listener.streamingText(sessionId, ''); + const failedEvent = result.events.find((event: LocalGenUIEvent) => event.type === LocalGenUIEventType.TurnFailed); + let failure = providerError.length > 0 ? providerError : (failedEvent && failedEvent.error ? failedEvent.error : ''); + if (failure === LOCAL_GENUI_TRUNCATED) { + failure = RemoteI18n.t('localGenui.truncated'); + } else if (providerError.length === 0 && failure.length > 0) { + // Contract/parser diagnostics are for the log, not for the person. + RemoteLogger.warn(`local genui generation rejected: ${failure.slice(0, 300)}`); + failure = RemoteI18n.t('localGenui.generationInvalid'); + } + if (failure.length > 0 || !result.generation || !result.identity) { + assistant.status = failure.length > 0 ? 'failed' : 'completed'; + assistant.error = failure; + await this.appendMessage(assistant); + if (result.identity) { + // The candidate never reached the owner; show the stored app again. + if (target) { + await this.openApp(target.appId); + } else { + this.setMountedApp(''); + this.bridge.unmount(); + this.listener.appChanged(undefined); + } + } + return; + } + const committedIdentity: LocalGenUIIdentity = result.identity; + if (target && committedIdentity.appId === target.appId && editBase.length > 0) { + // Edit mode: the tool carried a patch; the owner commits the program it produces. + const merged = await this.bridge.merge(editBase, result.generation.source, MERGE_TIMEOUT_MS); + if (merged.error.length > 0) { + RemoteLogger.warn(`local genui edit merge failed: ${merged.error.slice(0, 200)}`); + assistant.status = 'failed'; + assistant.error = RemoteI18n.t('localGenui.generationInvalid'); + await this.appendMessage(assistant); + await this.openApp(target.appId); + return; + } + RemoteLogger.info(`local genui edit merged ${committedIdentity.appId}: patch ${result.generation.source.split('\n').length} lines over base ${editBase.split('\n').length} -> ${merged.source.split('\n').length}`); + result.generation.source = merged.source; + } + assistant.type = 'genui'; + assistant.appId = committedIdentity.appId; + assistant.appTitle = result.generation.title; + const record = await this.owner.commitCandidate(sessionId, assistant.id, committedIdentity, result.generation); + await this.titleSessionAfterApp(sessionId, result.generation.title); + assistant.status = record.status; + await this.appendMessage(assistant); + const failedSource = record.sourceContent; + const verified = await this.verify(record); + // The reopen probe left the accepted revision mounted live: refresh its preview. + if (verified.status !== 'failed' && verified.status !== 'state_migration_required') { + await this.captureThumbnail(verified.appId); + } + await this.queueRepair(verified, failedSource); + assistant.status = verified.status; + await this.appendMessage(assistant); + await this.openApp(verified.appId); + } + + private async queueRepair(record: LocalGenUIAppRecord, failedSource: string): Promise { + let verification: LocalGenUIVerification | undefined = undefined; + try { + const parsed = JSON.parse(record.verificationJson.length > 0 ? record.verificationJson : '{}') as LocalGenUIVerification; + verification = Array.isArray(parsed.checks) ? parsed : undefined; + } catch (_err) { + verification = undefined; + } + if (!verification) { + return; + } + const repair = nextLocalRepair(record, verification, failedSource); + if (!repair) { + return; + } + // Persist the attempt first so a restart cannot repeat the same repair. + if (!(await this.owner.recordRepairAttempt(record.appId, repair.errorKey))) { + return; + } + RemoteLogger.info(`local genui automatic repair ${record.appId} attempt ${repair.attempt}`); + this.pendingRepair = { appId: record.appId, prompt: repair.prompt, base: failedSource }; + } + + /** Local acceptance: checker-mode probe, owner readback, then live reopen probe. */ + private async verify(record: LocalGenUIAppRecord): Promise { + if (record.status !== 'candidate') { + return record; + } + const identity = this.identityOf(record); + const host = this.presentationSource.presentation(); + const checkerReady = this.bridge.mountApp({ + identity, mode: 'checker', source: record.sourceContent, streaming: false, + sourceRevision: record.sourceRevision, stateRevision: record.stateRevision, stateJson: record.stateJson + }); + this.setMountedApp(record.appId); + const checkerOk = await this.withTimeout(checkerReady, READY_TIMEOUT_MS); + const checkerProbe = checkerOk ? await this.bridge.probe(PROBE_TIMEOUT_MS) : undefined; + // The runtime's measured canvas scale is the recorded truth. + const presentation: LocalGenUIPresentation = { + posture: host.posture, deviceWidth: host.deviceWidth, deviceHeight: host.deviceHeight, + safeTop: host.safeTop, safeBottom: host.safeBottom, + viewportScale: checkerProbe ? checkerProbe.canvasScale : host.viewportScale + }; + const readback = await this.repository.loadApp(record.appId); + const sourceHash = await Encoding.sha256(record.sourceContent); + const stateHash = await Encoding.sha256(record.stateJson); + const readbackMatches = readback !== undefined && readback.sourceRevision === record.sourceRevision && + readback.stateRevision === record.stateRevision && (await Encoding.sha256(readback.sourceContent)) === sourceHash && + (await Encoding.sha256(readback.stateJson)) === stateHash; + let reopenProbe: LocalProbeReport | undefined = undefined; + if (readback && readbackMatches) { + const liveReady = this.bridge.mountApp({ + identity, mode: 'live', source: readback.sourceContent, streaming: false, + sourceRevision: readback.sourceRevision, stateRevision: readback.stateRevision, stateJson: readback.stateJson + }); + if (await this.withTimeout(liveReady, READY_TIMEOUT_MS)) { + reopenProbe = await this.bridge.probe(PROBE_TIMEOUT_MS); + } + } + const checks = evaluateLocalAcceptance({ + probe: checkerProbe, + reopenProbe, + readbackMatches, + readbackDetail: readbackMatches ? `owner readback r${record.sourceRevision}/s${record.stateRevision}` : 'owner readback differs from the committed candidate', + canvas: this.contract.canvas, + presentation, + requiredChecks: this.contract.requiredChecks + }); + const verification = verificationOf(checks, this.contract.manifest, presentation, sourceHash, stateHash, new Date().toISOString()); + RemoteLogger.info(`local genui verification ${record.appId} r${record.sourceRevision}: ${checks.map((item) => `${item.name}=${item.result}`).join(',')}`); + checks.filter((item) => item.result !== 'passed').forEach((item) => RemoteLogger.info(`local genui check ${item.name}: ${item.detail}`)); + const boundary = checks.find((item) => item.name === 'content-boundary'); + if (boundary) { + RemoteLogger.info(`local genui geometry: ${boundary.detail}`); + } + const declared: Record = checkerProbe && checkerProbe.stateTypes ? checkerProbe.stateTypes : {}; + return await this.owner.recordVerification(record.appId, record.sourceRevision, verification, this.contract.requiredChecks, declared); + } + + private async withTimeout(promise: Promise, ms: number): Promise { + let timer = -1; + const timeout = new Promise((resolve: (value: boolean) => void) => { + timer = setTimeout(() => resolve(false), ms); + }); + const done = promise.then((): boolean => true); + const result = await Promise.race([done, timeout]); + clearTimeout(timer); + return result; + } + + private mountStreaming(identity: LocalGenUIIdentity, target: LocalGenUIAppRecord | undefined, base: string): void { + this.setMountedApp(identity.appId); + void this.bridge.mountApp({ + identity, mode: 'live', source: '', streaming: true, base, + sourceRevision: target ? target.sourceRevision + 1 : 1, + stateRevision: target ? target.stateRevision : 1, + stateJson: target ? target.stateJson : '{}' + }); + this.listener.appChanged({ appId: identity.appId, title: identity.title, status: 'candidate', detail: RemoteI18n.t('localGenui.generating'), unverified: [], sourceRevision: 0, streaming: true }); + } + + private async onRuntimeMessage(message: LocalRuntimeInbound): Promise { + const mount = this.bridge.currentMount(); + if (message.type === 'error') { + RemoteLogger.warn(`local genui runtime error ${message.code || ''}: ${message.message || ''}`); + return; + } + if (message.type === 'ready' && message.contractOk === false) { + this.listener.notice(RemoteI18n.f('localGenui.runtimeMismatch', message.reason || '')); + return; + } + if (message.type === 'ready' && mount && mount.mode === 'live' && !mount.streaming) { + const environment = HarmonyCollaborationService.environment(); + this.bridge.sendCollaborationAvailability(environment.unavailable.length === 0, environment.unavailable); + try { + const rows = await this.repository.calendarReceipts(mount.identity.appId); + this.bridge.sendCalendarReceipts(mount.identity.appId, mount.sourceRevision, rows.map((row: string): Object => JSON.parse(row) as Object)); + } catch (error) { + this.listener.notice(String(error)); + } + return; + } + if (message.type === 'orientation') { + if (mount && mount.mode === 'live' && !mount.streaming && message.appId === this.mountedAppId && + message.sourceRevision === mount.sourceRevision && + (message.orientation === 'auto' || message.orientation === 'portrait' || message.orientation === 'landscape')) { + this.listener.orientationChanged(message.orientation); + } + return; + } + // Only capability-bearing messages reach the action host. + if (message.type === 'capability' && message.op === 'unsubscribe') { + // Releases are always honored, even while a turn streams or after a remount. + void this.actions.handle(message, this.mountedAppId, mount ? mount.sourceRevision : 0); + return; + } + if (message.type !== 'state' && message.type !== 'action' && message.type !== 'query' && + message.type !== 'capability' && message.type !== 'haptic' && message.type !== 'collaboration') { + return; + } + if (!mount || mount.mode !== 'live' || mount.streaming) { + return; + } + const refused = await this.actions.handle(message, this.mountedAppId, mount.sourceRevision); + if (message.type === 'collaboration' && refused && message.requestId) { + this.bridge.sendCollaboration({ type: 'collaboration_result', appId: message.appId || '', + sourceRevision: message.sourceRevision || 0, requestId: message.requestId, status: 'failed', reason: refused, asset: '' }); + } + if (message.type === 'action' && message.action === 'CreateCalendarEvent' && message.requestId) { + this.bridge.sendCalendarResult(message.appId || '', message.sourceRevision || 0, message.requestId, refused.length === 0); + } + if (refused.length > 0) { + RemoteLogger.warn(`local genui refused runtime message: ${refused}`); + } + } + + private async saveState(appId: string, sourceRevision: number, baseStateRevision: number, stateJson: string): Promise { + const result = await this.owner.saveState(appId, sourceRevision, baseStateRevision, stateJson); + if (result.outcome === LocalStateSaveOutcome.Saved && result.record) { + this.bridge.sendState(appId, sourceRevision, result.record.stateRevision, result.record.stateJson, false); + } else if (result.outcome === LocalStateSaveOutcome.Conflict && result.record) { + this.bridge.sendState(appId, sourceRevision, result.record.stateRevision, result.record.stateJson, true); + } else { + this.listener.notice(RemoteI18n.f('localGenui.saveFailed', result.error)); + } + } + + /** A session still titled by its first prompt takes the first app's name. */ + private async titleSessionAfterApp(sessionId: string, appTitle: string): Promise { + const session = (await this.repository.listSessions()).find((item: LocalGenUISession) => item.id === sessionId); + if (!session || appTitle.trim().length === 0 || session.titleFromApp) { + return; + } + session.title = appTitle.trim(); + session.titleFromApp = true; + await this.repository.upsertSession(session); + if (this.activeSession && this.activeSession.id === sessionId) { + this.activeSession.title = session.title; + this.activeSession.titleFromApp = true; + } + await this.refreshSessions(); + } + + private async ensureSession(prompt: string, modelId: string): Promise { + if (this.activeSessionId.length > 0) { + return this.activeSessionId; + } + const now = new Date().toISOString(); + const title = prompt.replace(/\s+/g, ' ').slice(0, 24); + const session: LocalGenUISession = { id: `${LOCAL_GENUI_NAMESPACE}${util.generateRandomUUID(false)}`, title, createdAt: now, updatedAt: now, modelId }; + await this.repository.upsertSession(session); + this.activeSessionId = session.id; + this.activeSession = session; + this.messages = []; + await this.refreshSessions(); + return session.id; + } + + private async appendMessage(message: LocalGenUIMessage): Promise { + await this.repository.upsertMessage(message); + const index = this.messages.findIndex((item: LocalGenUIMessage) => item.id === message.id); + if (index >= 0) { + this.messages[index] = message; + } else { + this.messages.push(message); + } + if (message.sessionId === this.activeSessionId) { + this.listener.messagesChanged(message.sessionId, this.messages.slice()); + } + const sessions = await this.repository.listSessions(); + const session = sessions.find((item: LocalGenUISession) => item.id === message.sessionId); + if (session) { + session.updatedAt = message.createdAt > session.updatedAt ? message.createdAt : new Date().toISOString(); + await this.repository.upsertSession(session); + } + } + + /** Prompt history: recent text plus the current source of the targeted app. */ + private async history(sessionId: string, prompt: string, target: LocalGenUIAppRecord | undefined): Promise { + const history: LocalGenUIPromptMessage[] = []; + const recent = this.messages.filter((item: LocalGenUIMessage) => item.sessionId === sessionId && item.status !== 'failed'); + // The last entry is the current user prompt; it is appended below. + recent.slice(Math.max(0, recent.length - 1 - HISTORY_LIMIT), recent.length - 1).forEach((item: LocalGenUIMessage) => { + let content = item.text; + if (item.appId.length > 0) { + content = `${content}\n[Created mini app "${item.appTitle}"]`.trim(); + } + if (content.length > 0) { + history.push({ role: item.role === LocalGenUIMessageRole.User ? 'user' : 'assistant', content }); + } + }); + let current = prompt; + if (target && this.owner.isRunnable(target)) { + const runnable = LocalGenUIOwner.runnableRevision(target); + if (runnable) { + current = LocalGenUIEditMode.followUp(prompt, target.title, runnable.source, runnable.stateJson); + } + } + history.push({ role: 'user', content: current }); + return history; + } + + private message(sessionId: string, role: string, text: string, createdAt: string): LocalGenUIMessage { + return { id: Encoding.randomId('local-msg'), sessionId, role, type: 'text', text, appId: '', appTitle: '', status: 'completed', error: '', createdAt }; + } + + private identityOf(record: LocalGenUIAppRecord): LocalGenUIIdentity { + return { + appId: record.appId, + toolCallId: '', + title: record.title, + template: record.template, + libraryId: record.libraryId, + libraryRevision: record.libraryRevision, + designSpec: { id: record.designSpecId, revision: record.designSpecRevision }, + sourceFormat: record.sourceFormat + }; + } + + private viewOf(record: LocalGenUIAppRecord, streaming: boolean, detail: string): LocalGenUIAppView { + let unverified: string[] = []; + let summary = detail; + try { + const verification = JSON.parse(record.verificationJson.length > 0 ? record.verificationJson : '{}') as Record; + if (Array.isArray(verification['unverified'])) { + unverified = verification['unverified'] as string[]; + } + if (summary.length === 0 && typeof verification['error'] === 'string') { + summary = verification['error'] as string; + } + if (summary.length === 0 && typeof verification['migration'] === 'string') { + summary = verification['migration'] as string; + } + } catch (_err) { + // Unknown verification payloads are preserved and not interpreted. + } + return { appId: record.appId, title: record.title, status: record.status, detail: summary, unverified, sourceRevision: record.sourceRevision, streaming }; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIStreamParser.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIStreamParser.ets new file mode 100644 index 0000000..39f991a --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIStreamParser.ets @@ -0,0 +1,527 @@ +/** + * GenerativeUI tool-call argument parsing for Harmony Local GenUI. + * + * This mirrors the Desktop accumulator (agent-stream tool_call_accumulator.rs) + * and is verified against the same fixtures in + * src/shared/generative-ui/tool-call-fixtures.json. It is a JSON framing + * scanner only: it locates the program (top-level `source` in the local tool + * form, `source.content` in the shared envelope), decodes the JSON string + * incrementally and never parses OpenUI Lang. + */ + +export interface LocalGenUISourceChunk { + text: string; + reset: boolean; +} + +interface DecodedDelta { + text: string; + next: number; + closed: boolean; +} + +const BACKSLASH: number = 92; +const QUOTE: number = 34; + +function quotedStringEnd(input: string, start: number): number { + if (input.charCodeAt(start) !== QUOTE) { + return -1; + } + let index = start + 1; + while (index < input.length) { + const code = input.charCodeAt(index); + if (code === BACKSLASH) { + index += 2; + } else if (code === QUOTE) { + return index + 1; + } else { + index += 1; + } + } + return -1; +} + +function parseJsonString(encoded: string): string | undefined { + try { + const value: Object = JSON.parse(encoded) as Object; + return typeof value === 'string' ? value as string : undefined; + } catch (_err) { + return undefined; + } +} + +function isHex(text: string): boolean { + return /^[0-9a-fA-F]{4}$/.test(text); +} + +/** Decode the JSON string body from `cursor`, stopping before an incomplete escape. */ +function decodeJsonStringDelta(input: string, cursor: number): DecodedDelta | undefined { + let index = cursor; + while (index < input.length) { + const code = input.charCodeAt(index); + if (code === QUOTE) { + const text = parseJsonString(`"${input.slice(cursor, index)}"`); + return text === undefined ? undefined : { text, next: index + 1, closed: true }; + } + if (code !== BACKSLASH) { + index += 1; + continue; + } + if (index + 1 >= input.length) { + break; + } + const escape = input.charAt(index + 1); + let end = index + 2; + if (escape === 'u') { + const digits = input.slice(index + 2, index + 6); + if (digits.length < 4) { + break; + } + if (!isHex(digits)) { + return undefined; + } + const unit = parseInt(digits, 16); + end = index + 6; + if (unit >= 0xD800 && unit <= 0xDBFF) { + if (end + 2 > input.length) { + break; + } + if (input.slice(end, end + 2) !== '\\u') { + return undefined; + } + const low = input.slice(end + 2, end + 6); + if (low.length < 4) { + break; + } + if (!isHex(low)) { + return undefined; + } + const lowUnit = parseInt(low, 16); + if (lowUnit < 0xDC00 || lowUnit > 0xDFFF) { + return undefined; + } + end += 6; + } + } else if ('"\\/bfnrt'.indexOf(escape) < 0) { + return undefined; + } + index = end; + } + if (index === cursor) { + return { text: '', next: cursor, closed: false }; + } + const text = parseJsonString(`"${input.slice(cursor, index)}"`); + return text === undefined ? undefined : { text, next: index, closed: false }; +} + +/** Value starts of `"wanted":` members of objects, tolerant of an unfinished document. */ +function findObjectFieldStarts(input: string, wanted: string, topLevelOnly: boolean = false): number[] { + const stack: string[] = []; + const starts: number[] = []; + let index = 0; + while (index < input.length) { + const ch = input.charAt(index); + if (ch === '"') { + const end = quotedStringEnd(input, index); + if (end < 0) { + break; + } + const key = parseJsonString(input.slice(index, end)); + if (key !== undefined && stack.length > 0 && stack[stack.length - 1] === '{' && key === wanted && (!topLevelOnly || stack.length === 1)) { + let valueStart = end; + while (valueStart < input.length && /\s/.test(input.charAt(valueStart))) { + valueStart += 1; + } + if (input.charAt(valueStart) !== ':') { + // A string value can equal the field name; keep scanning for the member. + index = end; + continue; + } + valueStart += 1; + while (valueStart < input.length && /\s/.test(input.charAt(valueStart))) { + valueStart += 1; + } + starts.push(valueStart); + } + index = end; + } else if (ch === '{' || ch === '[') { + stack.push(ch); + index += 1; + } else if (ch === '}') { + if (stack.length > 0 && stack[stack.length - 1] === '{') { + stack.pop(); + } + index += 1; + } else if (ch === ']') { + if (stack.length > 0 && stack[stack.length - 1] === '[') { + stack.pop(); + } + index += 1; + } else { + index += 1; + } + } + return starts; +} + +function findObjectFieldStart(input: string, wanted: string): number { + const starts = findObjectFieldStarts(input, wanted); + return starts.length > 0 ? starts[0] : -1; +} + +function closedStringAt(input: string, start: number): string | undefined { + const end = quotedStringEnd(input, start); + return end < 0 ? undefined : parseJsonString(input.slice(start, end)); +} + +function findOpenUIContentStart(raw: string): number { + // Local tool form: `{"title": ..., "source": ""}`. + const flat = findObjectFieldStarts(raw, 'source', true); + if (flat.length > 0 && raw.charAt(flat[0]) === '"') { + return flat[0]; + } + const sources = findObjectFieldStarts(raw, 'source'); + for (let i = 0; i < sources.length; i++) { + const sourceStart = sources[i]; + if (raw.charAt(sourceStart) !== '{') { + continue; + } + const scope = raw.slice(sourceStart); + const kindStart = findObjectFieldStart(scope, 'kind'); + if (kindStart < 0) { + continue; + } + if (closedStringAt(scope, kindStart) !== 'openui-lang') { + // Free HTML documents stay on the completed-source path. + continue; + } + const contentStart = findObjectFieldStart(scope, 'content'); + // Providers can split between `:` and the opening quote; wait for it. + return contentStart < 0 || scope.charAt(contentStart) !== '"' ? -1 : sourceStart + contentStart; + } + return -1; +} + +/** + * Accumulates one GenerativeUI tool call. `apply` returns the newly decoded + * OpenUI text for this provider frame, if any. + */ +export class GenerativeUIArgumentAccumulator { + private raw: string = ''; + private contentStart: number = -1; + private scanned: number = -1; + private done: boolean = false; + private resetNext: boolean = false; + private seq: number = 0; + private content: string = ''; + + apply(chunk: string, snapshot: boolean): LocalGenUISourceChunk | undefined { + if (chunk.length === 0) { + return undefined; + } + const cumulative = this.raw.length > 0 && chunk.startsWith(this.raw); + if (snapshot || cumulative) { + if (chunk.startsWith(this.raw)) { + this.raw = chunk; + } else { + this.replace(chunk); + } + } else { + this.raw += chunk; + } + if (this.contentStart < 0) { + this.contentStart = findOpenUIContentStart(this.raw); + } + if (this.scanned < 0 && this.contentStart >= 0) { + this.scanned = this.contentStart + 1; + } + if (this.done || this.scanned < 0) { + return undefined; + } + const decoded = decodeJsonStringDelta(this.raw, this.scanned); + if (!decoded) { + return undefined; + } + this.scanned = decoded.next; + this.done = decoded.closed; + if (decoded.text.length === 0) { + return undefined; + } + const reset = this.resetNext; + this.resetNext = false; + this.content += decoded.text; + this.seq += 1; + return { text: decoded.text, reset }; + } + + rawArguments(): string { + return this.raw; + } + + source(): string { + return this.content; + } + + private replace(snapshot: string): void { + const resetStream = this.seq > 0; + this.raw = snapshot; + this.contentStart = -1; + this.scanned = -1; + this.done = false; + this.seq = 0; + this.content = ''; + this.resetNext = resetStream; + } +} + +export interface LocalGenUIGeneration { + ok: boolean; + error: string; + title: string; + description: string; + source: string; + valuesJson: string; +} + +/** + * Close-only structural repair, used only after a normal tool-use completion + * (Desktop applies JSON repair at the same boundary). It inserts closers a + * provider omitted before a mismatched closer or at the end; it never + * fabricates keys or values and refuses a dangling `,` or `:`. + */ +export function repairToolArgumentClosers(raw: string): string | undefined { + const stack: string[] = []; + let out = ''; + let inString = false; + let escape = false; + let last = ''; + let changed = false; + for (let i = 0; i < raw.length; i++) { + const ch = raw.charAt(i); + if (inString) { + out += ch; + if (escape) { + escape = false; + } else if (ch === '\\') { + escape = true; + } else if (ch === '"') { + inString = false; + last = '"'; + } + continue; + } + if (ch === '"') { + inString = true; + } else if (ch === '{' || ch === '[') { + stack.push(ch); + } else if (ch === '}' || ch === ']') { + const opener = ch === '}' ? '{' : '['; + if (stack.indexOf(opener) < 0) { + // Observed from DeepSeek: the value is already complete and the + // provider appends stray closers. Drop them only when nothing but + // closers and whitespace follows the closed root value. + if (stack.length === 0 && out.trim().length > 0 && /^[\s\]}]*$/.test(raw.substring(i))) { + return out; + } + return undefined; + } + while (stack.length > 0 && stack[stack.length - 1] !== opener) { + if (last === ',' || last === ':') { + return undefined; + } + out += stack.pop() === '{' ? '}' : ']'; + changed = true; + } + stack.pop(); + } + out += ch; + if (!/\s/.test(ch)) { + last = ch; + } + } + if (inString || last === ',' || last === ':') { + return undefined; + } + while (stack.length > 0) { + out += stack.pop() === '{' ? '}' : ']'; + changed = true; + } + return changed ? out : undefined; +} + +const RESERVED_KEYS: string[] = ['__proto__', 'constructor', 'prototype']; +const SURFACE_FIELDS: string[] = ['title', 'description', 'source']; + +function isPlainObject(value: Object | null | undefined): boolean { + return value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value); +} + +function rejected(error: string): LocalGenUIGeneration { + return { ok: false, error, title: '', description: '', source: '', valuesJson: '{}' }; +} + +/** + * Terminal assembly of a complete GenerativeUI tool call under the local + * schema. Owner-bound identity fields from the provider are rejected. + */ +export function assembleLocalGeneration(raw: string, ownerFields: string[], normalCompletion: boolean = false): LocalGenUIGeneration { + let input: Object; + try { + input = JSON.parse(raw) as Object; + } catch (_err) { + const repaired = normalCompletion ? repairToolArgumentClosers(raw) : undefined; + if (repaired === undefined) { + return rejected(`GenerativeUI arguments are incomplete or invalid JSON (length ${raw.length}, repair ${normalCompletion ? 'not applicable' : 'skipped'})`); + } + try { + input = JSON.parse(repaired) as Object; + } catch (repairErr) { + return rejected(`GenerativeUI arguments are incomplete or invalid JSON after repair (${String(repairErr).slice(0, 120)})`); + } + } + if (!isPlainObject(input)) { + return rejected('GenerativeUI arguments must be an object'); + } + const args = input as Record; + if (typeof args['source'] === 'string' && args['messages'] === undefined && args['protocol'] === undefined) { + return assembleFlatGeneration(args, ownerFields); + } + if (args['protocol'] !== 'openbitfun.genui.v1') { + return rejected('generation.protocol must be openbitfun.genui.v1'); + } + let messagesValue: Object = args['messages']; + if (typeof messagesValue === 'string') { + // Some providers (observed: Qwen) encode the array as a JSON string and + // drop one closer inside it; the same close-only repair applies. + const encoded = messagesValue as string; + try { + messagesValue = JSON.parse(encoded) as Object; + } catch (_err) { + const repaired = normalCompletion ? repairToolArgumentClosers(encoded) : undefined; + if (repaired === undefined) { + return rejected('generation.messages must be an array'); + } + try { + messagesValue = JSON.parse(repaired) as Object; + } catch (_repairErr) { + return rejected('generation.messages must be an array'); + } + } + } + if (!Array.isArray(messagesValue)) { + return rejected('generation.messages must be an array'); + } + const messages = messagesValue as Object[]; + for (let i = 0; i < messages.length; i++) { + const message = messages[i] as Record; + if (!isPlainObject(messages[i])) { + return rejected(`generation.messages[${i}] must be an object`); + } + if (message['updateComponents'] !== undefined || message['updateLogic'] !== undefined) { + return rejected('GenUI graph messages were removed; send a complete source document in createSurface.source'); + } + if (i > 0 && message['createSurface'] !== undefined) { + return rejected('generation.messages: createSurface may occur only once'); + } + } + if (messages.length === 0 || !isPlainObject((messages[0] as Record)['createSurface'])) { + return rejected('generation.messages[0]: createSurface is required and must be first'); + } + const surface = (messages[0] as Record)['createSurface'] as Record; + const keys = Object.keys(surface); + for (let i = 0; i < keys.length; i++) { + if (ownerFields.indexOf(keys[i]) >= 0) { + return rejected(`createSurface.${keys[i]} is owner-bound and is not accepted from the provider`); + } + if (SURFACE_FIELDS.indexOf(keys[i]) < 0) { + return rejected(`createSurface.${keys[i]} is not part of the local schema`); + } + } + const title = surface['title']; + if (typeof title !== 'string' || (title as string).trim().length === 0) { + return rejected('createSurface.title is required'); + } + const description = typeof surface['description'] === 'string' ? surface['description'] as string : ''; + if (!isPlainObject(surface['source'])) { + return rejected('createSurface.source is required'); + } + const source = surface['source'] as Record; + if (source['kind'] !== 'openui-lang') { + return rejected(`unsupported source kind ${String(source['kind'])}; local phase 1 accepts openui-lang only`); + } + const content = source['content']; + if (typeof content !== 'string' || (content as string).trim().length === 0) { + return rejected('createSurface.source.content is required'); + } + const values: Record = {}; + for (let i = 1; i < messages.length; i++) { + const message = messages[i] as Record; + const update = message['updateDataModel']; + if (!isPlainObject(update) || Object.keys(message).length !== 1) { + return rejected(`generation.messages[${i}]: only updateDataModel is supported after createSurface`); + } + const updateFields = update as Record; + const updateKeys = Object.keys(updateFields); + if (updateKeys.length !== 1 || updateKeys[0] !== 'values' || !isPlainObject(updateFields['values'])) { + return rejected(`generation.messages[${i}].updateDataModel accepts only values`); + } + const fields = updateFields['values'] as Record; + const names = Object.keys(fields); + for (let j = 0; j < names.length; j++) { + if (RESERVED_KEYS.indexOf(names[j]) >= 0) { + return rejected(`generation.messages[${i}].updateDataModel: reserved state ID`); + } + values[names[j]] = fields[names[j]]; + } + } + return { ok: true, error: '', title: (title as string).trim(), description, source: content as string, valuesJson: JSON.stringify(values) }; +} + +const FLAT_FIELDS: string[] = ['title', 'description', 'source', 'values']; + +/** The local tool form: `{title, source, description?, values?}`. */ +function assembleFlatGeneration(args: Record, ownerFields: string[]): LocalGenUIGeneration { + const keys = Object.keys(args); + for (let i = 0; i < keys.length; i++) { + if (ownerFields.indexOf(keys[i]) >= 0) { + return rejected(`${keys[i]} is owner-bound and is not accepted from the provider`); + } + if (FLAT_FIELDS.indexOf(keys[i]) < 0) { + return rejected(`${keys[i]} is not part of the local schema`); + } + } + const title = args['title']; + if (typeof title !== 'string' || (title as string).trim().length === 0) { + return rejected('title is required'); + } + const content = args['source'] as string; + if (content.trim().length === 0) { + return rejected('source is required'); + } + const description = typeof args['description'] === 'string' ? args['description'] as string : ''; + const values: Record = {}; + if (args['values'] !== undefined && args['values'] !== null) { + if (!isPlainObject(args['values'])) { + return rejected('values must be an object'); + } + const fields = args['values'] as Record; + const names = Object.keys(fields); + for (let j = 0; j < names.length; j++) { + if (RESERVED_KEYS.indexOf(names[j]) >= 0) { + return rejected('values: reserved state ID'); + } + values[names[j]] = fields[names[j]]; + } + } + return { ok: true, error: '', title: (title as string).trim(), description, source: content, valuesJson: JSON.stringify(values) }; +} + +/** A closed top-level-or-nested string member, used for early titles only. */ +export function extractClosedStringField(raw: string, field: string): string { + const start = findObjectFieldStart(raw, field); + if (start < 0) { + return ''; + } + const value = closedStringAt(raw, start); + return value === undefined ? '' : value; +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIThumbnailStore.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIThumbnailStore.ets new file mode 100644 index 0000000..8b29877 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIThumbnailStore.ets @@ -0,0 +1,88 @@ +import { image } from '@kit.ImageKit'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { RemoteLogger } from '../RemoteLogger'; +import { LocalGenUIIds } from './LocalGenUIModels'; + +/** + * Preview images of generated apps, taken from the real rendered runtime. + * Derived data: losing a thumbnail never affects the app, only its tile. + */ +export class LocalGenUIThumbnailStore { + private readonly directory: string; + + constructor(filesDir: string) { + this.directory = `${filesDir}/local-genui/thumbnails`; + } + + private prefix(appId: string): string { + LocalGenUIIds.require(appId, 'app'); + return `${appId.replace(/[^A-Za-z0-9_-]/g, '_')}-`; + } + + /** Versioned file names keep the image component from showing a cached preview. */ + private files(appId: string): string[] { + try { + if (!fs.accessSync(this.directory)) { + return []; + } + const prefix = this.prefix(appId); + return fs.listFileSync(this.directory).filter((name: string) => name.startsWith(prefix)).sort(); + } catch (_err) { + return []; + } + } + + existing(appId: string): string { + const files = this.files(appId); + return files.length > 0 ? `${this.directory}/${files[files.length - 1]}` : ''; + } + + /** Crops the top square of the rendered page and stores it as JPEG. */ + async save(appId: string, pixelMap: image.PixelMap): Promise { + try { + const info = await pixelMap.getImageInfo(); + const side = Math.min(info.size.width, info.size.height); + if (side <= 0) { + return ''; + } + await pixelMap.crop({ x: 0, y: 0, size: { width: side, height: side } }); + const target = Math.min(side, 480); + if (target < side) { + await pixelMap.scale(target / side, target / side); + } + const packer = image.createImagePacker(); + const data = await packer.packToData(pixelMap, { format: 'image/jpeg', quality: 86 }); + await packer.release(); + if (!fs.accessSync(this.directory)) { + fs.mkdirSync(this.directory, true); + } + const previous = this.files(appId); + const path = `${this.directory}/${this.prefix(appId)}${Date.now()}.jpg`; + const file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + fs.writeSync(file.fd, data); + } finally { + fs.closeSync(file); + } + previous.forEach((name: string) => this.unlink(`${this.directory}/${name}`)); + return path; + } catch (err) { + RemoteLogger.warn(`local genui thumbnail save failed: ${String(err)}`); + return ''; + } finally { + void pixelMap.release(); + } + } + + remove(appId: string): void { + this.files(appId).forEach((name: string) => this.unlink(`${this.directory}/${name}`)); + } + + private unlink(path: string): void { + try { + fs.unlinkSync(path); + } catch (_err) { + // Derived data; a stale file is harmless. + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUITurnNormalizer.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUITurnNormalizer.ets new file mode 100644 index 0000000..44f8d97 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUITurnNormalizer.ets @@ -0,0 +1,159 @@ +import { + LocalGenUIEvent, + LocalGenUIEventType, + LocalGenUIIdentity +} from './LocalGenUIModels'; +import { + assembleLocalGeneration, + extractClosedStringField, + GenerativeUIArgumentAccumulator, + LocalGenUIGeneration +} from './LocalGenUIStreamParser'; +import { LocalProviderFrame, LocalProviderFrameKind } from './LocalProviderSseParser'; + +/** Stable failure code for a provider stop caused by the output budget. */ +export const LOCAL_GENUI_TRUNCATED: string = 'output_truncated'; + +/** The owner binds identity; the provider never supplies it. */ +export interface LocalGenUIIdentityBinder { + bind: (toolCallId: string, title: string) => LocalGenUIIdentity; +} + +interface PendingToolCall { + id: string; + name: string; + accumulator: GenerativeUIArgumentAccumulator; +} + +export interface LocalGenUITurnResult { + events: LocalGenUIEvent[]; + identity?: LocalGenUIIdentity; + generation?: LocalGenUIGeneration; + assistantText: string; + stopReason: string; + warnings: string[]; +} + +/** + * Normalizes provider frames into the Local GenUI event order: + * turn.started, [genui.started], (genui.source.delta | message.delta)*, terminal. + */ +export class LocalGenUITurnNormalizer { + private readonly turnId: string; + private readonly toolName: string; + private readonly binder: LocalGenUIIdentityBinder; + private readonly calls: Map = new Map(); + private boundIndex: number = -1; + private identity?: LocalGenUIIdentity; + private seq: number = 0; + private assistantText: string = ''; + private stopReason: string = ''; + private providerError: string = ''; + private readonly warnings: string[] = []; + + constructor(turnId: string, toolName: string, binder: LocalGenUIIdentityBinder) { + this.turnId = turnId; + this.toolName = toolName; + this.binder = binder; + } + + started(): LocalGenUIEvent { + return { type: LocalGenUIEventType.TurnStarted, turnId: this.turnId }; + } + + accept(frames: LocalProviderFrame[]): LocalGenUIEvent[] { + const events: LocalGenUIEvent[] = []; + frames.forEach((item: LocalProviderFrame) => { + if (item.kind === LocalProviderFrameKind.Text) { + this.assistantText += item.text; + events.push({ type: LocalGenUIEventType.MessageDelta, turnId: this.turnId, text: item.text }); + } else if (item.kind === LocalProviderFrameKind.Tool) { + this.acceptTool(item, events); + } else if (item.kind === LocalProviderFrameKind.Stop) { + this.stopReason = item.stopReason; + } else if (item.kind === LocalProviderFrameKind.Error) { + this.providerError = item.text; + } + }); + return events; + } + + /** Terminal step. Text-only turns complete without a generation. */ + finish(ownerFields: string[]): LocalGenUITurnResult { + const events: LocalGenUIEvent[] = []; + let generation: LocalGenUIGeneration | undefined = undefined; + if (this.providerError.length > 0) { + events.push({ type: LocalGenUIEventType.TurnFailed, turnId: this.turnId, error: this.providerError }); + } else { + const bound = this.boundIndex >= 0 ? this.calls.get(this.boundIndex) : undefined; + if (bound) { + // Repair only after a normal tool-use completion, never after truncation. + const normal = ['tool_calls', 'tool_use', 'stop', 'end_turn'].indexOf(this.stopReason) >= 0; + generation = assembleLocalGeneration(bound.accumulator.rawArguments(), ownerFields, normal); + } + const truncated = this.stopReason === 'length' || this.stopReason === 'max_tokens'; + if (generation && !generation.ok && truncated) { + events.push({ type: LocalGenUIEventType.TurnFailed, turnId: this.turnId, error: LOCAL_GENUI_TRUNCATED }); + } else if (generation && !generation.ok) { + events.push({ type: LocalGenUIEventType.TurnFailed, turnId: this.turnId, error: generation.error }); + } else if (!bound && this.assistantText.trim().length === 0) { + events.push({ type: LocalGenUIEventType.TurnFailed, turnId: this.turnId, error: 'the model returned an empty response' }); + } else { + events.push({ type: LocalGenUIEventType.TurnCompleted, turnId: this.turnId }); + } + } + return { + events, + identity: this.identity, + generation, + assistantText: this.assistantText, + stopReason: this.stopReason, + warnings: this.warnings.slice() + }; + } + + private acceptTool(item: LocalProviderFrame, events: LocalGenUIEvent[]): void { + let call = this.calls.get(item.index); + if (!call || (item.toolCallId.length > 0 && call.id.length > 0 && call.id !== item.toolCallId)) { + call = { id: item.toolCallId, name: item.toolName, accumulator: new GenerativeUIArgumentAccumulator() }; + this.calls.set(item.index, call); + } + if (call.id.length === 0 && item.toolCallId.length > 0) { + call.id = item.toolCallId; + } + if (call.name.length === 0 && item.toolName.length > 0) { + call.name = item.toolName; + } + if (call.name !== this.toolName) { + if (call.name.length > 0 && item.arguments.length === 0) { + this.warnings.push(`ignored unsupported local tool ${call.name}`); + } + return; + } + if (this.boundIndex >= 0 && this.boundIndex !== item.index) { + if (item.arguments.length === 0) { + this.warnings.push('ignored a second GenerativeUI call in the same turn'); + } + return; + } + this.boundIndex = item.index; + const chunk = call.accumulator.apply(item.arguments, false); + if (!chunk) { + return; + } + if (!this.identity) { + const toolCallId = call.id.length > 0 ? call.id : `${this.turnId}:tool`; + this.identity = this.binder.bind(toolCallId, extractClosedStringField(call.accumulator.rawArguments(), 'title')); + events.push({ type: LocalGenUIEventType.GenUIStarted, turnId: this.turnId, identity: this.identity }); + } + if (chunk.reset) { + this.seq = 0; + } + events.push({ + type: LocalGenUIEventType.GenUISourceDelta, + turnId: this.turnId, + delta: { appId: this.identity.appId, seq: this.seq, reset: chunk.reset, text: chunk.text } + }); + this.seq += 1; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGestureClassifier.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGestureClassifier.ets new file mode 100644 index 0000000..7a694f5 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGestureClassifier.ets @@ -0,0 +1,145 @@ +/** + * Turns skeleton keypoints into discrete body gestures. Pure: the camera and + * detector feed it frames, tests feed it fixtures. + * + * Orientation-free: "raised" is measured along the body's own up direction + * (hips -> shoulders, or shoulders -> nose when hips are out of frame), so a + * rotated camera surface does not change the meaning of a gesture. + */ +export interface LocalGestureKeypoint { + /** skeletonDetection.SkeletonPointType value. */ + type: number; + x: number; + y: number; + score: number; +} + +export enum LocalGestureName { + RaiseLeft = 'raise_left_hand', + RaiseRight = 'raise_right_hand', + RaiseBoth = 'raise_both_hands' +} + +const NOSE = 0; +const LEFT_SHOULDER = 5; +const RIGHT_SHOULDER = 6; +const LEFT_WRIST = 9; +const RIGHT_WRIST = 10; +const LEFT_HIP = 11; +const RIGHT_HIP = 12; + +const MIN_SCORE = 0.3; +/** Wrist must be this many shoulder widths above its shoulder. */ +const RAISE_THRESHOLD = 0.35; +/** Below this it counts as lowered again (hysteresis). */ +const LOWER_THRESHOLD = 0.1; +/** Consecutive frames needed to accept a pose change. */ +const STABLE_FRAMES = 2; + +interface Vec { + x: number; + y: number; +} + +export interface LocalGestureFrame { + /** Wrist height above its shoulder, in shoulder widths, along the body's up axis. */ + leftLift: number; + rightLift: number; + /** False when the shoulders are not both visible. */ + tracked: boolean; +} + +const UNTRACKED: LocalGestureFrame = { leftLift: -1, rightLift: -1, tracked: false }; + +export class LocalGestureClassifier { + /** + * `mirrored` swaps the person's sides when the camera surface is a mirror + * image (front camera on some devices); calibrated per host. + */ + private readonly mirrored: boolean; + private pendingLeft: boolean = false; + private pendingRight: boolean = false; + private pendingCount: number = 0; + /** A gesture fires once per raise; lowering both hands re-arms. */ + private armed: boolean = true; + + constructor(mirrored: boolean) { + this.mirrored = mirrored; + } + + /** Per-frame measurement; exported for tests and diagnostics. */ + static measure(points: LocalGestureKeypoint[]): LocalGestureFrame { + const at = (type: number): Vec | undefined => { + const p = points.find((item: LocalGestureKeypoint) => item.type === type && item.score >= MIN_SCORE); + return p ? { x: p.x, y: p.y } : undefined; + }; + const ls = at(LEFT_SHOULDER); + const rs = at(RIGHT_SHOULDER); + if (!ls || !rs) { + return UNTRACKED; + } + const width = Math.hypot(ls.x - rs.x, ls.y - rs.y); + if (width <= 0) { + return UNTRACKED; + } + const shoulders: Vec = { x: (ls.x + rs.x) / 2, y: (ls.y + rs.y) / 2 }; + const lh = at(LEFT_HIP); + const rh = at(RIGHT_HIP); + const nose = at(NOSE); + let up: Vec; + if (lh && rh) { + up = { x: shoulders.x - (lh.x + rh.x) / 2, y: shoulders.y - (lh.y + rh.y) / 2 }; + } else if (nose) { + up = { x: nose.x - shoulders.x, y: nose.y - shoulders.y }; + } else { + return UNTRACKED; + } + const length = Math.hypot(up.x, up.y); + if (length <= 0) { + return UNTRACKED; + } + const unit: Vec = { x: up.x / length, y: up.y / length }; + const lift = (wrist: Vec | undefined, shoulder: Vec): number => + wrist ? ((wrist.x - shoulder.x) * unit.x + (wrist.y - shoulder.y) * unit.y) / width : -1; + return { leftLift: lift(at(LEFT_WRIST), ls), rightLift: lift(at(RIGHT_WRIST), rs), tracked: true }; + } + + /** Feed one frame; returns a gesture when one is completed. */ + accept(points: LocalGestureKeypoint[]): LocalGestureName | undefined { + const frame = LocalGestureClassifier.measure(points); + let leftLift = frame.leftLift; + let rightLift = frame.rightLift; + if (this.mirrored) { + const swap = leftLift; + leftLift = rightLift; + rightLift = swap; + } + if (!frame.tracked || (leftLift < LOWER_THRESHOLD && rightLift < LOWER_THRESHOLD)) { + this.armed = true; + } + const left = leftLift > RAISE_THRESHOLD; + const right = rightLift > RAISE_THRESHOLD; + if (left === this.pendingLeft && right === this.pendingRight) { + this.pendingCount += 1; + } else { + this.pendingLeft = left; + this.pendingRight = right; + this.pendingCount = 1; + } + if (this.pendingCount < STABLE_FRAMES || (!left && !right) || !this.armed) { + return undefined; + } + this.armed = false; + if (left && right) { + return LocalGestureName.RaiseBoth; + } + return left ? LocalGestureName.RaiseLeft : LocalGestureName.RaiseRight; + } + + reset(): void { + this.pendingLeft = false; + this.pendingRight = false; + this.pendingCount = 0; + this.armed = true; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalProviderSseParser.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalProviderSseParser.ets new file mode 100644 index 0000000..0676080 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalProviderSseParser.ets @@ -0,0 +1,209 @@ +/** + * Provider-specific SSE parsing for Local GenUI turns. Produces text deltas + * and raw tool-call argument frames; GenerativeUI semantics live in + * LocalGenUIStreamParser and the owner. + */ + +export enum LocalProviderProtocol { + Anthropic = 'anthropic', + OpenAi = 'openai' +} + +export enum LocalProviderFrameKind { + Text = 'text', + Tool = 'tool', + Stop = 'stop', + Error = 'error' +} + +export interface LocalProviderFrame { + kind: LocalProviderFrameKind; + text: string; + /** Provider stream index of the tool call. */ + index: number; + toolCallId: string; + toolName: string; + arguments: string; + stopReason: string; +} + +interface OpenAiFunctionDelta { + name?: string; + arguments?: string; +} + +interface OpenAiToolCallDelta { + index?: number; + id?: string; + function?: OpenAiFunctionDelta; +} + +interface OpenAiDelta { + content?: string | null; + tool_calls?: OpenAiToolCallDelta[]; +} + +interface OpenAiChoice { + delta?: OpenAiDelta; + finish_reason?: string | null; +} + +interface OpenAiError { + message?: string; +} + +interface OpenAiEvent { + choices?: OpenAiChoice[]; + error?: OpenAiError; +} + +interface AnthropicContentBlock { + type?: string; + id?: string; + name?: string; +} + +interface AnthropicDelta { + type?: string; + text?: string; + partial_json?: string; + stop_reason?: string; +} + +interface AnthropicError { + message?: string; +} + +interface AnthropicEvent { + type?: string; + index?: number; + content_block?: AnthropicContentBlock; + delta?: AnthropicDelta; + error?: AnthropicError; +} + +function frame(kind: LocalProviderFrameKind): LocalProviderFrame { + return { kind, text: '', index: -1, toolCallId: '', toolName: '', arguments: '', stopReason: '' }; +} + +export class LocalProviderSseParser { + private readonly protocol: LocalProviderProtocol; + private buffer: string = ''; + + constructor(protocol: LocalProviderProtocol) { + this.protocol = protocol; + } + + feed(chunk: string): LocalProviderFrame[] { + const frames: LocalProviderFrame[] = []; + if (chunk.length === 0) { + return frames; + } + this.buffer = (this.buffer + chunk).replace(/\r\n/g, '\n'); + let separator = this.buffer.indexOf('\n\n'); + while (separator >= 0) { + const event = this.buffer.slice(0, separator); + this.buffer = this.buffer.slice(separator + 2); + this.parseEvent(event, frames); + separator = this.buffer.indexOf('\n\n'); + } + return frames; + } + + finish(): LocalProviderFrame[] { + const frames: LocalProviderFrame[] = []; + const remaining = this.buffer.trim(); + this.buffer = ''; + if (remaining.length > 0) { + this.parseEvent(remaining, frames); + } + return frames; + } + + private parseEvent(text: string, frames: LocalProviderFrame[]): void { + let data = ''; + text.split('\n').forEach((line: string) => { + if (line.startsWith('data:')) { + const value = line.slice(5).trimStart(); + data += data.length > 0 ? `\n${value}` : value; + } + }); + if (data.length === 0 || data === '[DONE]') { + return; + } + try { + if (this.protocol === LocalProviderProtocol.OpenAi) { + this.parseOpenAi(JSON.parse(data) as OpenAiEvent, frames); + } else { + this.parseAnthropic(JSON.parse(data) as AnthropicEvent, frames); + } + } catch (_err) { + // Keepalive comments and partial provider metadata are not frames. + } + } + + private parseOpenAi(event: OpenAiEvent, frames: LocalProviderFrame[]): void { + if (event.error) { + const error = frame(LocalProviderFrameKind.Error); + error.text = event.error.message || 'provider error'; + frames.push(error); + return; + } + (event.choices || []).forEach((choice: OpenAiChoice) => { + const delta = choice.delta; + if (delta && typeof delta.content === 'string' && delta.content.length > 0) { + const text = frame(LocalProviderFrameKind.Text); + text.text = delta.content; + frames.push(text); + } + (delta && delta.tool_calls ? delta.tool_calls : []).forEach((call: OpenAiToolCallDelta) => { + const tool = frame(LocalProviderFrameKind.Tool); + tool.index = typeof call.index === 'number' ? call.index : 0; + tool.toolCallId = call.id || ''; + tool.toolName = call.function && call.function.name ? call.function.name : ''; + tool.arguments = call.function && call.function.arguments ? call.function.arguments : ''; + frames.push(tool); + }); + if (choice.finish_reason) { + const stop = frame(LocalProviderFrameKind.Stop); + stop.stopReason = choice.finish_reason; + frames.push(stop); + } + }); + } + + private parseAnthropic(event: AnthropicEvent, frames: LocalProviderFrame[]): void { + if (event.type === 'error') { + const error = frame(LocalProviderFrameKind.Error); + error.text = event.error && event.error.message ? event.error.message : 'provider error'; + frames.push(error); + return; + } + if (event.type === 'content_block_start' && event.content_block && event.content_block.type === 'tool_use') { + const tool = frame(LocalProviderFrameKind.Tool); + tool.index = event.index || 0; + tool.toolCallId = event.content_block.id || ''; + tool.toolName = event.content_block.name || ''; + frames.push(tool); + return; + } + if (event.type === 'content_block_delta' && event.delta) { + if (event.delta.type === 'text_delta' && event.delta.text) { + const text = frame(LocalProviderFrameKind.Text); + text.text = event.delta.text; + frames.push(text); + } else if (event.delta.type === 'input_json_delta' && typeof event.delta.partial_json === 'string') { + const tool = frame(LocalProviderFrameKind.Tool); + tool.index = event.index || 0; + tool.arguments = event.delta.partial_json; + frames.push(tool); + } + return; + } + if (event.type === 'message_delta' && event.delta && event.delta.stop_reason) { + const stop = frame(LocalProviderFrameKind.Stop); + stop.stopReason = event.delta.stop_reason; + frames.push(stop); + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/module.json5 b/src/apps/mobile/harmonyos/entry/src/main/module.json5 index 6e5460c..74cec4c 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/module.json5 +++ b/src/apps/mobile/harmonyos/entry/src/main/module.json5 @@ -40,6 +40,19 @@ "when": "inuse" } }, + { + "name": "ohos.permission.CAMERA", + "reason": "$string:permission_camera_reason", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.VIBRATE" + }, { "name": "ohos.permission.MICROPHONE", "reason": "$string:permission_microphone_reason", @@ -49,6 +62,26 @@ ], "when": "inuse" } + }, + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "$string:permission_calendar_reason", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.WRITE_CALENDAR", + "reason": "$string:permission_calendar_reason", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } } ], "pages": "$profile:main_pages", @@ -103,6 +136,22 @@ "resource": "$profile:backup_config" } ], + }, + { + // Home-screen cards of generated mini apps (Local GenUI). The card is an + // entry that opens the app in EntryAbility; it never runs the app. + "name": "LocalGenUIFormAbility", + "srcEntry": "./ets/genuiform/LocalGenUIFormAbility.ets", + "label": "$string:genui_card_name", + "description": "$string:genui_card_desc", + "type": "form", + "exported": true, + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:local_genui_form_config" + } + ] } ] } diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json index dd0bf44..963a9ac 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json @@ -93,16 +93,168 @@ "value": "Show app cards" }, { - "name": "sidebar_bot", - "value": "Bot" - }, - { - "name": "sidebar_botComingSoon", - "value": "In development. Stay tuned." + "name": "localGenui_entry", + "value": "Create mini apps" }, { "name": "sidebar_workspaceActionsHint", "value": "Long press to create a session in this workspace" + }, + { + "name": "permission_camera_reason", + "value": "Used by local mini apps that respond to body gestures; frames are analyzed on the device and never uploaded." + }, + { + "name": "permission_calendar_reason", + "value": "Used by local AI mini apps to create and manage OpenBitFun calendar events." + }, + { + "name": "genui_card_name", + "value": "AI mini app" + }, + { + "name": "genui_card_desc", + "value": "Opens a mini app generated on this phone" + }, + { + "name": "genui_card_pending", + "value": "Open OpenBitFun" + }, + { + "name": "genui_card_missing", + "value": "This mini app was deleted" + }, + { + "name": "collaboration_title", + "value": "跨设备取材验证" + }, + { + "name": "collaboration_requirements", + "value": "两端需登录同一华为账号并开启 WLAN 和蓝牙。由系统选择设备,每次接收一张图片。" + }, + { + "name": "collaboration_emulatorNotice", + "value": "模拟器用于验证构建和界面。系统能力声明不代表已发现设备;真实取材与回传需在支持的设备上验证。" + }, + { + "name": "collaboration_photo", + "value": "从其他设备拍照" + }, + { + "name": "collaboration_scan", + "value": "从其他设备扫描文档" + }, + { + "name": "collaboration_gallery", + "value": "选择其他设备的图片" + }, + { + "name": "collaboration_reset", + "value": "重新开始验证" + }, + { + "name": "collaboration_resize", + "value": "切换内容宽度" + }, + { + "name": "collaboration_resetNotice", + "value": "重新开始会关闭本地接收并清除预览,不代表已取消对端操作。此验证入口不保存图片,也不向模型发送图片。" + }, + { + "name": "collaboration_result", + "value": "已接收 {0} 张图片 · 系统状态码 {1}" + }, + { + "name": "collaboration_receivedImage", + "value": "跨设备接收的图片" + }, + { + "name": "collaboration_phase_ready", + "value": "等待选择取材方式" + }, + { + "name": "collaboration_phase_selecting", + "value": "等待在系统菜单选择设备" + }, + { + "name": "collaboration_phase_active", + "value": "协同已建立,等待对端操作" + }, + { + "name": "collaboration_phase_receiving", + "value": "正在接收和解析图片" + }, + { + "name": "collaboration_phase_completed", + "value": "图片接收完成" + }, + { + "name": "collaboration_phase_cancelled", + "value": "操作已取消" + }, + { + "name": "collaboration_phase_failed", + "value": "取材失败" + }, + { + "name": "collaboration_phase_closed", + "value": "本地接收已关闭" + }, + { + "name": "collaboration_phase_unavailable", + "value": "当前环境不可用" + }, + { + "name": "collaboration_reason_missingSyscap", + "value": "系统未声明跨设备取材能力。" + }, + { + "name": "collaboration_reason_version", + "value": "此取材适配需要 API 23 或更高版本,当前系统不支持。" + }, + { + "name": "collaboration_reason_deviceType", + "value": "当前设备类型不支持发起此操作。" + }, + { + "name": "collaboration_reason_probeFailed", + "value": "读取系统能力失败,请重新开始验证。" + }, + { + "name": "collaboration_reason_peerCancelled", + "value": "对端取消了操作。" + }, + { + "name": "collaboration_reason_localCancelled", + "value": "本端取消了操作。" + }, + { + "name": "collaboration_reason_invalidImage", + "value": "系统未返回有效的图片数据。" + }, + { + "name": "collaboration_reason_imageLimit", + "value": "超出本次验证的图片限制:一张图片,最大 32 MiB。" + }, + { + "name": "collaboration_reason_decodeFailed", + "value": "收到数据但无法解码为图片。" + }, + { + "name": "collaboration_reason_emptyResult", + "value": "传输结束,但未收到图片。" + }, + { + "name": "collaboration_reason_platformError", + "value": "系统协同返回错误,请查看状态码。" + }, + { + "name": "collaboration_inputTitle", + "value": "从其他设备取材" + }, + { + "name": "collaboration_closeInput", + "value": "结束本次接收" } ] } diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/base/profile/local_genui_form_config.json b/src/apps/mobile/harmonyos/entry/src/main/resources/base/profile/local_genui_form_config.json new file mode 100644 index 0000000..4fefb5a --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/base/profile/local_genui_form_config.json @@ -0,0 +1,23 @@ +{ + "forms": [ + { + "name": "local_genui_app", + "displayName": "$string:genui_card_name", + "description": "$string:genui_card_desc", + "src": "./ets/genuiform/pages/LocalGenUIAppCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDynamic": true, + "isDefault": true, + "updateEnabled": false, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json index 0047854..f295483 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json @@ -3225,16 +3225,376 @@ "value": "Show app cards" }, { - "name": "sidebar_bot", - "value": "Bot" + "name": "sidebar_workspaceActionsHint", + "value": "Long press to create a session in this workspace" }, { - "name": "sidebar_botComingSoon", - "value": "In development. Stay tuned." + "name": "permission_camera_reason", + "value": "Used by local mini apps that respond to body gestures; frames are analyzed on the device and never uploaded." }, { - "name": "sidebar_workspaceActionsHint", - "value": "Long press to create a session in this workspace" + "name": "permission_calendar_reason", + "value": "Used by local AI mini apps to create and manage OpenBitFun calendar events." + }, + { + "name": "localGenui_cameraOn", + "value": "Camera on" + }, + { + "name": "localGenui_networkUnavailable", + "value": "Can't reach the model service. Check the network or the model URL." + }, + { + "name": "localGenui_localBadge", + "value": "Runs on this phone" + }, + { + "name": "localGenui_newSession", + "value": "Start creating" + }, + { + "name": "localGenui_backToChat", + "value": "Conversation" + }, + { + "name": "localGenui_generating", + "value": "Generating…" + }, + { + "name": "localGenui_cancelled", + "value": "The turn was stopped." + }, + { + "name": "localGenui_modelNotConfigured", + "value": "Set up a model service for local mini apps first." + }, + { + "name": "localGenui_unsupportedAction", + "value": "%1$s is not available here: %2$s" + }, + { + "name": "localGenui_appMissing", + "value": "This app is no longer available." + }, + { + "name": "localGenui_appUnsupported", + "value": "This app was made with another version and cannot open yet. Its content is kept." + }, + { + "name": "localGenui_runtimeMismatch", + "value": "App components need an update. Update OpenBitFun and try again." + }, + { + "name": "localGenui_saveFailed", + "value": "The change was not saved: %1$s" + }, + { + "name": "localGenui_failed", + "value": "Could not create the app: %1$s" + }, + { + "name": "localGenui_status_candidate", + "value": "Getting ready" + }, + { + "name": "localGenui_status_displayable", + "value": "Ready to use" + }, + { + "name": "localGenui_status_accepted", + "value": "Ready to use" + }, + { + "name": "localGenui_status_failed", + "value": "Could not be created" + }, + { + "name": "localGenui_status_state_migration_required", + "value": "The new version does not fit your saved data, so the previous version is kept" + }, + { + "name": "localGenui_status_unsupported", + "value": "This version cannot open the app" + }, + { + "name": "localGenui_apiKey", + "value": "API key" + }, + { + "name": "localGenui_apiKeyKept", + "value": "Leave empty to keep the saved key" + }, + { + "name": "localGenui_saved", + "value": "Saved" + }, + { + "name": "localGenui_autoRepair", + "value": "The last app had a problem; fixing it automatically" + }, + { + "name": "localGenui_truncated", + "value": "The reply was too long to finish. Send it again, or ask for something simpler." + }, + { + "name": "localGenui_history", + "value": "Creation history" + }, + { + "name": "localGenui_noHistory", + "value": "No creation sessions yet" + }, + { + "name": "localGenui_generatedApps", + "value": "AI-generated mini app" + }, + { + "name": "localGenui_modelMissing", + "value": "This conversation's model was deleted. Choose another model." + }, + { + "name": "localGenui_manageModels", + "value": "Manage models" + }, + { + "name": "localGenui_addModel", + "value": "Add model" + }, + { + "name": "localGenui_editModel", + "value": "Edit model" + }, + { + "name": "localGenui_deleteModel", + "value": "Delete model" + }, + { + "name": "localGenui_noModels", + "value": "No models yet. Add one to start." + }, + { + "name": "localGenui_modelDisplayName", + "value": "Display name" + }, + { + "name": "localGenui_modelDisplayNameHint", + "value": "Optional, defaults to the model name" + }, + { + "name": "localGenui_fetchModels", + "value": "Fetch models" + }, + { + "name": "localGenui_noRemoteModels", + "value": "The service returned no models. Enter the model name manually." + }, + { + "name": "localGenui_addToGallery", + "value": "Add to MiniApps" + }, + { + "name": "localGenui_inGallery", + "value": "In MiniApps" + }, + { + "name": "localGenui_removeFromGallery", + "value": "Remove from MiniApps" + }, + { + "name": "localGenui_addedToGallery", + "value": "Added to MiniApps" + }, + { + "name": "localGenui_entry", + "value": "Create mini apps" + }, + { + "name": "localGenui_linkUnsupported", + "value": "This link cannot be opened in a local conversation." + }, + { + "name": "localGenui_generationInvalid", + "value": "The app could not be made this time. Try again or rephrase it." + }, + { + "name": "genui_card_name", + "value": "AI mini app" + }, + { + "name": "genui_card_desc", + "value": "Opens a mini app generated on this phone" + }, + { + "name": "genui_card_pending", + "value": "Open OpenBitFun" + }, + { + "name": "genui_card_missing", + "value": "This mini app was deleted" + }, + { + "name": "localGenui_addToDesktop", + "value": "Add to desktop" + }, + { + "name": "localGenui_addedToDesktop", + "value": "Added to desktop" + }, + { + "name": "localGenui_addToDesktopFailed", + "value": "Could not add to desktop" + }, + { + "name": "localGenui_appActions", + "value": "Mini app actions" + }, + { + "name": "localGenui_calendarCreated", + "value": "Calendar event added (ID %1$s)" + }, + { + "name": "localGenui_calendarUpdated", + "value": "Calendar event updated (ID %1$s)" + }, + { + "name": "localGenui_calendarDeleted", + "value": "Calendar event deleted (ID %1$s)" + }, + { + "name": "localGenui_calendarListed", + "value": "%1$s calendar events found" + }, + { + "name": "collaboration_title", + "value": "Cross-device media probe" + }, + { + "name": "collaboration_requirements", + "value": "Sign in with the same HUAWEI ID and enable Wi-Fi and Bluetooth on both devices. Choose a device in the system menu; receive one image per request." + }, + { + "name": "collaboration_emulatorNotice", + "value": "Use the emulator to verify the build and UI. A system capability declaration does not prove device discovery; real transfers require supported devices." + }, + { + "name": "collaboration_photo", + "value": "Take photo on another device" + }, + { + "name": "collaboration_scan", + "value": "Scan on another device" + }, + { + "name": "collaboration_gallery", + "value": "Choose image on another device" + }, + { + "name": "collaboration_reset", + "value": "Restart probe" + }, + { + "name": "collaboration_resize", + "value": "Toggle content width" + }, + { + "name": "collaboration_resetNotice", + "value": "Restart closes the local receiver and clears the preview; it does not confirm remote cancellation. This probe does not save images or send them to a model." + }, + { + "name": "collaboration_result", + "value": "Received {0} images · System status {1}" + }, + { + "name": "collaboration_receivedImage", + "value": "Image received from another device" + }, + { + "name": "collaboration_phase_ready", + "value": "Choose a media source" + }, + { + "name": "collaboration_phase_selecting", + "value": "Choose a device in the system menu" + }, + { + "name": "collaboration_phase_active", + "value": "Connected; waiting for the other device" + }, + { + "name": "collaboration_phase_receiving", + "value": "Receiving and decoding image" + }, + { + "name": "collaboration_phase_completed", + "value": "Image transfer complete" + }, + { + "name": "collaboration_phase_cancelled", + "value": "Operation cancelled" + }, + { + "name": "collaboration_phase_failed", + "value": "Media request failed" + }, + { + "name": "collaboration_phase_closed", + "value": "Local receiver closed" + }, + { + "name": "collaboration_phase_unavailable", + "value": "Unavailable in this environment" + }, + { + "name": "collaboration_reason_missingSyscap", + "value": "The system does not declare device interconnectivity support." + }, + { + "name": "collaboration_reason_version", + "value": "This media adapter requires API 23 or later; the current OS is unsupported." + }, + { + "name": "collaboration_reason_deviceType", + "value": "This device type cannot initiate this operation." + }, + { + "name": "collaboration_reason_probeFailed", + "value": "Cannot read system capabilities. Restart the probe." + }, + { + "name": "collaboration_reason_peerCancelled", + "value": "The other device cancelled the operation." + }, + { + "name": "collaboration_reason_localCancelled", + "value": "The operation was cancelled locally." + }, + { + "name": "collaboration_reason_invalidImage", + "value": "The system did not return valid image data." + }, + { + "name": "collaboration_reason_imageLimit", + "value": "Probe image limit exceeded: one image, up to 32 MiB." + }, + { + "name": "collaboration_reason_decodeFailed", + "value": "Data was received but could not be decoded as an image." + }, + { + "name": "collaboration_reason_emptyResult", + "value": "The transfer ended without an image." + }, + { + "name": "collaboration_reason_platformError", + "value": "The system collaboration service reported an error. See the status code." + }, + { + "name": "collaboration_inputTitle", + "value": "Get an image from another device" + }, + { + "name": "collaboration_closeInput", + "value": "Close this request" } ] } diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json new file mode 100644 index 0000000..39f8fc9 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json @@ -0,0 +1,173 @@ +{ + "contractVersion": 4, + "profile": "harmony", + "template": { + "id": "openbitfun.harmony.app", + "library": "openbitfun.harmony.v1", + "description": "Explicit Harmony delivery component application; root is Page (Col remains readable).", + "roots": [ + "Page", + "Col" + ] + }, + "library": { + "id": "openbitfun.harmony.v1", + "revision": 4, + "adapterKind": "harmony-genui", + "rootComponent": "Page", + "components": [ + "Badge", + "Box", + "Button", + "Caption", + "Card", + "Carousel", + "Catalog", + "Celebration", + "Chart", + "Checkbox", + "Checklist", + "Circle", + "Code", + "Col", + "CompareTable", + "Cover", + "CrossDeviceImage", + "DatePicker", + "Divider", + "Ellipse", + "EmptyState", + "Faq", + "Field", + "Flashcard", + "Form", + "FormCard", + "G", + "GestureTrigger", + "Grid", + "HeroStat", + "HtmlView", + "Icon", + "Icon3D", + "IconButton", + "Image", + "Input", + "ItemList", + "Label", + "Layout", + "Line", + "Link", + "List", + "ListItem", + "Map", + "MapMarker", + "Markdown", + "Math", + "Metric", + "Note", + "Page", + "Path", + "Plan", + "Plot", + "Polygon", + "Polyline", + "Popover", + "Pressable", + "ProCon", + "Progress", + "Prose", + "Quote", + "RadioGroup", + "RecordList", + "Rect", + "Row", + "Scoreboard", + "SearchImage", + "Section", + "Segmented", + "SegmentedControl", + "Select", + "Slider", + "Spacer", + "StatGrid", + "Steps", + "Svg", + "SvgText", + "TabPanel", + "Table", + "Tabs", + "Text", + "TextArea", + "Timeline", + "Timer", + "Title", + "TrendChart", + "YouTube" + ] + }, + "designSpec": { + "id": "harmony.phone.v1", + "revision": 1, + "label": "Harmony phone", + "componentLibraries": [ + "openbitfun.harmony.v1", + "openbitfun.harmony.readonly.v1" + ], + "sourceKinds": [ + "openui-lang", + "html-document" + ], + "styleResources": [ + "openbitfun-theme-tokens", + "openbitfun-harmony-components" + ], + "rules": [ + "Compose for a phone screen; the desktop preview shows it in a 360 CSS-pixel phone frame.", + "On a device the page fills the screen: narrow screens stack the page blocks; wide screens (unfolded or landscape) keep one full-width column across the fold with a header-row cover, and only Layout or a block sets peers side by side; never author widths or columns.", + "The host draws the phone shell, status bar and page gutter; generate screen content only.", + "Build the page from the Harmony page blocks (Page, Cover, Section and the blocks they hold) and their host-owned styles.", + "Choose the Page theme from the topic; HarmonyOS Symbol icons and Icon3D pictures follow the library schema." + ], + "viewport": { + "mode": "fixed", + "width": 360, + "height": 764, + "unit": "css-px" + }, + "shell": { + "kind": "phone", + "statusBarHeight": 36, + "hostOwnedParts": [ + "device-frame", + "status-bar", + "screen-viewport" + ], + "forbiddenContentSelectors": [ + "[data-gen-ui-host-part]", + ".gen-ui-phone-device", + ".gen-ui-phone-status-bar" + ], + "contentInsets": { + "top": 16, + "right": 16, + "bottom": 16, + "left": 16 + } + }, + "acceptance": { + "checks": [ + "actual-render", + "declared-interactions", + "save-reopen", + "fixed-viewport", + "host-shell", + "host-shell-duplication", + "content-boundary", + "no-horizontal-overflow" + ] + } + }, + "sourceKinds": [ + "openui-lang" + ] +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt new file mode 100644 index 0000000..5f7a158 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt @@ -0,0 +1,413 @@ +You are the Local GenUI assistant in the OpenBitFun HarmonyOS phone app. +You run without a workspace, shell, files, browsing or external tools. Never claim to use them. +When an interactive mini app helps the user, call the GenerativeUI tool exactly once with an OpenUI Lang program; otherwise answer in plain text. +Keep any surrounding text short. Answer in the user's language. +This phone provides local component state, new chat turns, the declared native calendar actions, gesture input, haptics and page orientation. Use the capability guidance below. Calendar controls are a default part of time-based planning apps; system writes run only when the user clicks them. Generic network queries, maps and video are unsupported; prefer inline data and the declared host-served picture components. + +You are an AI assistant that responds using openui-lang, a declarative UI language. Your ENTIRE response must be valid openui-lang code — no markdown, no explanations, just openui-lang. + +## Syntax Rules + +1. Each statement is on its own line: `identifier = Expression` +2. `root` is the entry point — every program must define `root = Page(...)` +3. Expressions are: strings ("..."), numbers, booleans (true/false), null, arrays ([...]), objects ({...}), or component calls TypeName(arg1, arg2, ...) +4. Use references for readability: define `name = ...` on one line, then use `name` later +5. EVERY variable (except root) MUST be referenced by at least one other variable. Unreferenced variables are silently dropped and will NOT render. Always include defined variables in their parent's children/items array. +6. Arguments are POSITIONAL (order matters, not names). Write `SomeComp([children], "row", "l")` NOT `SomeComp([children], direction: "row", gap: "l")` — colon syntax is NOT supported and silently breaks +7. Optional arguments can be omitted from the end +8. Declare mutable state with `$varName = defaultValue`. Components marked with `$binding` can read/write these. Undeclared $variables are auto-created with null default. +9. String concatenation: `"text" + $var + "more"` +10. Dot member access: `query.field` reads a field; on arrays it extracts that field from every element +11. Index access: `arr[0]`, `data[index]` +12. Arithmetic operators: +, -, *, /, % (work on numbers; + is string concat when either side is a string) +13. Comparison: ==, !=, >, <, >=, <= +14. Logical: &&, ||, ! (prefix) +15. Ternary: `condition ? valueIfTrue : valueIfFalse` +16. Parentheses for grouping: `(a + b) * c` +- Strings use double quotes with backslash escaping + +## Component Signatures + +Arguments marked with ? are optional. Sub-components can be inline or referenced; prefer references for better streaming. +Props typed `ActionExpression` accept one @step, or Action([@steps...]) for several. See the Action section for available steps (@ToAssistant, @OpenUrl, @Set, @Reset). +Props marked `$binding` accept a `$variable` reference for two-way binding. + +Col(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], gap?: number, align?: "start" | "center" | "end" | "stretch") — Vertical layout. Without gap it spaces blocks like an article. +Row(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger[], gap?: number, align?: "start" | "center" | "end" | "stretch", justify?: "start" | "center" | "end" | "between", wrap?: boolean) — Horizontal layout; items are vertically centered. +Box(children?: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[], direction?: "row" | "col", gap?: number, padding?: number, background?: string, radius?: string | number, border?: boolean, width?: number | string, height?: number | string, flex?: number, align?: "start" | "center" | "end" | "stretch", justify?: "start" | "center" | "end" | "between", wrap?: boolean) — Flex container, a column by default. radius also clips the content. +Grid(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog[], columns?: number, minChildWidth?: number, gap?: number) — Equal columns (default 2). With minChildWidth (px), columns drop on narrow screens. +Card(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], variant?: "outline" | "soft", padding?: number, gap?: number) — Panel with a border; soft is a filled panel for summaries. +Carousel(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[], itemWidth?: number, gap?: number) — Horizontal row that scrolls and snaps, each child an item itemWidth px wide (default 240): photos, cards, options, days. +Popover(trigger: string | any[], content: string | any[]) — Shows content in a small panel when the trigger is clicked: a definition, a source, details behind an Icon("info", "sm"). +Divider() +Spacer() — Fills the free space in a Row. +Title(text: string, size?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl", color?: string) — Heading; md for a card title, lg for a section, 2xl for a big number. +Text(text: string | any[], size?: "xs" | "sm" | "md" | "lg", color?: string, weight?: "normal" | "medium" | "semibold", italic?: boolean, lineThrough?: boolean, tabularNums?: boolean, maxLines?: number) — Paragraph; supports **bold**, *italic*, `code` and [links](https://…). text may be a list mixing strings and inline components. +Caption(text: string, color?: string) — Small secondary text. +Label(text: string) — Field or group label. +Badge(text: string, color?: "neutral" | "info" | "success" | "warning" | "danger" | "purple" | "pink", icon?: string) — Pill tag; icon is an optional leading lucide name. +Link(text: string, url: string) — Opens an http(s) URL in a new tab. +List(items: string | any[], marker?: "bullet" | "number" | "none", timeline?: boolean) — List items; marker can be bullet, number or none, and timeline joins markers with a line. +ListItem(title: string, description?: string, marker?: string, children?: string | any[]) — Marker replaces the bullet or number, e.g. a time or an emoji. +Markdown(text: string) — Prose with headings, lists, quotes, code and tables. +Quote(text: string, cite?: string) — A quotation or a callout with a side rule; cite names the source. +Code(code: string, language?: string) — Code block with a copy button. +Math(tex: string, inline?: boolean) — LaTeX formula, e.g. Math("E = mc^2"); inline true to sit in a Text list. +Button(label: string, action?: ActionExpression, variant?: "solid" | "outline" | "soft" | "ghost", color?: "primary" | "danger" | "success", size?: "sm" | "md" | "lg", icon?: "house" | "gearshape" | "magnifyingglass" | "checkmark" | "checkmark_circle" | "calendar" | "clock" | "person" | "location_up" | "doc_text" | "list_bullet" | "arrow_clockwise" | "plus" | "minus" | "xmark" | "info_circle" | "bell" | "photo" | "play" | "pause" | "wifi" | "map" | "thermometer" | "wind" | "sun_max" | "cloud_sun_fill" | "light_rain" | "leaf" | "flame" | "heart" | "star" | "cart" | "gift" | "car" | "fork_knife" | "cup" | "bag" | "keyboard" | "chevron_right" | "chevron_left" | "ellipsis_circle" | "line_3_horizontal" | "slider_horizontal_2" | "trash" | "share" | "download" | "envelope" | "message" | "camera" | "battery" | "moon" | "cloud" | "snowflake" | "bicycle", disabled?: boolean, block?: boolean) — Harmony capsule button. If an icon is useful, icon must be one of the listed HarmonyOS Symbol names; use Icon3D for concrete objects such as clothing. +IconButton(icon: "house" | "gearshape" | "magnifyingglass" | "checkmark" | "checkmark_circle" | "calendar" | "clock" | "person" | "location_up" | "doc_text" | "list_bullet" | "arrow_clockwise" | "plus" | "minus" | "xmark" | "info_circle" | "bell" | "photo" | "play" | "pause" | "wifi" | "map" | "thermometer" | "wind" | "sun_max" | "cloud_sun_fill" | "light_rain" | "leaf" | "flame" | "heart" | "star" | "cart" | "gift" | "car" | "fork_knife" | "cup" | "bag" | "keyboard" | "chevron_right" | "chevron_left" | "ellipsis_circle" | "line_3_horizontal" | "slider_horizontal_2" | "trash" | "share" | "download" | "envelope" | "message" | "camera" | "battery" | "moon" | "cloud" | "snowflake" | "bicycle", action?: ActionExpression, label?: string, variant?: "outline" | "ghost" | "solid") — Round Harmony icon-only button. icon must be one of the listed HarmonyOS Symbol names and label is read aloud. +Pressable(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[], action?: ActionExpression, selected?: boolean, padding?: number, background?: string, radius?: string | number) — Makes any content clickable, such as a tile or a swatch. +Input(value: string | number, label?: string, type?: "text" | "number", placeholder?: string) — Text or number field; a number field stores numbers. +TextArea(value: string, label?: string, placeholder?: string, rows?: number) — Multiline text field. +Select(value: string, options: string | {value: string, label: string, description?: string}[], label?: string, placeholder?: string) — Dropdown for long option lists. +SegmentedControl(value: string, options: string | {value: string, label: string, description?: string}[], block?: boolean) — Two to four short choices in a row. +Slider(value: number, min: number, max: number, step?: number, label?: string, unit?: string, marks?: {value: number, label: string}[]) — Shows a bound value; unit like % or $ formats the value. +Checkbox(checked: boolean, label: string, lineThrough?: boolean) — lineThrough strikes the label when checked, for to-do lists. +RadioGroup(value: string, options: string | {value: string, label: string, description?: string}[], label?: string, variant?: "list" | "pills" | "cards") — Pills for short choices; cards for choices that need a description line. +DatePicker(value: string, label?: string, min?: string, max?: string) — Dates are YYYY-MM-DD. +Timer(seconds: number, label?: string) — Countdown with start, pause and reset. It counts the bound seconds down to 0. +Form(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[]) — Groups fields; their values go with any @ToAssistant inside. +SearchImage(query: string, aspectRatio?: number, radius?: string | number, fit?: "cover" | "contain") — A real photo the app finds for an exact subject query. +Image(src: string, alt: string, aspectRatio?: number, radius?: string | number, fit?: "cover" | "contain") — Photo from a URL the user or a tool gave; if it fails, the host may search for alt. +Icon(name: "house" | "gearshape" | "magnifyingglass" | "checkmark" | "checkmark_circle" | "calendar" | "clock" | "person" | "location_up" | "doc_text" | "list_bullet" | "arrow_clockwise" | "plus" | "minus" | "xmark" | "info_circle" | "bell" | "photo" | "play" | "pause" | "wifi" | "map" | "thermometer" | "wind" | "sun_max" | "cloud_sun_fill" | "light_rain" | "leaf" | "flame" | "heart" | "star" | "cart" | "gift" | "car" | "fork_knife" | "cup" | "bag" | "keyboard" | "chevron_right" | "chevron_left" | "ellipsis_circle" | "line_3_horizontal" | "slider_horizontal_2" | "trash" | "share" | "download" | "envelope" | "message" | "camera" | "battery" | "moon" | "cloud" | "snowflake" | "bicycle", size?: "sm" | "md" | "lg" | "xl", color?: string) — HarmonyOS Symbol icon. name must be one of the listed names; this is not a Lucide icon API. Use Icon3D for concrete objects such as clothing. +Table(columns: string[], rows: any[][]) — Each row lists its cells in column order; a cell may be a component. Number columns align right. +Chart(type: "bar" | "line" | "area" | "pie" | "donut" | "scatter", data: object[], x?: string, series?: string[], format?: "number" | "currency" | "percent", currency?: string, stacked?: boolean, height?: number) — Rows of data; x is the category key, series the value keys. Supports bar, line, area, pie, donut and scatter. +Map(markers?: any[], route?: boolean, selected?: string, height?: number, query?: string) — Street map fitted to its markers; route draws the path and selected holds the clicked marker label. +MapMarker(label: string, lat: number, lng: number, category?: string, icon?: string) — A place on a Map; icon is one emoji, else the pin shows its number. +YouTube(video: string, title?: string) — Embedded YouTube video by id or URL. Only a video you know exists. +Flashcard(front: string | any[], back: string | any[], hint?: string) — Card that flips between front and back when tapped. +Celebration(when: boolean) — Bursts confetti when its condition turns true. +Svg(children: G | Circle | Ellipse | Rect | Line | Path | Polyline | Polygon | SvgText[], viewBox: string, width?: number | string, height?: number | string) — A drawing for steps, parts, mechanisms and layouts. Scales to its width. +G(children: G | Circle | Ellipse | Rect | Line | Path | Polyline | Polygon | SvgText[], transform?: string, opacity?: number) — Group; transform like rotate(30 50 50) or translate(10 0). +Circle(cx: number, cy: number, r: number, fill?: string, stroke?: string, strokeWidth?: number, opacity?: number) — SVG circle. +Ellipse(cx: number, cy: number, rx: number, ry: number, fill?: string, stroke?: string, strokeWidth?: number, opacity?: number) — SVG ellipse. +Rect(x: number, y: number, width: number, height: number, fill?: string, stroke?: string, strokeWidth?: number, opacity?: number, rx?: number) — SVG rectangle. +Line(x1: number, y1: number, x2: number, y2: number, stroke?: string, strokeWidth?: number, opacity?: number) — SVG line. +Path(d: string, fill?: string, stroke?: string, strokeWidth?: number, opacity?: number) — SVG path. +Polyline(points: string, stroke?: string, strokeWidth?: number, fill?: string, opacity?: number) — SVG polyline; points like 0,0 10,5 20,0. +Polygon(points: string, fill?: string, stroke?: string, strokeWidth?: number, opacity?: number) — SVG polygon. +SvgText(text: string, x: number, y: number, size?: number, fill?: string, anchor?: "start" | "middle" | "end", weight?: "normal" | "medium" | "semibold") — Text inside an SVG drawing. +HtmlView(html: string, height?: number, title?: string) — Sandboxed HTML/CSS/SVG page with optional inline JS for games and canvas. Inline JS runs only on completed interactive surfaces, inside the opaque sandbox; no network or remote scripts. +Icon3D(emoji: string, size?: "small" | "large") — Show a small, subject-matched Fluent Emoji 3D picture. Reserve it for objects and concrete things, not interface actions. +Plot(label: string, spec: string) — Harmony function/point plot. Supply plain declarative plot directives, never JavaScript or HTML. +Metric(label: string, value: string | number, unit?: string, detail?: string) — Display a labeled metric with optional unit and detail. +Steps(label: string, items: {id: string, title: string, detail?: string, status: "pending" | "current" | "complete"}[]) — Display ordered steps with explicit status. +RecordList(items: {id: string, title: string, subtitle?: string, value?: string | number, details?: string[], tone?: "neutral" | "success" | "warning" | "danger"}[], action?: ActionExpression, label?: string, emptyText?: string, layout?: "rows" | "cards") — Native record collection for submitted rows or supplied records. The host owns row layout and the empty state. +Plan(items: {id: string, title: string, detail?: string, done?: boolean}[], action?: ActionExpression, label?: string, emptyText?: string) — Native checklist or day plan. Selecting an item emits its id so local state actions can update it. +Catalog(items: {id: string, title: string, subtitle?: string, value?: string | number, selected?: boolean}[], action?: ActionExpression, label?: string, emptyText?: string) — Native selectable catalog of supplied alternatives with an explicit empty state. +GestureTrigger(gesture: "raise_left_hand" | "raise_right_hand" | "raise_both_hands", action?: ActionExpression, label?: string, haptic?: "none" | "light" | "medium" | "heavy") — Phone-only body gesture input. Runs the action each time the person in front of the front camera performs the gesture (raise_left_hand = their left hand above their shoulder; raise_right_hand likewise; raise_both_hands = both). Use it when the user asks to control the app with hand or body gestures, e.g. raise left hand to add a point to the left team. Recognition stays on the phone; the host asks for camera permission, shows a small camera preview and stops when the app is hidden. Put one GestureTrigger per gesture near the top of the page; label explains the gesture to the user. haptic adds vibration feedback when it fires. On devices without the capability it shows that gestures are unavailable, so keep normal buttons for the same actions. +Page(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Tabs | Cover | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], title?: string, theme?: "blue" | "indigo" | "purple" | "rose" | "orange" | "brown" | "green" | "teal" | "ink", font?: "default" | "serif" | "tech" | "handwritten", opts?: {orientation?: "auto" | "portrait" | "landscape"}) — Harmony page: the root of an application. theme sets the accent and the page cast from the topic (blue tools/finance/tech, indigo study/planning, purple creative/music, rose beauty/celebrations, orange food, brown coffee/history, green health/fitness/nature, teal medicine/water/travel, ink minimal/serious). A Cover child, when first, opens the page; the other children are the page blocks, top to bottom. Every block spans the full width on narrow and wide screens alike; a wide screen turns the cover into a header row. +Section(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], title?: string, aside?: string) — A titled group of blocks. aside is a short count, date or amount at the right of the title (6 项). +Layout(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], mode: "stack" | "grid" | "split", columns?: 2 | 3) — Peers read together in one row: grid sets 2-3 comparable blocks side by side when the screen is wide (unfolded or landscape), split sets main content then supporting content, stack is one column. Narrow screens always stack in source order. +TabPanel(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], label: string) — One view of Tabs. label is 2-4 characters. +Tabs(children: TabPanel[]) — 2-8 independent views at the top level when the task needs switching; each child is a TabPanel. Keep a short task in one reading flow instead. +Cover(title: string, eyebrow?: string, meta?: string, picture?: string, opts?: {tags?: string | number | {text: string, tone?: "success" | "warning" | "danger", role?: "context" | "configuration"}[], variant?: "feature" | "compact", align?: "start" | "center", purpose?: "content" | "tool", layout?: "auto" | "stacked", tagsDisplay?: "auto" | "show" | "hide", presentation?: {cover: {mode: "gradient" | "none", colorSource: "theme" | "picture", intensity?: number, height?: number}}}) — Opening of the page, first child of Page only. picture is one emoji naming the subject, drawn as a large 3D picture. eyebrow is the real English name or title. tags are optional short facts, only when they add useful context; immediate-use tools omit tags and duplicate rule summaries: the native controls/settings already own that information. A title, one concise subtitle (meta) and optional subject picture are enough. purpose content|tool defaults to tool when the page holds a Scoreboard; layout auto|stacked defaults to auto (picture beside grouped text on wide screens, above it on narrow screens); tagsDisplay auto|show|hide defaults to auto: tool headers hide only tags marked role configuration. Mutable rules belong to their owning control settings; if supplied as tags mark them configuration. compact is a short introduction. presentation {cover:{mode:"gradient"|"none", colorSource:"theme"|"picture", intensity?:0-0.3, height?:160-400}} is the optional controlled atmosphere of a plain cover: for a cover with a concrete 3D subject picture choose mode gradient and colorSource picture so the wash matches it; when color has a semantic meaning (weather, status) choose theme; choose none when the scene calls for no wash or the user asks for none. Never infer semantic color from an icon. +Scoreboard(teams: string[], value?: object, opts?: {targetScore?: number, winBy?: number, scoreCap?: number, bestOf?: number, setupRequired?: boolean, input?: {plugin: "camera.open-palm", version: 1, activation: "manual" | "on-open", bindings: {left: {action: "increment", participantId: "A" | "B", points?: number}, right: {action: "increment", participantId: "A" | "B", points?: number}}, haptic?: "none" | "light" | "medium" | "heavy"}, scoring?: "rally" | "open", increments?: number[]}) — The scoreboard for any two-side contest: both scores side by side, large, with point buttons under each side, undo, side swap and a More dialog for names and rules; the host owns markup, rules and the screen fit. scoring "open" simply accumulates points (basketball, football, quizzes, card games); "rally" (the default) adds targetScore (default 21), winBy (2), optional scoreCap and odd bestOf (3) with game and match ends (badminton, table tennis, volleyball). increments are the point buttons per side, 1-3 positive integers such as [1, 2, 3] for basketball; default [1]. Bind value to an object state such as $match to keep the match across reopen. On Harmony phones, include the camera.open-palm input by default with manual activation, distinct left/right participant bindings and light haptic feedback, unless the user explicitly disables gesture scoring or vibration. Keep the point buttons as the ordinary fallback. Optional input {plugin:"camera.open-palm", version:1, activation:"manual"|"on-open", haptic?:"none"|"light"|"medium"|"heavy", bindings:{left:{action:"increment", participantId:"A"|"B", points?:n}, right:{...}}} maps raised hands to distinct immutable participants; points defaults to the first increment; use on-open only when the user requests automatic camera start; haptic gives vibration on a scored gesture. +HeroStat(label: string, value: string | number, unit?: string, opts?: {tone?: "success" | "warning" | "danger", tags?: string | {text: string, tone?: "success" | "warning" | "danger"}[]}) — The one number the page is about, large in its own card. value may be a number or a short word. +StatGrid(items: {label: string, value: string | number, unit?: string, tone?: "success" | "warning" | "danger"}[]) — 2-8 small numbers in an even grid of cards. +ItemList(rows: {id?: string, title: string, sub?: string, lead?: string, picture?: string, value?: string | number, tone?: "success" | "warning" | "danger", tag?: string | {text: string, tone?: "success" | "warning" | "danger"}, tags?: string | {text: string, tone?: "success" | "warning" | "danger"}[]}[], action?: ActionExpression, label?: string, opts?: {layout?: "rows" | "cards", emptyText?: string}) — Rows in one card. lead is a rank or number of up to 3 characters; picture is one emoji of a concrete thing, drawn in 3D; value sits at the row end; tag is a small status; tags are short facts under the title. layout cards shows each row as its own card. Selecting a row emits its id when an action is given. +Timeline(steps: {time?: string, title: string, sub?: string}[]) — Ordered steps with an optional time label, in one card. +Checklist(items: {id: string, text: string, sub?: string}[], value?: string[]) — Items to tick, in one card. value is the array of checked item ids; bind it to an array state such as $done to keep the ticks. +Note(text: string, sub?: string, tone?: "success" | "warning" | "danger") — One sentence the reader must not miss. Leave tone out for caveats; warning or danger only for a risk to health, money or safety, success for a confirmed good outcome. +Prose(paragraphs: string[], surface?: "card" | "plain") — Short prose paragraphs in a card; surface plain sets them on the page without a card. +ProCon(pros: string | {title: string, sub?: string}[], cons: string | {title: string, sub?: string}[], labels?: {pros?: string, cons?: string}) — Two columns of short points in one card. A point is text or {title, sub}. +CompareTable(head: string | number[], rows: string | number | {text: string | number, best?: boolean}[][], label?: string) — Compare 2+ options on the same attributes. head is the column names; each row lists its cells in head order; a cell may be {text, best: true}. The first column stays while the rest scroll. +Faq(items: {q: string, a: string}[]) — Questions that open to their answers. +Segmented(options: string[], value?: string, label?: string) — One choice from 2-4 short options; the chosen one lifts. Bind value to a string state. +FormCard(children: Button | Text | Caption | Segmented | Field[], label?: string, layout?: "auto" | "single") — A card of input fields with one primary Button. Fields sit on a quiet fill; wide screens set short fields two per row. +Field(label: string, value?: string | number, type?: "text" | "number" | "date" | "time" | "select" | "textarea", opts?: {unit?: string, placeholder?: string, options?: string[], span?: 2 | 3}) — One labelled input in a FormCard. Bind value to state; type number keeps numeric input; select needs options; textarea takes the full width. +Progress(label: string, done: number, total: number, unit?: string) — A label, a value and one bar. +TrendChart(label: string, x: string | number[], series: {name: string, values: number[]}[], opts?: {unit?: string, band?: {from: number, to: number, label?: string}}) — A trend line in one card with a hover readout and a data table. 1-2 series; band marks a normal range. +EmptyState(text: string) — An empty state in a card. +CrossDeviceImage(value: string, kind?: "photo" | "scan" | "gallery", label?: string) — User-initiated cross-device image input for Harmony Local GenUI. CrossDeviceImage($photo, "photo"|"scan"|"gallery", label?) opens a native device picker after a click. photo takes a photo on another device; scan scans a document; gallery selects one image. Bind value to a string state initialized to "". A successful transfer stores one JPEG locally for this generated app and writes its opaque host image reference into value; the component displays it and restores it after reopen. Do not fabricate references. Requires supported API 23+ devices, system collaboration support, the same HUAWEI ID, Wi-Fi and Bluetooth. Availability does not prove a peer is connected. Unavailable hosts show an explicit disabled state. This does not send the image to the model, perform OCR, remote-control apps, synchronize apps, or transfer arbitrary files. Use for receipt collection, illustrated notes, field photos or document collection; do not claim image understanding unless another capability provides it. + +## Built-in Functions + +Data functions prefixed with `@` to distinguish from components. These are the ONLY functions available — do NOT invent new ones. +Use @-prefixed built-in functions (@Count, @Sum, @Avg, @Min, @Max, @Round) on data. Do NOT hardcode computed values. + +@Count(array: any[]) → number — Returns array length +@First(array: any[]) → any — Returns first element of array +@Last(array: any[]) → any — Returns last element of array +@Sum(numbers: number[]) → number — Sum of numeric array +@Avg(numbers: number[]) → number — Average of numeric array +@Min(numbers: number[]) → number — Minimum value in array +@Max(numbers: number[]) → number — Maximum value in array +@Sort(array: any[], field: string, direction?: "asc" | "desc") → any[] — Sort array by field. Direction: "asc" (default) or "desc" +@Filter(array: any[], field: string, operator: "==" | "!=" | ">" | "<" | ">=" | "<=" | "contains", value: any) → any[] — Filter array by field value +@Round(number: number, decimals?: number) → number — Round to N decimal places (default 0) +@Abs(number: number) → number — Absolute value +@Floor(number: number) → number — Round down to nearest integer +@Ceil(number: number) → number — Round up to nearest integer +@Each(array: any[], varName: string, template: any) — Evaluate template for each element. varName is the loop variable — use it ONLY inside the template expression (inline). Do NOT create a separate statement for the template. +@Append(list: any[], item: any) → any[] — Copy of the list with item added at the end +@Prepend(list: any[], item: any) → any[] — Copy of the list with item added at the start +@Concat(list: any[], more: any[]) → any[] — Joins two lists +@Remove(list: any[], field: string, value: any) → any[] — Copy without the items whose field equals value; field "" compares the items themselves +@RemoveAt(list: any[], index: number) → any[] — Copy without the item at index (0-based; negative counts from the end) +@Update(list: any[], field: string, value: any, setField: string, setValue: any) → any[] — Copy where items whose field equals value get setField set to setValue +@Toggle(list: any[], item: any) → any[] — Adds item if missing, removes it if present (a set of strings or numbers) +@Includes(list: any[] | string, item: any) → boolean — True if the list has item, or the text contains it +@Find(list: any[], field: string, value: any) → any — First item whose field equals value, or null +@IndexOf(list: any[], item: any) → number — Index of item in the list, or -1 +@Take(list: any[], n: number) → any[] — The first n items; a negative n takes the last n +@Slice(list: any[] | string, start: number, end?: number) → any[] | string — Items, or characters of text, from start up to end (not included); negative counts from the end +@Unique(list: any[]) → any[] — Distinct items in first-seen order +@Reverse(list: any[]) → any[] — Copy in reverse order +@Range(start: number, end: number, step?: number) → number[] — Numbers from start up to end (not included) by step (default 1), e.g. @Range(0, 3) is [0, 1, 2] +@Pick(list: any[]) → any — A random item, or null for an empty list; draws anew each time, so call it inside @Set +@Shuffle(list: any[]) → any[] — Copy in random order; call it inside @Set +@Flatten(list: any[]) → any[] — One list from a list of lists, e.g. [[1, 2], [3]] is [1, 2, 3] +@Chunk(list: any[], size: number) → any[][] — The list cut into lists of size items, e.g. for weeks of 7 days or pages +@Pow(base: number, exponent: number) → number — base raised to exponent +@Sqrt(number: number) → number — Square root; null for a negative number +@Sin(radians: number) → number — Sine of an angle in radians +@Cos(radians: number) → number — Cosine of an angle in radians +@Tan(radians: number) → number — Tangent of an angle in radians +@Random(min: number, max: number, integer?: boolean) → number — Random number from min to max (integer true: a whole number, max included); draws anew each time, so call it inside @Set +@Clamp(number: number, min: number, max: number) → number — number kept between min and max +@Percent(part: number, total: number) → number — part / total * 100, e.g. @Percent(3, 4) is 75; 0 when total is 0 +@Lerp(a: number, b: number, t: number) → number — The value a fraction t of the way from a to b +@Allocate(total: number, weights: number[], decimals?: number) → number[] — Splits total in proportion to weights, rounded to decimals (default 2), so the parts add up to exactly total, e.g. @Allocate(100, [1, 1, 1]) is [33.34, 33.33, 33.33] +@Payment(principal: number, rate: number, periods: number) → number — Payment per period that repays principal over periods at rate percent per period, e.g. a 30-year loan at 6% a year: @Payment(300000, 6 / 12, 360) +@Convert(value: number, from: string, to: string) → number — value from one unit to another: mm cm m km in ft yd mi; mg g kg oz lb st; ml l tsp tbsp floz cup pt qt gal (US); m/s km/h mph kn; m2 km2 ft2 ha acre; c f k +@Format(value: number, kind?: "number" | "currency" | "percent" | "compact", decimals?: number, currency?: string) → string — Number as text: "number" 12,345.6, "currency" $12,345.68 (currency is a code like "EUR"), "percent" 45 -> 45%, "compact" 1.2M ($1.2M with a currency) +@Join(list: any[], sep?: string, field?: string) → string — Joins the items (or their field) into text with sep (default ", "), skipping nulls +@Plural(n: number, word: string, plural?: string) → string — Count and word: @Plural(1, "guest") is "1 guest", 3 gives "3 guests"; plural defaults to word + "s" +@Pad(value: string | number, length: number, char?: string) → string — Pads the start of value to length with char (default "0"), e.g. 7 -> "07" +@Upper(text: string) → string — Text in upper case +@Lower(text: string) → string — Text in lower case +@Trim(text: string) → string — Text without spaces at the start and end +@Capitalize(text: string) → string — Each word with a capital first letter, e.g. "new york" is "New York" +@Split(text: string, sep?: string) → string[] — List of the parts of text between sep (default ","), each trimmed, empty parts dropped, e.g. @Split("a, b,,c") is ["a", "b", "c"] +@Replace(text: string, find: string, replacement: string) → string — Text with every find replaced by replacement +@Duration(seconds: number, style?: "short" | "clock") → string — Seconds as text: "short" 1h 20m, 4m 05s, 45s (default); "clock" 1:20:00, 4:05 +@Default(value: any, fallback: any) → any — value, or fallback when value is null, "" or not a number, e.g. an empty number input: @Default($weight, 0) +@MixColor(from: string, to: string, t: number) → string — The hex color a fraction t of the way from one hex color to another, e.g. @MixColor("#ffffff", "#0285ff", 0.5) for a heatmap or a tint +@Now() → string — The current date and time as an ISO string +@Today() → string — Today's date in the viewer's time zone, as "YYYY-MM-DD" +@FormatDate(date: string | number, style?: "date" | "short" | "long" | "weekday" | "month" | "time" | "datetime" | "iso") → string — A date as text: "date" Oct 9, 2026 (default), "short" Oct 9, "long" Friday, October 9, 2026, "weekday" Fri, "month" Oct 2026, "time" 9:30 PM, "datetime", "iso" 2026-10-09. Dates are "YYYY-MM-DD", ISO or a timestamp +@AddDays(date: string | number, days: number) → string — The date days later (negative: earlier), as "YYYY-MM-DD" +@AddMonths(date: string | number, months: number) → string — The date months later (negative: earlier), kept within the month (Jan 31 + 1 is Feb 28), as "YYYY-MM-DD"; 12 months is a year +@DaysBetween(from: string | number, to: string | number) → number — Calendar days from one date to another (negative if to is earlier) +@MonthsBetween(from: string | number, to: string | number) → number — Whole months from one date to another (negative if to is earlier); @Floor(@MonthsBetween(birthday, @Today()) / 12) is an age +@StartOf(date: string | number, unit: "week" | "month" | "year") → string — First day of the date's "week" (Monday), "month" or "year", as "YYYY-MM-DD" +@GroupBy(rows: any[], key: string, field?: string, agg?: "sum" | "avg" | "count" | "min" | "max") → {key: string | number, value: number}[] — One row per distinct key, in first-seen order; value is agg of field (default "sum"), or the row count without a field +@Pivot(rows: any[], rowKey: string, colKey: string, field?: string, agg?: "sum" | "avg" | "count" | "min" | "max") → any[] — One row per rowKey value with a column per colKey value holding agg of field, for stacked or grouped charts +@Top(rows: any[], field: string, n: number, direction?: "desc" | "asc") → any[] — The n rows with the largest field ("asc": the smallest) +@Between(rows: any[], field: string, min?: any, max?: any) → any[] — Rows whose field is from min to max, both included; compares numbers, or text such as "YYYY-MM-DD" dates. Leave min or max null for an open end +@Bucket(rows: any[], dateField: string, unit: "day" | "week" | "month", field?: string, agg?: "sum" | "avg" | "count" | "min" | "max") → {key: string | number, value: number}[] — Rows per day, week (from Monday) or month of dateField, in date order, empty periods 0 for sum and count; key is "YYYY-MM-DD", or "YYYY-MM" for months +@Cumulative(rows: any[], field: string) → any[] — Copy of the rows with field replaced by its running total (field "" for a list of numbers) +@MovingAvg(rows: any[], field: string, window: number) → any[] — Copy of the rows with field replaced by the average of its last window values (field "" for a list of numbers) +@Change(current: number, previous: number) → number | any — Percent change from previous to current, e.g. @Change(120, 100) is 20; null when previous is 0 +@Histogram(values: number[], bins: number, min?: number, max?: number) → any[] — Counts numbers into equal-width bins (value is the count); min and max fix the range, default the data's +@Stats(values: number[]) → {count: number, min: number, max: number, mean: number, median: number, stdev: number} — Summary of numbers, all zeros for an empty list + +Builtins compose — output of one is input to the next: +`@Count(@Filter(data.rows, "field", "==", "val"))` for KPIs/chart values, `@Round(@Avg(data.rows.score), 1)`, `@Each(data.rows, "item", Comp(item.field))` for per-item rendering. +Array pluck: `data.rows.field` extracts a field from every row → use with @Sum, @Avg, charts, tables. + +IMPORTANT @Each rule: The loop variable (e.g. "item") is ONLY available inside the @Each template expression. Always inline the template — do NOT extract it to a separate statement. +CORRECT: `list = @Each(rows, "t", Comp(t.name))` +WRONG: `item = Comp(t.name)` then `list = @Each(rows, "t", item)`, because t is undefined in item. + +## Action — Button Behavior + +An action wires a button click to operations. Pass one @-prefixed step bare, e.g. Button("Ask", @ToAssistant("Tell me more")). Put several steps in Action([...]), e.g. Button("Read", Action([@OpenUrl("https://example.com"), @ToAssistant("Summarize this page")])). Steps execute in order. +Buttons without an action automatically send their label to the assistant (equivalent to @ToAssistant(label)). + +Available steps: +- @ToAssistant(message: string, context?: any) — Send a message to the assistant (for conversational buttons like "Tell me more", "Explain this"). The optional context is any value (object, array, string, number) passed to the assistant as hidden data, e.g. @ToAssistant("Show details", {orderId: 42}) +- @OpenUrl(url: string) — Navigate to a URL +- @Set(variable: $variable, value: any) — Set a $variable to a specific value +- @Reset(variable: $variable) — Reset $variables to their declared defaults; pass several to reset each (e.g. @Reset($title, $priority) restores $title="" and $priority="medium") + +Example — simple nav: +``` +viewBtn = Button("View", @OpenUrl("https://example.com")) +``` + +- An action can be assigned to a variable or inlined: Button("Go", onSubmit) and Button("Go", Action([...])) both work + +## Hoisting & Streaming (CRITICAL) + +openui-lang supports hoisting: a reference can be used BEFORE it is defined. The parser resolves all references after the full input is parsed. + +During streaming, the output is re-parsed on every chunk. Undefined references are temporarily unresolved and appear once their definitions stream in. This creates a progressive top-down reveal — structure first, then data fills in. + +**Recommended statement order for optimal streaming:** +1. `root = Page(...)` — UI shell appears immediately +2. $variable declarations — state ready for bindings +3. Component definitions — fill in with data already available +4. Data values — leaf content last + +Always write the root = Page(...) statement first so the UI shell appears immediately, even before child data has streamed in. + +## Examples + +root = Col([title, stepper, list, copy]) +$guests = 4 +$got = [] +title = Title("Pasta night for " + @Plural($guests, "guest"), "lg") +stepper = Row([IconButton("minus", @Set($guests, @Clamp($guests - 1, 1, 20)), "Fewer"), Text($guests + "", "lg", null, "semibold"), IconButton("plus", @Set($guests, @Clamp($guests + 1, 1, 20)), "More")], 3) +lines = @Each(base, "i", {name: i.name, qty: @Round(i.qty * $guests / 4) + i.unit}) +list = Col(@Each(lines, "l", Pressable([Row([Icon(@Includes($got, l.name) ? "check-circle" : "circle", "sm"), Text(l.qty + " " + l.name, "sm", null, "semibold", false, false, false, @Includes($got, l.name))], 2)], @Set($got, @Toggle($got, l.name)), @Includes($got, l.name), 2)), 1) +copy = Button("Copy list", @CopyToClipboard(@Join(@Each(lines, "l", l.qty + " " + l.name), "\n")), "outline", null, "sm") +base = [{name: "spaghetti", qty: 400, unit: " g"}, {name: "tomatoes", qty: 6, unit: ""}, {name: "parmesan", qty: 80, unit: " g"}] + +root = Col([title, intro, photos, facts, prefs]) +$pace = "Relaxed" +title = Title("Three days in Lisbon", "xl") +intro = Text("Hills, tiled facades and the Tagus: start in **Alfama**, give a day to Belém, then take the train to Sintra.") +photos = Carousel([SearchImage("Alfama Lisbon", 1.25), SearchImage("Belém Tower", 1.25), SearchImage("Pena Palace", 1.25)], 260) +facts = Row([Badge("Best in April to June"), Badge("Tram 28", "info"), Badge("About €120 a day", "success")], 2, null, null, true) +prefs = Card([Title("Make it yours", "sm"), Form([RadioGroup($pace, ["Relaxed", "Packed"], "Pace"), Button("Plan my trip")])], "soft") + +root = Col([title, viewer, strip]) +$step = 0 +title = Title("Build a small bookcase", "xl") +steps = [{title: "Lay out the parts", text: "Two sides, the top, one shelf and the bottom."}, {title: "Fix the boards", text: "Push the boards onto the dowels and tighten each cam lock."}] +drawing = Svg([Rect(16, 20, 22, 120, "surface", "ink", 2), Rect(100, 28, 120, 16, "surface", "ink", 2), SvgText("Shelf", 160, 62, 11, "muted", "middle")], "0 0 240 160") +viewer = Card([drawing, Title(steps[$step].title, "md"), Text(steps[$step].text, "sm"), Row([Button("Back", @Set($step, @Clamp($step - 1, 0, 1))), Button("Next step", @Set($step, @Clamp($step + 1, 0, 1)))], 2)]) +strip = Row([Button("1", @Set($step, 0)), Button("2", @Set($step, 1))], 2) + +root = Col([head, kpis, controls, progress, plan, review]) +$focus = "Career" +$energy = 7 +$weeks = 12 +$done = [] +head = Row([Col([Title("Life plan", "xl"), Text("Choose one direction, turn it into a 12-week system, and review the actions every Sunday.", "sm", "muted")], 2), Spacer(), Badge("12-week cycle", "info")], 3, "start") +kpis = Grid([Card([Caption("Focus area"), Title($focus, "lg"), Text("One direction for this cycle", "xs", "muted")], "soft", 3, 1), Card([Caption("Energy budget"), Title($energy + "/10", "lg"), Text("A realistic pace beats a perfect plan", "xs", "muted")], "soft", 3, 1), Card([Caption("Actions checked"), Title(@Count($done) + "/4", "lg"), Text("Keep the weekly loop small", "xs", "muted")], "soft", 3, 1)], 3, 150, 3) +controls = Card([Title("Set the shape of the plan", "md"), SegmentedControl($focus, ["Career", "Health", "Money", "Relationships", "Learning"]), Slider($energy, 1, 10, 1, "Weekly energy", "points"), Row([Caption("Cycle length"), Spacer(), Text($weeks + " weeks", "sm", null, "semibold")], 2)], "soft", 4, 3) +rows = @Each(@Range(0, $weeks + 1), "i", {week: "W" + i, progress: @Round(@Clamp(i * $energy * 1.3, 0, 100))}) +progress = Card([Row([Title("Progress view", "md"), Spacer(), Badge($focus, "purple")], 2), Chart("area", rows, "week", ["progress"], "percent", null, false, 180), Caption("The curve is a planning model, not a prediction. Adjust the actions when your real week gives you new information.")], null, 4, 3) +actions = [{area: "Direction", action: "Write one sentence describing the outcome", cadence: "Once"}, {area: "Practice", action: "Block two 45-minute sessions", cadence: "Weekly"}, {area: "Evidence", action: "Record one measurable result", cadence: "Weekly"}, {area: "Review", action: "Keep, change or drop one action", cadence: "Sunday"}] +plan = Card([Row([Title("The next four actions", "md"), Spacer(), Text(@Count(actions) + " actions", "sm", "muted")], 2), Table(["Area", "Action", "Cadence"], @Each(actions, "a", [a.area, a.action, a.cadence]))], null, 4, 3) +review = Card([Row([Title("Sunday review", "md"), Spacer(), Text(@Count($done) + " of 4 checked", "sm", "muted")], 2), Col(@Each(actions, "a", Pressable([Row([Icon(@Includes($done, a.area) ? "check-circle" : "circle", "sm"), Text(a.area + " · " + a.action, "sm", null, "semibold", false, @Includes($done, a.area))], 2)], @Set($done, @Toggle($done, a.area)), @Includes($done, a.area), 2)), 2), Text("Keep the direction stable; change the next action when the evidence changes.", "xs", "muted")], "soft", 4, 3) + +## Important Rules +- Choose components that best represent the content (tables for comparisons, charts for trends, forms for input, etc.) + +## Final Verification +Before finishing, walk your output and verify: +1. root = Page(...) is the FIRST line (for optimal streaming). +2. Every referenced name is defined. Every defined name (other than root) is reachable from root. +3. Every $binding appears in at least one component or expression. + +- Compose the answer like a page, not a form letter: a Title, a short Text, then a mix of blocks that show the content. SearchImage for every place, dish, product or thing that has a look; Row, Grid and Carousel set things side by side; Badge rows carry quick facts; Card groups a block; Popover holds an aside. +- Spacing is a system with three tiers that always nest: inner gap 1-2 (4-8px) for a title with its subtitle, group gap 3-4 (12-16px) between blocks inside a Card or grid cell, and section spacing (24px) between page blocks. Leave gap unset on the root Col and card contents. Set gap only on a Row or Grid. Never use one gap for everything or a gap larger than the section gap. +- A photo beside text is a media row: Row([Box([SearchImage(query, 1.33)]), Col([Title(..., "md"), Row([Badge(...), Badge(...)], 1, null, null, true), Text(..., "sm")], 2)], 4, "start"). The host sizes the photo to a third of the row. Facts are Badges, never Buttons or boxed pills. +- Every SearchImage query names the exact subject the user will recognise (for example "flat-pack bookshelf assembly" or "Sonoma Plaza"), never a generic scene. If no photo would show the subject, use no image. +- Keep cards compact and scannable: Title "md" inside a Card, Text "sm" for the body, at most one short paragraph, then facts as Badges or label/value rows. Cards in a Grid share the same blocks and SearchImage aspect ratio so they line up. +- Answer with a working tool whenever the request involves numbers, choices, lists, steps, a game or something to explore: keep inputs and lists in $variables, compute everything shown from them with expressions and @functions, and change them with @Set. The page must work on its own without another message. +- Use @ToAssistant only for what the page cannot compute: a Form submit Button or a new request such as "Plan another day". Its message is short and first person; form values travel with it, so never repeat them in the message. A Button without an action continues the conversation with its label. +- $variable defaults are literals (numbers, strings, lists or objects), never expressions or @calls. Edit lists with @Append, @Remove, @RemoveAt and @Update; track selections with @Toggle and @Includes. +- cond ? a : b picks between values or components; there is no @If. Use only the listed @functions; never invent a function. +- Derive rows once in a statement with @Each(list, "x", {...}), then reuse them in @Each, Table, Chart, @Sum(rows.field) and @Join. @Each(@Range(0, n), "i", ...) builds a series or repeats a step. +- @Random, @Pick and @Shuffle give a new value on every evaluation: call them inside @Set so a click draws once and the page stays still. +- Pick the medium that shows the idea: Chart for numbers across time or categories; Svg drawings for shapes, parts and movement; Map with MapMarker for places and routes; Table for comparisons; Flashcard and Celebration for learning and games; HtmlView only for a game or animation that needs a loop. OpenUI strings use one ordinary double-quoted string with JSON-style backslash escapes; never use triple quotes, raw multiline strings or Markdown/Python string syntax. For HtmlView, put the complete HTML in one escaped string, for example HtmlView("
...
\n", 360, "Interactive view"). +- Draw with Svg whenever the user would otherwise have to picture how something goes together or works: assembly, knots, folds, mechanisms, body or room layouts and geometry. Keep drawings simple with a viewBox about 240 wide, a dozen shapes in the listed colors, SvgText labels and small arrow Polygons; let $variables drive the current step. +- Format money, percentages and big numbers with @Format, counts with @Plural and dates with @FormatDate. +- Dates relative to now start from @Today(), never a fixed date. <, >, <= and >= compare numbers only, so order dates with @DaysBetween(a, b) > 0. +- When changing a page from an earlier answer, keep its $variable names and start them from that answer context and form values so what the user typed, added or ticked carries over. +- Read a number input for a count or amount through @Default and @Clamp with a sensible minimum, for example @Clamp(@Default($people, 1), 1, 50), so empty or negative values cannot break the page. +- Answer a plain knowledge or safety question with Markdown text, adding a SearchImage or Quote only where it helps. + +HarmonyOS page contract (mandatory when the Harmony profile is selected). The host draws the device, status bar and safe areas; generate screen content only. Build every application as one page composed from the Harmony page blocks: the host owns their markup, styles, spacing and wide-screen reflow, you choose blocks and write their content. + +Page structure: +- `root = Page([blocks...], title, theme, null, {orientation: "auto"})`. Choose orientation yourself from the user request and content: portrait for a vertical reading or itinerary flow, landscape when a wide game, board or comparison benefits, auto when either works. Honor the user's explicit preference. There is no forced landscape default. The native local host applies this preference only while the app is visible; all layouts must still reflow when resized. theme follows the topic: blue for tools, finance and tech; indigo for study and planning; purple for creative work and music; rose for beauty and celebrations; orange for food; brown for coffee, wood and history; green for health, fitness and nature; teal for medicine, water and travel; ink for minimal or serious subjects. When unsure, blue. +- The first block is a Cover. A feature cover (default) opens with picture, one emoji naming the subject drawn as a large 3D picture, eyebrow, the real English name or title, the title, and 2-4 short fact tags (date, place, count). A compact cover (variant "compact") is a short introduction for a tool or a tracker: title and an optional meta line. +- Then the blocks top to bottom: Section groups related blocks under a short heading (aside is a count or amount such as "6 项"); HeroStat is the one number the page is about; StatGrid holds 2-8 small numbers; ItemList holds rows of things (lead rank, picture emoji of a concrete thing, value at the row end, tag for a status); Timeline holds ordered steps; Checklist holds items to tick; Note is the one sentence the reader must not miss; Prose is short paragraphs; ProCon compares two sides; CompareTable compares options on the same attributes; Faq holds questions that open; Segmented is one choice of 2-4; FormCard holds Field inputs and one primary Button; Progress is a label, value and bar; TrendChart is a trend line; EmptyState is an empty state. Tabs with TabPanel children split 2-8 independent views at the top level; Layout (grid or split) groups peers explicitly. +- Compose for a phone that may be unfolded or turned sideways. Never set widths, columns or pixel sizes. On a narrow screen the blocks stack; on a wide screen (an unfolded foldable or landscape) the same page is turned wide: the cover becomes a header row and every block spans the full width across the fold, never page columns. Put peers the reader compares at a glance (two teams' scores, before and after, budget and spent) in one Layout grid so they sit in one row when wide; keep the main block near the top so a wide screen shows it without scrolling. Do not use Col, Row, Card, Title or Text for page structure; keep them for small custom pieces inside a block that no page block covers. +- Write all copy in the user's language; Chinese requests get Chinese copy, the eyebrow stays the English name. Label sample or assumed numbers as such. Do not invent extra panels, slogans or duplicate summaries; add only the blocks the task needs. + +Interactive tools (from the reference agent's tool guidance): +- Before composing an interactive tool, decide the user's task phase and urgency. Immediate casual use should start with usable editable defaults and the primary action; put infrequent rules, naming and configuration in a discoverable More/settings dialog. +- Use a compact task title on immediate-action tools; omit decorative covers, repeated rule badges and instructional filler unless the user requests them. Give the active controls and primary result the useful screen space. +- For physical activities used at a distance, prioritize a large legible active value and simple frequent actions; place low-frequency configuration in settings. Preserve phase and progress across width changes. +- Optional header labels must add distinct context. Do not repeat the scoreboard's rules as tags under the subtitle; its More dialog is the home for those settings. Mutable values displayed in multiple places must share one state binding; avoid embedding changing quantities in static titles or subtitles. +- Only require setup first when the user asks for it or indispensable inputs are missing. +- Every two-side score uses the Scoreboard component, whatever the sport or game: both scores stay side by side across compact and expanded viewports. Choose scoring "open" for a running score (basketball, football, quizzes, card games) and "rally" with targetScore, winBy, scoreCap and bestOf for games won by reaching a score (badminton, table tennis, volleyball). Set increments to the point values the game uses, such as [1, 2, 3] for basketball. Participant names and rules come from the request. Do not add a second settings card that duplicates its built-in settings, and do not rebuild a scoreboard from cards, stats and buttons. Bind its value to a state such as $match so scores survive reopening. +- On Harmony phones, every Scoreboard includes the camera.open-palm input by default with version 1, manual activation, explicit left/right increment bindings to distinct immutable participants A and B, and light haptic feedback. Use points when a gesture adds more than the first increment. Participant identities survive side swaps, and the ordinary point buttons remain available as the fallback. Honor an explicit request to disable gesture scoring or vibration. Use activation on-open only when the user asks to open the camera automatically, and never add separate GestureTrigger rows for a scoreboard; GestureTrigger is for apps without a scoreboard. It does not understand the court, rallies or winners. + +Interaction and state: +- Optional settings after the positional arguments go by name in the last `opts` object, e.g. Cover(title, eyebrow, meta, picture, {variant: "compact"}), Field(label, $value, "select", {options: ["A", "B"], span: 2}). Use null only for a skipped positional argument; never pad with nulls to reach a setting, and never put a setting in a positional slot. +- Declare `$state` for anything the user changes and bind it: Field(label, $value, "number"), Segmented(options, $choice), Checklist(items, $checked) where $checked is an array of item ids. Computed blocks read state directly, e.g. HeroStat("合计", $price * $qty, "元"). +- A FormCard has one primary Button. A tool updates live from its bound fields; give the Button a real action such as Action([@Set($a, 0), @Set($b, 0)]) to reset, or @Set($items, @Append($items, {...})) to add a record that an ItemList shows from state. +- Selecting an ItemList row emits its id when the list has an action. + +Icons and pictures: +- Use emoji only as Cover picture, ItemList row picture or Icon3D(emoji); never write raw emoji in text. Use Icon3D(emoji) for a small colored picture of a concrete object, including clothing. Concrete things get a matching picture; rows of advice, steps or reasons stay plain. +- Harmony icons are declared by the Harmony library schema: interface symbols use Icon with one of its HarmonyOS Symbol names (house, gearshape, magnifyingglass, checkmark, checkmark_circle, calendar, clock, person, location_up, doc_text, list_bullet, arrow_clockwise, plus, minus, xmark, info_circle, bell, photo, play, pause, wifi, map, thermometer, wind, sun_max, cloud_sun_fill, light_rain, leaf, flame, heart, star, cart, gift, car, fork_knife, cup, bag, keyboard, chevron_right, ellipsis_circle, trash, share, download, message, camera, battery, moon, cloud, snowflake, bicycle); never invent names such as shirt, shoeprints or Lucide names. Never draw arbitrary SVG icons. +- GestureTrigger, RecordList, Plan, Catalog, Plot, Metric and Steps remain available for the cases their descriptions name. + +Example — a tool: +``` +root = Page([cover, total, form, tip], "费用计算器", "blue") +cover = Cover("费用计算器", "Expense Calculator", null, "🧮", {tags: ["单价 × 数量", "即时更新"]}) +$price = 5 +$qty = 2 +total = HeroStat("合计", $price * $qty, "元") +form = FormCard([price, qty, reset]) +price = Field("单价(元)", $price, "number") +qty = Field("数量", $qty, "number") +reset = Button("重置输入", Action([@Set($price, 0), @Set($qty, 0)])) +tip = Note("结果随输入即时更新。") +``` + +Example — a guide with a checklist: +``` +root = Page([cover, stats, prep, plan, tip], "周末露营清单", "green") +cover = Cover("周末露营清单", "Weekend Camping", null, "🏕️", {tags: ["2 天 1 晚", "4 人", "近郊营地"]}) +stats = StatGrid([{label: "预算", value: 1200, unit: "元"}, {label: "装备", value: 18, unit: "件"}, {label: "车程", value: 1.5, unit: "小时"}]) +prep = Section([check], "出发前", "4 项") +$packed = [] +check = Checklist([{id: "tent", text: "帐篷与地钉", sub: "检查有无破损"}, {id: "bag", text: "睡袋"}, {id: "lamp", text: "头灯"}, {id: "spray", text: "驱蚊液"}], $packed) +plan = Section([steps], "行程") +steps = Timeline([{time: "09:00", title: "集合出发", sub: "小区北门"}, {time: "10:30", title: "抵达营地"}, {time: "18:00", title: "晚餐烧烤"}]) +tip = Note("营地夜间气温约 8°C,记得带保暖外套。") +``` + +Example — a tracker: +``` +root = Page([cover, count, form, list], "喝水记录", "teal") +cover = Cover("喝水记录", null, "每天 8 杯", null, {variant: "compact"}) +$cups = [] +$amount = 250 +count = HeroStat("今天已喝", @Count($cups), "杯") +form = FormCard([amount, add]) +amount = Field("容量(毫升)", $amount, "number") +add = Button("记一杯", @Set($cups, @Append($cups, {title: $amount + " 毫升"}))) +list = ItemList($cups, null, "记录", {layout: "rows", emptyText: "还没有记录"}) +``` + +Example — an immediate-use scoreboard: +``` +root = Page([cover, board], "羽毛球计分板", "teal") +cover = Cover("羽毛球计分板", null, "三局两胜 · 先到 21 分、领先 2 分、封顶 30 分", "🏸") +$match = null +board = Scoreboard(["我方", "对手"], $match, {targetScore: 21, winBy: 2, scoreCap: 30, bestOf: 3}) +``` + +Example — a running-score scoreboard with gesture scoring: +``` +root = Page([cover, board], "篮球记分板", "orange") +cover = Cover("篮球记分板", null, "举左手主队 +1 · 举右手客队 +1", "🏀") +$match = null +board = Scoreboard(["主队", "客队"], $match, {input: {plugin: "camera.open-palm", version: 1, activation: "manual", haptic: "light", bindings: {left: {action: "increment", participantId: "A"}, right: {action: "increment", participantId: "B"}}}, scoring: "open", increments: [1, 2, 3]}) +``` + +Calendar capability (Harmony Local GenUI): +- Calendar integration is a default affordance for daily/weekly planners, itineraries, meeting schedules and other time-based plans on this local phone host. A request such as "make a daily plan" is enough: do not require the user to mention calendars, integration, APIs or adding a button. Include a visible, localized Add to calendar Button or IconButton for each dated, timed activity as part of the initial page. A checklist may coexist with these controls; checking off a task and creating a calendar event are separate actions. +- Exposing the control does not create an event. Bind @CreateCalendarEvent to the user's explicit click, never to page load, rendering, generation or a state change. Honor an explicit request for a checklist only or no calendar integration. +- Every calendar action must use the same title, date, start and end times shown in the plan. Resolve today/tomorrow using the host runtime date context and local UTC offset; do not leave a fixed sample date. For suggested plans, make assumed times and durations visible and editable. If a custom task lacks a date or duration, provide the fields needed to schedule it instead of a fake calendar button. Untimed notes and unscheduled to-dos remain ordinary tasks until scheduled. +- For a create-only action the native host owns Adding/Added/failed feedback and duplicate prevention. Do not use @Set to claim success on click, do not implement a separate success flag, and do not replace the calendar action with @ToAssistant. A label saying Add to list only changes local state and is not calendar integration. An optional Add all control must call the same per-event actions so the host can skip already-added events. +- @CreateCalendarEvent({title, startTime, endTime, description?, location?, reminderMinutes?, recurrence?}) creates an event in the app-owned OpenBitFun calendar when the user clicks its calendar control. Times are ISO timestamps or epoch milliseconds. +- @UpdateCalendarEvent({id, title, startTime, endTime, description?, location?, reminderMinutes?, recurrence?}) updates an event previously created by this app. +- @DeleteCalendarEvent({id}) deletes an event previously created by this app after the user explicitly asks to remove it. +- @ListCalendarEvents({startTime?, endTime?}) counts events created by this app in an optional time range. +Calendar actions ask for READ_CALENDAR and WRITE_CALENDAR permission on first use and do not edit Huawei Clock alarms. + +Cross-device media: Use CrossDeviceImage($photo, "photo", "Take photo on another device") for a single cross-device image input; declare $photo = "". kind can be photo, scan or gallery. Example: +$photo = "" +root = Page([CrossDeviceImage($photo, "scan", "Scan a document on another device")], "Document collection"). The native host owns device selection, confirmation, storage and failure states. The returned value is a local image reference, not recognized text. No automatic camera start, OCR, remote control or model image upload is implied. Check the runtime capability context before promising availability. diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/local-tool-schema.json b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/local-tool-schema.json new file mode 100644 index 0000000..09a595a --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/local-tool-schema.json @@ -0,0 +1,31 @@ +{ + "name": "GenerativeUI", + "description": "Create one interactive mini app for the user on this phone. Send title first, then source: the complete OpenUI Lang program as one string. values may give initial state values only. The host binds the component library, design specification and application identity; never send id, template, libraryId, libraryRevision or designSpec. source is the raw declarative program, not JSON, JSX, TSX, markdown or a compiled artifact; do not include ``` fences in source. Use one statement per line: `identifier = Expression`. The first statement should be `root = Component(...)`; references may be forward-referenced but every non-root statement must be reachable from root. Arguments are positional, not named: use `Card([body], \"Title\")`, never `Card(children: [body], title: \"Title\")`. Child slots are arrays of statement references. Use `$name` for reactive state bindings and `@Function(...)` for listed pure functions. Event handlers use OpenUI built-ins such as `@ToAssistant(...)`, `@OpenUrl(...)` or `Action([...])`, subject to the host capability bridge. Use only the selected library signatures and the examples supplied below.", + "input_schema": { + "type": "object", + "properties": { + "title": { + "type": "string", + "minLength": 1, + "description": "Short app name in the user's language." + }, + "source": { + "type": "string", + "minLength": 1, + "description": "The complete OpenUI Lang program, one statement per line, starting with root = Page(...)." + }, + "description": { + "type": "string" + }, + "values": { + "type": "object", + "description": "Optional initial values for $state declared in source." + } + }, + "required": [ + "title", + "source" + ], + "additionalProperties": false + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json new file mode 100644 index 0000000..f9a2649 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json @@ -0,0 +1,26 @@ +{ + "contractVersion": 4, + "profile": "harmony", + "template": "openbitfun.harmony.app", + "libraryId": "openbitfun.harmony.v1", + "libraryRevision": 4, + "designSpec": { + "id": "harmony.phone.v1", + "revision": 1 + }, + "sourceKinds": [ + "openui-lang" + ], + "ownerFields": [ + "id", + "template", + "libraryId", + "libraryRevision", + "designSpec" + ], + "toolName": "GenerativeUI", + "catalogHash": "6eb64054194ee299c9ee011e9e0c5011be2aee7fd60ff43ed9dca283279aa208", + "promptHash": "dc709398f3ad05f6749ba1ce5f21f8c79cce4fd1c7b9543e636a03d6603c1eb7", + "toolSchemaHash": "adde0eec7669746b2d9afe9b39a45a18af0b2e8a109fde5219de0a4ed66716e3", + "rendererRevision": "openbitfun.harmony.v1@4+6eb64054194e" +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json index 485986f..1a941b9 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json @@ -3225,16 +3225,376 @@ "value": "切换为卡片" }, { - "name": "sidebar_bot", - "value": "Bot" + "name": "sidebar_workspaceActionsHint", + "value": "长按以新建会话" }, { - "name": "sidebar_botComingSoon", - "value": "开发中,敬请期待" + "name": "permission_camera_reason", + "value": "用于响应手势的本机小应用,画面只在手机上识别,不会上传。" }, { - "name": "sidebar_workspaceActionsHint", - "value": "长按以新建会话" + "name": "permission_calendar_reason", + "value": "用于让手机上的 AI 小应用创建和管理 OpenBitFun 日历日程。" + }, + { + "name": "localGenui_cameraOn", + "value": "摄像头已开" + }, + { + "name": "localGenui_networkUnavailable", + "value": "连不上模型服务,请检查网络或模型地址。" + }, + { + "name": "localGenui_localBadge", + "value": "在本机运行" + }, + { + "name": "localGenui_newSession", + "value": "开始创作" + }, + { + "name": "localGenui_backToChat", + "value": "对话" + }, + { + "name": "localGenui_generating", + "value": "正在生成…" + }, + { + "name": "localGenui_cancelled", + "value": "本轮已停止。" + }, + { + "name": "localGenui_modelNotConfigured", + "value": "请先为本地小应用配置模型服务。" + }, + { + "name": "localGenui_unsupportedAction", + "value": "此处不支持 %1$s:%2$s" + }, + { + "name": "localGenui_appMissing", + "value": "找不到这个应用了。" + }, + { + "name": "localGenui_appUnsupported", + "value": "这个应用是用其他版本做的,暂时打不开,内容已保留。" + }, + { + "name": "localGenui_runtimeMismatch", + "value": "应用组件需要更新,请升级 OpenBitFun 后再试。" + }, + { + "name": "localGenui_saveFailed", + "value": "修改未保存:%1$s" + }, + { + "name": "localGenui_failed", + "value": "没有生成成功:%1$s" + }, + { + "name": "localGenui_status_candidate", + "value": "正在准备" + }, + { + "name": "localGenui_status_displayable", + "value": "可以使用" + }, + { + "name": "localGenui_status_accepted", + "value": "可以使用" + }, + { + "name": "localGenui_status_failed", + "value": "没有生成成功" + }, + { + "name": "localGenui_status_state_migration_required", + "value": "新版本和已有数据不兼容,已保留原来的版本" + }, + { + "name": "localGenui_status_unsupported", + "value": "当前版本打不开这个应用" + }, + { + "name": "localGenui_apiKey", + "value": "API 密钥" + }, + { + "name": "localGenui_apiKeyKept", + "value": "留空则保留已保存的密钥" + }, + { + "name": "localGenui_saved", + "value": "已保存" + }, + { + "name": "localGenui_autoRepair", + "value": "刚才的应用有点问题,正在自动修正" + }, + { + "name": "localGenui_truncated", + "value": "内容太长没能生成完,可以再发一次,或者让它做得简单些。" + }, + { + "name": "localGenui_history", + "value": "创作记录" + }, + { + "name": "localGenui_noHistory", + "value": "还没有创作记录" + }, + { + "name": "localGenui_generatedApps", + "value": "AI 生成的小应用" + }, + { + "name": "localGenui_modelMissing", + "value": "这个会话使用的模型已删除,请重新选择模型。" + }, + { + "name": "localGenui_manageModels", + "value": "管理模型" + }, + { + "name": "localGenui_addModel", + "value": "添加模型" + }, + { + "name": "localGenui_editModel", + "value": "编辑模型" + }, + { + "name": "localGenui_deleteModel", + "value": "删除模型" + }, + { + "name": "localGenui_noModels", + "value": "还没有模型,先添加一个。" + }, + { + "name": "localGenui_modelDisplayName", + "value": "显示名称" + }, + { + "name": "localGenui_modelDisplayNameHint", + "value": "可选,默认使用模型名称" + }, + { + "name": "localGenui_fetchModels", + "value": "获取模型列表" + }, + { + "name": "localGenui_noRemoteModels", + "value": "服务没有返回模型列表,请手动填写模型名称。" + }, + { + "name": "localGenui_addToGallery", + "value": "添加到小应用" + }, + { + "name": "localGenui_inGallery", + "value": "已在小应用中" + }, + { + "name": "localGenui_removeFromGallery", + "value": "从小应用移除" + }, + { + "name": "localGenui_addedToGallery", + "value": "已添加到小应用" + }, + { + "name": "localGenui_entry", + "value": "创建小应用" + }, + { + "name": "localGenui_linkUnsupported", + "value": "本地会话中无法打开这个链接。" + }, + { + "name": "localGenui_generationInvalid", + "value": "这次没能做出应用,再发一次试试,或者换个说法。" + }, + { + "name": "genui_card_name", + "value": "AI 小应用" + }, + { + "name": "genui_card_desc", + "value": "打开在本机生成的小应用" + }, + { + "name": "genui_card_pending", + "value": "打开 OpenBitFun" + }, + { + "name": "genui_card_missing", + "value": "小应用已删除" + }, + { + "name": "localGenui_addToDesktop", + "value": "添加到桌面" + }, + { + "name": "localGenui_addedToDesktop", + "value": "已添加到桌面" + }, + { + "name": "localGenui_addToDesktopFailed", + "value": "无法添加到桌面" + }, + { + "name": "localGenui_appActions", + "value": "小应用操作" + }, + { + "name": "localGenui_calendarCreated", + "value": "已添加日程(编号 %1$s)" + }, + { + "name": "localGenui_calendarUpdated", + "value": "已更新日程(编号 %1$s)" + }, + { + "name": "localGenui_calendarDeleted", + "value": "已删除日程(编号 %1$s)" + }, + { + "name": "localGenui_calendarListed", + "value": "找到 %1$s 个日程" + }, + { + "name": "collaboration_title", + "value": "跨设备取材验证" + }, + { + "name": "collaboration_requirements", + "value": "两端需登录同一华为账号并开启 WLAN 和蓝牙。由系统选择设备,每次接收一张图片。" + }, + { + "name": "collaboration_emulatorNotice", + "value": "模拟器用于验证构建和界面。系统能力声明不代表已发现设备;真实取材与回传需在支持的设备上验证。" + }, + { + "name": "collaboration_photo", + "value": "从其他设备拍照" + }, + { + "name": "collaboration_scan", + "value": "从其他设备扫描文档" + }, + { + "name": "collaboration_gallery", + "value": "选择其他设备的图片" + }, + { + "name": "collaboration_reset", + "value": "重新开始验证" + }, + { + "name": "collaboration_resize", + "value": "切换内容宽度" + }, + { + "name": "collaboration_resetNotice", + "value": "重新开始会关闭本地接收并清除预览,不代表已取消对端操作。此验证入口不保存图片,也不向模型发送图片。" + }, + { + "name": "collaboration_result", + "value": "已接收 {0} 张图片 · 系统状态码 {1}" + }, + { + "name": "collaboration_receivedImage", + "value": "跨设备接收的图片" + }, + { + "name": "collaboration_phase_ready", + "value": "等待选择取材方式" + }, + { + "name": "collaboration_phase_selecting", + "value": "等待在系统菜单选择设备" + }, + { + "name": "collaboration_phase_active", + "value": "协同已建立,等待对端操作" + }, + { + "name": "collaboration_phase_receiving", + "value": "正在接收和解析图片" + }, + { + "name": "collaboration_phase_completed", + "value": "图片接收完成" + }, + { + "name": "collaboration_phase_cancelled", + "value": "操作已取消" + }, + { + "name": "collaboration_phase_failed", + "value": "取材失败" + }, + { + "name": "collaboration_phase_closed", + "value": "本地接收已关闭" + }, + { + "name": "collaboration_phase_unavailable", + "value": "当前环境不可用" + }, + { + "name": "collaboration_reason_missingSyscap", + "value": "系统未声明跨设备取材能力。" + }, + { + "name": "collaboration_reason_version", + "value": "此取材适配需要 API 23 或更高版本,当前系统不支持。" + }, + { + "name": "collaboration_reason_deviceType", + "value": "当前设备类型不支持发起此操作。" + }, + { + "name": "collaboration_reason_probeFailed", + "value": "读取系统能力失败,请重新开始验证。" + }, + { + "name": "collaboration_reason_peerCancelled", + "value": "对端取消了操作。" + }, + { + "name": "collaboration_reason_localCancelled", + "value": "本端取消了操作。" + }, + { + "name": "collaboration_reason_invalidImage", + "value": "系统未返回有效的图片数据。" + }, + { + "name": "collaboration_reason_imageLimit", + "value": "超出本次验证的图片限制:一张图片,最大 32 MiB。" + }, + { + "name": "collaboration_reason_decodeFailed", + "value": "收到数据但无法解码为图片。" + }, + { + "name": "collaboration_reason_emptyResult", + "value": "传输结束,但未收到图片。" + }, + { + "name": "collaboration_reason_platformError", + "value": "系统协同返回错误,请查看状态码。" + }, + { + "name": "collaboration_inputTitle", + "value": "从其他设备取材" + }, + { + "name": "collaboration_closeInput", + "value": "结束本次接收" } ] } diff --git a/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/HMSymbolVF.ttf b/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/HMSymbolVF.ttf new file mode 100644 index 0000000..06664fb Binary files /dev/null and b/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/HMSymbolVF.ttf differ diff --git a/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/LICENSE.txt b/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/LICENSE.txt new file mode 100644 index 0000000..9cd4524 --- /dev/null +++ b/src/apps/mobile/harmonyos/genui-runtime/fonts/hm-symbol/LICENSE.txt @@ -0,0 +1,33 @@ +License Notice +Copyright 2021 Huawei Device Co., Ltd. +HarmonyOS Sans Fonts Software is licensed under HarmonyOS Sans Fonts License Agreement. + +-------------------------------------------------------------------------------- +HarmonyOS Sans Fonts License Agreement + +THIS HARMONYOS SANS FONTS LICENSE AGREEMENT ("AGREEMENT") IS A LEGAL AGREEMENT BETWEEN YOU (EITHER A SINGLE INDIVIDUAL, OR SINGLE LEGAL ENTITY) AND HUAWEI DEVICE CO., LTD.( "LICENSOR")FOR THE USE OF THE HARMONYOS SANS FONTS ACCOMPANYING THIS AGREEMENT.BY DOWNLOADING,COPYING OR OTHERWISE USING HARMONYOS SANS FONTS YOU INDICATE THAT YOU AGREE TO BE BOUND BY ALL OF THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT, YOU MAY NOT DOWNLOAD, COPY OR OTHERWISE USE THE HARMONYOS SANS FONTS, AND YOU SHALL PROMPTLY DESTROY AND DELETE ALL THE HARMONYOS SANS FONTS. + +1.Definition +"HarmonyOS Sans Fonts" shall mean the collection of fonts software components provided by Licensor under this Agreement and clearly marked as "HarmonyOS¬ Sans". + +"YOU" shall mean an individual or legal entity exercising permissions granted by this Agreement. + +2.GRANT OF LICENSE + +Subject to the terms and conditions of this Agreement, Licensor hereby grant YOU a non-transferable, non-exclusive, royalty-free, revocable, worldwide copyright license to use,copy, merge, embed, bundle, redistribute and/or sell unmodified copies of HarmonyOS Sans Fonts with any software except for fonts software,subject to the following conditions: +1)YOU shall make a prominent notice in the software to state that HarmonyOS Sans Fonts are used. +2)YOU may not make any modifications to HarmonyOS Sans Fonts or any of their individual components. +3)Neither HarmonyOS Sans Fonts nor any of their individual components may be redistributed or sold in a stand-alone base. This limitation does not apply to any work created by using HarmonyOS Sans Fonts. You can freely distribute or sell your work, such as materials, logos, application software etc. created by using HarmonyOS Sans Fonts. +4)YOU shall retain the copyright notice and this Agreement in any copies of HarmonyOS Sans Fonts. + +3.Termination +This Agreement will be automatically terminated if YOU breach any of this Agreement. + +4.NO WARRANTY +YOU AGREE THAT THE HARMONYOS SANS FONTS ARE PROVIDED BY LICENSOR ON AN "AS IS" BASIS. LICENSOR MAKES NO WARRANTY, EXPRESSED OR IMPLIED OR STATUTORY, WITH RESPECT TO ANY OF THE HARMONYOS SANS FONTS, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. + +5.NO LIABILITY + +IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY DIRECT OR INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE OF OR INABILITY TO USE HARMONYOS SANS FONTS, WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHER LEGAL THEORY, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +YOU EXPRESSLY ASSUME ALL LIABILITIES AND RISKS FOR USE OF HARMONYOS SANS FONTS. SHOULD THE HARMONYOS SANS FONTS PROVE DEFECTIVE, YOU ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. diff --git a/src/apps/mobile/harmonyos/genui-runtime/package.json b/src/apps/mobile/harmonyos/genui-runtime/package.json new file mode 100644 index 0000000..9f34aff --- /dev/null +++ b/src/apps/mobile/harmonyos/genui-runtime/package.json @@ -0,0 +1,24 @@ +{ + "name": "@openbitfun/harmony-genui-runtime", + "private": true, + "type": "module", + "dependencies": { + "@openuidev/lang-core": "1.0.2", + "@openuidev/react-lang": "1.0.2", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "lucide-react": "^0.560.0", + "katex": "^0.16.25", + "maplibre-gl": "^6.16.0", + "react-markdown": "^10.1.0", + "remark-gfm": "^4.0.1", + "zod": "^4.6.7", + "@openbitfun/theme-openbitfun": "workspace:^", + "decode-named-character-reference": "1.3.0" + }, + "devDependencies": { + "vite": "^7.0.4", + "@vitejs/plugin-react": "^4.6.0", + "sass": "^1.93.2" + } +} diff --git a/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.scss b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.scss new file mode 100644 index 0000000..b293298 --- /dev/null +++ b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.scss @@ -0,0 +1,21 @@ +.gen-ui-application { container-type: inline-size; padding: 20px; color: var(--openbitfun-color-content-primary); background: var(--openbitfun-color-surface-canvas); font-size: var(--openbitfun-type-body-md-font-size); line-height: var(--openbitfun-type-body-md-line-height); } +.gen-ui-application > [role="alert"] { color: var(--openbitfun-color-status-danger-content); } + +.gen-ui-host-viewport { min-width: 0; } +.gen-ui-phone-device { box-sizing: border-box; width: 390px; margin-inline: auto; padding: 13px; border: 1px solid var(--openbitfun-color-border-default); border-radius: 40px; background: var(--openbitfun-color-surface-panel); box-shadow: var(--openbitfun-shadow-lg); } +.gen-ui-phone-viewport { box-sizing: border-box; width: 360px; height: 764px; overflow: hidden; border-radius: 27px; background: var(--openbitfun-color-surface-canvas); color: var(--openbitfun-color-content-primary); } +.gen-ui-phone-status-bar { box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; color: var(--openbitfun-color-content-primary); background: var(--openbitfun-color-surface-canvas); font-family: var(--openbitfun-type-body-sm-font-family); font-size: var(--openbitfun-type-body-sm-font-size); font-weight: var(--openbitfun-type-body-sm-font-weight); line-height: var(--openbitfun-type-body-sm-line-height); } +.gen-ui-phone-status-bar__indicators { font-size: var(--openbitfun-type-body-sm-font-size); } +.gen-ui-phone-content { box-sizing: border-box; width: 360px; height: calc(100% - 36px); overflow: auto; padding: 16px; } +.gen-ui-phone-content > .gen-ui-application { box-sizing: border-box; width: 100%; min-height: 100%; padding: 0; background: transparent; } +.gen-ui-phone-content .gen-ui-application__header h1 { font-size: var(--openbitfun-type-heading-section-font-size); line-height: var(--openbitfun-type-heading-section-line-height); } +.gen-ui-phone-content [data-gen-ui-node] { max-width: 100%; } +.gen-ui-phone-viewport--native { width: 100%; height: auto; min-height: 100%; border-radius: 0; overflow: visible; } +/* On the device the page fills the screen; the Harmony page kit owns its gutter. */ +.gen-ui-phone-content--native { width: 100%; height: auto; min-height: 100%; overflow: visible; } +.gen-ui-phone-content:has(> .gen-ui-application--harmony-genui) { padding: 0; } +.gen-ui-application--document { min-width: 0; padding: 0; background: transparent; } +.gen-ui-html-document { width: 100%; min-width: 0; overflow: hidden; } +.gen-ui-html-document__frame { display: block; width: 100%; min-width: 0; min-height: 220px; height: 100%; border: 0; background: transparent; color-scheme: inherit; } +.gen-ui-phone-content .gen-ui-html-document { width: 100%; min-height: 100%; } +.gen-ui-phone-content .gen-ui-html-document__frame { height: calc(764px - 36px - 32px); min-height: 0; } diff --git a/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx new file mode 100644 index 0000000..a75e213 --- /dev/null +++ b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx @@ -0,0 +1,181 @@ +import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; +import type { GenUIAppDefinition, GenUIAppEnvelope, GenUIAppState } from './genUITypes'; +import { designSpecForApp, libraryFor, preflightGenUIApp } from './genUIContract'; +import { GenUIStateStore, genUIContentKey, validateGenUIState } from './genUIState'; +import type { GenUIVerification } from './genUIVerification'; +import './GenUIApplication.scss'; +import GenUIHostSurface, { type GenUIHostShellMode } from './GenUIHostSurface'; +import GenUISourceDocument from './GenUISourceDocument'; +import { inspectGenUIHtmlSource } from './GenUIHtmlDocument'; +import type { GenUIOpenUIActionEvent, GenUIOpenUIToolProvider } from './genUIOpenUI'; +import type { GenUIHtmlBridge } from './GenUIHtmlDocument'; +import { GenUIStream } from './genUIStream'; +import { genUIProduct, type GenUIProduct } from './genUIProduct'; +import type { GenUIAsyncRuntime, GenUIProviderInput, GenUITargetEvent } from './genUIAsyncCapabilities'; +import { createGenUIAsyncRuntime } from './genUIAsyncCapabilities'; +import { HARMONY_STYLE_RESOURCE_CSS } from './components/vendor/harmonyStyles'; +import { HARMONY_GENUI_SCOPED_CSS } from './components/vendor/harmony-genui/harmonyGenuiStyles.generated'; +import { HARMONY_AURORA_CSS } from './components/harmonyAuroraStyles'; +import { harmonyPresentation } from './harmonyPresentation'; +import type { GenUIRenderDiagnostic } from './genUIRenderDiagnostics'; +import { installGenUIGenerationPresentation, type GenUIGenerationPresentation } from './genUIGenerationPresentation'; + +export interface GenUIApplicationProps { + product?: GenUIProduct; + definition: GenUIAppEnvelope; + initialState?: GenUIAppState; + readOnly?: boolean; + streaming?: boolean; + restoredFromStorage?: boolean; + preview?: boolean; + onStateChange?: (state: GenUIAppState) => void | Promise; + /** Persist only after the owning surface has accepted the source. */ + persistState?: boolean; + onAction?: (event: GenUIOpenUIActionEvent) => void | Promise; + toolProvider?: GenUIOpenUIToolProvider; + asyncProvider?: GenUIProviderInput; + asyncPermissions?: readonly string[]; + asyncTarget?: 'local' | 'workspace' | 'peer' | 'unsupported'; + asyncTargetId?: string; + onTargetEvent?: (event: GenUITargetEvent) => void | Promise; + htmlBridge?: GenUIHtmlBridge; + onVerification?: (report: GenUIVerification) => void; + /** Device hosts that draw their own frame/status bar use `native`. */ + hostShell?: GenUIHostShellMode; + onParseResult?: (result: unknown) => void; +} + +export default function GenUIApplication(props: GenUIApplicationProps) { + return ; +} + +function Application({ product = genUIProduct, definition, initialState, readOnly = false, preview = false, streaming = false, restoredFromStorage = false, onStateChange, persistState = true, onAction, toolProvider, asyncProvider, asyncPermissions, asyncTarget = 'local', asyncTargetId, onTargetEvent, htmlBridge, onVerification, hostShell = 'emulated', onParseResult }: GenUIApplicationProps) { + const stream = useRef(new GenUIStream()); + const sourceKey = genUIContentKey(definition); + const app = useMemo(() => (streaming ? stream.current.project(definition, product.catalog) : definition as GenUIAppDefinition), [definition, streaming, product]); + const definitionKey = sourceKey; + const preflight = useMemo(() => streaming ? { accepted: true, issues: [] } : preflightGenUIApp(app, false, product.catalog), [app, streaming, product]); + const designSpec = designSpecForApp(app, product.catalog); + const library = libraryFor(app, product.catalog); + const source = app.source; + const harmony = app.libraryId.startsWith('openbitfun.harmony'); + const harmonyStyle = harmonyPresentation(app); + // Keep one async controller for the mounted FlowChat application. The + // source key still changes for admission and late-result isolation, but it + // must not remount every map/image component as OpenUI receives fragments. + // Keep provider identity stable across OpenUI source fragments. The + // renderer reconciles completed statements while streaming; using the full + // source text here would abort an image/route request on every token. + const runtimeIdentity = `${app.id}:${app.libraryId}:${app.source?.kind ?? 'unknown'}`; + const asyncRuntime = useMemo(() => createGenUIAsyncRuntime({ + provider: asyncProvider ?? toolProvider, + appId: app.id, + sourceKey: runtimeIdentity, + policy: { permissions: asyncPermissions, target: asyncTarget, targetId: asyncTargetId }, + onTargetEvent, + }), [asyncProvider, toolProvider, app.id, runtimeIdentity, asyncPermissions, asyncTarget, asyncTargetId, onTargetEvent]); + const runtimeSourceInitialized = useRef(false); + useLayoutEffect(() => { + asyncRuntime?.updateSourceKey?.(runtimeIdentity, runtimeSourceInitialized.current); + runtimeSourceInitialized.current = true; + }, [asyncRuntime, runtimeIdentity]); + useEffect(() => { + if (!asyncRuntime) return; + asyncRuntime.setTargetEventHandler?.(onTargetEvent); + }, [asyncRuntime, onTargetEvent]); + useEffect(() => () => asyncRuntime?.abortAll('GenUI source was replaced or unmounted'), [asyncRuntime]); + const sourceIssues = useMemo(() => source?.kind === 'html-document' ? inspectGenUIHtmlSource(source, designSpec) : [], [source, designSpec]); + const generationPresentation = useRef(undefined); + useEffect(() => { + if (streaming) { + const presentation = installGenUIGenerationPresentation({ + root: Array.from(document.querySelectorAll('[data-gen-ui-app]')) + .find(element => element.dataset.genUiApp === app.id), + }); + generationPresentation.current = presentation; + return () => { + if (generationPresentation.current === presentation) { + presentation.dispose(); + generationPresentation.current = undefined; + } + }; + } + + const presentation = generationPresentation.current; + generationPresentation.current = undefined; + if (presentation) void presentation.finish(); + return () => presentation?.dispose(); + }, [streaming]); + const store = useRef(new GenUIStateStore()); + const [state, setState] = useState(() => store.current.initialize(app, initialState)); + const [persistence, setPersistence] = useState('unverified'); + const [saveError, setSaveError] = useState(''); + const [openUIError, setOpenUIError] = useState(''); + const [observed, setObserved] = useState(false); + const baseline = useRef(initialState); + const dirty = useRef(false); + const alive = useRef(true); + const stateRef = useRef(state); + stateRef.current = state; + const lastStateKey = useRef(genUIContentKey(state)); + // Treat verification as an event sink. Hosts commonly update their own + // state from a report, which gives them a new callback identity on the next + // render. The report itself is keyed by reportKey; callback identity must + // not cause the effect to emit the same report again. + const onVerificationRef = useRef(onVerification); + useEffect(() => () => { alive.current = false; }, []); + useEffect(() => { onVerificationRef.current = onVerification; }, [onVerification]); + useEffect(() => { + baseline.current = initialState; + if (!dirty.current) setState(store.current.initialize(app, initialState)); + }, [definitionKey, app, initialState]); + const stateIssues = preflight.accepted ? validateGenUIState(app, state) : []; + const renderErrors = !library ? [`GenUI library ${app.libraryId}@${app.libraryRevision} is unavailable`] : !source ? ['GenUI source is required; semantic graph documents were removed'] : sourceIssues.length ? sourceIssues : openUIError ? [openUIError] : []; + const render: GenUIVerification['render'] = renderErrors.length ? 'failed' : streaming ? 'unverified' : 'passed'; + const checks: GenUIVerification['checks'] = renderErrors.length || stateIssues.length ? 'failed' : source?.kind === 'html-document' ? 'passed' : streaming ? 'unverified' : 'passed'; + const report: GenUIVerification = { + definitionKey, + state, + checks, + preflight: streaming ? 'unverified' : preflight.accepted && !stateIssues.length ? 'passed' : 'failed', + render, + interaction: observed ? 'observed' : 'unverified', + persistence, + reopen: restoredFromStorage ? 'restored' : 'unverified', + issues: [...preflight.issues, ...stateIssues, ...renderErrors.map(message => ({ path: 'source', message, code: 'render', severity: 'error' as const })), ...(saveError ? [{ path: 'app_state', message: saveError, code: 'persistence', severity: 'error' as const }] : [])], + }; + const reportKey = JSON.stringify(report); + useEffect(() => { onVerificationRef.current?.(JSON.parse(reportKey)); }, [reportKey]); + // Streaming only controls parser mode. It must not disable already mounted + // local controls; persistence remains explicitly gated by persistState. + // A streamed source is an interactive transient preview. Only a confirmed + // render failure (or an explicitly read-only/preview host) locks controls; + // persistence is still independently gated by `persistState`. + const locked = readOnly || preview || render === 'failed'; + const save = (next: GenUIAppState) => { + if (!persistState || locked || !onStateChange) return; + setPersistence('saving'); setSaveError(''); + Promise.resolve(onStateChange(next)).then(() => { if (alive.current) setPersistence('saved'); }, error => { if (alive.current) { setPersistence('failed'); setSaveError(error instanceof Error ? error.message : String(error)); } }); + }; + if (!source) { + return
Semantic graph GenUI documents are no longer supported. Generate a complete OpenUI or HTML source document.
; + } + return +
+ {harmony ? ${REPORTER}${html}`; +} + +export const HtmlView = defineComponent({ + name: "HtmlView", + props: z.object({ + html: z.string(), + height: z.number().optional(), + title: z.string().optional(), + }), + description: "Sandboxed HTML page with inline JS, for games and canvas. No network except script CDNs. Fits its content unless height is set.", + component: function HtmlViewView({ props }) { + const streaming = useIsStreaming(); + const frame = useRef(null); + const box = useRef(null); + const scheme = useColorScheme(box); + const fixed = typeof props.height === "number" && props.height > 0 ? Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, props.height)) : null; + const [measured, setMeasured] = useState(null); + const html = typeof props.html === "string" ? props.html : ""; + const srcDoc = useMemo(() => documentFor(html, scheme), [html, scheme]); + + useEffect(() => { + if (fixed) return; + const onMessage = (event: MessageEvent) => { + if (event.source !== frame.current?.contentWindow) return; + const data = event.data as { type?: unknown; height?: unknown }; + if (data?.type === "iui-html-view-height" && typeof data.height === "number" && Number.isFinite(data.height)) { + setMeasured(Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, data.height))); + } + }; + window.addEventListener("message", onMessage); + frame.current?.contentWindow?.postMessage("iui-html-view-measure", "*"); + return () => window.removeEventListener("message", onMessage); + }, [fixed]); + + // A page that is still streaming would reload on every chunk; it runs once complete. + const height = fixed ?? measured ?? AUTO_START; + return ( +
+ {streaming ? ( +
Preparing the interactive view…
+ ) : ( +