@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,211 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { convertMessages } from "@localapp/sdk-agent";
|
|
3
|
+
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
4
|
+
|
|
5
|
+
describe("assistant-ui-adapter > convertMessages", () => {
|
|
6
|
+
it("转换空消息数组", () => {
|
|
7
|
+
expect(convertMessages([])).toEqual([]);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("转换用户文本消息", () => {
|
|
11
|
+
const msgs: AgentMessage[] = [
|
|
12
|
+
{ role: "user", content: "你好", timestamp: Date.now() },
|
|
13
|
+
];
|
|
14
|
+
const result = convertMessages(msgs);
|
|
15
|
+
expect(result).toHaveLength(1);
|
|
16
|
+
expect(result[0].role).toBe("user");
|
|
17
|
+
expect(result[0].content).toBe("你好");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("转换用户消息(数组 content)", () => {
|
|
21
|
+
const msgs: AgentMessage[] = [
|
|
22
|
+
{
|
|
23
|
+
role: "user",
|
|
24
|
+
content: [{ type: "text", text: "hello" }],
|
|
25
|
+
timestamp: Date.now(),
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
const result = convertMessages(msgs);
|
|
29
|
+
expect(result).toHaveLength(1);
|
|
30
|
+
expect(result[0].content).toBe("hello");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("转换助手文本消息", () => {
|
|
34
|
+
const msgs: AgentMessage[] = [
|
|
35
|
+
{
|
|
36
|
+
role: "assistant",
|
|
37
|
+
content: [{ type: "text", text: "好的" }],
|
|
38
|
+
api: "openai" as any,
|
|
39
|
+
provider: "openai" as any,
|
|
40
|
+
model: "gpt-4",
|
|
41
|
+
usage: {} as any,
|
|
42
|
+
stopReason: "stop",
|
|
43
|
+
timestamp: Date.now(),
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
const result = convertMessages(msgs);
|
|
47
|
+
expect(result).toHaveLength(1);
|
|
48
|
+
expect(result[0].role).toBe("assistant");
|
|
49
|
+
const parts = result[0].content as any[];
|
|
50
|
+
expect(parts[0]).toEqual({ type: "text", text: "好的" });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("转换助手消息中的工具调用", () => {
|
|
54
|
+
const msgs: AgentMessage[] = [
|
|
55
|
+
{
|
|
56
|
+
role: "assistant",
|
|
57
|
+
content: [
|
|
58
|
+
{ type: "text", text: "我来填写" },
|
|
59
|
+
{
|
|
60
|
+
type: "toolCall",
|
|
61
|
+
id: "call_1",
|
|
62
|
+
name: "fillForm",
|
|
63
|
+
arguments: { field: "name", value: "张三" },
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
api: "openai" as any,
|
|
67
|
+
provider: "openai" as any,
|
|
68
|
+
model: "gpt-4",
|
|
69
|
+
usage: {} as any,
|
|
70
|
+
stopReason: "toolUse",
|
|
71
|
+
timestamp: Date.now(),
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
const result = convertMessages(msgs);
|
|
75
|
+
const parts = result[0].content as any[];
|
|
76
|
+
expect(parts).toHaveLength(2);
|
|
77
|
+
expect(parts[0]).toEqual({ type: "text", text: "我来填写" });
|
|
78
|
+
expect(parts[1].type).toBe("tool-call");
|
|
79
|
+
expect(parts[1].toolCallId).toBe("call_1");
|
|
80
|
+
expect(parts[1].toolName).toBe("fillForm");
|
|
81
|
+
expect(parts[1].args).toEqual({ field: "name", value: "张三" });
|
|
82
|
+
expect(parts[1].argsText).toBe('{"field":"name","value":"张三"}');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("将 ToolResultMessage 合并回 assistant 消息的 tool-call part", () => {
|
|
86
|
+
const msgs: AgentMessage[] = [
|
|
87
|
+
{
|
|
88
|
+
role: "assistant",
|
|
89
|
+
content: [
|
|
90
|
+
{
|
|
91
|
+
type: "toolCall",
|
|
92
|
+
id: "c1",
|
|
93
|
+
name: "fillForm",
|
|
94
|
+
arguments: { field: "name" },
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
api: "openai" as any,
|
|
98
|
+
provider: "openai" as any,
|
|
99
|
+
model: "gpt-4",
|
|
100
|
+
usage: {} as any,
|
|
101
|
+
stopReason: "toolUse",
|
|
102
|
+
timestamp: Date.now(),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
role: "toolResult",
|
|
106
|
+
toolCallId: "c1",
|
|
107
|
+
toolName: "fillForm",
|
|
108
|
+
content: [{ type: "text", text: '"已填写 name"' }],
|
|
109
|
+
isError: false,
|
|
110
|
+
timestamp: Date.now(),
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const result = convertMessages(msgs);
|
|
114
|
+
// tool result should NOT produce a separate message
|
|
115
|
+
expect(result).toHaveLength(1);
|
|
116
|
+
const parts = result[0].content as any[];
|
|
117
|
+
expect(parts[0].type).toBe("tool-call");
|
|
118
|
+
expect(parts[0].result).toBe('"已填写 name"');
|
|
119
|
+
expect(parts[0].isError).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("多条 tool result 合并到同一条 assistant 消息", () => {
|
|
123
|
+
const msgs: AgentMessage[] = [
|
|
124
|
+
{
|
|
125
|
+
role: "assistant",
|
|
126
|
+
content: [
|
|
127
|
+
{ type: "toolCall", id: "c1", name: "fillForm", arguments: { field: "name" } },
|
|
128
|
+
{ type: "toolCall", id: "c2", name: "fillForm", arguments: { field: "dept" } },
|
|
129
|
+
],
|
|
130
|
+
api: "openai" as any,
|
|
131
|
+
provider: "openai" as any,
|
|
132
|
+
model: "gpt-4",
|
|
133
|
+
usage: {} as any,
|
|
134
|
+
stopReason: "toolUse",
|
|
135
|
+
timestamp: Date.now(),
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
role: "toolResult",
|
|
139
|
+
toolCallId: "c1",
|
|
140
|
+
toolName: "fillForm",
|
|
141
|
+
content: [{ type: "text", text: '"已填写 name"' }],
|
|
142
|
+
isError: false,
|
|
143
|
+
timestamp: Date.now(),
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
role: "toolResult",
|
|
147
|
+
toolCallId: "c2",
|
|
148
|
+
toolName: "fillForm",
|
|
149
|
+
content: [{ type: "text", text: '"已填写 dept"' }],
|
|
150
|
+
isError: false,
|
|
151
|
+
timestamp: Date.now(),
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
const result = convertMessages(msgs);
|
|
155
|
+
expect(result).toHaveLength(1);
|
|
156
|
+
const parts = result[0].content as any[];
|
|
157
|
+
expect(parts[0].result).toBe('"已填写 name"');
|
|
158
|
+
expect(parts[1].result).toBe('"已填写 dept"');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("tool result isError 标记正确传递", () => {
|
|
162
|
+
const msgs: AgentMessage[] = [
|
|
163
|
+
{
|
|
164
|
+
role: "assistant",
|
|
165
|
+
content: [
|
|
166
|
+
{ type: "toolCall", id: "c1", name: "submitForm", arguments: {} },
|
|
167
|
+
],
|
|
168
|
+
api: "openai" as any,
|
|
169
|
+
provider: "openai" as any,
|
|
170
|
+
model: "gpt-4",
|
|
171
|
+
usage: {} as any,
|
|
172
|
+
stopReason: "toolUse",
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
role: "toolResult",
|
|
177
|
+
toolCallId: "c1",
|
|
178
|
+
toolName: "submitForm",
|
|
179
|
+
content: [{ type: "text", text: '"缺少必填字段"' }],
|
|
180
|
+
isError: true,
|
|
181
|
+
timestamp: Date.now(),
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
const result = convertMessages(msgs);
|
|
185
|
+
const parts = result[0].content as any[];
|
|
186
|
+
expect(parts[0].result).toBe('"缺少必填字段"');
|
|
187
|
+
expect(parts[0].isError).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("完整的对话消息序列转换", () => {
|
|
191
|
+
const msgs: AgentMessage[] = [
|
|
192
|
+
{ role: "user", content: "帮我请假", timestamp: 1000 },
|
|
193
|
+
{
|
|
194
|
+
role: "assistant",
|
|
195
|
+
content: [{ type: "text", text: "好的,我来帮你" }],
|
|
196
|
+
api: "openai" as any,
|
|
197
|
+
provider: "openai" as any,
|
|
198
|
+
model: "gpt-4",
|
|
199
|
+
usage: {} as any,
|
|
200
|
+
stopReason: "stop",
|
|
201
|
+
timestamp: 2000,
|
|
202
|
+
},
|
|
203
|
+
{ role: "user", content: "谢谢", timestamp: 3000 },
|
|
204
|
+
];
|
|
205
|
+
const result = convertMessages(msgs);
|
|
206
|
+
expect(result).toHaveLength(3);
|
|
207
|
+
expect(result[0].role).toBe("user");
|
|
208
|
+
expect(result[1].role).toBe("assistant");
|
|
209
|
+
expect(result[2].role).toBe("user");
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
const root = path.resolve(__dirname, "..");
|
|
6
|
+
|
|
7
|
+
function readTemplateFile(relativePath: string) {
|
|
8
|
+
return fs.readFileSync(path.join(root, relativePath), "utf-8");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe("business modeling template guidance", () => {
|
|
12
|
+
it("CLAUDE.md 列出业务应用建模 skill 入口", () => {
|
|
13
|
+
const claude = readTemplateFile("CLAUDE.md");
|
|
14
|
+
expect(claude).toContain("业务");
|
|
15
|
+
expect(claude).toMatch(/业务应用建模|business-app-model|业务建模/);
|
|
16
|
+
expect(claude).toContain(".claude/skills/localapp-business");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it(".claude/skills/ 包含业务应用建模 skill 文件", () => {
|
|
20
|
+
const skillPath = path.join(root, ".claude", "skills", "localapp-business", "SKILL.md");
|
|
21
|
+
expect(fs.existsSync(skillPath)).toBe(true);
|
|
22
|
+
|
|
23
|
+
const skill = fs.readFileSync(skillPath, "utf-8");
|
|
24
|
+
expect(skill).toContain("name: localapp-business");
|
|
25
|
+
expect(skill).toContain("申请类");
|
|
26
|
+
expect(skill).toContain("审批类");
|
|
27
|
+
expect(skill).toContain("分配类");
|
|
28
|
+
expect(skill).toContain("目录类");
|
|
29
|
+
expect(skill).toContain("ownerField");
|
|
30
|
+
expect(skill).toContain("statusField");
|
|
31
|
+
expect(skill).toContain("recordAccess");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("localapp-data skill 包含业务模型与记录级权限说明", () => {
|
|
35
|
+
const dataSkill = readTemplateFile(".claude/skills/localapp-data/SKILL.md");
|
|
36
|
+
expect(dataSkill).toContain("business");
|
|
37
|
+
expect(dataSkill).toContain("defaultFrom");
|
|
38
|
+
expect(dataSkill).toContain("enum");
|
|
39
|
+
expect(dataSkill).toContain("recordAccess");
|
|
40
|
+
expect(dataSkill).toContain("ownerField");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("localapp-auth skill 包含 usePermissions / <Can> 用法", () => {
|
|
44
|
+
const authSkill = readTemplateFile(".claude/skills/localapp-auth/SKILL.md");
|
|
45
|
+
expect(authSkill).toContain("usePermissions");
|
|
46
|
+
expect(authSkill).toContain("<Can");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("default App.tsx 业务模型示例", () => {
|
|
51
|
+
it("示例包含当前用户归属的业务字段", () => {
|
|
52
|
+
const app = readTemplateFile(path.join("src", "App.tsx"));
|
|
53
|
+
expect(app).toMatch(/created_by|ownerId|assigneeId|owner_field|createdBy/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("示例包含状态字段", () => {
|
|
57
|
+
const app = readTemplateFile(path.join("src", "App.tsx"));
|
|
58
|
+
expect(app).toMatch(/status|state/);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("示例展示 usePermissions 或 <Can> 权限 UI 模式", () => {
|
|
62
|
+
const app = readTemplateFile(path.join("src", "App.tsx"));
|
|
63
|
+
expect(app).toMatch(/usePermissions|<Can/);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("示例从 @localapp/sdk-react 导入 usePermissions 或 Can", () => {
|
|
67
|
+
const app = readTemplateFile(path.join("src", "App.tsx"));
|
|
68
|
+
expect(app).toMatch(/from ["']@localapp\/sdk-react["']/);
|
|
69
|
+
expect(app).toMatch(/usePermissions|\bCan\b/);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { createClient, LocalAppError } from "@localapp/sdk";
|
|
3
|
+
|
|
4
|
+
function mockFetch(url: string, init?: RequestInit) {
|
|
5
|
+
const method = init?.method || "GET";
|
|
6
|
+
const body = init?.body ? JSON.parse(init.body as string) : undefined;
|
|
7
|
+
return Promise.resolve({
|
|
8
|
+
ok: true,
|
|
9
|
+
status: 200,
|
|
10
|
+
json: () => Promise.resolve({ success: true, data: { method, url, body } }),
|
|
11
|
+
} as Response);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("createClient basePath detection", () => {
|
|
15
|
+
const originalLocation = window.location;
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
// @ts-expect-error restore location
|
|
19
|
+
window.location = originalLocation;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("detects basePath from /serve/{userId}/{name}/ path", () => {
|
|
23
|
+
delete (window as any).location;
|
|
24
|
+
(window as any).location = { pathname: "/serve/alice/my-app/index.html", origin: "http://localhost:3000" };
|
|
25
|
+
const client = createClient();
|
|
26
|
+
expect(client.basePath).toBe("/serve/alice/my-app/api");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("defaults to /api for root path", () => {
|
|
30
|
+
delete (window as any).location;
|
|
31
|
+
(window as any).location = { pathname: "/", origin: "http://localhost:3000" };
|
|
32
|
+
const client = createClient();
|
|
33
|
+
expect(client.basePath).toBe("/api");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("detects basePath from /serve/{userId}/{name}/ (trailing slash)", () => {
|
|
37
|
+
delete (window as any).location;
|
|
38
|
+
(window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
|
|
39
|
+
const client = createClient();
|
|
40
|
+
expect(client.basePath).toBe("/serve/alice/my-app/api");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("createClient CRUD methods", () => {
|
|
45
|
+
let client: ReturnType<typeof createClient>;
|
|
46
|
+
let fetchSpy: ReturnType<typeof vi.fn>;
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
delete (window as any).location;
|
|
50
|
+
(window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
|
|
51
|
+
fetchSpy = vi.fn(mockFetch);
|
|
52
|
+
globalThis.fetch = fetchSpy;
|
|
53
|
+
client = createClient();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("me() calls GET /api/me", async () => {
|
|
57
|
+
fetchSpy.mockResolvedValueOnce({
|
|
58
|
+
ok: true,
|
|
59
|
+
status: 200,
|
|
60
|
+
json: () => Promise.resolve({ success: true, data: { id: "alice", name: "alice" } }),
|
|
61
|
+
} as Response);
|
|
62
|
+
|
|
63
|
+
const result = await client.me();
|
|
64
|
+
expect(fetchSpy).toHaveBeenCalledWith("/api/me", { method: "GET" });
|
|
65
|
+
expect(result).toEqual({ id: "alice", name: "alice" });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("time() calls GET {basePath}/time", async () => {
|
|
69
|
+
fetchSpy.mockResolvedValueOnce({
|
|
70
|
+
ok: true,
|
|
71
|
+
status: 200,
|
|
72
|
+
json: () => Promise.resolve({ success: true, data: { now: "2026-07-01T09:00:00.000Z", today: "2026-07-01" } }),
|
|
73
|
+
} as Response);
|
|
74
|
+
|
|
75
|
+
const result = await client.time();
|
|
76
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/time", { method: "GET" });
|
|
77
|
+
expect(result).toEqual({ now: "2026-07-01T09:00:00.000Z", today: "2026-07-01" });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("list() calls system named query first", async () => {
|
|
81
|
+
fetchSpy.mockResolvedValueOnce({
|
|
82
|
+
ok: true,
|
|
83
|
+
status: 200,
|
|
84
|
+
json: () => Promise.resolve({
|
|
85
|
+
success: true,
|
|
86
|
+
data: { rows: [{ id: 1, title: "hello" }], pagination: { offset: 0, limit: 50, total: 1 } },
|
|
87
|
+
}),
|
|
88
|
+
} as Response);
|
|
89
|
+
|
|
90
|
+
const result = await client.list("posts");
|
|
91
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.list", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: { "Content-Type": "application/json" },
|
|
94
|
+
body: JSON.stringify({ params: { offset: 0, limit: 50 } }),
|
|
95
|
+
});
|
|
96
|
+
expect(result.rows).toEqual([{ id: 1, title: "hello" }]);
|
|
97
|
+
expect(result.pagination.total).toBe(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("list() passes filters, offset, limit, sort, order as named params", async () => {
|
|
101
|
+
fetchSpy.mockResolvedValueOnce({
|
|
102
|
+
ok: true,
|
|
103
|
+
status: 200,
|
|
104
|
+
json: () => Promise.resolve({ success: true, data: { rows: [], pagination: { offset: 10, limit: 5, total: 0 } } }),
|
|
105
|
+
} as Response);
|
|
106
|
+
|
|
107
|
+
await client.list("posts", { filters: { status: "published" }, offset: 10, limit: 5, sort: "created_at", order: "desc" });
|
|
108
|
+
expect(fetchSpy).toHaveBeenCalledWith(
|
|
109
|
+
"/serve/alice/my-app/api/queries/$posts.list",
|
|
110
|
+
{
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { "Content-Type": "application/json" },
|
|
113
|
+
body: JSON.stringify({ params: { offset: 10, limit: 5, sort: "created_at", order: "desc", status: "published" } }),
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("get() calls system named query first", async () => {
|
|
119
|
+
fetchSpy.mockResolvedValueOnce({
|
|
120
|
+
ok: true,
|
|
121
|
+
status: 200,
|
|
122
|
+
json: () => Promise.resolve({ success: true, data: { id: 1, title: "hello" } }),
|
|
123
|
+
} as Response);
|
|
124
|
+
|
|
125
|
+
const result = await client.get("posts", 1);
|
|
126
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.get", {
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: { "Content-Type": "application/json" },
|
|
129
|
+
body: JSON.stringify({ params: { id: 1 } }),
|
|
130
|
+
});
|
|
131
|
+
expect(result).toEqual({ id: 1, title: "hello" });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("create() 在 mutation 后用 lastInsertRowId 调 $<resource>.get 拉完整 row", async () => {
|
|
135
|
+
fetchSpy.mockResolvedValueOnce({
|
|
136
|
+
ok: true,
|
|
137
|
+
status: 200,
|
|
138
|
+
json: () => Promise.resolve({ success: true, data: { changes: 1, lastInsertRowId: 1 } }),
|
|
139
|
+
} as Response);
|
|
140
|
+
fetchSpy.mockResolvedValueOnce({
|
|
141
|
+
ok: true,
|
|
142
|
+
status: 200,
|
|
143
|
+
json: () => Promise.resolve({ success: true, data: { rows: [{ id: 1, title: "new" }] } }),
|
|
144
|
+
} as Response);
|
|
145
|
+
|
|
146
|
+
const result = await client.create<{ id: number; title: string }>("posts", { title: "new" });
|
|
147
|
+
expect(fetchSpy).toHaveBeenNthCalledWith(1, "/serve/alice/my-app/api/mutations/$posts.create", {
|
|
148
|
+
method: "POST",
|
|
149
|
+
headers: { "Content-Type": "application/json" },
|
|
150
|
+
body: JSON.stringify({ params: { title: "new" } }),
|
|
151
|
+
});
|
|
152
|
+
expect(fetchSpy).toHaveBeenNthCalledWith(2, "/serve/alice/my-app/api/queries/$posts.get", {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: { "Content-Type": "application/json" },
|
|
155
|
+
body: JSON.stringify({ params: { id: 1 } }),
|
|
156
|
+
});
|
|
157
|
+
expect(result).toEqual({ id: 1, title: "new" });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("update() 在 mutation 后调 get 拉最新 row", async () => {
|
|
161
|
+
fetchSpy.mockResolvedValueOnce({
|
|
162
|
+
ok: true,
|
|
163
|
+
status: 200,
|
|
164
|
+
json: () => Promise.resolve({ success: true, data: { changes: 1, lastInsertRowId: 0 } }),
|
|
165
|
+
} as Response);
|
|
166
|
+
fetchSpy.mockResolvedValueOnce({
|
|
167
|
+
ok: true,
|
|
168
|
+
status: 200,
|
|
169
|
+
json: () => Promise.resolve({ success: true, data: { rows: [{ id: 1, title: "updated" }] } }),
|
|
170
|
+
} as Response);
|
|
171
|
+
|
|
172
|
+
const result = await client.update<{ id: number; title: string }>("posts", 1, { title: "updated" });
|
|
173
|
+
expect(fetchSpy).toHaveBeenNthCalledWith(1, "/serve/alice/my-app/api/mutations/$posts.update", {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: { "Content-Type": "application/json" },
|
|
176
|
+
body: JSON.stringify({ params: { id: 1, title: "updated" } }),
|
|
177
|
+
});
|
|
178
|
+
expect(fetchSpy).toHaveBeenNthCalledWith(2, "/serve/alice/my-app/api/queries/$posts.get", {
|
|
179
|
+
method: "POST",
|
|
180
|
+
headers: { "Content-Type": "application/json" },
|
|
181
|
+
body: JSON.stringify({ params: { id: 1 } }),
|
|
182
|
+
});
|
|
183
|
+
expect(result).toEqual({ id: 1, title: "updated" });
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("delete() calls system named mutation first", async () => {
|
|
187
|
+
fetchSpy.mockResolvedValueOnce({
|
|
188
|
+
ok: true,
|
|
189
|
+
status: 200,
|
|
190
|
+
json: () => Promise.resolve({ success: true, data: { deleted: true, id: 1 } }),
|
|
191
|
+
} as Response);
|
|
192
|
+
|
|
193
|
+
await client.delete("posts", 1);
|
|
194
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/mutations/$posts.delete", {
|
|
195
|
+
method: "POST",
|
|
196
|
+
headers: { "Content-Type": "application/json" },
|
|
197
|
+
body: JSON.stringify({ params: { id: 1 } }),
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("count() calls system named query first", async () => {
|
|
202
|
+
fetchSpy.mockResolvedValueOnce({
|
|
203
|
+
ok: true,
|
|
204
|
+
status: 200,
|
|
205
|
+
json: () => Promise.resolve({ success: true, data: { count: 42 } }),
|
|
206
|
+
} as Response);
|
|
207
|
+
|
|
208
|
+
const result = await client.count("posts");
|
|
209
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.count", {
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers: { "Content-Type": "application/json" },
|
|
212
|
+
body: JSON.stringify({ params: {} }),
|
|
213
|
+
});
|
|
214
|
+
expect(result).toBe(42);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("count() passes filters as named params", async () => {
|
|
218
|
+
fetchSpy.mockResolvedValueOnce({
|
|
219
|
+
ok: true,
|
|
220
|
+
status: 200,
|
|
221
|
+
json: () => Promise.resolve({ success: true, data: { count: 10 } }),
|
|
222
|
+
} as Response);
|
|
223
|
+
|
|
224
|
+
await client.count("posts", { status: "published" });
|
|
225
|
+
expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.count", {
|
|
226
|
+
method: "POST",
|
|
227
|
+
headers: { "Content-Type": "application/json" },
|
|
228
|
+
body: JSON.stringify({ params: { status: "published" } }),
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// 原 "count() falls back to list pagination total when an old runtime returns 404"
|
|
233
|
+
// 和 "count() does not fall back for auth, validation, or server errors" 两个测试
|
|
234
|
+
// 已随 REST CRUD fallback 整体移除(restrict-app-api-to-named-sql 变更)。
|
|
235
|
+
// count 现在只调 named SQL,未声明 $<resource>.count 时直接抛 LocalAppError。
|
|
236
|
+
|
|
237
|
+
it("users() calls GET /api/users", async () => {
|
|
238
|
+
fetchSpy.mockResolvedValueOnce({
|
|
239
|
+
ok: true,
|
|
240
|
+
status: 200,
|
|
241
|
+
json: () => Promise.resolve({ success: true, data: [{ id: "alice", name: "alice", displayName: null }] }),
|
|
242
|
+
} as Response);
|
|
243
|
+
|
|
244
|
+
const result = await client.users();
|
|
245
|
+
expect(fetchSpy).toHaveBeenCalledWith("/api/users", { method: "GET" });
|
|
246
|
+
expect(result).toEqual([{ id: "alice", name: "alice", displayName: null }]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("groups() calls GET /api/groups", async () => {
|
|
250
|
+
fetchSpy.mockResolvedValueOnce({
|
|
251
|
+
ok: true,
|
|
252
|
+
status: 200,
|
|
253
|
+
json: () => Promise.resolve({ success: true, data: [{ id: "g1", name: "team", description: null, isCreator: true }] }),
|
|
254
|
+
} as Response);
|
|
255
|
+
|
|
256
|
+
const result = await client.groups();
|
|
257
|
+
expect(fetchSpy).toHaveBeenCalledWith("/api/groups", { method: "GET" });
|
|
258
|
+
expect(result).toEqual([{ id: "g1", name: "team", description: null, isCreator: true }]);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("groupMembers() calls GET /api/groups/{groupId}", async () => {
|
|
262
|
+
fetchSpy.mockResolvedValueOnce({
|
|
263
|
+
ok: true,
|
|
264
|
+
status: 200,
|
|
265
|
+
json: () => Promise.resolve({ success: true, data: { members: [{ id: "alice", name: "alice", displayName: null }] } }),
|
|
266
|
+
} as Response);
|
|
267
|
+
|
|
268
|
+
const result = await client.groupMembers("g1");
|
|
269
|
+
expect(fetchSpy).toHaveBeenCalledWith("/api/groups/g1", { method: "GET" });
|
|
270
|
+
expect(result).toEqual([{ id: "alice", name: "alice", displayName: null }]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("throws on non-ok response", async () => {
|
|
274
|
+
fetchSpy.mockResolvedValueOnce({
|
|
275
|
+
ok: false,
|
|
276
|
+
status: 401,
|
|
277
|
+
json: () => Promise.resolve({ success: false, error: "Authentication required" }),
|
|
278
|
+
} as Response);
|
|
279
|
+
|
|
280
|
+
await expect(client.list("posts")).rejects.toThrow("Authentication required");
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("LocalAppError", () => {
|
|
285
|
+
it("extends Error", () => {
|
|
286
|
+
const err = new LocalAppError("test", 401);
|
|
287
|
+
expect(err).toBeInstanceOf(Error);
|
|
288
|
+
expect(err).toBeInstanceOf(LocalAppError);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("carries status code", () => {
|
|
292
|
+
const err = new LocalAppError("Auth required", 401);
|
|
293
|
+
expect(err.message).toBe("Auth required");
|
|
294
|
+
expect(err.status).toBe(401);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("has correct name", () => {
|
|
298
|
+
const err = new LocalAppError("test", 500);
|
|
299
|
+
expect(err.name).toBe("LocalAppError");
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe("request() throws LocalAppError", () => {
|
|
304
|
+
let client: ReturnType<typeof createClient>;
|
|
305
|
+
let fetchSpy: ReturnType<typeof vi.fn>;
|
|
306
|
+
|
|
307
|
+
beforeEach(() => {
|
|
308
|
+
delete (window as any).location;
|
|
309
|
+
(window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
|
|
310
|
+
fetchSpy = vi.fn();
|
|
311
|
+
globalThis.fetch = fetchSpy;
|
|
312
|
+
client = createClient();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("throws LocalAppError with status 401 on auth failure", async () => {
|
|
316
|
+
fetchSpy.mockResolvedValueOnce({
|
|
317
|
+
ok: false,
|
|
318
|
+
status: 401,
|
|
319
|
+
json: () => Promise.resolve({ success: false, error: "Authentication required" }),
|
|
320
|
+
} as Response);
|
|
321
|
+
|
|
322
|
+
try {
|
|
323
|
+
await client.list("posts");
|
|
324
|
+
expect.fail("Should have thrown");
|
|
325
|
+
} catch (e) {
|
|
326
|
+
expect(e).toBeInstanceOf(LocalAppError);
|
|
327
|
+
expect((e as LocalAppError).status).toBe(401);
|
|
328
|
+
expect((e as LocalAppError).message).toBe("Authentication required");
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("throws LocalAppError with status 403 on forbidden", async () => {
|
|
333
|
+
fetchSpy.mockResolvedValueOnce({
|
|
334
|
+
ok: false,
|
|
335
|
+
status: 403,
|
|
336
|
+
json: () => Promise.resolve({ success: false, error: "Access denied" }),
|
|
337
|
+
} as Response);
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
await client.get("posts", 1);
|
|
341
|
+
expect.fail("Should have thrown");
|
|
342
|
+
} catch (e) {
|
|
343
|
+
expect(e).toBeInstanceOf(LocalAppError);
|
|
344
|
+
expect((e as LocalAppError).status).toBe(403);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("throws LocalAppError with fallback message when no error field", async () => {
|
|
349
|
+
fetchSpy.mockResolvedValueOnce({
|
|
350
|
+
ok: false,
|
|
351
|
+
status: 500,
|
|
352
|
+
json: () => Promise.resolve({ success: false }),
|
|
353
|
+
} as Response);
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
await client.me();
|
|
357
|
+
expect.fail("Should have thrown");
|
|
358
|
+
} catch (e) {
|
|
359
|
+
expect(e).toBeInstanceOf(LocalAppError);
|
|
360
|
+
expect((e as LocalAppError).status).toBe(500);
|
|
361
|
+
expect((e as LocalAppError).message).toBe("HTTP 500");
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("throws LocalAppError when an error response is not JSON", async () => {
|
|
366
|
+
fetchSpy.mockResolvedValueOnce({
|
|
367
|
+
ok: false,
|
|
368
|
+
status: 502,
|
|
369
|
+
json: () => Promise.reject(new SyntaxError("Unexpected token <")),
|
|
370
|
+
text: () => Promise.resolve("<html>bad gateway</html>"),
|
|
371
|
+
} as unknown as Response);
|
|
372
|
+
|
|
373
|
+
try {
|
|
374
|
+
await client.me();
|
|
375
|
+
expect.fail("Should have thrown");
|
|
376
|
+
} catch (e) {
|
|
377
|
+
expect(e).toBeInstanceOf(LocalAppError);
|
|
378
|
+
expect((e as LocalAppError).status).toBe(502);
|
|
379
|
+
expect((e as LocalAppError).message).toBe("HTTP 502");
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|