From 5149865c387ab252f76be5784cbb99a4af0cb361 Mon Sep 17 00:00:00 2001 From: Dan Brewster Date: Tue, 12 May 2026 02:06:10 -0400 Subject: [PATCH 01/25] add a2ui message rendering --- apps/tlon-web/cosmos.config.json | 3 +- apps/tlon-web/vite.cosmos.config.mts | 87 +++ packages/api/src/__tests__/a2ui.test.ts | 100 +++ .../src/__tests__/postContent.a2ui.test.ts | 39 ++ packages/api/src/client/a2ui.ts | 340 ++++++++++ packages/api/src/client/content-helpers.ts | 4 + packages/api/src/client/index.ts | 1 + packages/api/src/client/postContent.ts | 15 + packages/app/fixtures/A2UI.fixture.tsx | 626 ++++++++++++++++++ .../ChatMessage/StaticChatMessage.tsx | 31 + .../ui/components/PostContent/A2UIBlock.tsx | 280 ++++++++ .../components/PostContent/BlockRenderer.tsx | 3 + .../PostContent/ContentRenderer.tsx | 2 + .../components/PostContent/contentUtils.tsx | 7 + 14 files changed, 1536 insertions(+), 2 deletions(-) create mode 100644 apps/tlon-web/vite.cosmos.config.mts create mode 100644 packages/api/src/__tests__/a2ui.test.ts create mode 100644 packages/api/src/__tests__/postContent.a2ui.test.ts create mode 100644 packages/api/src/client/a2ui.ts create mode 100644 packages/app/fixtures/A2UI.fixture.tsx create mode 100644 packages/app/ui/components/PostContent/A2UIBlock.tsx diff --git a/apps/tlon-web/cosmos.config.json b/apps/tlon-web/cosmos.config.json index b0e1a3281c..5b43149a2e 100644 --- a/apps/tlon-web/cosmos.config.json +++ b/apps/tlon-web/cosmos.config.json @@ -3,12 +3,11 @@ "hostname": "localhost", "port": 5555, "vite": { - "configPath": "./vite.config.mts" + "configPath": "./vite.cosmos.config.mts" }, "dom": { "containerQuerySelector": "#app" }, "fixturesLocation": "../../packages/app/fixtures", - "rendererUrl": "http://localhost:5050/apps/groups/", "plugins": ["react-cosmos-plugin-vite"] } diff --git a/apps/tlon-web/vite.cosmos.config.mts b/apps/tlon-web/vite.cosmos.config.mts new file mode 100644 index 0000000000..09eed7b58a --- /dev/null +++ b/apps/tlon-web/vite.cosmos.config.mts @@ -0,0 +1,87 @@ +/// +import { tamaguiPlugin } from '@tamagui/vite-plugin'; +import react from '@vitejs/plugin-react'; +import fs from 'fs'; +import { fileURLToPath } from 'url'; +import { Plugin, PluginOption, defineConfig, loadEnv } from 'vite'; +import svgr from 'vite-plugin-svgr'; + +import expo52PatchPlugin from './expo52PatchPlugin'; +import packageJson from './package.json'; +import reactNativeWeb from './reactNativeWebPlugin'; + +// Dedicated Vite config for React Cosmos. +// +// react-cosmos-plugin-vite 7.2.0 misbehaves when the host config sets `base`: +// the renderer swap can miss, causing the real app to boot inside the renderer. +// Keep Cosmos on a minimal config without `base`, Urbit proxy, PWA, or Sentry. +export default defineConfig(({ mode }) => { + process.env.VITE_STORAGE_VERSION = packageJson.version; + Object.assign(process.env, loadEnv(mode, process.cwd())); + + return { + envPrefix: ['VITE_', 'TAMAGUI_'], + plugins: [ + cosmosIndexHtmlPlugin(), + exportingRawText(/\.sql$/), + expo52PatchPlugin(), + react({ + babel: { + plugins: [ + '@babel/plugin-proposal-export-namespace-from', + 'react-native-worklets/plugin', + ], + }, + jsxImportSource: '@welldone-software/why-did-you-render', + }) as PluginOption[], + svgr({ include: '**/*.svg' }) as Plugin, + reactNativeWeb(), + tamaguiPlugin({ + config: './tamagui.config.ts', + platform: 'web', + }) as Plugin, + ], + resolve: { + conditions: ['tlon-source'], + dedupe: ['@tanstack/react-query'], + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)), + 'virtual:pwa-register/react': fileURLToPath( + new URL('./src/logic/useAppUpdatesStub.ts', import.meta.url) + ), + 'react-native-reanimated': fileURLToPath( + new URL('../../node_modules/react-native-reanimated', import.meta.url) + ), + }, + }, + optimizeDeps: { + exclude: ['sqlocal', 'virtual:pwa-register/react'], + }, + }; +}); + +function cosmosIndexHtmlPlugin(): Plugin { + return { + name: 'cosmos index html', + enforce: 'pre', + transformIndexHtml(html) { + return html.replace( + /\s*