@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,70 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import type { UserToolDef } from "./types.js";
|
|
4
|
+
|
|
5
|
+
function createGetCurrentUserTool(): AgentTool {
|
|
6
|
+
return {
|
|
7
|
+
name: "getCurrentUser",
|
|
8
|
+
label: "Get current user",
|
|
9
|
+
description: "Return the current signed-in user id and name, or null when unauthenticated.",
|
|
10
|
+
parameters: Type.Object({}),
|
|
11
|
+
execute: async () => {
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetch("/api/me", { credentials: "include" });
|
|
14
|
+
if (!res.ok) return { content: [{ type: "text", text: "null" }], details: {} };
|
|
15
|
+
const body = await res.json();
|
|
16
|
+
if (!body.success || !body.data) return { content: [{ type: "text", text: "null" }], details: {} };
|
|
17
|
+
return {
|
|
18
|
+
content: [{ type: "text", text: JSON.stringify({ id: body.data.id, name: body.data.name }) }],
|
|
19
|
+
details: body.data,
|
|
20
|
+
};
|
|
21
|
+
} catch {
|
|
22
|
+
return { content: [{ type: "text", text: "null" }], details: {} };
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createSystemTools(): AgentTool[] {
|
|
29
|
+
return [createGetCurrentUserTool()];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function convertUserTool(name: string, getDef: () => UserToolDef): AgentTool {
|
|
33
|
+
const def = getDef();
|
|
34
|
+
if (!def.description) {
|
|
35
|
+
console.warn(`[Agent SDK] Tool "${name}" is missing a description; add one to help the LLM understand it.`);
|
|
36
|
+
}
|
|
37
|
+
const properties: Record<string, any> = {};
|
|
38
|
+
const required: string[] = [];
|
|
39
|
+
|
|
40
|
+
for (const [key, field] of Object.entries(def.parameters)) {
|
|
41
|
+
const t = field.type;
|
|
42
|
+
const prop: any = { type: t, description: field.description };
|
|
43
|
+
properties[key] = prop;
|
|
44
|
+
if (field.required) required.push(key);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
name,
|
|
49
|
+
label: name,
|
|
50
|
+
description: def.description,
|
|
51
|
+
parameters: required.length > 0
|
|
52
|
+
? Type.Object(properties, { required })
|
|
53
|
+
: Type.Object(properties),
|
|
54
|
+
execute: async (_id, params) => {
|
|
55
|
+
try {
|
|
56
|
+
const result = await getDef().execute(params as Record<string, unknown>);
|
|
57
|
+
return {
|
|
58
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
59
|
+
details: result,
|
|
60
|
+
};
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: "text", text: `Execution failed: ${err instanceof Error ? err.message : String(err)}` }],
|
|
64
|
+
details: {},
|
|
65
|
+
isError: true,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentMessage, AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
|
|
3
|
+
export interface UserToolDef {
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
[key: string]: {
|
|
7
|
+
type: "string" | "number" | "boolean";
|
|
8
|
+
required?: boolean;
|
|
9
|
+
description?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UseAgentOptions {
|
|
16
|
+
tools?: Record<string, UserToolDef>;
|
|
17
|
+
systemHint?: string;
|
|
18
|
+
shellIntegration?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface UseAgentReturn {
|
|
22
|
+
send: (text: string) => void;
|
|
23
|
+
messages: AgentMessage[];
|
|
24
|
+
isRunning: boolean;
|
|
25
|
+
error: string | null;
|
|
26
|
+
chatOpen?: boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
+
import { Agent } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import type { AgentMessage, AgentEvent } from "@earendil-works/pi-agent-core";
|
|
4
|
+
import { createStreamFn } from "./llm-adapter.js";
|
|
5
|
+
import { createSystemTools, convertUserTool } from "./tools.js";
|
|
6
|
+
import { fetchSchemaContext, buildSystemPrompt, buildSystemContext } from "./context.js";
|
|
7
|
+
import { postToParent, isToggleChatMessage } from "./postmessage-types.js";
|
|
8
|
+
import type { UseAgentOptions, UseAgentReturn, UserToolDef } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export function parseAppName(): string | null {
|
|
11
|
+
const pathname = window.location.pathname;
|
|
12
|
+
const match = pathname.match(/^\/serve\/[^/]+\/([^/]+)/);
|
|
13
|
+
return match ? match[1] : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function fetchUser(): Promise<{ name: string } | null> {
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch("/api/me", { credentials: "include" });
|
|
19
|
+
if (!res.ok) return { name: "未知" };
|
|
20
|
+
const body = await res.json();
|
|
21
|
+
if (!body.success || !body.data) return null;
|
|
22
|
+
return { name: body.data.name };
|
|
23
|
+
} catch {
|
|
24
|
+
return { name: "未知" };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useAgent(options?: UseAgentOptions): UseAgentReturn {
|
|
29
|
+
const [messages, setMessages] = useState<AgentMessage[]>([]);
|
|
30
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
31
|
+
const [error, setError] = useState<string | null>(null);
|
|
32
|
+
const [chatOpen, setChatOpen] = useState(false);
|
|
33
|
+
|
|
34
|
+
const agentRef = useRef<Agent | null>(null);
|
|
35
|
+
const optionsRef = useRef(options);
|
|
36
|
+
optionsRef.current = options;
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
|
|
41
|
+
async function init() {
|
|
42
|
+
const proxyUrl = window.location.origin;
|
|
43
|
+
const streamFn = createStreamFn({ proxyUrl });
|
|
44
|
+
const appName = parseAppName();
|
|
45
|
+
|
|
46
|
+
const [user, schemaCtx] = await Promise.all([
|
|
47
|
+
fetchUser(),
|
|
48
|
+
fetchSchemaContext(),
|
|
49
|
+
]);
|
|
50
|
+
if (cancelled) return;
|
|
51
|
+
|
|
52
|
+
const systemContext = buildSystemContext(user, appName);
|
|
53
|
+
const systemPrompt = buildSystemPrompt(systemContext, schemaCtx, optionsRef.current?.systemHint);
|
|
54
|
+
const tools = [...createSystemTools()];
|
|
55
|
+
for (const name of Object.keys(optionsRef.current?.tools ?? {})) {
|
|
56
|
+
tools.push(convertUserTool(name, () => (optionsRef.current?.tools ?? {})[name] as UserToolDef));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const agent = new Agent({
|
|
60
|
+
streamFn,
|
|
61
|
+
initialState: { systemPrompt },
|
|
62
|
+
});
|
|
63
|
+
agent.state.tools = tools;
|
|
64
|
+
|
|
65
|
+
agent.subscribe((event: AgentEvent) => {
|
|
66
|
+
if (cancelled) return;
|
|
67
|
+
handleEvent(event);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
agentRef.current = agent;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleEvent(event: AgentEvent) {
|
|
74
|
+
switch (event.type) {
|
|
75
|
+
case "agent_start":
|
|
76
|
+
setIsRunning(true);
|
|
77
|
+
setError(null);
|
|
78
|
+
break;
|
|
79
|
+
case "agent_end":
|
|
80
|
+
setIsRunning(false);
|
|
81
|
+
setMessages([...agentRef.current!.state.messages]);
|
|
82
|
+
break;
|
|
83
|
+
case "message_end":
|
|
84
|
+
setMessages([...agentRef.current!.state.messages]);
|
|
85
|
+
break;
|
|
86
|
+
case "message_update":
|
|
87
|
+
setMessages([...agentRef.current!.state.messages]);
|
|
88
|
+
break;
|
|
89
|
+
case "tool_execution_start":
|
|
90
|
+
case "tool_execution_end":
|
|
91
|
+
setMessages([...agentRef.current!.state.messages]);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (event.type === "message_end" || event.type === "agent_end") {
|
|
96
|
+
const errMsg = agentRef.current?.state.errorMessage;
|
|
97
|
+
if (errMsg) setError(errMsg);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
init();
|
|
102
|
+
|
|
103
|
+
return () => {
|
|
104
|
+
cancelled = true;
|
|
105
|
+
if (agentRef.current) {
|
|
106
|
+
agentRef.current.abort();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
const send = useCallback((text: string) => {
|
|
112
|
+
if (!agentRef.current) return;
|
|
113
|
+
if (agentRef.current.state.isStreaming) return;
|
|
114
|
+
setError(null);
|
|
115
|
+
agentRef.current.prompt(text);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
// Shell integration: listen for toggle_chat from parent
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!optionsRef.current?.shellIntegration) return;
|
|
121
|
+
|
|
122
|
+
// Declare custom mode to Shell
|
|
123
|
+
postToParent({ type: "localapp:ai_custom_mode" });
|
|
124
|
+
|
|
125
|
+
function onMessage(event: MessageEvent) {
|
|
126
|
+
if (isToggleChatMessage(event.data)) {
|
|
127
|
+
setChatOpen((prev) => !prev);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
window.addEventListener("message", onMessage);
|
|
131
|
+
return () => window.removeEventListener("message", onMessage);
|
|
132
|
+
}, []);
|
|
133
|
+
|
|
134
|
+
const result: UseAgentReturn = { send, messages, isRunning, error };
|
|
135
|
+
if (options?.shellIntegration) {
|
|
136
|
+
result.chatOpen = chatOpen;
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { getPlatformEditSessionRegistry } from "./native-registry.js";
|
|
3
|
+
import type { PlatformEditSession } from "./native-registry.js";
|
|
4
|
+
|
|
5
|
+
export type PlatformEditSessionInput = PlatformEditSession | null | undefined;
|
|
6
|
+
|
|
7
|
+
export function registerEditSessionForShell(session: PlatformEditSessionInput): void | (() => void) {
|
|
8
|
+
if (!session) return;
|
|
9
|
+
|
|
10
|
+
const registry = getPlatformEditSessionRegistry();
|
|
11
|
+
if (!registry) return;
|
|
12
|
+
|
|
13
|
+
return registry.registerEditSession({
|
|
14
|
+
canSave: session.canSave,
|
|
15
|
+
canUndo: session.canUndo,
|
|
16
|
+
canRedo: session.canRedo,
|
|
17
|
+
busy: session.busy ?? false,
|
|
18
|
+
onSave: session.onSave,
|
|
19
|
+
onUndo: session.onUndo,
|
|
20
|
+
onRedo: session.onRedo,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useRegisterEditSession(session: PlatformEditSessionInput): void {
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!session) return;
|
|
27
|
+
let cleanup: void | (() => void);
|
|
28
|
+
let stopped = false;
|
|
29
|
+
let attempts = 0;
|
|
30
|
+
|
|
31
|
+
const register = () => {
|
|
32
|
+
if (stopped || cleanup) return;
|
|
33
|
+
cleanup = registerEditSessionForShell(session);
|
|
34
|
+
attempts += 1;
|
|
35
|
+
if (!cleanup && attempts < 20) {
|
|
36
|
+
window.setTimeout(register, 50);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
register();
|
|
41
|
+
return () => {
|
|
42
|
+
stopped = true;
|
|
43
|
+
cleanup?.();
|
|
44
|
+
};
|
|
45
|
+
}, [
|
|
46
|
+
session?.canSave,
|
|
47
|
+
session?.canUndo,
|
|
48
|
+
session?.canRedo,
|
|
49
|
+
session?.busy,
|
|
50
|
+
session?.onSave,
|
|
51
|
+
session?.onUndo,
|
|
52
|
+
session?.onRedo,
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { PostMessageBridge } from "./postmessage-bridge.js";
|
|
3
|
+
import { postToParent } from "./postmessage-types.js";
|
|
4
|
+
import type { ToolSchema } from "./postmessage-types.js";
|
|
5
|
+
import type { UserToolDef } from "./types.js";
|
|
6
|
+
import { getDevRegistry } from "./dev-bridge.js";
|
|
7
|
+
import { getPlatformToolRegistry } from "./native-registry.js";
|
|
8
|
+
|
|
9
|
+
export interface UseRegisterToolsOptions {
|
|
10
|
+
tools?: Record<string, UserToolDef>;
|
|
11
|
+
systemHint?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function toSchema(tools: Record<string, UserToolDef>): ToolSchema[] {
|
|
15
|
+
return Object.entries(tools).map(([name, def]) => {
|
|
16
|
+
const properties: Record<string, { type: string; description?: string }> = {};
|
|
17
|
+
const required: string[] = [];
|
|
18
|
+
for (const [key, field] of Object.entries(def.parameters)) {
|
|
19
|
+
const { type, description } = field;
|
|
20
|
+
properties[key] = { type, ...(description ? { description } : {}) };
|
|
21
|
+
if (field.required) required.push(key);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
description: def.description,
|
|
26
|
+
parameters: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties,
|
|
29
|
+
...(required.length > 0 ? { required } : {}),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toExecuteFns(tools: Record<string, UserToolDef>): Record<string, (args: Record<string, unknown>) => Promise<unknown>> {
|
|
36
|
+
const executeFns: Record<string, (args: Record<string, unknown>) => Promise<unknown>> = {};
|
|
37
|
+
for (const [name, def] of Object.entries(tools)) {
|
|
38
|
+
executeFns[name] = def.execute;
|
|
39
|
+
}
|
|
40
|
+
return executeFns;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function registerToolsForShell(
|
|
44
|
+
tools: Record<string, UserToolDef>,
|
|
45
|
+
systemHint?: string,
|
|
46
|
+
): void | (() => void) {
|
|
47
|
+
const schemas = toSchema(tools);
|
|
48
|
+
const executeFns = toExecuteFns(tools);
|
|
49
|
+
const devRegistry = getDevRegistry();
|
|
50
|
+
|
|
51
|
+
if (devRegistry) {
|
|
52
|
+
devRegistry.registerTools(schemas, executeFns, systemHint);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const nativeRegistry = getPlatformToolRegistry();
|
|
57
|
+
if (nativeRegistry) {
|
|
58
|
+
return nativeRegistry.registerTools(schemas, executeFns, systemHint);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
postToParent({
|
|
62
|
+
type: "localapp:register_tools",
|
|
63
|
+
tools: schemas,
|
|
64
|
+
systemHint,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const bridge = new PostMessageBridge();
|
|
68
|
+
for (const [name, def] of Object.entries(tools)) {
|
|
69
|
+
bridge.registerTool(name, def.execute);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return () => {
|
|
73
|
+
bridge.destroy();
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function useRegisterTools(options: UseRegisterToolsOptions = {}): void {
|
|
78
|
+
const cleanupRef = useRef<void | (() => void)>(undefined);
|
|
79
|
+
const optionsRef = useRef(options);
|
|
80
|
+
optionsRef.current = options;
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const { tools, systemHint } = optionsRef.current;
|
|
84
|
+
if (!tools || Object.keys(tools).length === 0) return;
|
|
85
|
+
|
|
86
|
+
cleanupRef.current = registerToolsForShell(tools, systemHint);
|
|
87
|
+
return () => {
|
|
88
|
+
cleanupRef.current?.();
|
|
89
|
+
cleanupRef.current = undefined;
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { createPlatformRuntime, isPlatformResponseMessage } from "../src/platform-runtime.js";
|
|
3
|
+
|
|
4
|
+
function response(id: string, result: unknown) {
|
|
5
|
+
return new MessageEvent("message", {
|
|
6
|
+
data: { type: "localapp:platform_response", id, ok: true, result },
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe("platform runtime", () => {
|
|
11
|
+
let mockPostMessage: ReturnType<typeof vi.fn>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockPostMessage = vi.fn();
|
|
15
|
+
vi.spyOn(window, "parent", "get").mockReturnValue({
|
|
16
|
+
postMessage: mockPostMessage,
|
|
17
|
+
} as any);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("sends headless platform capability requests to the parent shell", async () => {
|
|
25
|
+
const runtime = createPlatformRuntime({ requestId: () => "req-download" });
|
|
26
|
+
const done = runtime.downloadFile({
|
|
27
|
+
filename: "report.csv",
|
|
28
|
+
mimeType: "text/csv",
|
|
29
|
+
data: "a,b\n1,2",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
33
|
+
{
|
|
34
|
+
type: "localapp:platform_request",
|
|
35
|
+
id: "req-download",
|
|
36
|
+
capability: "downloadFile",
|
|
37
|
+
payload: { filename: "report.csv", mimeType: "text/csv", data: "a,b\n1,2" },
|
|
38
|
+
},
|
|
39
|
+
window.location.origin,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
window.dispatchEvent(response("req-download", { success: true }));
|
|
43
|
+
await expect(done).resolves.toEqual({ success: true });
|
|
44
|
+
runtime.destroy();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("exposes user, time, clipboard, route, confirm, and AI capabilities without owning app UI", async () => {
|
|
48
|
+
const ids = ["req-user", "req-time", "req-copy", "req-route", "req-confirm", "req-ai"];
|
|
49
|
+
const runtime = createPlatformRuntime({ requestId: () => ids.shift() ?? "req-extra" });
|
|
50
|
+
|
|
51
|
+
const userPromise = runtime.getCurrentUser();
|
|
52
|
+
const timePromise = runtime.getServerTime();
|
|
53
|
+
const copyPromise = runtime.copyText("hello");
|
|
54
|
+
const routePromise = runtime.openRoute({ href: "/my/apps" });
|
|
55
|
+
const confirmPromise = runtime.confirm({
|
|
56
|
+
title: "Delete record",
|
|
57
|
+
message: "Confirm deleting this record?",
|
|
58
|
+
confirmText: "Delete",
|
|
59
|
+
cancelText: "Cancel",
|
|
60
|
+
tone: "danger",
|
|
61
|
+
});
|
|
62
|
+
const aiPromise = runtime.ai.open();
|
|
63
|
+
|
|
64
|
+
const messages = mockPostMessage.mock.calls.map((call) => call[0]);
|
|
65
|
+
expect(messages.map((msg) => msg.capability)).toEqual([
|
|
66
|
+
"getCurrentUser",
|
|
67
|
+
"getServerTime",
|
|
68
|
+
"copyText",
|
|
69
|
+
"openRoute",
|
|
70
|
+
"confirm",
|
|
71
|
+
"ai.open",
|
|
72
|
+
]);
|
|
73
|
+
expect(messages[2].payload).toEqual({ text: "hello" });
|
|
74
|
+
expect(messages[3].payload).toEqual({ href: "/my/apps" });
|
|
75
|
+
expect(messages[4].payload).toEqual({
|
|
76
|
+
title: "Delete record",
|
|
77
|
+
message: "Confirm deleting this record?",
|
|
78
|
+
confirmText: "Delete",
|
|
79
|
+
cancelText: "Cancel",
|
|
80
|
+
tone: "danger",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
window.dispatchEvent(response("req-user", { id: "test-owner", name: "test-owner" }));
|
|
84
|
+
window.dispatchEvent(response("req-time", { now: "2026-06-18T12:00:00.000Z" }));
|
|
85
|
+
window.dispatchEvent(response("req-copy", { success: true }));
|
|
86
|
+
window.dispatchEvent(response("req-route", { success: true }));
|
|
87
|
+
window.dispatchEvent(response("req-confirm", true));
|
|
88
|
+
window.dispatchEvent(response("req-ai", { success: true }));
|
|
89
|
+
|
|
90
|
+
await expect(userPromise).resolves.toEqual({ id: "test-owner", name: "test-owner" });
|
|
91
|
+
await expect(timePromise).resolves.toEqual({ now: "2026-06-18T12:00:00.000Z" });
|
|
92
|
+
await expect(copyPromise).resolves.toEqual({ success: true });
|
|
93
|
+
await expect(routePromise).resolves.toEqual({ success: true });
|
|
94
|
+
await expect(confirmPromise).resolves.toBe(true);
|
|
95
|
+
await expect(aiPromise).resolves.toEqual({ success: true });
|
|
96
|
+
runtime.destroy();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("recognizes platform response messages", () => {
|
|
100
|
+
expect(isPlatformResponseMessage({ type: "localapp:platform_response", id: "1", ok: true })).toBe(true);
|
|
101
|
+
expect(isPlatformResponseMessage({ type: "localapp:platform_request", id: "1" })).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("sends same-window platform requests when no parent shell exists", async () => {
|
|
105
|
+
vi.restoreAllMocks();
|
|
106
|
+
vi.spyOn(window, "parent", "get").mockReturnValue(window);
|
|
107
|
+
const onRequest = vi.fn((event: Event) => {
|
|
108
|
+
const detail = (event as CustomEvent).detail;
|
|
109
|
+
window.dispatchEvent(response(detail.id, { success: true }));
|
|
110
|
+
});
|
|
111
|
+
window.addEventListener("localapp:platform_request", onRequest);
|
|
112
|
+
|
|
113
|
+
const runtime = createPlatformRuntime({ requestId: () => "local-copy" });
|
|
114
|
+
|
|
115
|
+
await expect(runtime.copyText("local")).resolves.toEqual({ success: true });
|
|
116
|
+
expect(onRequest).toHaveBeenCalledTimes(1);
|
|
117
|
+
expect(onRequest.mock.calls[0]?.[0]).toMatchObject({
|
|
118
|
+
detail: {
|
|
119
|
+
type: "localapp:platform_request",
|
|
120
|
+
id: "local-copy",
|
|
121
|
+
capability: "copyText",
|
|
122
|
+
payload: { text: "local" },
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
window.removeEventListener("localapp:platform_request", onRequest);
|
|
126
|
+
runtime.destroy();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("routes same-window confirm through the platform host", async () => {
|
|
130
|
+
vi.restoreAllMocks();
|
|
131
|
+
vi.spyOn(window, "parent", "get").mockReturnValue(window);
|
|
132
|
+
const nativeConfirm = vi.spyOn(window, "confirm").mockReturnValue(false);
|
|
133
|
+
const onRequest = vi.fn((event: Event) => {
|
|
134
|
+
const detail = (event as CustomEvent).detail;
|
|
135
|
+
window.dispatchEvent(response(detail.id, true));
|
|
136
|
+
});
|
|
137
|
+
window.addEventListener("localapp:platform_request", onRequest);
|
|
138
|
+
const runtime = createPlatformRuntime({ requestId: () => "local-confirm" });
|
|
139
|
+
|
|
140
|
+
await expect(runtime.confirm({ title: "Confirm action", message: "Continue?" })).resolves.toBe(true);
|
|
141
|
+
expect(onRequest).toHaveBeenCalledTimes(1);
|
|
142
|
+
expect(onRequest.mock.calls[0]?.[0]).toMatchObject({
|
|
143
|
+
detail: {
|
|
144
|
+
type: "localapp:platform_request",
|
|
145
|
+
id: "local-confirm",
|
|
146
|
+
capability: "confirm",
|
|
147
|
+
payload: { title: "Confirm action", message: "Continue?" },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(nativeConfirm).not.toHaveBeenCalled();
|
|
151
|
+
window.removeEventListener("localapp:platform_request", onRequest);
|
|
152
|
+
runtime.destroy();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { PostMessageBridge } from "../src/postmessage-bridge.js";
|
|
3
|
+
|
|
4
|
+
function createMessageEvent(data: unknown): MessageEvent {
|
|
5
|
+
return new MessageEvent("message", { data, source: {} as MessageEventSource });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
describe("PostMessageBridge", () => {
|
|
9
|
+
let bridge: PostMessageBridge;
|
|
10
|
+
let mockPostMessage: ReturnType<typeof vi.fn>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockPostMessage = vi.fn();
|
|
14
|
+
// Mock window.parent getter to return consistent object
|
|
15
|
+
vi.spyOn(window, "parent", "get").mockReturnValue({
|
|
16
|
+
postMessage: mockPostMessage,
|
|
17
|
+
} as any);
|
|
18
|
+
bridge = new PostMessageBridge();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
bridge.destroy();
|
|
23
|
+
vi.restoreAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("executes a registered tool and posts result to parent", async () => {
|
|
27
|
+
const execute = vi.fn().mockResolvedValue("filled name");
|
|
28
|
+
bridge.registerTool("fillForm", execute);
|
|
29
|
+
|
|
30
|
+
window.dispatchEvent(
|
|
31
|
+
createMessageEvent({
|
|
32
|
+
type: "localapp:tool_call",
|
|
33
|
+
callId: "c1",
|
|
34
|
+
toolName: "fillForm",
|
|
35
|
+
args: { field: "name", value: "张三" },
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalled());
|
|
40
|
+
|
|
41
|
+
expect(execute).toHaveBeenCalledWith({ field: "name", value: "张三" });
|
|
42
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
43
|
+
{ type: "localapp:tool_result", callId: "c1", result: "filled name", isError: false },
|
|
44
|
+
window.location.origin,
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("handles concurrent tool calls independently", async () => {
|
|
49
|
+
const exec1 = vi.fn().mockResolvedValue("result1");
|
|
50
|
+
const exec2 = vi.fn().mockResolvedValue("result2");
|
|
51
|
+
bridge.registerTool("tool1", exec1);
|
|
52
|
+
bridge.registerTool("tool2", exec2);
|
|
53
|
+
|
|
54
|
+
window.dispatchEvent(
|
|
55
|
+
createMessageEvent({ type: "localapp:tool_call", callId: "c1", toolName: "tool1", args: {} }),
|
|
56
|
+
);
|
|
57
|
+
window.dispatchEvent(
|
|
58
|
+
createMessageEvent({ type: "localapp:tool_call", callId: "c2", toolName: "tool2", args: {} }),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
await vi.waitFor(() => {
|
|
62
|
+
expect(exec1).toHaveBeenCalled();
|
|
63
|
+
expect(exec2).toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const calls = mockPostMessage.mock.calls.map((c: any[]) => c[0]);
|
|
67
|
+
expect(calls).toContainEqual({ type: "localapp:tool_result", callId: "c1", result: "result1", isError: false });
|
|
68
|
+
expect(calls).toContainEqual({ type: "localapp:tool_result", callId: "c2", result: "result2", isError: false });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("posts error result when execute throws", async () => {
|
|
72
|
+
const execute = vi.fn().mockRejectedValue(new Error("boom"));
|
|
73
|
+
bridge.registerTool("failTool", execute);
|
|
74
|
+
|
|
75
|
+
window.dispatchEvent(
|
|
76
|
+
createMessageEvent({ type: "localapp:tool_call", callId: "e1", toolName: "failTool", args: {} }),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
await vi.waitFor(() => expect(execute).toHaveBeenCalled());
|
|
80
|
+
|
|
81
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
82
|
+
{ type: "localapp:tool_result", callId: "e1", result: "boom", isError: true },
|
|
83
|
+
window.location.origin,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("ignores messages for unregistered tools", async () => {
|
|
88
|
+
window.dispatchEvent(
|
|
89
|
+
createMessageEvent({ type: "localapp:tool_call", callId: "x1", toolName: "unknown", args: {} }),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
93
|
+
expect(mockPostMessage).not.toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("ignores non-tool_call messages", async () => {
|
|
97
|
+
const execute = vi.fn();
|
|
98
|
+
bridge.registerTool("tool1", execute);
|
|
99
|
+
|
|
100
|
+
window.dispatchEvent(createMessageEvent({ type: "localapp:register_tools", tools: [] }));
|
|
101
|
+
window.dispatchEvent(createMessageEvent({ type: "something_else" }));
|
|
102
|
+
|
|
103
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
104
|
+
expect(execute).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("stops listening after destroy", async () => {
|
|
108
|
+
const execute = vi.fn();
|
|
109
|
+
bridge.registerTool("tool1", execute);
|
|
110
|
+
bridge.destroy();
|
|
111
|
+
|
|
112
|
+
window.dispatchEvent(
|
|
113
|
+
createMessageEvent({ type: "localapp:tool_call", callId: "d1", toolName: "tool1", args: {} }),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
117
|
+
expect(execute).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
});
|