@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,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-device-actions
|
|
3
|
+
description: >
|
|
4
|
+
在当前点击应用按钮的电脑上执行受用户确认和最小权限约束的本地操作。
|
|
5
|
+
适用于导出、写入用户明确选择的目录、调用本机工具等通用设备能力;不包含任何特定应用的安装协议。
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 通用 Device Actions
|
|
9
|
+
|
|
10
|
+
Device Action 是统一 Server 提供给应用的受控本机操作能力。应用通过 SDK 的 `device.run()` 发起请求。它不是远程控制,也不选择另一台设备:一次请求永远由当前点击按钮的这台电脑上的本地 Server 执行。
|
|
11
|
+
|
|
12
|
+
## 设计要求
|
|
13
|
+
|
|
14
|
+
1. 在执行前展示标题、说明、输入值、目标路径和权限;失败时展示可读错误和可重试入口。
|
|
15
|
+
2. `filesystemRead` / `filesystemWrite` 只列出实际需要的绝对目录,优先使用用户刚刚选择的单一目录,不申请家目录或根目录。
|
|
16
|
+
3. 默认关闭 `network` 和 `childProcess`。开启 `childProcess` 等于允许当前操作系统用户权限下的任意子进程,必须单独解释风险。
|
|
17
|
+
4. 脚本只接收结构化 `input`,校验相对名称、大小和路径边界;输出 JSON 可序列化、有限大小且有稳定类型。
|
|
18
|
+
5. Scheme 只负责传递短期激活票据;脚本、依赖、凭据和用户数据留在 Server 端。
|
|
19
|
+
|
|
20
|
+
## 最小写入示例
|
|
21
|
+
|
|
22
|
+
下面的示例把用户显式选中的文件写入用户显式选择的目录。应用应在调用前完成 `selectedRoot` 和 `relativeName` 的确认,并把 `selectedRoot` 规范化为绝对路径。
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { useDeviceAction } from "@localapp/sdk-react";
|
|
26
|
+
|
|
27
|
+
type WriteResult = { path: string; bytes: number };
|
|
28
|
+
|
|
29
|
+
export function ExportButton({ selectedRoot }: { selectedRoot: string }) {
|
|
30
|
+
const { run, loading, error } = useDeviceAction<WriteResult>();
|
|
31
|
+
|
|
32
|
+
async function exportFile() {
|
|
33
|
+
const snapshot = await run({
|
|
34
|
+
title: "导出用户选择的文件",
|
|
35
|
+
description: `将结果写入:${selectedRoot}`,
|
|
36
|
+
permissions: { filesystemWrite: [selectedRoot] },
|
|
37
|
+
input: {
|
|
38
|
+
selectedRoot,
|
|
39
|
+
relativeName: "exports/result.json",
|
|
40
|
+
contents: JSON.stringify({ exportedAt: new Date().toISOString() }),
|
|
41
|
+
},
|
|
42
|
+
script: `
|
|
43
|
+
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
44
|
+
const { resolve, relative, dirname } = await import("node:path");
|
|
45
|
+
const root = resolve(input.selectedRoot);
|
|
46
|
+
const output = resolve(root, input.relativeName);
|
|
47
|
+
if (relative(root, output).startsWith("..")) throw new Error("目标路径越界");
|
|
48
|
+
await mkdir(dirname(output), { recursive: true });
|
|
49
|
+
await writeFile(output, input.contents, { encoding: "utf8", flag: "w" });
|
|
50
|
+
return { path: output, bytes: Buffer.byteLength(input.contents, "utf8") };
|
|
51
|
+
`,
|
|
52
|
+
});
|
|
53
|
+
return snapshot.result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return <button onClick={exportFile} disabled={loading}>{error ? "重试导出" : "导出"}</button>;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
实际应用应将内容和文件名限制在业务需要的范围内,避免把任意脚本、任意绝对路径或 Server secret 作为输入传给 Action。
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-notify
|
|
3
|
+
description: >
|
|
4
|
+
LocalApp 通知(Notifications)能力使用指南。当用户提到"通知"、"notify"、
|
|
5
|
+
"推送消息"、"桌面弹窗"、"订阅应用"、"收件箱"、"_localapp_notifiers"、
|
|
6
|
+
"manifest notify"时使用。也适用于用户说"应用要发通知给订阅者"、
|
|
7
|
+
"团队通知"、"怎么实现推送"等场景。
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# LocalApp 通知能力
|
|
11
|
+
|
|
12
|
+
让订阅了本应用的用户在收件箱 / 桌面 daemon 收到本应用推送的通知。
|
|
13
|
+
|
|
14
|
+
## 启用通知(manifest.json)
|
|
15
|
+
|
|
16
|
+
在 manifest 加 `notify.enabled: true` 即可开启 **Level 1 owner-only** 模式:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"name": "leave-app",
|
|
21
|
+
"distDir": "dist",
|
|
22
|
+
"notify": { "enabled": true }
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
上传后 Platform Shell 会在该 app 的导航栏显示 🔔 按钮,其他用户可以订阅。
|
|
27
|
+
默认情况下 **只有 app owner** 能调 notify 端点推送通知。
|
|
28
|
+
|
|
29
|
+
## 三层权限模型
|
|
30
|
+
|
|
31
|
+
| Level | 配置 | 谁能发通知 |
|
|
32
|
+
|-------|------|-----------|
|
|
33
|
+
| 1 | `{ enabled: true }`(默认) | 仅 app owner |
|
|
34
|
+
| 2 | app 数据库建 `_localapp_notifiers` 表 | owner + 表中所有 user_id |
|
|
35
|
+
| 3 | `notify.permission = { table, userColumn, where? }` | owner + 自定义 SQL 命中的用户 |
|
|
36
|
+
|
|
37
|
+
### Level 2:团队通知(推荐中级用法)
|
|
38
|
+
|
|
39
|
+
在你的 app SQLite 中创建约定表(schema 固定):
|
|
40
|
+
|
|
41
|
+
```sql
|
|
42
|
+
CREATE TABLE _localapp_notifiers (user_id TEXT PRIMARY KEY);
|
|
43
|
+
INSERT INTO _localapp_notifiers (user_id) VALUES ('alice');
|
|
44
|
+
INSERT INTO _localapp_notifiers (user_id) VALUES ('bob');
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
server 自动检测该表存在 → 切到 Level 2,表中 user 都能调 notify。
|
|
48
|
+
|
|
49
|
+
### Level 3:自定义 SQL(高级)
|
|
50
|
+
|
|
51
|
+
`manifest.json`:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"notify": {
|
|
56
|
+
"enabled": true,
|
|
57
|
+
"permission": {
|
|
58
|
+
"table": "users",
|
|
59
|
+
"userColumn": "id",
|
|
60
|
+
"where": "role = 'supervisor'"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
server 执行:`SELECT 1 FROM users WHERE id = ? AND (role = 'supervisor') LIMIT 1`
|
|
67
|
+
|
|
68
|
+
**安全约束**(违反则回退到 Level 1/2):
|
|
69
|
+
- `table` / `userColumn` 必须是 `[A-Za-z_][A-Za-z0-9_]*` 标识符
|
|
70
|
+
- `where` 不得含分号、注释、UNION/INSERT/UPDATE/DELETE/DROP 等关键字
|
|
71
|
+
|
|
72
|
+
## 调用 notify 端点
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
// 浏览器内(前端 JS),同源 fetch
|
|
76
|
+
await fetch("/serve/{owner}/{app}/api/notify", {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/json" },
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
title: "新请假申请", // 必填,≤200
|
|
81
|
+
body: "张三 提交了年假申请", // 可选,≤1000
|
|
82
|
+
url: "/{owner}/{app}/leaves/123", // 可选,必须相对路径
|
|
83
|
+
priority: "normal", // 可选,normal|high
|
|
84
|
+
to: ["alice", "bob"], // 可选,定向接收者;缺省广播给所有订阅者
|
|
85
|
+
data: { leaveId: 123 }, // 可选,序列化 ≤4KB
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**关键约束**:
|
|
91
|
+
- 必须带 `Referer` 头,且 pathname 以 `/{owner}/{app}/` 开头(防跨 app 冒用)
|
|
92
|
+
- 每个 app 限流:100/小时 + 10/分钟(突发)。超额返回 429 + Retry-After
|
|
93
|
+
|
|
94
|
+
## 等级 × 优先级路由矩阵
|
|
95
|
+
|
|
96
|
+
订阅者选的等级(all / important / muted)影响 WS 推送,但**不影响入库**:
|
|
97
|
+
|
|
98
|
+
| level \ priority | normal | high |
|
|
99
|
+
|------------------|--------|------|
|
|
100
|
+
| all | 入库+推送 | 入库+推送 |
|
|
101
|
+
| important | 仅入库 | 入库+推送 |
|
|
102
|
+
| muted | 仅入库 | 仅入库 |
|
|
103
|
+
|
|
104
|
+
muted 即使 high 也不推送——用户主权优先于发布者紧急程度。
|
|
105
|
+
|
|
106
|
+
## 测试 checklist
|
|
107
|
+
|
|
108
|
+
- [ ] manifest 含 `notify.enabled: true`
|
|
109
|
+
- [ ] 上传后访问 `/{owner}/{app}/`,导航栏出现 🔔 按钮
|
|
110
|
+
- [ ] 用非 owner 账号订阅,刷新后按钮显示等级
|
|
111
|
+
- [ ] owner 调 notify → 订阅者收件箱可见
|
|
112
|
+
- [ ] 浏览器开发者工具检查请求带 `Referer` 头
|
|
113
|
+
|
|
114
|
+
## 更多
|
|
115
|
+
|
|
116
|
+
- [收件箱 API](../../../packages/server/src/routes/inbox.ts)
|
|
117
|
+
- [订阅 API](../../../packages/server/src/routes/subscribe.ts)
|
|
118
|
+
- [WS 消息总线](../../../packages/server/src/routes/ws.ts)(daemon 客户端用)
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-transitions
|
|
3
|
+
description: >
|
|
4
|
+
LocalApp 状态流转(state transitions)建模指南——把业务状态的合法迁移
|
|
5
|
+
作为前端元数据声明在 schema `business.transitions[]`,前端用 `useTransitions()`
|
|
6
|
+
本地计算可用动作;实际执行由应用在 `backend/resources/<table>/mutations.json`
|
|
7
|
+
中声明的 named mutation(如 `$<table>.<action>`)承担。当用户要在 LocalApp
|
|
8
|
+
项目中实现请假/报销/工单等带"提交""审批""驳回""完成"等状态变化的应用时触发;
|
|
9
|
+
也适用于用户说"提交后不能改"、"审批通过/拒绝"、"任务流转"、"状态机"、
|
|
10
|
+
"按钮控制状态"等场景。
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# LocalApp 状态流转
|
|
14
|
+
|
|
15
|
+
业务状态变化通过 **`business.transitions[]` 元数据 + named mutation 执行** 完成,
|
|
16
|
+
**不要用 `useUpdate` 改 status 字段**。
|
|
17
|
+
|
|
18
|
+
核心思路(两段式):
|
|
19
|
+
|
|
20
|
+
1. **元数据声明**:把"哪些状态可以转出/转入、谁能转、目标状态"写进 schema 的
|
|
21
|
+
`business.transitions[]`,前端 SDK 据此本地计算可用按钮。
|
|
22
|
+
2. **执行入口**:在 `backend/resources/<table>/mutations.json` 中为每个状态流转
|
|
23
|
+
声明对应的 named mutation(如 `$leaves.submit`、`$leaves.approve`),SQL 中
|
|
24
|
+
显式校验当前状态(WHERE 子句)并写入目标状态。
|
|
25
|
+
|
|
26
|
+
> 平台不再提供 `/api/{resource}/{id}/transitions` 服务端执行端点(restrict-app-api-to-named-sql
|
|
27
|
+
> 变更移除)。transitions 降级为前端 UI 提示用的元数据,状态机的正确性由 SQL WHERE
|
|
28
|
+
> 子句保证。
|
|
29
|
+
|
|
30
|
+
## schema business.transitions 格式
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"fields": {
|
|
35
|
+
"title": { "type": "string", "constraints": { "required": true } },
|
|
36
|
+
"created_by": { "type": "string" },
|
|
37
|
+
"status": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"constraints": { "defaultValue": "draft", "enum": ["draft", "submitted", "approved", "rejected"] }
|
|
40
|
+
},
|
|
41
|
+
"submitted_at": { "type": "timestamp" },
|
|
42
|
+
"reviewed_by": { "type": "string" },
|
|
43
|
+
"reviewed_at": { "type": "timestamp" }
|
|
44
|
+
},
|
|
45
|
+
"business": {
|
|
46
|
+
"kind": "request",
|
|
47
|
+
"ownerField": "created_by",
|
|
48
|
+
"statusField": "status",
|
|
49
|
+
"initialStatus": "draft",
|
|
50
|
+
"transitions": [
|
|
51
|
+
{ "name": "submit", "label": "提交", "from": ["draft"], "to": "submitted" },
|
|
52
|
+
{ "name": "approve", "label": "批准", "from": ["submitted"], "to": "approved" },
|
|
53
|
+
{ "name": "reject", "label": "驳回", "from": ["submitted"], "to": "rejected" }
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
字段含义:
|
|
60
|
+
|
|
61
|
+
- `statusField`:状态字段名(必须存在于 migration 表结构中)
|
|
62
|
+
- `initialStatus`:新建记录的初始状态(不写时为 null)
|
|
63
|
+
- `transitions[]`:合法状态迁移定义(前端 UI 用)
|
|
64
|
+
- `name`:transition 唯一标识(用于命名 `$<resource>.<name>` mutation)
|
|
65
|
+
- `label`:显示给用户的按钮文字
|
|
66
|
+
- `from`:当前状态必须命中此数组之一才允许执行(前端据此过滤可用按钮)
|
|
67
|
+
- `to`:执行后写入 statusField 的值(仅作 UI 提示,实际写入由 SQL 负责)
|
|
68
|
+
|
|
69
|
+
> `access` / `set` 字段在原服务端执行模型下有意义,现已移除。访问控制改由
|
|
70
|
+
> named mutation 的 `access` 字段表达,字段写入(如 `reviewed_at = :now`、
|
|
71
|
+
> `reviewed_by = :currentUser.id`)改由 SQL 语句直接表达。
|
|
72
|
+
|
|
73
|
+
## named mutation:状态流转的实际执行入口
|
|
74
|
+
|
|
75
|
+
为每个 transition 在 `backend/resources/<table>/mutations.json` 声明对应的
|
|
76
|
+
named mutation。SQL 中**必须**在 WHERE 子句校验当前状态:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"$schema": "https://localapp.dev/schemas/backend/mutations.schema.json",
|
|
81
|
+
"mutations": {
|
|
82
|
+
"$leaves.submit": {
|
|
83
|
+
"kind": "mutation",
|
|
84
|
+
"access": "owner",
|
|
85
|
+
"params": { "id": { "type": "number", "required": true } },
|
|
86
|
+
"sql": "UPDATE leaves SET status = 'submitted', submitted_at = :now WHERE id = :id AND status = 'draft' AND created_by = :currentUserId"
|
|
87
|
+
},
|
|
88
|
+
"$leaves.approve": {
|
|
89
|
+
"kind": "mutation",
|
|
90
|
+
"access": "authenticated",
|
|
91
|
+
"params": { "id": { "type": "number", "required": true } },
|
|
92
|
+
"sql": "UPDATE leaves SET status = 'approved', reviewed_by = :currentUserId, reviewed_at = :now WHERE id = :id AND status = 'submitted' AND reviewed_by = :currentUserId"
|
|
93
|
+
},
|
|
94
|
+
"$leaves.reject": {
|
|
95
|
+
"kind": "mutation",
|
|
96
|
+
"access": "authenticated",
|
|
97
|
+
"params": { "id": { "type": "number", "required": true } },
|
|
98
|
+
"sql": "UPDATE leaves SET status = 'rejected', reviewed_at = :now WHERE id = :id AND status = 'submitted' AND reviewed_by = :currentUserId"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
要点:
|
|
105
|
+
|
|
106
|
+
- WHERE 子句包含 `status = '<from>'` 防止非法状态流转
|
|
107
|
+
- WHERE 子句包含权限校验(如 `created_by = :currentUserId`、`reviewed_by = :currentUserId`)实现访问控制
|
|
108
|
+
- `:currentUserId` / `:now` 等系统变量由 named SQL 执行器自动注入,前端无法伪造
|
|
109
|
+
- mutation 的 `access` 字段提供额外的声明级访问控制(如 `"owner"` 限定记录所有者)
|
|
110
|
+
|
|
111
|
+
## React SDK Hook
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { useTransitions } from "@localapp/sdk-react";
|
|
115
|
+
import type { BusinessMetadata } from "@localapp/sdk-react";
|
|
116
|
+
|
|
117
|
+
// 从 /_schemas 端点或静态 import 拿到 schema 元数据
|
|
118
|
+
const leaveSchema: BusinessMetadata = {
|
|
119
|
+
statusField: "status",
|
|
120
|
+
transitions: [
|
|
121
|
+
{ name: "submit", label: "提交", from: ["draft"], to: "submitted" },
|
|
122
|
+
{ name: "approve", label: "批准", from: ["submitted"], to: "approved" },
|
|
123
|
+
{ name: "reject", label: "驳回", from: ["submitted"], to: "rejected" },
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function LeaveRow({ leave }: { leave: Leave }) {
|
|
128
|
+
// 本地计算可用 transitions,不发网络请求
|
|
129
|
+
const { transitions, transition, loading, error } = useTransitions<Leave>(
|
|
130
|
+
"leaves",
|
|
131
|
+
leave,
|
|
132
|
+
leaveSchema,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div>
|
|
137
|
+
<span>{leave.title} — 状态: {leave.status}</span>
|
|
138
|
+
{error && <p className="text-red-500">{error.message}</p>}
|
|
139
|
+
<div>
|
|
140
|
+
{transitions.map((t) => (
|
|
141
|
+
<Button
|
|
142
|
+
key={t.name}
|
|
143
|
+
disabled={loading}
|
|
144
|
+
onClick={async () => {
|
|
145
|
+
try {
|
|
146
|
+
// 内部调用 mutate('$leaves.<name>', { id: leave.id, ...payload })
|
|
147
|
+
await transition(t.name);
|
|
148
|
+
} catch {
|
|
149
|
+
// LocalAppError 已写入 hook 的 error 状态
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
{t.label}
|
|
154
|
+
</Button>
|
|
155
|
+
))}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`useTransitions(resource, record, schema, options?)` 行为:
|
|
163
|
+
|
|
164
|
+
- `record` 必须含 `id` 字段,可为 `null`(适合列表占位行)
|
|
165
|
+
- 本地根据 `schema.statusField` 取 record 当前状态,过滤 `transitions.from` 命中项
|
|
166
|
+
- `transition(name, payload?)`:调用 `mutate('$<resource>.<name>', { id: record.id, ...payload })`
|
|
167
|
+
- `options.onSuccess(result)`:执行成功回调,传入 mutate 返回的 ExecResult
|
|
168
|
+
- 任何错误以 `LocalAppError` 形式写入 `error`
|
|
169
|
+
|
|
170
|
+
## 开发模式验证 transitions
|
|
171
|
+
|
|
172
|
+
运行 `localapp dev` 后,用 Dev Toolkit 验证状态机:
|
|
173
|
+
|
|
174
|
+
- Identity:切到记录所有者、审批人、无权用户和未登录用户,确认按钮显示与 named mutation 的 access 字段一致。
|
|
175
|
+
- Time:切到固定 ISO 时间,执行包含 `:now` 的 mutation,确认 `submitted_at`、`reviewed_at` 等字段写入固定时间。
|
|
176
|
+
- Data:用 snapshot 保存 draft/submitted 等关键状态,restore 后重复验证不同路径。
|
|
177
|
+
- Diagnostics:检查最近请求和 `manifest.business.transitions` 是否与按钮展示一致。
|
|
178
|
+
|
|
179
|
+
切换身份、时间或 restore snapshot 后 DevShell 会派发 `localapp:dev-context-changed`,列表和详情 hooks 会自动刷新。
|
|
180
|
+
|
|
181
|
+
## 为什么不要用 `useUpdate` 改状态
|
|
182
|
+
|
|
183
|
+
- ❌ `useUpdate` 走的是 `$<resource>.update` named mutation,作者可能没在 SQL 里加 status 守卫,前端可以随意把 "approved" 改回 "draft"
|
|
184
|
+
- ❌ 没有 `:now` / `:currentUser.id` 等系统变量自动注入,时间戳和审批人字段需要前端自己填,容易伪造或不一致
|
|
185
|
+
- ❌ 权限分散在 React 组件里,没有集中的"审批人才能改"语义
|
|
186
|
+
|
|
187
|
+
> 在新的 named SQL 唯一通道模型下,`useUpdate` 和 transition mutation 都是 named
|
|
188
|
+
> mutation,技术上没有强制的差异。但**约定**上:状态字段(statusField)的变更
|
|
189
|
+
> 必须走 `$<resource>.<action>` 风格的 transition mutation(含状态守卫),其它
|
|
190
|
+
> 字段的编辑才用 `$<resource>.update`。模板和 Agent 指引据此约束。
|
|
191
|
+
|
|
192
|
+
## 常见模式
|
|
193
|
+
|
|
194
|
+
### 申请-审批(request)
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
draft ──submit──▶ submitted ──approve──▶ approved
|
|
198
|
+
└──reject───▶ rejected
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
- `$leave.submit`:`WHERE id=:id AND status='draft' AND created_by=:currentUserId`
|
|
202
|
+
- `$leave.approve`:`WHERE id=:id AND status='submitted' AND reviewed_by=:currentUserId`,SET 写入 `reviewed_by` / `reviewed_at`
|
|
203
|
+
- `$leave.reject`:同 approve,但 SET 写入 `status='rejected'`
|
|
204
|
+
|
|
205
|
+
### 任务流转(assignment)
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
todo ──start──▶ in_progress ──complete──▶ done
|
|
209
|
+
└──cancel──▶ cancelled
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- `$task.start`:`WHERE id=:id AND status='todo' AND assignee_id=:currentUserId`
|
|
213
|
+
- `$task.complete`:`WHERE id=:id AND status='in_progress' AND assignee_id=:currentUserId`,SET `completed_at`
|
|
214
|
+
- `$task.cancel`:`WHERE id=:id AND status IN ('todo', 'in_progress')`(多源迁移)
|
|
215
|
+
|
|
216
|
+
### 草稿发布(catalog)
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
draft ──publish──▶ published
|
|
220
|
+
draft ──archive──▶ archived
|
|
221
|
+
published ──unpublish──▶ draft
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- 适合产品/文章/配置类目录的发布开关
|
|
225
|
+
- 用 `access: "authenticated"` 默认策略,由 named mutation 的 access 字段控制谁能调用
|
|
226
|
+
|
|
227
|
+
## 反模式
|
|
228
|
+
|
|
229
|
+
- ❌ 用 `useUpdate("leaves", { status: "approved" })` 改状态——绕过状态机守卫
|
|
230
|
+
- ❌ 在前端拼好时间戳或用户 ID 提交——应该用 SQL 里的 `:now` / `:currentUserId` 系统变量
|
|
231
|
+
- ❌ 在 React 中根据当前状态硬编码按钮(`status === "draft" && <Button>提交</Button>`)——和 schema 中的 `from` 不一致时会失同步,应改用 `useTransitions` 本地计算
|
|
232
|
+
- ❌ mutation SQL 忘记在 WHERE 中加状态守卫——非法状态流转将不被拦截
|
|
233
|
+
|
|
234
|
+
## 与其他 skill 的关系
|
|
235
|
+
|
|
236
|
+
- 业务模型选择和 `recordAccess` 配套:见 `localapp-business.md`
|
|
237
|
+
- CRUD Hook 不适合做状态变化:见 `localapp-data.md`
|
|
238
|
+
- `usePermissions()` / `<Can>` 用于 UI 展示判断:见 `localapp-auth.md`
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localapp-ui
|
|
3
|
+
description: >
|
|
4
|
+
LocalApp 应用 UI 开发指南。当前项目预置 shadcn/ui 全量组件。
|
|
5
|
+
当用户要求美化界面、创建表单、列表、仪表盘、管理页、弹窗、筛选器、
|
|
6
|
+
导航布局,或提到 shadcn、组件库、UI、交互体验时使用此 skill。
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# LocalApp UI 组件开发
|
|
10
|
+
|
|
11
|
+
当前模板已经预置 shadcn/ui 全量组件源码,组件位于 `src/components/ui/`。
|
|
12
|
+
|
|
13
|
+
## 导入约定
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { Button } from "@/components/ui/button";
|
|
17
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
18
|
+
import { Input } from "@/components/ui/input";
|
|
19
|
+
import { Label } from "@/components/ui/label";
|
|
20
|
+
import { cn } from "@/lib/utils";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
优先使用 `@/components/ui/*` 和 `@/lib/utils`,不要复制新的组件库实现。
|
|
24
|
+
|
|
25
|
+
## 基础组件优先
|
|
26
|
+
|
|
27
|
+
默认用基础组件组合业务界面:
|
|
28
|
+
|
|
29
|
+
- 表单:`Label`、`Input`、`Textarea`、`Select`、`Checkbox`、`RadioGroup`、`Button`
|
|
30
|
+
- 数据展示:`Card`、`Table`、`Badge`、`Skeleton`、`Empty`
|
|
31
|
+
- 反馈与确认:`Alert`、`Dialog`、`AlertDialog`、`Sonner`
|
|
32
|
+
- 页面组织:`Tabs`、`Separator`、`ScrollArea`
|
|
33
|
+
|
|
34
|
+
除非用户明确需要复杂交互,不要把简单表单或列表做成多层弹窗、命令面板或大型导航。
|
|
35
|
+
|
|
36
|
+
## 复杂组件使用边界
|
|
37
|
+
|
|
38
|
+
以下复杂组件仅在需求明确匹配时使用:
|
|
39
|
+
|
|
40
|
+
- `Command` / `Combobox`:大量选项搜索、快捷命令、全局搜索
|
|
41
|
+
- `Popover`:轻量浮层选择器、筛选器、日期选择承载层
|
|
42
|
+
- `Calendar`:日期或区间选择
|
|
43
|
+
- `Carousel`:图片或内容轮播
|
|
44
|
+
- `Resizable`:可拖拽分栏工作台
|
|
45
|
+
- `Navigation Menu` / `Sidebar`:多页面或多模块应用导航
|
|
46
|
+
- `Chart`:统计图表或趋势分析
|
|
47
|
+
|
|
48
|
+
如果页面只有一个表单、一个 CRUD 列表或一个简单仪表盘,先用基础组件完成清晰可用的体验。
|
|
49
|
+
|
|
50
|
+
## LocalApp 应用模式
|
|
51
|
+
|
|
52
|
+
业务应用通常按这个结构组织:
|
|
53
|
+
|
|
54
|
+
1. 顶部区域显示当前用户、应用标题和主要动作
|
|
55
|
+
2. 中间区域使用 `Card` 承载表单、列表、详情或统计
|
|
56
|
+
3. 数据读取用 `useList` / `useGet` / `useCount`
|
|
57
|
+
4. 数据写入用 `useCreate` / `useUpdate` / `useDelete`,并在成功后 `refresh()`
|
|
58
|
+
5. 表单控件必须有 `Label htmlFor` 关联到对应控件 `id`
|
|
59
|
+
6. 加载、错误、空状态都要有可见 UI
|
|
60
|
+
|
|
61
|
+
## 视觉约束
|
|
62
|
+
|
|
63
|
+
- 让界面服务业务,不做组件陈列页
|
|
64
|
+
- 使用克制的间距、边框、背景和层级
|
|
65
|
+
- 不要用大量渐变、装饰性图形或单一色系堆满页面
|
|
66
|
+
- 操作按钮文字要具体,例如“添加任务”“保存资料”,不要只写“提交”
|
|
67
|
+
- 列表和表格要能快速扫描,重要状态用 `Badge` 标记
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# LocalApp 内容上传
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
平台提供 `useUpload` Hook,让用户可以在前端应用中上传图片或 PDF。内容存储在平台对象存储中,通过返回的 URL 访问。
|
|
6
|
+
|
|
7
|
+
应用代码应通过 `useUpload()` 上传文件。SDK 从当前应用 resource base 推导上传端点:开发页面使用相对 `/api/content/upload`,正式应用会请求 `/serve/<owner>/<app>/api/content/upload`。Server 返回的 `url` 始终是完整应用作用域 `/serve/<owner>/<app>/api/content/<key>`;直接使用该 URL,不要手工拼接全局 `/api/content/{key}`。
|
|
8
|
+
|
|
9
|
+
> 应用内容上传的旧 `/api/upload` 别名已移除;应用代码不得调用 `/api/upload`,所有图片、PDF 等内容统一走 `/api/content/upload`。Server 仍可能保留同路径的、经过认证的部署兼容传输,用于把旧 multipart 发布请求规范化为 `.localapp` 后交给正式安装器;它不是应用内容 API,也不是第二套安装实现。
|
|
10
|
+
|
|
11
|
+
## 限制
|
|
12
|
+
|
|
13
|
+
- **支持的文件类型**: png、jpg、jpeg、gif、webp、svg、pdf
|
|
14
|
+
- **单文件最大**: 10MB
|
|
15
|
+
- 平台同时验证扩展名、MIME 和文件签名;不能仅修改后缀绕过限制
|
|
16
|
+
|
|
17
|
+
使用内容能力时,在 `manifest.json` 声明实际需求,例如:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"requires": {
|
|
22
|
+
"content": {
|
|
23
|
+
"mimeTypes": ["image/png", "application/pdf"],
|
|
24
|
+
"maxBytes": 10485760,
|
|
25
|
+
"inlinePreview": ["image/png", "application/pdf"]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
安装前使用 `localapp check --json` 校验声明与实际代码,随后使用 `localapp app install --target <server-profile>`。命令返回正式应用路径后,仍需在 `/<owner>/<app>/` 验证图片/PDF 读取,PDF 场景还应验证完整读取或 Range 请求。
|
|
32
|
+
|
|
33
|
+
## useUpload() — 上传图片
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { useUpload } from "@localapp/sdk-react";
|
|
37
|
+
|
|
38
|
+
function ImageUploader() {
|
|
39
|
+
const { upload, loading, error } = useUpload();
|
|
40
|
+
|
|
41
|
+
const handleFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
const file = e.target.files?.[0];
|
|
43
|
+
if (!file) return;
|
|
44
|
+
try {
|
|
45
|
+
const result = await upload(file);
|
|
46
|
+
console.log("上传成功:", result.key, result.url);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error("上传失败:", err);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div>
|
|
54
|
+
<input type="file" accept="image/*" onChange={handleFile} disabled={loading} />
|
|
55
|
+
{loading && <p>上传中...</p>}
|
|
56
|
+
{error && <p>错误: {error.message}</p>}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**返回值:**
|
|
63
|
+
- `upload(file: File)` — 上传函数,返回 `{ key: string, url: string }`
|
|
64
|
+
- `loading` — boolean,上传中为 true
|
|
65
|
+
- `error` — LocalAppError | null,上传失败时的错误信息
|
|
66
|
+
|
|
67
|
+
**UploadResult:**
|
|
68
|
+
- `key` — 文件在存储中的唯一标识(如 `abc123.png`)
|
|
69
|
+
- `url` — 文件的访问路径(SDK 自动处理,可直接用作 `<img src={url}>`)
|
|
70
|
+
|
|
71
|
+
## 常用模式:表单中集成图片上传
|
|
72
|
+
|
|
73
|
+
上传图片后将 key 存入数据记录,显示图片时使用 `url` 字段构建完整路径。
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import { useCreate } from "@localapp/sdk-react";
|
|
77
|
+
import { useList } from "@localapp/sdk-react";
|
|
78
|
+
import { useUpload } from "@localapp/sdk-react";
|
|
79
|
+
|
|
80
|
+
interface Product {
|
|
81
|
+
id: number;
|
|
82
|
+
name: string;
|
|
83
|
+
imageKey: string;
|
|
84
|
+
imageUrl: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ProductForm() {
|
|
88
|
+
const { create } = useCreate<Product>("products");
|
|
89
|
+
const { refresh } = useList<Product>("products");
|
|
90
|
+
const { upload, loading: uploading } = useUpload();
|
|
91
|
+
const [imagePreview, setImagePreview] = useState<string | null>(null);
|
|
92
|
+
|
|
93
|
+
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
const form = e.target as HTMLFormElement;
|
|
96
|
+
const name = (form.elements.namedItem("name") as HTMLInputElement).value;
|
|
97
|
+
const fileInput = form.elements.namedItem("image") as HTMLInputElement;
|
|
98
|
+
const file = fileInput.files?.[0];
|
|
99
|
+
|
|
100
|
+
if (!file) return;
|
|
101
|
+
|
|
102
|
+
// 1. 先上传图片
|
|
103
|
+
const uploadResult = await upload(file);
|
|
104
|
+
|
|
105
|
+
// 2. 创建数据记录,存储图片 key 和 url
|
|
106
|
+
await create({
|
|
107
|
+
name,
|
|
108
|
+
imageKey: uploadResult.key,
|
|
109
|
+
imageUrl: uploadResult.url,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
form.reset();
|
|
113
|
+
setImagePreview(null);
|
|
114
|
+
refresh();
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
118
|
+
const file = e.target.files?.[0];
|
|
119
|
+
if (!file) return;
|
|
120
|
+
// 预览:使用本地 Object URL
|
|
121
|
+
setImagePreview(URL.createObjectURL(file));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<form onSubmit={handleSubmit}>
|
|
126
|
+
<input name="name" placeholder="Product name" required />
|
|
127
|
+
<input name="image" type="file" accept="image/*" onChange={handleFileChange} required />
|
|
128
|
+
{imagePreview && <img src={imagePreview} style={{ maxHeight: 100 }} />}
|
|
129
|
+
<button type="submit" disabled={uploading}>{uploading ? "上传中..." : "添加产品"}</button>
|
|
130
|
+
</form>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 显示已上传的图片
|
|
136
|
+
|
|
137
|
+
数据记录中的 `imageUrl` 可以直接用作 `img` 的 `src`:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
function ProductList() {
|
|
141
|
+
const { rows } = useList<Product>("products");
|
|
142
|
+
return (
|
|
143
|
+
<div>
|
|
144
|
+
{rows.map(p => (
|
|
145
|
+
<div key={p.id}>
|
|
146
|
+
<img src={p.imageUrl} alt={p.name} style={{ maxHeight: 100 }} />
|
|
147
|
+
<p>{p.name}</p>
|
|
148
|
+
</div>
|
|
149
|
+
))}
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 错误处理
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { LocalAppError } from "@localapp/sdk";
|
|
159
|
+
|
|
160
|
+
const { upload } = useUpload();
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
const result = await upload(file);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (e instanceof LocalAppError) {
|
|
166
|
+
if (e.status === 400) console.error("不支持的文件类型");
|
|
167
|
+
if (e.status === 401) console.error("需要登录");
|
|
168
|
+
if (e.status === 413) console.error("文件超过 10MB 限制");
|
|
169
|
+
if (e.status === 403) console.error("无权限");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|