@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,263 @@
|
|
|
1
|
+
import type { AssistantMessage, Context, Model, SimpleStreamOptions, AssistantMessageEventStream } from "@earendil-works/pi-ai";
|
|
2
|
+
import { createAssistantMessageEventStream } from "@earendil-works/pi-ai";
|
|
3
|
+
|
|
4
|
+
export interface LlmAdapterOptions {
|
|
5
|
+
proxyUrl: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function createStreamFn(options: LlmAdapterOptions) {
|
|
9
|
+
return (
|
|
10
|
+
_model: Model<any>,
|
|
11
|
+
context: Context,
|
|
12
|
+
_options?: SimpleStreamOptions,
|
|
13
|
+
): AssistantMessageEventStream => {
|
|
14
|
+
const stream = createAssistantMessageEventStream();
|
|
15
|
+
const apiBase = options.proxyUrl;
|
|
16
|
+
|
|
17
|
+
(async () => {
|
|
18
|
+
try {
|
|
19
|
+
const res = await fetch(`${apiBase}/api/llm/chat`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
credentials: "include",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
messages: [
|
|
25
|
+
...(context.systemPrompt ? [{ role: "system", content: context.systemPrompt }] : []),
|
|
26
|
+
...(context.messages ?? []).map((m) => {
|
|
27
|
+
if (m.role === "user") {
|
|
28
|
+
return {
|
|
29
|
+
role: "user",
|
|
30
|
+
content: typeof m.content === "string" ? m.content : JSON.stringify(m.content),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (m.role === "assistant") {
|
|
34
|
+
const text = m.content
|
|
35
|
+
.filter((c: any) => c.type === "text")
|
|
36
|
+
.map((c: any) => c.text)
|
|
37
|
+
.join("");
|
|
38
|
+
const toolCalls = m.content
|
|
39
|
+
.filter((c: any) => c.type === "toolCall")
|
|
40
|
+
.map((c: any) => ({
|
|
41
|
+
id: c.id,
|
|
42
|
+
type: "function",
|
|
43
|
+
function: { name: c.name, arguments: typeof c.arguments === "string" ? c.arguments : JSON.stringify(c.arguments) },
|
|
44
|
+
}));
|
|
45
|
+
const msg: any = { role: "assistant", content: text || null };
|
|
46
|
+
if (toolCalls.length > 0) msg.tool_calls = toolCalls;
|
|
47
|
+
if ((m as any).reasoning_content) msg.reasoning_content = (m as any).reasoning_content;
|
|
48
|
+
return msg;
|
|
49
|
+
}
|
|
50
|
+
if (m.role === "toolResult") {
|
|
51
|
+
const text = m.content
|
|
52
|
+
.filter((c: any) => c.type === "text")
|
|
53
|
+
.map((c: any) => c.text)
|
|
54
|
+
.join("\n");
|
|
55
|
+
return { role: "tool", content: text, tool_call_id: m.toolCallId };
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}).filter(Boolean)],
|
|
59
|
+
tools: context.tools?.map((t) => ({
|
|
60
|
+
type: "function",
|
|
61
|
+
function: {
|
|
62
|
+
name: t.name,
|
|
63
|
+
description: t.description,
|
|
64
|
+
parameters: t.parameters,
|
|
65
|
+
},
|
|
66
|
+
})),
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
const errText = await res.text().catch(() => "Unknown error");
|
|
72
|
+
const errorMsg = res.status === 401 ? "请先登录" : `LLM 请求失败: ${errText}`;
|
|
73
|
+
stream.push({
|
|
74
|
+
type: "error",
|
|
75
|
+
reason: "error",
|
|
76
|
+
error: {
|
|
77
|
+
role: "assistant",
|
|
78
|
+
content: [{ type: "text", text: errorMsg }],
|
|
79
|
+
api: "openai",
|
|
80
|
+
provider: "proxy",
|
|
81
|
+
model: "unknown",
|
|
82
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
83
|
+
stopReason: "error",
|
|
84
|
+
errorMessage: errorMsg,
|
|
85
|
+
timestamp: Date.now(),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
stream.end();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!res.body) {
|
|
93
|
+
stream.push({
|
|
94
|
+
type: "error",
|
|
95
|
+
reason: "error",
|
|
96
|
+
error: {
|
|
97
|
+
role: "assistant",
|
|
98
|
+
content: [{ type: "text", text: "Empty response" }],
|
|
99
|
+
api: "openai",
|
|
100
|
+
provider: "proxy",
|
|
101
|
+
model: "unknown",
|
|
102
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
103
|
+
stopReason: "error",
|
|
104
|
+
errorMessage: "Empty response body",
|
|
105
|
+
timestamp: Date.now(),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
stream.end();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const reader = res.body.getReader();
|
|
113
|
+
const decoder = new TextDecoder();
|
|
114
|
+
let buffer = "";
|
|
115
|
+
let contentIndex = 0;
|
|
116
|
+
let fullText = "";
|
|
117
|
+
let fullReasoning = "";
|
|
118
|
+
let started = false;
|
|
119
|
+
const toolCallBuffers: Map<number, { id: string; name: string; args: string }> = new Map();
|
|
120
|
+
|
|
121
|
+
const partial: AssistantMessage = {
|
|
122
|
+
role: "assistant",
|
|
123
|
+
content: [],
|
|
124
|
+
api: "openai",
|
|
125
|
+
provider: "proxy",
|
|
126
|
+
model: "unknown",
|
|
127
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
128
|
+
stopReason: "stop",
|
|
129
|
+
timestamp: Date.now(),
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
while (true) {
|
|
133
|
+
const { done, value } = await reader.read();
|
|
134
|
+
if (done) break;
|
|
135
|
+
|
|
136
|
+
buffer += decoder.decode(value, { stream: true });
|
|
137
|
+
const lines = buffer.split("\n");
|
|
138
|
+
buffer = lines.pop() || "";
|
|
139
|
+
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
const trimmed = line.trim();
|
|
142
|
+
if (!trimmed.startsWith("data: ")) continue;
|
|
143
|
+
const data = trimmed.slice(6);
|
|
144
|
+
if (data === "[DONE]") {
|
|
145
|
+
if (started && fullText) {
|
|
146
|
+
stream.push({ type: "text_end", contentIndex, content: fullText, partial });
|
|
147
|
+
}
|
|
148
|
+
for (const [idx, buf] of toolCallBuffers) {
|
|
149
|
+
if (!partial.content.some((c: any) => c.type === "toolCall" && c.id === buf.id)) {
|
|
150
|
+
let parsedArgs: Record<string, any> = {};
|
|
151
|
+
try { parsedArgs = JSON.parse(buf.args); } catch { parsedArgs = { raw: buf.args }; }
|
|
152
|
+
const toolCall = { type: "toolCall" as const, id: buf.id, name: buf.name, arguments: parsedArgs };
|
|
153
|
+
partial.content.push(toolCall);
|
|
154
|
+
stream.push({ type: "toolcall_end", contentIndex, toolCall, partial });
|
|
155
|
+
contentIndex++;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const reason: "stop" | "toolUse" = toolCallBuffers.size > 0 ? "toolUse" : "stop";
|
|
159
|
+
stream.push({ type: "done", reason, message: { ...partial, stopReason: reason } });
|
|
160
|
+
stream.end();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
const chunk = JSON.parse(data);
|
|
166
|
+
if (chunk.error) {
|
|
167
|
+
const errMsg = chunk.error?.message || chunk.error;
|
|
168
|
+
stream.push({
|
|
169
|
+
type: "error",
|
|
170
|
+
reason: "error",
|
|
171
|
+
error: {
|
|
172
|
+
...partial,
|
|
173
|
+
content: [{ type: "text", text: String(errMsg) }],
|
|
174
|
+
stopReason: "error",
|
|
175
|
+
errorMessage: String(errMsg),
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
stream.end();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const delta = chunk.choices?.[0]?.delta;
|
|
183
|
+
if (delta?.reasoning_content) {
|
|
184
|
+
fullReasoning += delta.reasoning_content;
|
|
185
|
+
(partial as any).reasoning_content = fullReasoning;
|
|
186
|
+
}
|
|
187
|
+
if (delta?.content) {
|
|
188
|
+
if (!started) {
|
|
189
|
+
stream.push({ type: "start", partial });
|
|
190
|
+
stream.push({ type: "text_start", contentIndex, partial });
|
|
191
|
+
started = true;
|
|
192
|
+
}
|
|
193
|
+
fullText += delta.content;
|
|
194
|
+
partial.content = [{ type: "text" as const, text: fullText }];
|
|
195
|
+
stream.push({ type: "text_delta", contentIndex, delta: delta.content, partial });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (delta?.tool_calls) {
|
|
199
|
+
for (const tc of delta.tool_calls) {
|
|
200
|
+
const idx = tc.index ?? 0;
|
|
201
|
+
if (!toolCallBuffers.has(idx)) {
|
|
202
|
+
toolCallBuffers.set(idx, { id: tc.id || `tc_${Date.now()}`, name: tc.function?.name || "", args: "" });
|
|
203
|
+
if (!started) {
|
|
204
|
+
stream.push({ type: "start", partial });
|
|
205
|
+
started = true;
|
|
206
|
+
}
|
|
207
|
+
stream.push({ type: "toolcall_start", contentIndex, partial });
|
|
208
|
+
}
|
|
209
|
+
const buf = toolCallBuffers.get(idx)!;
|
|
210
|
+
if (tc.function?.name) buf.name = tc.function.name;
|
|
211
|
+
if (tc.function?.arguments) {
|
|
212
|
+
buf.args += tc.function.arguments;
|
|
213
|
+
stream.push({ type: "toolcall_delta", contentIndex, delta: tc.function.arguments, partial });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (chunk.choices?.[0]?.finish_reason === "tool_calls") {
|
|
219
|
+
for (const [idx, buf] of toolCallBuffers) {
|
|
220
|
+
let parsedArgs: Record<string, any> = {};
|
|
221
|
+
try { parsedArgs = JSON.parse(buf.args); } catch { parsedArgs = { raw: buf.args }; }
|
|
222
|
+
const toolCall = { type: "toolCall" as const, id: buf.id, name: buf.name, arguments: parsedArgs };
|
|
223
|
+
partial.content.push(toolCall);
|
|
224
|
+
stream.push({ type: "toolcall_end", contentIndex, toolCall, partial });
|
|
225
|
+
contentIndex++;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} catch {
|
|
229
|
+
// Skip unparseable lines
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Stream ended without [DONE]
|
|
235
|
+
if (!started) {
|
|
236
|
+
stream.push({ type: "start", partial });
|
|
237
|
+
}
|
|
238
|
+
stream.push({ type: "done", reason: "stop", message: partial });
|
|
239
|
+
stream.end();
|
|
240
|
+
} catch (err) {
|
|
241
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
242
|
+
stream.push({
|
|
243
|
+
type: "error",
|
|
244
|
+
reason: "error",
|
|
245
|
+
error: {
|
|
246
|
+
role: "assistant",
|
|
247
|
+
content: [{ type: "text", text: msg }],
|
|
248
|
+
api: "openai",
|
|
249
|
+
provider: "proxy",
|
|
250
|
+
model: "unknown",
|
|
251
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
252
|
+
stopReason: "error",
|
|
253
|
+
errorMessage: msg,
|
|
254
|
+
timestamp: Date.now(),
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
stream.end();
|
|
258
|
+
}
|
|
259
|
+
})();
|
|
260
|
+
|
|
261
|
+
return stream;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ToolSchema } from "./postmessage-types.js";
|
|
2
|
+
|
|
3
|
+
export type NativeToolExecute = (args: Record<string, unknown>) => Promise<unknown>;
|
|
4
|
+
|
|
5
|
+
export interface PlatformToolRegistry {
|
|
6
|
+
registerTools(
|
|
7
|
+
tools: ToolSchema[],
|
|
8
|
+
executeFns: Record<string, NativeToolExecute>,
|
|
9
|
+
systemHint?: string,
|
|
10
|
+
): void | (() => void);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PlatformEditSession {
|
|
14
|
+
canSave: boolean;
|
|
15
|
+
canUndo: boolean;
|
|
16
|
+
canRedo: boolean;
|
|
17
|
+
busy?: boolean;
|
|
18
|
+
onSave: () => void | Promise<void>;
|
|
19
|
+
onUndo: () => void | Promise<void>;
|
|
20
|
+
onRedo: () => void | Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PlatformEditSessionRegistry {
|
|
24
|
+
registerEditSession(session: PlatformEditSession): void | (() => void);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const TOOL_REGISTRY_KEY = "__localapp_platform_tool_registry__";
|
|
28
|
+
const EDIT_SESSION_REGISTRY_KEY = "__localapp_platform_edit_session_registry__";
|
|
29
|
+
|
|
30
|
+
type RegistryGlobal = typeof globalThis & {
|
|
31
|
+
__localapp_platform_tool_registry__?: PlatformToolRegistry | null;
|
|
32
|
+
__localapp_platform_edit_session_registry__?: PlatformEditSessionRegistry | null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function registryGlobal(): RegistryGlobal {
|
|
36
|
+
return globalThis as RegistryGlobal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function setPlatformToolRegistry(registry: PlatformToolRegistry | null): void {
|
|
40
|
+
registryGlobal()[TOOL_REGISTRY_KEY] = registry;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getPlatformToolRegistry(): PlatformToolRegistry | null {
|
|
44
|
+
return registryGlobal()[TOOL_REGISTRY_KEY] ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isPlatformToolRegistryAvailable(): boolean {
|
|
48
|
+
return getPlatformToolRegistry() !== null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function setPlatformEditSessionRegistry(registry: PlatformEditSessionRegistry | null): void {
|
|
52
|
+
registryGlobal()[EDIT_SESSION_REGISTRY_KEY] = registry;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getPlatformEditSessionRegistry(): PlatformEditSessionRegistry | null {
|
|
56
|
+
return registryGlobal()[EDIT_SESSION_REGISTRY_KEY] ?? null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isPlatformEditSessionRegistryAvailable(): boolean {
|
|
60
|
+
return getPlatformEditSessionRegistry() !== null;
|
|
61
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPlatformResponseMessage,
|
|
3
|
+
postToParent,
|
|
4
|
+
type PlatformCapability,
|
|
5
|
+
type PlatformRequestMessage,
|
|
6
|
+
type PlatformResponseMessage,
|
|
7
|
+
} from "./postmessage-types.js";
|
|
8
|
+
|
|
9
|
+
export interface PlatformUser {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
displayName?: string | null;
|
|
13
|
+
avatarUrl?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DownloadFileOptions {
|
|
17
|
+
filename: string;
|
|
18
|
+
mimeType?: string;
|
|
19
|
+
data: string | ArrayBuffer | Blob;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface OpenRouteOptions {
|
|
23
|
+
href: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ConfirmOptions {
|
|
27
|
+
title?: string;
|
|
28
|
+
message: string;
|
|
29
|
+
confirmText?: string;
|
|
30
|
+
cancelText?: string;
|
|
31
|
+
tone?: "default" | "danger";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PlatformRuntime {
|
|
35
|
+
getCurrentUser(): Promise<PlatformUser | null>;
|
|
36
|
+
getServerTime(): Promise<{ now: string }>;
|
|
37
|
+
copyText(text: string): Promise<{ success: true }>;
|
|
38
|
+
downloadFile(options: DownloadFileOptions): Promise<{ success: true }>;
|
|
39
|
+
confirm(options: ConfirmOptions): Promise<boolean>;
|
|
40
|
+
openRoute(options: OpenRouteOptions): Promise<{ success: true }>;
|
|
41
|
+
ai: {
|
|
42
|
+
open(): Promise<{ success: true }>;
|
|
43
|
+
close(): Promise<{ success: true }>;
|
|
44
|
+
toggle(): Promise<{ success: true }>;
|
|
45
|
+
};
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface CreatePlatformRuntimeOptions {
|
|
50
|
+
requestId?: () => string;
|
|
51
|
+
timeoutMs?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type PendingRequest = {
|
|
55
|
+
resolve: (value: unknown) => void;
|
|
56
|
+
reject: (reason?: unknown) => void;
|
|
57
|
+
timeout: ReturnType<typeof setTimeout>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
61
|
+
|
|
62
|
+
function defaultRequestId(): string {
|
|
63
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
|
|
64
|
+
return crypto.randomUUID();
|
|
65
|
+
}
|
|
66
|
+
return `platform-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sendToHost(message: PlatformRequestMessage): void {
|
|
70
|
+
if (window.parent && window.parent !== window) {
|
|
71
|
+
postToParent(message);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
window.dispatchEvent(new CustomEvent("localapp:platform_request", { detail: message }));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createPlatformRuntime(options: CreatePlatformRuntimeOptions = {}): PlatformRuntime {
|
|
78
|
+
const requestId = options.requestId ?? defaultRequestId;
|
|
79
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
80
|
+
const pending = new Map<string, PendingRequest>();
|
|
81
|
+
|
|
82
|
+
function onMessage(event: MessageEvent) {
|
|
83
|
+
if (!isPlatformResponseMessage(event.data)) return;
|
|
84
|
+
const message: PlatformResponseMessage = event.data;
|
|
85
|
+
const entry = pending.get(message.id);
|
|
86
|
+
if (!entry) return;
|
|
87
|
+
pending.delete(message.id);
|
|
88
|
+
clearTimeout(entry.timeout);
|
|
89
|
+
if (message.ok) {
|
|
90
|
+
entry.resolve(message.result);
|
|
91
|
+
} else {
|
|
92
|
+
entry.reject(new Error(message.error || "Platform capability request failed"));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
window.addEventListener("message", onMessage);
|
|
97
|
+
|
|
98
|
+
function request<T>(capability: PlatformCapability, payload?: unknown): Promise<T> {
|
|
99
|
+
const id = requestId();
|
|
100
|
+
const message: PlatformRequestMessage = {
|
|
101
|
+
type: "localapp:platform_request",
|
|
102
|
+
id,
|
|
103
|
+
capability,
|
|
104
|
+
...(payload === undefined ? {} : { payload }),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return new Promise<T>((resolve, reject) => {
|
|
108
|
+
const timeout = setTimeout(() => {
|
|
109
|
+
pending.delete(id);
|
|
110
|
+
reject(new Error(`Platform capability request timed out: ${capability}`));
|
|
111
|
+
}, timeoutMs);
|
|
112
|
+
pending.set(id, { resolve: resolve as (value: unknown) => void, reject, timeout });
|
|
113
|
+
sendToHost(message);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
getCurrentUser: () => request<PlatformUser | null>("getCurrentUser"),
|
|
119
|
+
getServerTime: () => request<{ now: string }>("getServerTime"),
|
|
120
|
+
copyText: (text: string) => request<{ success: true }>("copyText", { text }),
|
|
121
|
+
downloadFile: (payload: DownloadFileOptions) => request<{ success: true }>("downloadFile", payload),
|
|
122
|
+
confirm: (payload: ConfirmOptions) => request<boolean>("confirm", payload),
|
|
123
|
+
openRoute: (payload: OpenRouteOptions) => request<{ success: true }>("openRoute", payload),
|
|
124
|
+
ai: {
|
|
125
|
+
open: () => request<{ success: true }>("ai.open"),
|
|
126
|
+
close: () => request<{ success: true }>("ai.close"),
|
|
127
|
+
toggle: () => request<{ success: true }>("ai.toggle"),
|
|
128
|
+
},
|
|
129
|
+
destroy: () => {
|
|
130
|
+
window.removeEventListener("message", onMessage);
|
|
131
|
+
for (const [id, entry] of pending.entries()) {
|
|
132
|
+
clearTimeout(entry.timeout);
|
|
133
|
+
entry.reject(new Error("Platform runtime destroyed"));
|
|
134
|
+
pending.delete(id);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let platformSingleton: PlatformRuntime | null = null;
|
|
141
|
+
|
|
142
|
+
function getPlatformSingleton(): PlatformRuntime {
|
|
143
|
+
if (!platformSingleton) platformSingleton = createPlatformRuntime();
|
|
144
|
+
return platformSingleton;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export const platform: PlatformRuntime = {
|
|
148
|
+
getCurrentUser: () => getPlatformSingleton().getCurrentUser(),
|
|
149
|
+
getServerTime: () => getPlatformSingleton().getServerTime(),
|
|
150
|
+
copyText: (text: string) => getPlatformSingleton().copyText(text),
|
|
151
|
+
downloadFile: (options: DownloadFileOptions) => getPlatformSingleton().downloadFile(options),
|
|
152
|
+
confirm: (options: ConfirmOptions) => getPlatformSingleton().confirm(options),
|
|
153
|
+
openRoute: (options: OpenRouteOptions) => getPlatformSingleton().openRoute(options),
|
|
154
|
+
ai: {
|
|
155
|
+
open: () => getPlatformSingleton().ai.open(),
|
|
156
|
+
close: () => getPlatformSingleton().ai.close(),
|
|
157
|
+
toggle: () => getPlatformSingleton().ai.toggle(),
|
|
158
|
+
},
|
|
159
|
+
destroy: () => {
|
|
160
|
+
platformSingleton?.destroy();
|
|
161
|
+
platformSingleton = null;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
export { isPlatformResponseMessage };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isToolCallMessage, postToParent } from "./postmessage-types.js";
|
|
2
|
+
import type { ToolResultMessage } from "./postmessage-types.js";
|
|
3
|
+
import type { UserToolDef } from "./types.js";
|
|
4
|
+
|
|
5
|
+
type ExecuteFn = (args: Record<string, unknown>) => Promise<unknown>;
|
|
6
|
+
|
|
7
|
+
export class PostMessageBridge {
|
|
8
|
+
private tools = new Map<string, ExecuteFn>();
|
|
9
|
+
private handler: (event: MessageEvent) => void;
|
|
10
|
+
private activeCalls = new Map<string, Promise<void>>();
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.handler = this.onMessage.bind(this);
|
|
14
|
+
window.addEventListener("message", this.handler);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
registerTool(name: string, execute: ExecuteFn): void {
|
|
18
|
+
this.tools.set(name, execute);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
unregisterTool(name: string): void {
|
|
22
|
+
this.tools.delete(name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private onMessage(event: MessageEvent): void {
|
|
26
|
+
if (!isToolCallMessage(event.data)) return;
|
|
27
|
+
|
|
28
|
+
const { callId, toolName, args } = event.data;
|
|
29
|
+
const execute = this.tools.get(toolName);
|
|
30
|
+
if (!execute) return;
|
|
31
|
+
|
|
32
|
+
const promise = this.executeAndRespond(callId, toolName, execute, args);
|
|
33
|
+
this.activeCalls.set(callId, promise);
|
|
34
|
+
promise.finally(() => this.activeCalls.delete(callId));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private async executeAndRespond(
|
|
38
|
+
callId: string,
|
|
39
|
+
toolName: string,
|
|
40
|
+
execute: ExecuteFn,
|
|
41
|
+
args: Record<string, unknown>,
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
let result: unknown;
|
|
44
|
+
let isError = false;
|
|
45
|
+
try {
|
|
46
|
+
result = await execute(args);
|
|
47
|
+
} catch (e: unknown) {
|
|
48
|
+
result = e instanceof Error ? e.message : String(e);
|
|
49
|
+
isError = true;
|
|
50
|
+
}
|
|
51
|
+
const msg: ToolResultMessage = { type: "localapp:tool_result", callId, result, isError };
|
|
52
|
+
postToParent(msg);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
destroy(): void {
|
|
56
|
+
window.removeEventListener("message", this.handler);
|
|
57
|
+
this.tools.clear();
|
|
58
|
+
this.activeCalls.clear();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// ---- Shell/app message protocol ----
|
|
2
|
+
|
|
3
|
+
const PREFIX = "localapp:";
|
|
4
|
+
|
|
5
|
+
// Native same-page runtime is the production default. These message types are
|
|
6
|
+
// retained for legacy framed apps, dev compatibility, and same-window events.
|
|
7
|
+
|
|
8
|
+
// ---- App to Shell messages ----
|
|
9
|
+
|
|
10
|
+
export interface RegisterToolsMessage {
|
|
11
|
+
type: typeof PREFIX extends `${infer P}` ? `${P}register_tools` : never;
|
|
12
|
+
tools: ToolSchema[];
|
|
13
|
+
systemHint?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AiCustomModeMessage {
|
|
17
|
+
type: "localapp:ai_custom_mode";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface HideShellMessage {
|
|
21
|
+
type: "localapp:hide_shell";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type PlatformCapability =
|
|
25
|
+
| "getCurrentUser"
|
|
26
|
+
| "getServerTime"
|
|
27
|
+
| "copyText"
|
|
28
|
+
| "downloadFile"
|
|
29
|
+
| "confirm"
|
|
30
|
+
| "openRoute"
|
|
31
|
+
| "auth.login"
|
|
32
|
+
| "ai.open"
|
|
33
|
+
| "ai.close"
|
|
34
|
+
| "ai.toggle";
|
|
35
|
+
|
|
36
|
+
export interface PlatformRequestMessage {
|
|
37
|
+
type: "localapp:platform_request";
|
|
38
|
+
id: string;
|
|
39
|
+
capability: PlatformCapability;
|
|
40
|
+
payload?: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface PlatformResponseMessage {
|
|
44
|
+
type: "localapp:platform_response";
|
|
45
|
+
id: string;
|
|
46
|
+
ok: boolean;
|
|
47
|
+
result?: unknown;
|
|
48
|
+
error?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ToolResultMessage {
|
|
52
|
+
type: "localapp:tool_result";
|
|
53
|
+
callId: string;
|
|
54
|
+
result: unknown;
|
|
55
|
+
isError?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ---- Shell to App messages ----
|
|
59
|
+
|
|
60
|
+
export interface ToolCallMessage {
|
|
61
|
+
type: "localapp:tool_call";
|
|
62
|
+
callId: string;
|
|
63
|
+
toolName: string;
|
|
64
|
+
args: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ToggleChatMessage {
|
|
68
|
+
type: "localapp:toggle_chat";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ---- Shared types ----
|
|
72
|
+
|
|
73
|
+
export interface ToolSchema {
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
parameters: {
|
|
77
|
+
type: "object";
|
|
78
|
+
properties: {
|
|
79
|
+
[key: string]: {
|
|
80
|
+
type: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
required?: string[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---- Message type guards ----
|
|
89
|
+
|
|
90
|
+
function isObject(v: unknown): v is Record<string, unknown> {
|
|
91
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isRegisterToolsMessage(v: unknown): v is RegisterToolsMessage {
|
|
95
|
+
return isObject(v) && v.type === "localapp:register_tools";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function isAiCustomModeMessage(v: unknown): v is AiCustomModeMessage {
|
|
99
|
+
return isObject(v) && v.type === "localapp:ai_custom_mode";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isToolResultMessage(v: unknown): v is ToolResultMessage {
|
|
103
|
+
return isObject(v) && v.type === "localapp:tool_result";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function isToolCallMessage(v: unknown): v is ToolCallMessage {
|
|
107
|
+
return isObject(v) && v.type === "localapp:tool_call";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function isToggleChatMessage(v: unknown): v is ToggleChatMessage {
|
|
111
|
+
return isObject(v) && v.type === "localapp:toggle_chat";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function isHideShellMessage(v: unknown): v is HideShellMessage {
|
|
115
|
+
return isObject(v) && v.type === "localapp:hide_shell";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function isPlatformRequestMessage(v: unknown): v is PlatformRequestMessage {
|
|
119
|
+
return (
|
|
120
|
+
isObject(v) &&
|
|
121
|
+
v.type === "localapp:platform_request" &&
|
|
122
|
+
typeof v.id === "string" &&
|
|
123
|
+
typeof v.capability === "string"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function isPlatformResponseMessage(v: unknown): v is PlatformResponseMessage {
|
|
128
|
+
return (
|
|
129
|
+
isObject(v) &&
|
|
130
|
+
v.type === "localapp:platform_response" &&
|
|
131
|
+
typeof v.id === "string" &&
|
|
132
|
+
typeof v.ok === "boolean"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---- Helper to send messages ----
|
|
137
|
+
|
|
138
|
+
export function postToParent(message: unknown): void {
|
|
139
|
+
if (window.parent && window.parent !== window) {
|
|
140
|
+
window.parent.postMessage(message, window.location.origin);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function postToIframe(iframe: HTMLIFrameElement, message: unknown): void {
|
|
145
|
+
iframe.contentWindow?.postMessage(message, window.location.origin);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function hideShell(): void {
|
|
149
|
+
postToParent({ type: "localapp:hide_shell" });
|
|
150
|
+
}
|