@patodo/localapp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.localapp-artifact.json +2731 -0
- package/LICENSE +21 -0
- package/README.md +288 -0
- package/bin/localapp.mjs +34182 -0
- package/package.json +21 -0
- package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
- package/runtime/native/adapter-manifest.json +85 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
- package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/linux-x64/localapp-notifications +0 -0
- package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
- package/runtime/native/win32-x64/localapp-native.exe +0 -0
- package/runtime/server/.localapp-server-runtime.json +133 -0
- package/runtime/server/bin/server-cli.cjs +8343 -0
- package/runtime/server/bin/server.mjs +8 -0
- package/runtime/server/bin/worker.cjs +144339 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
- package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
- package/runtime/server/node_modules/sql.js/package.json +58 -0
- package/runtime/server/package.json +11 -0
- package/runtime/server/runner/localapp-runner.mjs +324 -0
- package/runtime/server/web/404.html +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
- package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
- package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
- package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
- package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
- package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
- package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
- package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
- package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
- package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
- package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
- package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
- package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
- package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
- package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
- package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
- package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
- package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
- package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
- package/runtime/server/web/home/redline-launch-hero.png +0 -0
- package/runtime/server/web/inbox.html +1 -0
- package/runtime/server/web/inbox.txt +27 -0
- package/runtime/server/web/index.html +1 -0
- package/runtime/server/web/index.txt +27 -0
- package/runtime/server/web/my/analytics.html +1 -0
- package/runtime/server/web/my/analytics.txt +27 -0
- package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
- package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
- package/runtime/server/web/my/apps.html +1 -0
- package/runtime/server/web/my/apps.txt +27 -0
- package/runtime/server/web/my/dashboard.html +1 -0
- package/runtime/server/web/my/dashboard.txt +27 -0
- package/runtime/server/web/my/device-actions.html +1 -0
- package/runtime/server/web/my/device-actions.txt +24 -0
- package/runtime/server/web/my/device-notifications.html +1 -0
- package/runtime/server/web/my/device-notifications.txt +24 -0
- package/runtime/server/web/my/favorites.html +1 -0
- package/runtime/server/web/my/favorites.txt +27 -0
- package/runtime/server/web/my/groups.html +1 -0
- package/runtime/server/web/my/groups.txt +27 -0
- package/runtime/server/web/my/info.html +1 -0
- package/runtime/server/web/my/info.txt +27 -0
- package/runtime/server/web/my/keys.html +1 -0
- package/runtime/server/web/my/keys.txt +27 -0
- package/runtime/server/web/my/orgs.html +1 -0
- package/runtime/server/web/my/orgs.txt +27 -0
- package/runtime/server/web/my/pages.html +1 -0
- package/runtime/server/web/my/pages.txt +27 -0
- package/runtime/server/web/my/peers.html +1 -0
- package/runtime/server/web/my/peers.txt +24 -0
- package/runtime/server/web/my/recent.html +1 -0
- package/runtime/server/web/my/recent.txt +27 -0
- package/runtime/server/web/my/settings.html +1 -0
- package/runtime/server/web/my/settings.txt +27 -0
- package/runtime/server/web/my/studio.html +1 -0
- package/runtime/server/web/my/studio.txt +24 -0
- package/runtime/server/web/my/subscriptions.html +1 -0
- package/runtime/server/web/my/subscriptions.txt +27 -0
- package/runtime/server/web/my/system.html +1 -0
- package/runtime/server/web/my/system.txt +24 -0
- package/runtime/server/web/my/tasks.html +1 -0
- package/runtime/server/web/my/tasks.txt +24 -0
- package/runtime/server/web/my/users.html +1 -0
- package/runtime/server/web/my/users.txt +27 -0
- package/runtime/server/web/my.html +1 -0
- package/runtime/server/web/my.txt +27 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
- package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
- package/runtime/server/web/platform-shell-preview.html +1 -0
- package/runtime/server/web/platform-shell-preview.txt +23 -0
- package/runtime/server/web/setup.html +1 -0
- package/runtime/server/web/setup.txt +23 -0
- package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
- package/template/.claude/skills/localapp/SKILL.md +80 -0
- package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
- package/template/.claude/skills/localapp-business/SKILL.md +325 -0
- package/template/.claude/skills/localapp-data/SKILL.md +381 -0
- package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
- package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
- package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
- package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
- package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
- package/template/AGENTS.md +33 -0
- package/template/CLAUDE.md +117 -0
- package/template/ISSUES.md +32 -0
- package/template/backend/resources/work_items/mutations.json +83 -0
- package/template/backend/resources/work_items/queries.json +83 -0
- package/template/backend/resources/work_items/schema.json +31 -0
- package/template/backend/schemas/mutations.schema.json +15 -0
- package/template/backend/schemas/queries.schema.json +36 -0
- package/template/backend/schemas/resource-schema.schema.json +25 -0
- package/template/components.json +25 -0
- package/template/index.html +12 -0
- package/template/migrations/001_work_items.sql +6 -0
- package/template/package.json +70 -0
- package/template/postcss.config.js +5 -0
- package/template/runtime/dev-shell.tsx +6398 -0
- package/template/runtime/hooks/use-mobile.ts +19 -0
- package/template/runtime/issue-reference.ts +44 -0
- package/template/runtime/lib/utils.ts +6 -0
- package/template/runtime/package.json +14 -0
- package/template/runtime/platform-capabilities.json +109 -0
- package/template/runtime/sdk/agent/package.json +51 -0
- package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
- package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
- package/template/runtime/sdk/agent/src/context.ts +56 -0
- package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
- package/template/runtime/sdk/agent/src/index.ts +19 -0
- package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
- package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
- package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
- package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
- package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
- package/template/runtime/sdk/agent/src/tools.ts +70 -0
- package/template/runtime/sdk/agent/src/types.ts +27 -0
- package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
- package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
- package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
- package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
- package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
- package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
- package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
- package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
- package/template/runtime/sdk/agent/tsconfig.json +18 -0
- package/template/runtime/sdk/agent/vitest.config.ts +8 -0
- package/template/runtime/sdk/backend/package.json +15 -0
- package/template/runtime/sdk/backend/src/index.ts +92 -0
- package/template/runtime/sdk/backend/tsconfig.json +8 -0
- package/template/runtime/sdk/core/package.json +15 -0
- package/template/runtime/sdk/core/src/client.ts +317 -0
- package/template/runtime/sdk/core/src/collaboration.ts +66 -0
- package/template/runtime/sdk/core/src/desktop.ts +469 -0
- package/template/runtime/sdk/core/src/device.ts +112 -0
- package/template/runtime/sdk/core/src/index.ts +6 -0
- package/template/runtime/sdk/core/src/invalidate.ts +40 -0
- package/template/runtime/sdk/core/src/types.ts +108 -0
- package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
- package/template/runtime/sdk/core/tests/client.test.ts +424 -0
- package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
- package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
- package/template/runtime/sdk/core/tests/device.test.ts +69 -0
- package/template/runtime/sdk/core/tsconfig.json +17 -0
- package/template/runtime/sdk/react/package.json +34 -0
- package/template/runtime/sdk/react/src/client.ts +7 -0
- package/template/runtime/sdk/react/src/components/can.tsx +24 -0
- package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
- package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
- package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
- package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
- package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
- package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
- package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
- package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
- package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
- package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
- package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
- package/template/runtime/sdk/react/src/index.ts +40 -0
- package/template/runtime/sdk/react/src/permissions.ts +94 -0
- package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
- package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
- package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
- package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
- package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
- package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
- package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
- package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
- package/template/runtime/sdk/react/tsconfig.json +18 -0
- package/template/runtime/sdk/react/vitest.config.ts +9 -0
- package/template/runtime/sdk/react/vitest.setup.ts +6 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
- package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/index.d.ts +19 -0
- package/template/runtime/server-core/dist/index.d.ts.map +1 -0
- package/template/runtime/server-core/dist/index.js +35 -0
- package/template/runtime/server-core/dist/index.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
- package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
- package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
- package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
- package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
- package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
- package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
- package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
- package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
- package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/access-control.js +138 -0
- package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
- package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
- package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
- package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
- package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
- package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
- package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
- package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
- package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
- package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
- package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
- package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
- package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
- package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
- package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/migrations.js +180 -0
- package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
- package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
- package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/record-access.js +81 -0
- package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
- package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/transitions.js +142 -0
- package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
- package/template/runtime/server-core/dist/types/models.d.ts +163 -0
- package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
- package/template/runtime/server-core/dist/types/models.js +3 -0
- package/template/runtime/server-core/dist/types/models.js.map +1 -0
- package/template/runtime/server-core/package.json +24 -0
- package/template/runtime/styles/preset.css +282 -0
- package/template/runtime/sync-template-command.cjs +19 -0
- package/template/runtime/sync-template.cjs +71 -0
- package/template/runtime/tsconfig.base.json +20 -0
- package/template/runtime/version.json +3 -0
- package/template/runtime/vite-plugin.mjs +309 -0
- package/template/src/App.tsx +273 -0
- package/template/src/components/ui/accordion.tsx +79 -0
- package/template/src/components/ui/alert-dialog.tsx +197 -0
- package/template/src/components/ui/alert.tsx +76 -0
- package/template/src/components/ui/aspect-ratio.tsx +11 -0
- package/template/src/components/ui/avatar.tsx +110 -0
- package/template/src/components/ui/badge.tsx +49 -0
- package/template/src/components/ui/breadcrumb.tsx +122 -0
- package/template/src/components/ui/button-group.tsx +83 -0
- package/template/src/components/ui/button.tsx +67 -0
- package/template/src/components/ui/calendar.tsx +221 -0
- package/template/src/components/ui/card.tsx +103 -0
- package/template/src/components/ui/carousel.tsx +240 -0
- package/template/src/components/ui/chart.tsx +373 -0
- package/template/src/components/ui/checkbox.tsx +31 -0
- package/template/src/components/ui/collapsible.tsx +33 -0
- package/template/src/components/ui/combobox.tsx +299 -0
- package/template/src/components/ui/command.tsx +193 -0
- package/template/src/components/ui/context-menu.tsx +261 -0
- package/template/src/components/ui/dialog.tsx +168 -0
- package/template/src/components/ui/direction.tsx +22 -0
- package/template/src/components/ui/drawer.tsx +132 -0
- package/template/src/components/ui/dropdown-menu.tsx +269 -0
- package/template/src/components/ui/empty.tsx +104 -0
- package/template/src/components/ui/field.tsx +238 -0
- package/template/src/components/ui/hover-card.tsx +42 -0
- package/template/src/components/ui/input-group.tsx +154 -0
- package/template/src/components/ui/input-otp.tsx +87 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/item.tsx +196 -0
- package/template/src/components/ui/kbd.tsx +26 -0
- package/template/src/components/ui/label.tsx +22 -0
- package/template/src/components/ui/menubar.tsx +280 -0
- package/template/src/components/ui/native-select.tsx +61 -0
- package/template/src/components/ui/navigation-menu.tsx +164 -0
- package/template/src/components/ui/pagination.tsx +129 -0
- package/template/src/components/ui/popover.tsx +87 -0
- package/template/src/components/ui/progress.tsx +31 -0
- package/template/src/components/ui/radio-group.tsx +42 -0
- package/template/src/components/ui/resizable.tsx +50 -0
- package/template/src/components/ui/scroll-area.tsx +53 -0
- package/template/src/components/ui/select.tsx +192 -0
- package/template/src/components/ui/separator.tsx +26 -0
- package/template/src/components/ui/sheet.tsx +145 -0
- package/template/src/components/ui/sidebar.tsx +700 -0
- package/template/src/components/ui/skeleton.tsx +13 -0
- package/template/src/components/ui/slider.tsx +59 -0
- package/template/src/components/ui/sonner.tsx +47 -0
- package/template/src/components/ui/spinner.tsx +10 -0
- package/template/src/components/ui/switch.tsx +33 -0
- package/template/src/components/ui/table.tsx +114 -0
- package/template/src/components/ui/tabs.tsx +90 -0
- package/template/src/components/ui/textarea.tsx +18 -0
- package/template/src/components/ui/toggle-group.tsx +89 -0
- package/template/src/components/ui/toggle.tsx +45 -0
- package/template/src/components/ui/tooltip.tsx +57 -0
- package/template/src/hooks/use-mobile.ts +3 -0
- package/template/src/index.css +4 -0
- package/template/src/lib/utils.ts +3 -0
- package/template/src/main.tsx +10 -0
- package/template/src/vite-env.d.ts +1 -0
- package/template/template.gitignore +10 -0
- package/template/template.npmrc +1 -0
- package/template/tests/agent-context.test.ts +69 -0
- package/template/tests/agent-guidance-template.test.ts +49 -0
- package/template/tests/agent-runtime.test.ts +198 -0
- package/template/tests/agent-tools.test.ts +150 -0
- package/template/tests/agent-use-agent.test.ts +86 -0
- package/template/tests/assistant-ui-adapter.test.ts +211 -0
- package/template/tests/business-modeling-template.test.ts +71 -0
- package/template/tests/client.test.ts +382 -0
- package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
- package/template/tests/dev-shell-context.test.tsx +40 -0
- package/template/tests/dev-shell-template.test.ts +2593 -0
- package/template/tests/invalidation.test.ts +126 -0
- package/template/tests/main-tsx.test.ts +28 -0
- package/template/tests/media-preview-template.test.ts +21 -0
- package/template/tests/mutations.test.ts +224 -0
- package/template/tests/react.test.ts +302 -0
- package/template/tests/redirect.test.ts +51 -0
- package/template/tests/skill-docs.test.ts +76 -0
- package/template/tests/state-transitions-template.test.ts +61 -0
- package/template/tests/template-ui.test.ts +145 -0
- package/template/tests/upload.test.ts +143 -0
- package/template/tests/vite-plugin.test.ts +426 -0
- package/template/tests/vite-proxy-security.test.ts +153 -0
- package/template/tsconfig.json +11 -0
- package/template/vite.config.ts +7 -0
- package/template/vitest.config.ts +16 -0
- package/template/vitest.setup.ts +1 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const VIRTUAL_ID = "\0virtual:localapp-dev.tsx";
|
|
7
|
+
const VIRTUAL_RESOLVE_REQUEST = "/virtual:localapp-dev.tsx";
|
|
8
|
+
const DEV_SHELL_OPTIMIZE_DEPS = ["react-markdown", "remark-gfm", "unified", "remark-parse"];
|
|
9
|
+
const DEV_CSRF_COOKIE = "localapp_dev_csrf";
|
|
10
|
+
const UNSAFE_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
11
|
+
|
|
12
|
+
function boundedProxyContext(requestPath) {
|
|
13
|
+
const escaped = requestPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
14
|
+
return `^${escaped}(?:/|\\?|$)`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 读取项目根的 .localapp/dev-config.json。
|
|
19
|
+
* 缺失或解析失败时返回空对象(dev server 不配 proxy)。
|
|
20
|
+
*/
|
|
21
|
+
function loadDevConfig(projectRoot) {
|
|
22
|
+
try {
|
|
23
|
+
const configPath = path.resolve(projectRoot, ".localapp/dev-config.json");
|
|
24
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
25
|
+
return JSON.parse(raw);
|
|
26
|
+
} catch {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 构建注入 X-API-Key header 的 configure 钩子。
|
|
33
|
+
* dev 模式下 vite proxy 默认不传 cookie/credentials,靠 api_key 鉴权。
|
|
34
|
+
*/
|
|
35
|
+
function buildAuthConfigure(apiKey, devConfig = {}) {
|
|
36
|
+
if (!apiKey && !devConfig.pageName) return undefined;
|
|
37
|
+
return (proxy) => {
|
|
38
|
+
proxy.on("proxyReq", (proxyReq) => {
|
|
39
|
+
if (apiKey) proxyReq.setHeader("X-API-Key", apiKey);
|
|
40
|
+
if (devConfig.pageName) proxyReq.setHeader("X-LocalApp-Dev-Page", devConfig.pageName);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function buildDeviceActionConfigure(apiKey, serverUrl, rawAppScope, shellAppScope, devConfig = {}) {
|
|
46
|
+
if (!apiKey && !rawAppScope && !devConfig.pageName) return undefined;
|
|
47
|
+
return (proxy) => {
|
|
48
|
+
proxy.on("proxyReq", (proxyReq, req) => {
|
|
49
|
+
if (apiKey) proxyReq.setHeader("X-API-Key", apiKey);
|
|
50
|
+
if (devConfig.pageName) proxyReq.setHeader("X-LocalApp-Dev-Page", devConfig.pageName);
|
|
51
|
+
const requestPath = req.url?.split("?", 1)[0];
|
|
52
|
+
if (rawAppScope && req.method === "POST" && ["/api/device-actions", "/api/desktop-actions"].includes(requestPath)) {
|
|
53
|
+
const query = req.url.slice(requestPath.length);
|
|
54
|
+
const endpoint = requestPath.endsWith("device-actions") ? "device-actions" : "desktop-actions";
|
|
55
|
+
proxyReq.path = `${rawAppScope}/api/${endpoint}${query}`;
|
|
56
|
+
proxyReq.setHeader("Referer", `${new URL(serverUrl).origin}${shellAppScope}/`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function buildDeviceActionProxy(devConfig, serverUrl) {
|
|
63
|
+
const hasAppScope = Boolean(devConfig.userId && devConfig.pageName);
|
|
64
|
+
const encodedApp = hasAppScope
|
|
65
|
+
? `${encodeURIComponent(devConfig.userId)}/${encodeURIComponent(devConfig.pageName)}`
|
|
66
|
+
: undefined;
|
|
67
|
+
const rawAppScope = encodedApp ? `/serve/${encodedApp}` : undefined;
|
|
68
|
+
const shellAppScope = encodedApp ? `/${encodedApp}` : undefined;
|
|
69
|
+
const configure = buildDeviceActionConfigure(
|
|
70
|
+
devConfig.apiKey,
|
|
71
|
+
serverUrl,
|
|
72
|
+
rawAppScope,
|
|
73
|
+
shellAppScope,
|
|
74
|
+
devConfig,
|
|
75
|
+
);
|
|
76
|
+
return {
|
|
77
|
+
target: serverUrl,
|
|
78
|
+
changeOrigin: true,
|
|
79
|
+
...(configure ? { configure } : {}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 根据 dev-config 构建 vite proxy 配置。
|
|
85
|
+
* - 所有 API 都走 canonical Server;页面级 API 重写到 /serve/<userId>/<pageName>/api/*
|
|
86
|
+
* - Device Action 创建请求重写到当前开发应用,能力、状态和事件请求走 Server 全局端点
|
|
87
|
+
* - apiKey 非空时所有转发请求注入 X-API-Key header
|
|
88
|
+
*/
|
|
89
|
+
export function buildProxy(devConfig, serverUrl) {
|
|
90
|
+
const proxy = {};
|
|
91
|
+
const configure = buildAuthConfigure(devConfig.apiKey, devConfig);
|
|
92
|
+
|
|
93
|
+
if (!serverUrl) return undefined;
|
|
94
|
+
|
|
95
|
+
const globalEndpoints = [
|
|
96
|
+
"/api/me",
|
|
97
|
+
"/api/users",
|
|
98
|
+
"/api/groups",
|
|
99
|
+
"/api/llm",
|
|
100
|
+
"/api/issues",
|
|
101
|
+
"/api/platform",
|
|
102
|
+
];
|
|
103
|
+
for (const ep of globalEndpoints) {
|
|
104
|
+
proxy[boundedProxyContext(ep)] = { target: serverUrl, changeOrigin: true, ...(configure ? { configure } : {}) };
|
|
105
|
+
}
|
|
106
|
+
proxy[boundedProxyContext("/api/device-actions")] = buildDeviceActionProxy(devConfig, serverUrl);
|
|
107
|
+
proxy[boundedProxyContext("/api/desktop-actions")] = buildDeviceActionProxy(devConfig, serverUrl);
|
|
108
|
+
proxy[boundedProxyContext("/api/dev")] = { target: serverUrl, changeOrigin: true, ...(configure ? { configure } : {}) };
|
|
109
|
+
proxy[boundedProxyContext("/serve")] = { target: serverUrl, changeOrigin: true, ...(configure ? { configure } : {}) };
|
|
110
|
+
|
|
111
|
+
if (devConfig.userId && devConfig.pageName) {
|
|
112
|
+
const apiPrefix = `/serve/${devConfig.userId}/${devConfig.pageName}/api`;
|
|
113
|
+
proxy["/api"] = {
|
|
114
|
+
target: serverUrl,
|
|
115
|
+
changeOrigin: true,
|
|
116
|
+
rewrite: (p) => p.replace(/^\/api/, apiPrefix),
|
|
117
|
+
...(configure ? { configure } : {}),
|
|
118
|
+
};
|
|
119
|
+
} else {
|
|
120
|
+
proxy["/api"] = { target: serverUrl, changeOrigin: true, ...(configure ? { configure } : {}) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { proxy };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function requireCanonicalDevConfig(devConfig) {
|
|
127
|
+
const missing = [];
|
|
128
|
+
for (const field of ["serverUrl", "userId", "pageName"]) {
|
|
129
|
+
if (typeof devConfig?.[field] !== "string" || !devConfig[field].trim()) missing.push(field);
|
|
130
|
+
}
|
|
131
|
+
if (!Number.isInteger(devConfig?.appServerPort) || devConfig.appServerPort < 1 || devConfig.appServerPort > 65535) {
|
|
132
|
+
missing.push("appServerPort");
|
|
133
|
+
}
|
|
134
|
+
if (missing.length > 0) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`localapp: .localapp/dev-config.json is missing required canonical Server fields: ${missing.join(", ")}. Run 'localapp dev' instead of starting Vite directly.`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const serverUrlMatch = /^http:\/\/127\.0\.0\.1:([1-9][0-9]{0,4})$/.exec(devConfig.serverUrl);
|
|
140
|
+
if (!serverUrlMatch || Number(serverUrlMatch[1]) > 65535) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"localapp: .localapp/dev-config.json serverUrl must be exact http://127.0.0.1:<nonzero-port> with no credentials, path, query, or fragment. Run 'localapp dev' to regenerate it.",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function installDevProxySecurity(server, devConfig, csrfToken) {
|
|
148
|
+
const allowedOrigins = new Set([
|
|
149
|
+
`http://127.0.0.1:${devConfig.appServerPort}`,
|
|
150
|
+
`http://localhost:${devConfig.appServerPort}`,
|
|
151
|
+
`https://127.0.0.1:${devConfig.appServerPort}`,
|
|
152
|
+
`https://localhost:${devConfig.appServerPort}`,
|
|
153
|
+
]);
|
|
154
|
+
server.middlewares.use((req, res, next) => {
|
|
155
|
+
const requestPath = new URL(req.url ?? "/", "http://127.0.0.1").pathname;
|
|
156
|
+
const isCredentialedMutation = UNSAFE_METHODS.has(req.method ?? "GET")
|
|
157
|
+
&& (requestPath === "/api" || requestPath.startsWith("/api/") || requestPath === "/serve" || requestPath.startsWith("/serve/"));
|
|
158
|
+
if (isCredentialedMutation) {
|
|
159
|
+
const origin = typeof req.headers.origin === "string" ? req.headers.origin : "";
|
|
160
|
+
const cookies = typeof req.headers.cookie === "string" ? req.headers.cookie.split(";") : [];
|
|
161
|
+
const hasCsrfCookie = cookies.some((cookie) => {
|
|
162
|
+
const [name, value] = cookie.trim().split("=", 2);
|
|
163
|
+
return name === DEV_CSRF_COOKIE && value === csrfToken;
|
|
164
|
+
});
|
|
165
|
+
if (!allowedOrigins.has(origin) || !hasCsrfCookie) {
|
|
166
|
+
res.statusCode = 403;
|
|
167
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
168
|
+
res.end(JSON.stringify({ success: false, error: "LocalApp dev proxy rejected a cross-origin request" }));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!(req.headers.cookie ?? "").includes(`${DEV_CSRF_COOKIE}=`)) {
|
|
173
|
+
res.setHeader(
|
|
174
|
+
"Set-Cookie",
|
|
175
|
+
`${DEV_CSRF_COOKIE}=${csrfToken}; Path=/; HttpOnly; SameSite=Strict`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
next();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function buildDevServer(devConfig, userServer = {}, apiKey) {
|
|
183
|
+
requireCanonicalDevConfig(devConfig);
|
|
184
|
+
if (typeof apiKey !== "string" || !apiKey) {
|
|
185
|
+
throw new Error("localapp: private LOCALAPP_DEV_API_KEY is unavailable. Run 'localapp dev' instead of starting Vite directly.");
|
|
186
|
+
}
|
|
187
|
+
const proxyConfig = buildProxy({ ...devConfig, apiKey }, devConfig.serverUrl);
|
|
188
|
+
return {
|
|
189
|
+
...userServer,
|
|
190
|
+
...(proxyConfig ?? {}),
|
|
191
|
+
host: "127.0.0.1",
|
|
192
|
+
allowedHosts: ["localhost", "127.0.0.1"],
|
|
193
|
+
...(Number.isInteger(devConfig.appServerPort)
|
|
194
|
+
? { port: devConfig.appServerPort, strictPort: true }
|
|
195
|
+
: {}),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 虚拟模块代码:仅 dev 模式注入。
|
|
201
|
+
* 用户 main.tsx 永远只 render(<App />),DevShell 由这里挂载。
|
|
202
|
+
*/
|
|
203
|
+
function buildDevShellVirtualModule() {
|
|
204
|
+
return [
|
|
205
|
+
'import React from "react";',
|
|
206
|
+
'import { createRoot } from "react-dom/client";',
|
|
207
|
+
'import { DevShell } from "@localapp/app-kit/dev-shell";',
|
|
208
|
+
'import "/src/index.css";',
|
|
209
|
+
'import App from "/src/App.tsx";',
|
|
210
|
+
"",
|
|
211
|
+
"createRoot(document.getElementById(\"root\")).render(",
|
|
212
|
+
" React.createElement(",
|
|
213
|
+
" React.StrictMode,",
|
|
214
|
+
" null,",
|
|
215
|
+
" React.createElement(DevShell, null, React.createElement(App)),",
|
|
216
|
+
" ),",
|
|
217
|
+
");",
|
|
218
|
+
"",
|
|
219
|
+
].join("\n");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* localapp vite plugin:封装 dev proxy、@ alias、react 支持、DevShell 虚拟注入。
|
|
224
|
+
*
|
|
225
|
+
* DevShell 注入:dev 模式下 transformIndexHtml 把 main.tsx 替换为虚拟模块,
|
|
226
|
+
* 虚拟模块导入 DevShell 包裹 App;生产构建时所有钩子 no-op,DevShell 不进入 bundle。
|
|
227
|
+
*
|
|
228
|
+
* 用 .mjs 而不是 .ts 是因为该文件会被 vite.config.ts 直接 import,
|
|
229
|
+
* 经过 Node 加载而非 Vite 编译;Node 26+ 的 type stripping 限制
|
|
230
|
+
* 不覆盖 node_modules 下的 .ts 文件。
|
|
231
|
+
*
|
|
232
|
+
* 用法(用户项目根的 vite.config.ts):
|
|
233
|
+
* ```ts
|
|
234
|
+
* import { defineConfig } from "vite";
|
|
235
|
+
* import { localapp } from "@localapp/app-kit/vite";
|
|
236
|
+
*
|
|
237
|
+
* export default defineConfig({
|
|
238
|
+
* plugins: [localapp()],
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* 测试场景下可通过 options.command 显式传入 'serve' 或 'build' 模拟 vite 环境。
|
|
243
|
+
*/
|
|
244
|
+
export function localapp(options = {}) {
|
|
245
|
+
const projectRoot = process.cwd();
|
|
246
|
+
const devConfig = options.devConfig ?? loadDevConfig(projectRoot);
|
|
247
|
+
const devApiKey = options.devApiKey ?? process.env.LOCALAPP_DEV_API_KEY;
|
|
248
|
+
const devCsrfToken = options.devCsrfToken ?? randomBytes(32).toString("hex");
|
|
249
|
+
let command = options.command;
|
|
250
|
+
|
|
251
|
+
const localappPlugin = {
|
|
252
|
+
name: "localapp-runtime",
|
|
253
|
+
config(userConfig, configEnv) {
|
|
254
|
+
command = command || configEnv?.command;
|
|
255
|
+
const devServer = command === "serve"
|
|
256
|
+
? buildDevServer(devConfig, userConfig.server, devApiKey)
|
|
257
|
+
: userConfig.server;
|
|
258
|
+
return {
|
|
259
|
+
...userConfig,
|
|
260
|
+
optimizeDeps: {
|
|
261
|
+
...userConfig.optimizeDeps,
|
|
262
|
+
include: Array.from(new Set([
|
|
263
|
+
...(userConfig.optimizeDeps?.include ?? []),
|
|
264
|
+
...DEV_SHELL_OPTIMIZE_DEPS,
|
|
265
|
+
])),
|
|
266
|
+
},
|
|
267
|
+
resolve: {
|
|
268
|
+
...userConfig.resolve,
|
|
269
|
+
alias: {
|
|
270
|
+
...userConfig.resolve?.alias,
|
|
271
|
+
"@": path.resolve(projectRoot, "./src"),
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
...(devServer ? { server: devServer } : {}),
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
transformIndexHtml(html) {
|
|
278
|
+
if (command !== "serve") return html;
|
|
279
|
+
return html.replace(
|
|
280
|
+
/<script([^>]*?)src="\/src\/main\.tsx(?:\?[^"]*)?"[^>]*><\/script>/g,
|
|
281
|
+
`<script type="module" src="${VIRTUAL_RESOLVE_REQUEST}"></script>`,
|
|
282
|
+
);
|
|
283
|
+
},
|
|
284
|
+
buildStart() {
|
|
285
|
+
if (command !== "serve") return;
|
|
286
|
+
const appPath = path.resolve(projectRoot, "src/App.tsx");
|
|
287
|
+
if (!fs.existsSync(appPath)) {
|
|
288
|
+
console.error(
|
|
289
|
+
`localapp: src/App.tsx not found. The dev shell assumes App at src/App.tsx.`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
configureServer(server) {
|
|
294
|
+
installDevProxySecurity(server, devConfig, devCsrfToken);
|
|
295
|
+
},
|
|
296
|
+
resolveId(id) {
|
|
297
|
+
if (command !== "serve") return null;
|
|
298
|
+
if (id === VIRTUAL_RESOLVE_REQUEST) return VIRTUAL_ID;
|
|
299
|
+
return null;
|
|
300
|
+
},
|
|
301
|
+
load(id) {
|
|
302
|
+
if (command !== "serve") return null;
|
|
303
|
+
if (id === VIRTUAL_ID) return buildDevShellVirtualModule();
|
|
304
|
+
return null;
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
return [react(), localappPlugin];
|
|
309
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Can,
|
|
4
|
+
useMe,
|
|
5
|
+
useMutation,
|
|
6
|
+
useTransitions,
|
|
7
|
+
useQuery,
|
|
8
|
+
type BusinessMetadata,
|
|
9
|
+
} from "@localapp/sdk-react";
|
|
10
|
+
import { useRegisterTools } from "@localapp/sdk-agent";
|
|
11
|
+
import { Badge } from "@/components/ui/badge";
|
|
12
|
+
import { Button } from "@/components/ui/button";
|
|
13
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
14
|
+
import { Input } from "@/components/ui/input";
|
|
15
|
+
import { Label } from "@/components/ui/label";
|
|
16
|
+
|
|
17
|
+
interface WorkItem {
|
|
18
|
+
id: number;
|
|
19
|
+
title: string;
|
|
20
|
+
status: "todo" | "doing" | "done";
|
|
21
|
+
created_by?: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface WorkItemsResult {
|
|
25
|
+
rows: WorkItem[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface DashboardResult {
|
|
29
|
+
rows: Array<{ status: WorkItem["status"]; count: number }>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const WORK_ITEM_BUSINESS: BusinessMetadata = {
|
|
33
|
+
statusField: "status",
|
|
34
|
+
recordAccess: {
|
|
35
|
+
create: { mode: "authenticated" },
|
|
36
|
+
update: { mode: "ownerField", field: "created_by" },
|
|
37
|
+
delete: { mode: "ownerField", field: "created_by" },
|
|
38
|
+
},
|
|
39
|
+
transitions: [
|
|
40
|
+
{ name: "start", label: "开始", from: ["todo"], to: "doing" },
|
|
41
|
+
{ name: "complete", label: "完成", from: ["doing"], to: "done" },
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const WORK_ITEM_SCHEMA = {
|
|
46
|
+
business: {
|
|
47
|
+
...WORK_ITEM_BUSINESS,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function WorkItemRow({
|
|
52
|
+
item,
|
|
53
|
+
onDone,
|
|
54
|
+
}: {
|
|
55
|
+
item: WorkItem;
|
|
56
|
+
onDone: () => Promise<void>;
|
|
57
|
+
}) {
|
|
58
|
+
const done = item.status === "done";
|
|
59
|
+
const { transitions, transition, loading: transitioning } = useTransitions("work_items", item, WORK_ITEM_BUSINESS, {
|
|
60
|
+
onSuccess: () => {
|
|
61
|
+
void onDone();
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className="flex items-center justify-between rounded-lg border p-3">
|
|
67
|
+
<div>
|
|
68
|
+
<p className="font-medium">{item.title}</p>
|
|
69
|
+
<p className="text-xs text-muted-foreground">
|
|
70
|
+
ID: {item.id}
|
|
71
|
+
{item.created_by ? ` · 创建者: ${item.created_by}` : ""}
|
|
72
|
+
</p>
|
|
73
|
+
</div>
|
|
74
|
+
<div className="flex items-center gap-2">
|
|
75
|
+
<Badge variant={done ? "default" : "outline"}>
|
|
76
|
+
{done ? "已完成" : item.status === "doing" ? "进行中" : "待处理"}
|
|
77
|
+
</Badge>
|
|
78
|
+
{transitions.map((itemTransition) => (
|
|
79
|
+
<Button
|
|
80
|
+
key={itemTransition.name}
|
|
81
|
+
variant="outline"
|
|
82
|
+
size="sm"
|
|
83
|
+
disabled={transitioning}
|
|
84
|
+
onClick={() => void transition(itemTransition.name)}
|
|
85
|
+
>
|
|
86
|
+
{itemTransition.label ?? itemTransition.name}
|
|
87
|
+
</Button>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default function App() {
|
|
95
|
+
const { me, loading: loadingMe } = useMe();
|
|
96
|
+
const listQuery = useQuery<WorkItemsResult>();
|
|
97
|
+
const dashboardQuery = useQuery<DashboardResult>();
|
|
98
|
+
const { mutate, loading: mutating, error: mutationError } = useMutation();
|
|
99
|
+
const [items, setItems] = useState<WorkItem[]>([]);
|
|
100
|
+
const [dashboard, setDashboard] = useState<DashboardResult["rows"]>([]);
|
|
101
|
+
const [title, setTitle] = useState("");
|
|
102
|
+
|
|
103
|
+
async function refresh() {
|
|
104
|
+
const [list, stats] = await Promise.all([
|
|
105
|
+
listQuery.query("work_items.mine", { limit: 50, offset: 0 }),
|
|
106
|
+
dashboardQuery.query("work_items.dashboard"),
|
|
107
|
+
]);
|
|
108
|
+
setItems(list.rows);
|
|
109
|
+
setDashboard(stats.rows);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function createWorkItem(nextTitle = title) {
|
|
113
|
+
const trimmed = nextTitle.trim();
|
|
114
|
+
if (!trimmed) return "请输入工作项标题";
|
|
115
|
+
|
|
116
|
+
await mutate("$work_items.create", {
|
|
117
|
+
title: trimmed,
|
|
118
|
+
status: "todo",
|
|
119
|
+
});
|
|
120
|
+
setTitle("");
|
|
121
|
+
await refresh();
|
|
122
|
+
return `已创建工作项: ${trimmed}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function completeWorkItem(id: number) {
|
|
126
|
+
await mutate("$work_items.complete", { id });
|
|
127
|
+
await refresh();
|
|
128
|
+
return `已完成工作项 #${id}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
void refresh();
|
|
133
|
+
}, []);
|
|
134
|
+
|
|
135
|
+
useRegisterTools({
|
|
136
|
+
tools: {
|
|
137
|
+
createWorkItem: {
|
|
138
|
+
description: "创建一个工作项",
|
|
139
|
+
parameters: {
|
|
140
|
+
title: { type: "string", required: true, description: "工作项标题" },
|
|
141
|
+
},
|
|
142
|
+
execute: async (args) => createWorkItem(String(args.title ?? "")),
|
|
143
|
+
},
|
|
144
|
+
completeWorkItem: {
|
|
145
|
+
description: "完成一个工作项",
|
|
146
|
+
parameters: {
|
|
147
|
+
id: { type: "number", required: true, description: "工作项 ID" },
|
|
148
|
+
},
|
|
149
|
+
execute: async (args) => completeWorkItem(Number(args.id)),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
systemHint: "这是一个工作项示例应用。创建和完成都使用 named SQL mutation。",
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const counts = useMemo(() => {
|
|
156
|
+
const map = new Map(dashboard.map((row) => [row.status, Number(row.count)]));
|
|
157
|
+
return {
|
|
158
|
+
todo: map.get("todo") ?? 0,
|
|
159
|
+
doing: map.get("doing") ?? 0,
|
|
160
|
+
done: map.get("done") ?? 0,
|
|
161
|
+
};
|
|
162
|
+
}, [dashboard]);
|
|
163
|
+
|
|
164
|
+
const querying = listQuery.loading || dashboardQuery.loading;
|
|
165
|
+
const error = listQuery.error ?? dashboardQuery.error ?? mutationError;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<main className="min-h-screen bg-background px-6 py-8 text-foreground">
|
|
169
|
+
<div className="mx-auto flex w-full max-w-5xl flex-col gap-6">
|
|
170
|
+
<header className="flex flex-col gap-3 border-b pb-5 sm:flex-row sm:items-end sm:justify-between">
|
|
171
|
+
<div>
|
|
172
|
+
<p className="text-sm text-muted-foreground">LocalApp App</p>
|
|
173
|
+
<h1 className="text-3xl font-semibold tracking-tight">工作项</h1>
|
|
174
|
+
</div>
|
|
175
|
+
<Badge variant="secondary">
|
|
176
|
+
{loadingMe ? "正在识别用户" : me ? `你好,${me.name}` : "未登录访客"}
|
|
177
|
+
</Badge>
|
|
178
|
+
</header>
|
|
179
|
+
|
|
180
|
+
<div className="grid gap-4 sm:grid-cols-3">
|
|
181
|
+
<Card>
|
|
182
|
+
<CardHeader className="pb-2">
|
|
183
|
+
<CardDescription>待处理</CardDescription>
|
|
184
|
+
<CardTitle className="text-3xl">{counts.todo}</CardTitle>
|
|
185
|
+
</CardHeader>
|
|
186
|
+
</Card>
|
|
187
|
+
<Card>
|
|
188
|
+
<CardHeader className="pb-2">
|
|
189
|
+
<CardDescription>进行中</CardDescription>
|
|
190
|
+
<CardTitle className="text-3xl">{counts.doing}</CardTitle>
|
|
191
|
+
</CardHeader>
|
|
192
|
+
</Card>
|
|
193
|
+
<Card>
|
|
194
|
+
<CardHeader className="pb-2">
|
|
195
|
+
<CardDescription>已完成</CardDescription>
|
|
196
|
+
<CardTitle className="text-3xl">{counts.done}</CardTitle>
|
|
197
|
+
</CardHeader>
|
|
198
|
+
</Card>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div className="grid gap-4 lg:grid-cols-[360px_1fr]">
|
|
202
|
+
<Card>
|
|
203
|
+
<CardHeader>
|
|
204
|
+
<CardTitle>新建工作项</CardTitle>
|
|
205
|
+
<CardDescription>当前用户会作为创建者写入。</CardDescription>
|
|
206
|
+
</CardHeader>
|
|
207
|
+
<CardContent>
|
|
208
|
+
<form
|
|
209
|
+
className="space-y-4"
|
|
210
|
+
onSubmit={async (event) => {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
await createWorkItem();
|
|
213
|
+
}}
|
|
214
|
+
>
|
|
215
|
+
<div className="space-y-2">
|
|
216
|
+
<Label htmlFor="work-title">标题</Label>
|
|
217
|
+
<Input
|
|
218
|
+
id="work-title"
|
|
219
|
+
value={title}
|
|
220
|
+
onChange={(event) => setTitle(event.target.value)}
|
|
221
|
+
placeholder="例如:整理审批规则"
|
|
222
|
+
required
|
|
223
|
+
/>
|
|
224
|
+
</div>
|
|
225
|
+
<Can action="create" schema={WORK_ITEM_SCHEMA}>
|
|
226
|
+
<Button type="submit" disabled={mutating || !title.trim()} className="w-full">
|
|
227
|
+
{mutating ? "创建中..." : "创建"}
|
|
228
|
+
</Button>
|
|
229
|
+
</Can>
|
|
230
|
+
</form>
|
|
231
|
+
{error ? (
|
|
232
|
+
<p className="mt-4 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
233
|
+
{error.message}
|
|
234
|
+
</p>
|
|
235
|
+
) : null}
|
|
236
|
+
</CardContent>
|
|
237
|
+
</Card>
|
|
238
|
+
|
|
239
|
+
<Card>
|
|
240
|
+
<CardHeader className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
|
|
241
|
+
<div>
|
|
242
|
+
<CardTitle>我的工作项</CardTitle>
|
|
243
|
+
<CardDescription>只显示当前用户创建的记录。</CardDescription>
|
|
244
|
+
</div>
|
|
245
|
+
<Button variant="outline" onClick={() => refresh()} disabled={querying}>
|
|
246
|
+
刷新
|
|
247
|
+
</Button>
|
|
248
|
+
</CardHeader>
|
|
249
|
+
<CardContent>
|
|
250
|
+
{querying && items.length === 0 ? (
|
|
251
|
+
<p className="text-sm text-muted-foreground">正在加载...</p>
|
|
252
|
+
) : items.length === 0 ? (
|
|
253
|
+
<div className="rounded-lg border border-dashed p-6 text-center text-sm text-muted-foreground">
|
|
254
|
+
暂无工作项。
|
|
255
|
+
</div>
|
|
256
|
+
) : (
|
|
257
|
+
<div className="space-y-2">
|
|
258
|
+
{items.map((item) => (
|
|
259
|
+
<WorkItemRow
|
|
260
|
+
key={item.id}
|
|
261
|
+
item={item}
|
|
262
|
+
onDone={refresh}
|
|
263
|
+
/>
|
|
264
|
+
))}
|
|
265
|
+
</div>
|
|
266
|
+
)}
|
|
267
|
+
</CardContent>
|
|
268
|
+
</Card>
|
|
269
|
+
</div>
|
|
270
|
+
</div>
|
|
271
|
+
</main>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Accordion as AccordionPrimitive } from "radix-ui"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
function Accordion({
|
|
8
|
+
className,
|
|
9
|
+
...props
|
|
10
|
+
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
|
11
|
+
return (
|
|
12
|
+
<AccordionPrimitive.Root
|
|
13
|
+
data-slot="accordion"
|
|
14
|
+
className={cn("flex w-full flex-col", className)}
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function AccordionItem({
|
|
21
|
+
className,
|
|
22
|
+
...props
|
|
23
|
+
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
|
24
|
+
return (
|
|
25
|
+
<AccordionPrimitive.Item
|
|
26
|
+
data-slot="accordion-item"
|
|
27
|
+
className={cn("not-last:border-b", className)}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function AccordionTrigger({
|
|
34
|
+
className,
|
|
35
|
+
children,
|
|
36
|
+
...props
|
|
37
|
+
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
|
38
|
+
return (
|
|
39
|
+
<AccordionPrimitive.Header className="flex">
|
|
40
|
+
<AccordionPrimitive.Trigger
|
|
41
|
+
data-slot="accordion-trigger"
|
|
42
|
+
className={cn(
|
|
43
|
+
"group/accordion-trigger relative flex flex-1 items-start justify-between rounded-lg border border-transparent py-2.5 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:after:border-ring disabled:pointer-events-none disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
|
|
44
|
+
className
|
|
45
|
+
)}
|
|
46
|
+
{...props}
|
|
47
|
+
>
|
|
48
|
+
{children}
|
|
49
|
+
<ChevronDownIcon data-slot="accordion-trigger-icon" className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden" />
|
|
50
|
+
<ChevronUpIcon data-slot="accordion-trigger-icon" className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline" />
|
|
51
|
+
</AccordionPrimitive.Trigger>
|
|
52
|
+
</AccordionPrimitive.Header>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function AccordionContent({
|
|
57
|
+
className,
|
|
58
|
+
children,
|
|
59
|
+
...props
|
|
60
|
+
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
|
61
|
+
return (
|
|
62
|
+
<AccordionPrimitive.Content
|
|
63
|
+
data-slot="accordion-content"
|
|
64
|
+
className="overflow-hidden text-sm data-open:animate-accordion-down data-closed:animate-accordion-up"
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
className={cn(
|
|
69
|
+
"h-(--radix-accordion-content-height) pt-0 pb-2.5 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",
|
|
70
|
+
className
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</div>
|
|
75
|
+
</AccordionPrimitive.Content>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|