@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.
Files changed (527) hide show
  1. package/.localapp-artifact.json +2731 -0
  2. package/LICENSE +21 -0
  3. package/README.md +288 -0
  4. package/bin/localapp.mjs +34182 -0
  5. package/package.json +21 -0
  6. package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
  7. package/runtime/native/adapter-manifest.json +85 -0
  8. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
  9. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  10. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  11. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  12. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
  13. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  14. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  15. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  16. package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
  17. package/runtime/native/linux-x64/localapp-notifications +0 -0
  18. package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
  19. package/runtime/native/win32-x64/localapp-native.exe +0 -0
  20. package/runtime/server/.localapp-server-runtime.json +133 -0
  21. package/runtime/server/bin/server-cli.cjs +8343 -0
  22. package/runtime/server/bin/server.mjs +8 -0
  23. package/runtime/server/bin/worker.cjs +144339 -0
  24. package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
  25. package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
  26. package/runtime/server/node_modules/sql.js/package.json +58 -0
  27. package/runtime/server/package.json +11 -0
  28. package/runtime/server/runner/localapp-runner.mjs +324 -0
  29. package/runtime/server/web/404.html +1 -0
  30. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
  31. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
  32. package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
  33. package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
  34. package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
  35. package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
  36. package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
  37. package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
  38. package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
  39. package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
  40. package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
  41. package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
  42. package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
  43. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
  44. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
  45. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
  46. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
  47. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
  48. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
  49. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
  50. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
  51. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
  52. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
  53. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
  54. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
  55. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
  56. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
  57. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
  58. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
  59. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
  60. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
  61. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
  62. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
  63. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
  64. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
  65. package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
  66. package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
  67. package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
  68. package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
  69. package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
  70. package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
  71. package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
  72. package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
  73. package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
  74. package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
  75. package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
  76. package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  77. package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
  78. package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
  79. package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
  80. package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
  81. package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
  82. package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
  83. package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
  84. package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
  85. package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
  86. package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
  87. package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
  88. package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
  89. package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
  90. package/runtime/server/web/home/redline-launch-hero.png +0 -0
  91. package/runtime/server/web/inbox.html +1 -0
  92. package/runtime/server/web/inbox.txt +27 -0
  93. package/runtime/server/web/index.html +1 -0
  94. package/runtime/server/web/index.txt +27 -0
  95. package/runtime/server/web/my/analytics.html +1 -0
  96. package/runtime/server/web/my/analytics.txt +27 -0
  97. package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
  98. package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
  99. package/runtime/server/web/my/apps.html +1 -0
  100. package/runtime/server/web/my/apps.txt +27 -0
  101. package/runtime/server/web/my/dashboard.html +1 -0
  102. package/runtime/server/web/my/dashboard.txt +27 -0
  103. package/runtime/server/web/my/device-actions.html +1 -0
  104. package/runtime/server/web/my/device-actions.txt +24 -0
  105. package/runtime/server/web/my/device-notifications.html +1 -0
  106. package/runtime/server/web/my/device-notifications.txt +24 -0
  107. package/runtime/server/web/my/favorites.html +1 -0
  108. package/runtime/server/web/my/favorites.txt +27 -0
  109. package/runtime/server/web/my/groups.html +1 -0
  110. package/runtime/server/web/my/groups.txt +27 -0
  111. package/runtime/server/web/my/info.html +1 -0
  112. package/runtime/server/web/my/info.txt +27 -0
  113. package/runtime/server/web/my/keys.html +1 -0
  114. package/runtime/server/web/my/keys.txt +27 -0
  115. package/runtime/server/web/my/orgs.html +1 -0
  116. package/runtime/server/web/my/orgs.txt +27 -0
  117. package/runtime/server/web/my/pages.html +1 -0
  118. package/runtime/server/web/my/pages.txt +27 -0
  119. package/runtime/server/web/my/peers.html +1 -0
  120. package/runtime/server/web/my/peers.txt +24 -0
  121. package/runtime/server/web/my/recent.html +1 -0
  122. package/runtime/server/web/my/recent.txt +27 -0
  123. package/runtime/server/web/my/settings.html +1 -0
  124. package/runtime/server/web/my/settings.txt +27 -0
  125. package/runtime/server/web/my/studio.html +1 -0
  126. package/runtime/server/web/my/studio.txt +24 -0
  127. package/runtime/server/web/my/subscriptions.html +1 -0
  128. package/runtime/server/web/my/subscriptions.txt +27 -0
  129. package/runtime/server/web/my/system.html +1 -0
  130. package/runtime/server/web/my/system.txt +24 -0
  131. package/runtime/server/web/my/tasks.html +1 -0
  132. package/runtime/server/web/my/tasks.txt +24 -0
  133. package/runtime/server/web/my/users.html +1 -0
  134. package/runtime/server/web/my/users.txt +27 -0
  135. package/runtime/server/web/my.html +1 -0
  136. package/runtime/server/web/my.txt +27 -0
  137. package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
  138. package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
  139. package/runtime/server/web/platform-shell-preview.html +1 -0
  140. package/runtime/server/web/platform-shell-preview.txt +23 -0
  141. package/runtime/server/web/setup.html +1 -0
  142. package/runtime/server/web/setup.txt +23 -0
  143. package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
  144. package/template/.claude/skills/localapp/SKILL.md +80 -0
  145. package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
  146. package/template/.claude/skills/localapp-business/SKILL.md +325 -0
  147. package/template/.claude/skills/localapp-data/SKILL.md +381 -0
  148. package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
  149. package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
  150. package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
  151. package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
  152. package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
  153. package/template/AGENTS.md +33 -0
  154. package/template/CLAUDE.md +117 -0
  155. package/template/ISSUES.md +32 -0
  156. package/template/backend/resources/work_items/mutations.json +83 -0
  157. package/template/backend/resources/work_items/queries.json +83 -0
  158. package/template/backend/resources/work_items/schema.json +31 -0
  159. package/template/backend/schemas/mutations.schema.json +15 -0
  160. package/template/backend/schemas/queries.schema.json +36 -0
  161. package/template/backend/schemas/resource-schema.schema.json +25 -0
  162. package/template/components.json +25 -0
  163. package/template/index.html +12 -0
  164. package/template/migrations/001_work_items.sql +6 -0
  165. package/template/package.json +70 -0
  166. package/template/postcss.config.js +5 -0
  167. package/template/runtime/dev-shell.tsx +6398 -0
  168. package/template/runtime/hooks/use-mobile.ts +19 -0
  169. package/template/runtime/issue-reference.ts +44 -0
  170. package/template/runtime/lib/utils.ts +6 -0
  171. package/template/runtime/package.json +14 -0
  172. package/template/runtime/platform-capabilities.json +109 -0
  173. package/template/runtime/sdk/agent/package.json +51 -0
  174. package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
  175. package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
  176. package/template/runtime/sdk/agent/src/context.ts +56 -0
  177. package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
  178. package/template/runtime/sdk/agent/src/index.ts +19 -0
  179. package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
  180. package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
  181. package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
  182. package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
  183. package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
  184. package/template/runtime/sdk/agent/src/tools.ts +70 -0
  185. package/template/runtime/sdk/agent/src/types.ts +27 -0
  186. package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
  187. package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
  188. package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
  189. package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
  190. package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
  191. package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
  192. package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
  193. package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
  194. package/template/runtime/sdk/agent/tsconfig.json +18 -0
  195. package/template/runtime/sdk/agent/vitest.config.ts +8 -0
  196. package/template/runtime/sdk/backend/package.json +15 -0
  197. package/template/runtime/sdk/backend/src/index.ts +92 -0
  198. package/template/runtime/sdk/backend/tsconfig.json +8 -0
  199. package/template/runtime/sdk/core/package.json +15 -0
  200. package/template/runtime/sdk/core/src/client.ts +317 -0
  201. package/template/runtime/sdk/core/src/collaboration.ts +66 -0
  202. package/template/runtime/sdk/core/src/desktop.ts +469 -0
  203. package/template/runtime/sdk/core/src/device.ts +112 -0
  204. package/template/runtime/sdk/core/src/index.ts +6 -0
  205. package/template/runtime/sdk/core/src/invalidate.ts +40 -0
  206. package/template/runtime/sdk/core/src/types.ts +108 -0
  207. package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
  208. package/template/runtime/sdk/core/tests/client.test.ts +424 -0
  209. package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
  210. package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
  211. package/template/runtime/sdk/core/tests/device.test.ts +69 -0
  212. package/template/runtime/sdk/core/tsconfig.json +17 -0
  213. package/template/runtime/sdk/react/package.json +34 -0
  214. package/template/runtime/sdk/react/src/client.ts +7 -0
  215. package/template/runtime/sdk/react/src/components/can.tsx +24 -0
  216. package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
  217. package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
  218. package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
  219. package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
  220. package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
  221. package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
  222. package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
  223. package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
  224. package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
  225. package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
  226. package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
  227. package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
  228. package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
  229. package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
  230. package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
  231. package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
  232. package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
  233. package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
  234. package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
  235. package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
  236. package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
  237. package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
  238. package/template/runtime/sdk/react/src/index.ts +40 -0
  239. package/template/runtime/sdk/react/src/permissions.ts +94 -0
  240. package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
  241. package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
  242. package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
  243. package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
  244. package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
  245. package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
  246. package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
  247. package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
  248. package/template/runtime/sdk/react/tsconfig.json +18 -0
  249. package/template/runtime/sdk/react/vitest.config.ts +9 -0
  250. package/template/runtime/sdk/react/vitest.setup.ts +6 -0
  251. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
  252. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
  253. package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
  254. package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
  255. package/template/runtime/server-core/dist/index.d.ts +19 -0
  256. package/template/runtime/server-core/dist/index.d.ts.map +1 -0
  257. package/template/runtime/server-core/dist/index.js +35 -0
  258. package/template/runtime/server-core/dist/index.js.map +1 -0
  259. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
  260. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
  261. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
  262. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
  263. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
  264. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
  265. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
  266. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
  267. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
  268. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
  269. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
  270. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
  271. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
  272. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
  273. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
  274. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
  275. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
  276. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
  277. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
  278. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
  279. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
  280. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
  281. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
  282. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
  283. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
  284. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
  285. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
  286. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
  287. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
  288. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
  289. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
  290. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
  291. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
  292. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
  293. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
  294. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
  295. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
  296. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
  297. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
  298. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
  299. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
  300. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
  301. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
  302. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
  303. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
  304. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
  305. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
  306. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
  307. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
  308. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
  309. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
  310. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
  311. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
  312. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
  313. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
  314. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
  315. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
  316. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
  317. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
  318. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
  319. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
  320. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
  321. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
  322. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
  323. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
  324. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
  325. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
  326. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
  327. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
  328. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
  329. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
  330. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
  331. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
  332. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
  333. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
  334. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
  335. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
  336. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
  337. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
  338. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
  339. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
  340. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
  341. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
  342. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
  343. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
  344. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
  345. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
  346. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
  347. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
  348. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
  349. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
  350. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
  351. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
  352. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
  353. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
  354. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
  355. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
  356. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
  357. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
  358. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
  359. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
  360. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
  361. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
  362. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
  363. package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
  364. package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
  365. package/template/runtime/server-core/dist/lib/access-control.js +138 -0
  366. package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
  367. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
  368. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
  369. package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
  370. package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
  371. package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
  372. package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
  373. package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
  374. package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
  375. package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
  376. package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
  377. package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
  378. package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
  379. package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
  380. package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
  381. package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
  382. package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
  383. package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
  384. package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
  385. package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
  386. package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
  387. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
  388. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
  389. package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
  390. package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
  391. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
  392. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
  393. package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
  394. package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
  395. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
  396. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
  397. package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
  398. package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
  399. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
  400. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
  401. package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
  402. package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
  403. package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
  404. package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
  405. package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
  406. package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
  407. package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
  408. package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
  409. package/template/runtime/server-core/dist/lib/migrations.js +180 -0
  410. package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
  411. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
  412. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
  413. package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
  414. package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
  415. package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
  416. package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
  417. package/template/runtime/server-core/dist/lib/record-access.js +81 -0
  418. package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
  419. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
  420. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
  421. package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
  422. package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
  423. package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
  424. package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
  425. package/template/runtime/server-core/dist/lib/transitions.js +142 -0
  426. package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
  427. package/template/runtime/server-core/dist/types/models.d.ts +163 -0
  428. package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
  429. package/template/runtime/server-core/dist/types/models.js +3 -0
  430. package/template/runtime/server-core/dist/types/models.js.map +1 -0
  431. package/template/runtime/server-core/package.json +24 -0
  432. package/template/runtime/styles/preset.css +282 -0
  433. package/template/runtime/sync-template-command.cjs +19 -0
  434. package/template/runtime/sync-template.cjs +71 -0
  435. package/template/runtime/tsconfig.base.json +20 -0
  436. package/template/runtime/version.json +3 -0
  437. package/template/runtime/vite-plugin.mjs +309 -0
  438. package/template/src/App.tsx +273 -0
  439. package/template/src/components/ui/accordion.tsx +79 -0
  440. package/template/src/components/ui/alert-dialog.tsx +197 -0
  441. package/template/src/components/ui/alert.tsx +76 -0
  442. package/template/src/components/ui/aspect-ratio.tsx +11 -0
  443. package/template/src/components/ui/avatar.tsx +110 -0
  444. package/template/src/components/ui/badge.tsx +49 -0
  445. package/template/src/components/ui/breadcrumb.tsx +122 -0
  446. package/template/src/components/ui/button-group.tsx +83 -0
  447. package/template/src/components/ui/button.tsx +67 -0
  448. package/template/src/components/ui/calendar.tsx +221 -0
  449. package/template/src/components/ui/card.tsx +103 -0
  450. package/template/src/components/ui/carousel.tsx +240 -0
  451. package/template/src/components/ui/chart.tsx +373 -0
  452. package/template/src/components/ui/checkbox.tsx +31 -0
  453. package/template/src/components/ui/collapsible.tsx +33 -0
  454. package/template/src/components/ui/combobox.tsx +299 -0
  455. package/template/src/components/ui/command.tsx +193 -0
  456. package/template/src/components/ui/context-menu.tsx +261 -0
  457. package/template/src/components/ui/dialog.tsx +168 -0
  458. package/template/src/components/ui/direction.tsx +22 -0
  459. package/template/src/components/ui/drawer.tsx +132 -0
  460. package/template/src/components/ui/dropdown-menu.tsx +269 -0
  461. package/template/src/components/ui/empty.tsx +104 -0
  462. package/template/src/components/ui/field.tsx +238 -0
  463. package/template/src/components/ui/hover-card.tsx +42 -0
  464. package/template/src/components/ui/input-group.tsx +154 -0
  465. package/template/src/components/ui/input-otp.tsx +87 -0
  466. package/template/src/components/ui/input.tsx +19 -0
  467. package/template/src/components/ui/item.tsx +196 -0
  468. package/template/src/components/ui/kbd.tsx +26 -0
  469. package/template/src/components/ui/label.tsx +22 -0
  470. package/template/src/components/ui/menubar.tsx +280 -0
  471. package/template/src/components/ui/native-select.tsx +61 -0
  472. package/template/src/components/ui/navigation-menu.tsx +164 -0
  473. package/template/src/components/ui/pagination.tsx +129 -0
  474. package/template/src/components/ui/popover.tsx +87 -0
  475. package/template/src/components/ui/progress.tsx +31 -0
  476. package/template/src/components/ui/radio-group.tsx +42 -0
  477. package/template/src/components/ui/resizable.tsx +50 -0
  478. package/template/src/components/ui/scroll-area.tsx +53 -0
  479. package/template/src/components/ui/select.tsx +192 -0
  480. package/template/src/components/ui/separator.tsx +26 -0
  481. package/template/src/components/ui/sheet.tsx +145 -0
  482. package/template/src/components/ui/sidebar.tsx +700 -0
  483. package/template/src/components/ui/skeleton.tsx +13 -0
  484. package/template/src/components/ui/slider.tsx +59 -0
  485. package/template/src/components/ui/sonner.tsx +47 -0
  486. package/template/src/components/ui/spinner.tsx +10 -0
  487. package/template/src/components/ui/switch.tsx +33 -0
  488. package/template/src/components/ui/table.tsx +114 -0
  489. package/template/src/components/ui/tabs.tsx +90 -0
  490. package/template/src/components/ui/textarea.tsx +18 -0
  491. package/template/src/components/ui/toggle-group.tsx +89 -0
  492. package/template/src/components/ui/toggle.tsx +45 -0
  493. package/template/src/components/ui/tooltip.tsx +57 -0
  494. package/template/src/hooks/use-mobile.ts +3 -0
  495. package/template/src/index.css +4 -0
  496. package/template/src/lib/utils.ts +3 -0
  497. package/template/src/main.tsx +10 -0
  498. package/template/src/vite-env.d.ts +1 -0
  499. package/template/template.gitignore +10 -0
  500. package/template/template.npmrc +1 -0
  501. package/template/tests/agent-context.test.ts +69 -0
  502. package/template/tests/agent-guidance-template.test.ts +49 -0
  503. package/template/tests/agent-runtime.test.ts +198 -0
  504. package/template/tests/agent-tools.test.ts +150 -0
  505. package/template/tests/agent-use-agent.test.ts +86 -0
  506. package/template/tests/assistant-ui-adapter.test.ts +211 -0
  507. package/template/tests/business-modeling-template.test.ts +71 -0
  508. package/template/tests/client.test.ts +382 -0
  509. package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
  510. package/template/tests/dev-shell-context.test.tsx +40 -0
  511. package/template/tests/dev-shell-template.test.ts +2593 -0
  512. package/template/tests/invalidation.test.ts +126 -0
  513. package/template/tests/main-tsx.test.ts +28 -0
  514. package/template/tests/media-preview-template.test.ts +21 -0
  515. package/template/tests/mutations.test.ts +224 -0
  516. package/template/tests/react.test.ts +302 -0
  517. package/template/tests/redirect.test.ts +51 -0
  518. package/template/tests/skill-docs.test.ts +76 -0
  519. package/template/tests/state-transitions-template.test.ts +61 -0
  520. package/template/tests/template-ui.test.ts +145 -0
  521. package/template/tests/upload.test.ts +143 -0
  522. package/template/tests/vite-plugin.test.ts +426 -0
  523. package/template/tests/vite-proxy-security.test.ts +153 -0
  524. package/template/tsconfig.json +11 -0
  525. package/template/vite.config.ts +7 -0
  526. package/template/vitest.config.ts +16 -0
  527. package/template/vitest.setup.ts +1 -0
@@ -0,0 +1,211 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { convertMessages } from "@localapp/sdk-agent";
3
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
4
+
5
+ describe("assistant-ui-adapter > convertMessages", () => {
6
+ it("转换空消息数组", () => {
7
+ expect(convertMessages([])).toEqual([]);
8
+ });
9
+
10
+ it("转换用户文本消息", () => {
11
+ const msgs: AgentMessage[] = [
12
+ { role: "user", content: "你好", timestamp: Date.now() },
13
+ ];
14
+ const result = convertMessages(msgs);
15
+ expect(result).toHaveLength(1);
16
+ expect(result[0].role).toBe("user");
17
+ expect(result[0].content).toBe("你好");
18
+ });
19
+
20
+ it("转换用户消息(数组 content)", () => {
21
+ const msgs: AgentMessage[] = [
22
+ {
23
+ role: "user",
24
+ content: [{ type: "text", text: "hello" }],
25
+ timestamp: Date.now(),
26
+ },
27
+ ];
28
+ const result = convertMessages(msgs);
29
+ expect(result).toHaveLength(1);
30
+ expect(result[0].content).toBe("hello");
31
+ });
32
+
33
+ it("转换助手文本消息", () => {
34
+ const msgs: AgentMessage[] = [
35
+ {
36
+ role: "assistant",
37
+ content: [{ type: "text", text: "好的" }],
38
+ api: "openai" as any,
39
+ provider: "openai" as any,
40
+ model: "gpt-4",
41
+ usage: {} as any,
42
+ stopReason: "stop",
43
+ timestamp: Date.now(),
44
+ },
45
+ ];
46
+ const result = convertMessages(msgs);
47
+ expect(result).toHaveLength(1);
48
+ expect(result[0].role).toBe("assistant");
49
+ const parts = result[0].content as any[];
50
+ expect(parts[0]).toEqual({ type: "text", text: "好的" });
51
+ });
52
+
53
+ it("转换助手消息中的工具调用", () => {
54
+ const msgs: AgentMessage[] = [
55
+ {
56
+ role: "assistant",
57
+ content: [
58
+ { type: "text", text: "我来填写" },
59
+ {
60
+ type: "toolCall",
61
+ id: "call_1",
62
+ name: "fillForm",
63
+ arguments: { field: "name", value: "张三" },
64
+ },
65
+ ],
66
+ api: "openai" as any,
67
+ provider: "openai" as any,
68
+ model: "gpt-4",
69
+ usage: {} as any,
70
+ stopReason: "toolUse",
71
+ timestamp: Date.now(),
72
+ },
73
+ ];
74
+ const result = convertMessages(msgs);
75
+ const parts = result[0].content as any[];
76
+ expect(parts).toHaveLength(2);
77
+ expect(parts[0]).toEqual({ type: "text", text: "我来填写" });
78
+ expect(parts[1].type).toBe("tool-call");
79
+ expect(parts[1].toolCallId).toBe("call_1");
80
+ expect(parts[1].toolName).toBe("fillForm");
81
+ expect(parts[1].args).toEqual({ field: "name", value: "张三" });
82
+ expect(parts[1].argsText).toBe('{"field":"name","value":"张三"}');
83
+ });
84
+
85
+ it("将 ToolResultMessage 合并回 assistant 消息的 tool-call part", () => {
86
+ const msgs: AgentMessage[] = [
87
+ {
88
+ role: "assistant",
89
+ content: [
90
+ {
91
+ type: "toolCall",
92
+ id: "c1",
93
+ name: "fillForm",
94
+ arguments: { field: "name" },
95
+ },
96
+ ],
97
+ api: "openai" as any,
98
+ provider: "openai" as any,
99
+ model: "gpt-4",
100
+ usage: {} as any,
101
+ stopReason: "toolUse",
102
+ timestamp: Date.now(),
103
+ },
104
+ {
105
+ role: "toolResult",
106
+ toolCallId: "c1",
107
+ toolName: "fillForm",
108
+ content: [{ type: "text", text: '"已填写 name"' }],
109
+ isError: false,
110
+ timestamp: Date.now(),
111
+ },
112
+ ];
113
+ const result = convertMessages(msgs);
114
+ // tool result should NOT produce a separate message
115
+ expect(result).toHaveLength(1);
116
+ const parts = result[0].content as any[];
117
+ expect(parts[0].type).toBe("tool-call");
118
+ expect(parts[0].result).toBe('"已填写 name"');
119
+ expect(parts[0].isError).toBe(false);
120
+ });
121
+
122
+ it("多条 tool result 合并到同一条 assistant 消息", () => {
123
+ const msgs: AgentMessage[] = [
124
+ {
125
+ role: "assistant",
126
+ content: [
127
+ { type: "toolCall", id: "c1", name: "fillForm", arguments: { field: "name" } },
128
+ { type: "toolCall", id: "c2", name: "fillForm", arguments: { field: "dept" } },
129
+ ],
130
+ api: "openai" as any,
131
+ provider: "openai" as any,
132
+ model: "gpt-4",
133
+ usage: {} as any,
134
+ stopReason: "toolUse",
135
+ timestamp: Date.now(),
136
+ },
137
+ {
138
+ role: "toolResult",
139
+ toolCallId: "c1",
140
+ toolName: "fillForm",
141
+ content: [{ type: "text", text: '"已填写 name"' }],
142
+ isError: false,
143
+ timestamp: Date.now(),
144
+ },
145
+ {
146
+ role: "toolResult",
147
+ toolCallId: "c2",
148
+ toolName: "fillForm",
149
+ content: [{ type: "text", text: '"已填写 dept"' }],
150
+ isError: false,
151
+ timestamp: Date.now(),
152
+ },
153
+ ];
154
+ const result = convertMessages(msgs);
155
+ expect(result).toHaveLength(1);
156
+ const parts = result[0].content as any[];
157
+ expect(parts[0].result).toBe('"已填写 name"');
158
+ expect(parts[1].result).toBe('"已填写 dept"');
159
+ });
160
+
161
+ it("tool result isError 标记正确传递", () => {
162
+ const msgs: AgentMessage[] = [
163
+ {
164
+ role: "assistant",
165
+ content: [
166
+ { type: "toolCall", id: "c1", name: "submitForm", arguments: {} },
167
+ ],
168
+ api: "openai" as any,
169
+ provider: "openai" as any,
170
+ model: "gpt-4",
171
+ usage: {} as any,
172
+ stopReason: "toolUse",
173
+ timestamp: Date.now(),
174
+ },
175
+ {
176
+ role: "toolResult",
177
+ toolCallId: "c1",
178
+ toolName: "submitForm",
179
+ content: [{ type: "text", text: '"缺少必填字段"' }],
180
+ isError: true,
181
+ timestamp: Date.now(),
182
+ },
183
+ ];
184
+ const result = convertMessages(msgs);
185
+ const parts = result[0].content as any[];
186
+ expect(parts[0].result).toBe('"缺少必填字段"');
187
+ expect(parts[0].isError).toBe(true);
188
+ });
189
+
190
+ it("完整的对话消息序列转换", () => {
191
+ const msgs: AgentMessage[] = [
192
+ { role: "user", content: "帮我请假", timestamp: 1000 },
193
+ {
194
+ role: "assistant",
195
+ content: [{ type: "text", text: "好的,我来帮你" }],
196
+ api: "openai" as any,
197
+ provider: "openai" as any,
198
+ model: "gpt-4",
199
+ usage: {} as any,
200
+ stopReason: "stop",
201
+ timestamp: 2000,
202
+ },
203
+ { role: "user", content: "谢谢", timestamp: 3000 },
204
+ ];
205
+ const result = convertMessages(msgs);
206
+ expect(result).toHaveLength(3);
207
+ expect(result[0].role).toBe("user");
208
+ expect(result[1].role).toBe("assistant");
209
+ expect(result[2].role).toBe("user");
210
+ });
211
+ });
@@ -0,0 +1,71 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+
5
+ const root = path.resolve(__dirname, "..");
6
+
7
+ function readTemplateFile(relativePath: string) {
8
+ return fs.readFileSync(path.join(root, relativePath), "utf-8");
9
+ }
10
+
11
+ describe("business modeling template guidance", () => {
12
+ it("CLAUDE.md 列出业务应用建模 skill 入口", () => {
13
+ const claude = readTemplateFile("CLAUDE.md");
14
+ expect(claude).toContain("业务");
15
+ expect(claude).toMatch(/业务应用建模|business-app-model|业务建模/);
16
+ expect(claude).toContain(".claude/skills/localapp-business");
17
+ });
18
+
19
+ it(".claude/skills/ 包含业务应用建模 skill 文件", () => {
20
+ const skillPath = path.join(root, ".claude", "skills", "localapp-business", "SKILL.md");
21
+ expect(fs.existsSync(skillPath)).toBe(true);
22
+
23
+ const skill = fs.readFileSync(skillPath, "utf-8");
24
+ expect(skill).toContain("name: localapp-business");
25
+ expect(skill).toContain("申请类");
26
+ expect(skill).toContain("审批类");
27
+ expect(skill).toContain("分配类");
28
+ expect(skill).toContain("目录类");
29
+ expect(skill).toContain("ownerField");
30
+ expect(skill).toContain("statusField");
31
+ expect(skill).toContain("recordAccess");
32
+ });
33
+
34
+ it("localapp-data skill 包含业务模型与记录级权限说明", () => {
35
+ const dataSkill = readTemplateFile(".claude/skills/localapp-data/SKILL.md");
36
+ expect(dataSkill).toContain("business");
37
+ expect(dataSkill).toContain("defaultFrom");
38
+ expect(dataSkill).toContain("enum");
39
+ expect(dataSkill).toContain("recordAccess");
40
+ expect(dataSkill).toContain("ownerField");
41
+ });
42
+
43
+ it("localapp-auth skill 包含 usePermissions / <Can> 用法", () => {
44
+ const authSkill = readTemplateFile(".claude/skills/localapp-auth/SKILL.md");
45
+ expect(authSkill).toContain("usePermissions");
46
+ expect(authSkill).toContain("<Can");
47
+ });
48
+ });
49
+
50
+ describe("default App.tsx 业务模型示例", () => {
51
+ it("示例包含当前用户归属的业务字段", () => {
52
+ const app = readTemplateFile(path.join("src", "App.tsx"));
53
+ expect(app).toMatch(/created_by|ownerId|assigneeId|owner_field|createdBy/);
54
+ });
55
+
56
+ it("示例包含状态字段", () => {
57
+ const app = readTemplateFile(path.join("src", "App.tsx"));
58
+ expect(app).toMatch(/status|state/);
59
+ });
60
+
61
+ it("示例展示 usePermissions 或 <Can> 权限 UI 模式", () => {
62
+ const app = readTemplateFile(path.join("src", "App.tsx"));
63
+ expect(app).toMatch(/usePermissions|<Can/);
64
+ });
65
+
66
+ it("示例从 @localapp/sdk-react 导入 usePermissions 或 Can", () => {
67
+ const app = readTemplateFile(path.join("src", "App.tsx"));
68
+ expect(app).toMatch(/from ["']@localapp\/sdk-react["']/);
69
+ expect(app).toMatch(/usePermissions|\bCan\b/);
70
+ });
71
+ });
@@ -0,0 +1,382 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { createClient, LocalAppError } from "@localapp/sdk";
3
+
4
+ function mockFetch(url: string, init?: RequestInit) {
5
+ const method = init?.method || "GET";
6
+ const body = init?.body ? JSON.parse(init.body as string) : undefined;
7
+ return Promise.resolve({
8
+ ok: true,
9
+ status: 200,
10
+ json: () => Promise.resolve({ success: true, data: { method, url, body } }),
11
+ } as Response);
12
+ }
13
+
14
+ describe("createClient basePath detection", () => {
15
+ const originalLocation = window.location;
16
+
17
+ afterEach(() => {
18
+ // @ts-expect-error restore location
19
+ window.location = originalLocation;
20
+ });
21
+
22
+ it("detects basePath from /serve/{userId}/{name}/ path", () => {
23
+ delete (window as any).location;
24
+ (window as any).location = { pathname: "/serve/alice/my-app/index.html", origin: "http://localhost:3000" };
25
+ const client = createClient();
26
+ expect(client.basePath).toBe("/serve/alice/my-app/api");
27
+ });
28
+
29
+ it("defaults to /api for root path", () => {
30
+ delete (window as any).location;
31
+ (window as any).location = { pathname: "/", origin: "http://localhost:3000" };
32
+ const client = createClient();
33
+ expect(client.basePath).toBe("/api");
34
+ });
35
+
36
+ it("detects basePath from /serve/{userId}/{name}/ (trailing slash)", () => {
37
+ delete (window as any).location;
38
+ (window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
39
+ const client = createClient();
40
+ expect(client.basePath).toBe("/serve/alice/my-app/api");
41
+ });
42
+ });
43
+
44
+ describe("createClient CRUD methods", () => {
45
+ let client: ReturnType<typeof createClient>;
46
+ let fetchSpy: ReturnType<typeof vi.fn>;
47
+
48
+ beforeEach(() => {
49
+ delete (window as any).location;
50
+ (window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
51
+ fetchSpy = vi.fn(mockFetch);
52
+ globalThis.fetch = fetchSpy;
53
+ client = createClient();
54
+ });
55
+
56
+ it("me() calls GET /api/me", async () => {
57
+ fetchSpy.mockResolvedValueOnce({
58
+ ok: true,
59
+ status: 200,
60
+ json: () => Promise.resolve({ success: true, data: { id: "alice", name: "alice" } }),
61
+ } as Response);
62
+
63
+ const result = await client.me();
64
+ expect(fetchSpy).toHaveBeenCalledWith("/api/me", { method: "GET" });
65
+ expect(result).toEqual({ id: "alice", name: "alice" });
66
+ });
67
+
68
+ it("time() calls GET {basePath}/time", async () => {
69
+ fetchSpy.mockResolvedValueOnce({
70
+ ok: true,
71
+ status: 200,
72
+ json: () => Promise.resolve({ success: true, data: { now: "2026-07-01T09:00:00.000Z", today: "2026-07-01" } }),
73
+ } as Response);
74
+
75
+ const result = await client.time();
76
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/time", { method: "GET" });
77
+ expect(result).toEqual({ now: "2026-07-01T09:00:00.000Z", today: "2026-07-01" });
78
+ });
79
+
80
+ it("list() calls system named query first", async () => {
81
+ fetchSpy.mockResolvedValueOnce({
82
+ ok: true,
83
+ status: 200,
84
+ json: () => Promise.resolve({
85
+ success: true,
86
+ data: { rows: [{ id: 1, title: "hello" }], pagination: { offset: 0, limit: 50, total: 1 } },
87
+ }),
88
+ } as Response);
89
+
90
+ const result = await client.list("posts");
91
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.list", {
92
+ method: "POST",
93
+ headers: { "Content-Type": "application/json" },
94
+ body: JSON.stringify({ params: { offset: 0, limit: 50 } }),
95
+ });
96
+ expect(result.rows).toEqual([{ id: 1, title: "hello" }]);
97
+ expect(result.pagination.total).toBe(1);
98
+ });
99
+
100
+ it("list() passes filters, offset, limit, sort, order as named params", async () => {
101
+ fetchSpy.mockResolvedValueOnce({
102
+ ok: true,
103
+ status: 200,
104
+ json: () => Promise.resolve({ success: true, data: { rows: [], pagination: { offset: 10, limit: 5, total: 0 } } }),
105
+ } as Response);
106
+
107
+ await client.list("posts", { filters: { status: "published" }, offset: 10, limit: 5, sort: "created_at", order: "desc" });
108
+ expect(fetchSpy).toHaveBeenCalledWith(
109
+ "/serve/alice/my-app/api/queries/$posts.list",
110
+ {
111
+ method: "POST",
112
+ headers: { "Content-Type": "application/json" },
113
+ body: JSON.stringify({ params: { offset: 10, limit: 5, sort: "created_at", order: "desc", status: "published" } }),
114
+ },
115
+ );
116
+ });
117
+
118
+ it("get() calls system named query first", async () => {
119
+ fetchSpy.mockResolvedValueOnce({
120
+ ok: true,
121
+ status: 200,
122
+ json: () => Promise.resolve({ success: true, data: { id: 1, title: "hello" } }),
123
+ } as Response);
124
+
125
+ const result = await client.get("posts", 1);
126
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.get", {
127
+ method: "POST",
128
+ headers: { "Content-Type": "application/json" },
129
+ body: JSON.stringify({ params: { id: 1 } }),
130
+ });
131
+ expect(result).toEqual({ id: 1, title: "hello" });
132
+ });
133
+
134
+ it("create() 在 mutation 后用 lastInsertRowId 调 $<resource>.get 拉完整 row", async () => {
135
+ fetchSpy.mockResolvedValueOnce({
136
+ ok: true,
137
+ status: 200,
138
+ json: () => Promise.resolve({ success: true, data: { changes: 1, lastInsertRowId: 1 } }),
139
+ } as Response);
140
+ fetchSpy.mockResolvedValueOnce({
141
+ ok: true,
142
+ status: 200,
143
+ json: () => Promise.resolve({ success: true, data: { rows: [{ id: 1, title: "new" }] } }),
144
+ } as Response);
145
+
146
+ const result = await client.create<{ id: number; title: string }>("posts", { title: "new" });
147
+ expect(fetchSpy).toHaveBeenNthCalledWith(1, "/serve/alice/my-app/api/mutations/$posts.create", {
148
+ method: "POST",
149
+ headers: { "Content-Type": "application/json" },
150
+ body: JSON.stringify({ params: { title: "new" } }),
151
+ });
152
+ expect(fetchSpy).toHaveBeenNthCalledWith(2, "/serve/alice/my-app/api/queries/$posts.get", {
153
+ method: "POST",
154
+ headers: { "Content-Type": "application/json" },
155
+ body: JSON.stringify({ params: { id: 1 } }),
156
+ });
157
+ expect(result).toEqual({ id: 1, title: "new" });
158
+ });
159
+
160
+ it("update() 在 mutation 后调 get 拉最新 row", async () => {
161
+ fetchSpy.mockResolvedValueOnce({
162
+ ok: true,
163
+ status: 200,
164
+ json: () => Promise.resolve({ success: true, data: { changes: 1, lastInsertRowId: 0 } }),
165
+ } as Response);
166
+ fetchSpy.mockResolvedValueOnce({
167
+ ok: true,
168
+ status: 200,
169
+ json: () => Promise.resolve({ success: true, data: { rows: [{ id: 1, title: "updated" }] } }),
170
+ } as Response);
171
+
172
+ const result = await client.update<{ id: number; title: string }>("posts", 1, { title: "updated" });
173
+ expect(fetchSpy).toHaveBeenNthCalledWith(1, "/serve/alice/my-app/api/mutations/$posts.update", {
174
+ method: "POST",
175
+ headers: { "Content-Type": "application/json" },
176
+ body: JSON.stringify({ params: { id: 1, title: "updated" } }),
177
+ });
178
+ expect(fetchSpy).toHaveBeenNthCalledWith(2, "/serve/alice/my-app/api/queries/$posts.get", {
179
+ method: "POST",
180
+ headers: { "Content-Type": "application/json" },
181
+ body: JSON.stringify({ params: { id: 1 } }),
182
+ });
183
+ expect(result).toEqual({ id: 1, title: "updated" });
184
+ });
185
+
186
+ it("delete() calls system named mutation first", async () => {
187
+ fetchSpy.mockResolvedValueOnce({
188
+ ok: true,
189
+ status: 200,
190
+ json: () => Promise.resolve({ success: true, data: { deleted: true, id: 1 } }),
191
+ } as Response);
192
+
193
+ await client.delete("posts", 1);
194
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/mutations/$posts.delete", {
195
+ method: "POST",
196
+ headers: { "Content-Type": "application/json" },
197
+ body: JSON.stringify({ params: { id: 1 } }),
198
+ });
199
+ });
200
+
201
+ it("count() calls system named query first", async () => {
202
+ fetchSpy.mockResolvedValueOnce({
203
+ ok: true,
204
+ status: 200,
205
+ json: () => Promise.resolve({ success: true, data: { count: 42 } }),
206
+ } as Response);
207
+
208
+ const result = await client.count("posts");
209
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.count", {
210
+ method: "POST",
211
+ headers: { "Content-Type": "application/json" },
212
+ body: JSON.stringify({ params: {} }),
213
+ });
214
+ expect(result).toBe(42);
215
+ });
216
+
217
+ it("count() passes filters as named params", async () => {
218
+ fetchSpy.mockResolvedValueOnce({
219
+ ok: true,
220
+ status: 200,
221
+ json: () => Promise.resolve({ success: true, data: { count: 10 } }),
222
+ } as Response);
223
+
224
+ await client.count("posts", { status: "published" });
225
+ expect(fetchSpy).toHaveBeenCalledWith("/serve/alice/my-app/api/queries/$posts.count", {
226
+ method: "POST",
227
+ headers: { "Content-Type": "application/json" },
228
+ body: JSON.stringify({ params: { status: "published" } }),
229
+ });
230
+ });
231
+
232
+ // 原 "count() falls back to list pagination total when an old runtime returns 404"
233
+ // 和 "count() does not fall back for auth, validation, or server errors" 两个测试
234
+ // 已随 REST CRUD fallback 整体移除(restrict-app-api-to-named-sql 变更)。
235
+ // count 现在只调 named SQL,未声明 $<resource>.count 时直接抛 LocalAppError。
236
+
237
+ it("users() calls GET /api/users", async () => {
238
+ fetchSpy.mockResolvedValueOnce({
239
+ ok: true,
240
+ status: 200,
241
+ json: () => Promise.resolve({ success: true, data: [{ id: "alice", name: "alice", displayName: null }] }),
242
+ } as Response);
243
+
244
+ const result = await client.users();
245
+ expect(fetchSpy).toHaveBeenCalledWith("/api/users", { method: "GET" });
246
+ expect(result).toEqual([{ id: "alice", name: "alice", displayName: null }]);
247
+ });
248
+
249
+ it("groups() calls GET /api/groups", async () => {
250
+ fetchSpy.mockResolvedValueOnce({
251
+ ok: true,
252
+ status: 200,
253
+ json: () => Promise.resolve({ success: true, data: [{ id: "g1", name: "team", description: null, isCreator: true }] }),
254
+ } as Response);
255
+
256
+ const result = await client.groups();
257
+ expect(fetchSpy).toHaveBeenCalledWith("/api/groups", { method: "GET" });
258
+ expect(result).toEqual([{ id: "g1", name: "team", description: null, isCreator: true }]);
259
+ });
260
+
261
+ it("groupMembers() calls GET /api/groups/{groupId}", async () => {
262
+ fetchSpy.mockResolvedValueOnce({
263
+ ok: true,
264
+ status: 200,
265
+ json: () => Promise.resolve({ success: true, data: { members: [{ id: "alice", name: "alice", displayName: null }] } }),
266
+ } as Response);
267
+
268
+ const result = await client.groupMembers("g1");
269
+ expect(fetchSpy).toHaveBeenCalledWith("/api/groups/g1", { method: "GET" });
270
+ expect(result).toEqual([{ id: "alice", name: "alice", displayName: null }]);
271
+ });
272
+
273
+ it("throws on non-ok response", async () => {
274
+ fetchSpy.mockResolvedValueOnce({
275
+ ok: false,
276
+ status: 401,
277
+ json: () => Promise.resolve({ success: false, error: "Authentication required" }),
278
+ } as Response);
279
+
280
+ await expect(client.list("posts")).rejects.toThrow("Authentication required");
281
+ });
282
+ });
283
+
284
+ describe("LocalAppError", () => {
285
+ it("extends Error", () => {
286
+ const err = new LocalAppError("test", 401);
287
+ expect(err).toBeInstanceOf(Error);
288
+ expect(err).toBeInstanceOf(LocalAppError);
289
+ });
290
+
291
+ it("carries status code", () => {
292
+ const err = new LocalAppError("Auth required", 401);
293
+ expect(err.message).toBe("Auth required");
294
+ expect(err.status).toBe(401);
295
+ });
296
+
297
+ it("has correct name", () => {
298
+ const err = new LocalAppError("test", 500);
299
+ expect(err.name).toBe("LocalAppError");
300
+ });
301
+ });
302
+
303
+ describe("request() throws LocalAppError", () => {
304
+ let client: ReturnType<typeof createClient>;
305
+ let fetchSpy: ReturnType<typeof vi.fn>;
306
+
307
+ beforeEach(() => {
308
+ delete (window as any).location;
309
+ (window as any).location = { pathname: "/serve/alice/my-app/", origin: "http://localhost:3000" };
310
+ fetchSpy = vi.fn();
311
+ globalThis.fetch = fetchSpy;
312
+ client = createClient();
313
+ });
314
+
315
+ it("throws LocalAppError with status 401 on auth failure", async () => {
316
+ fetchSpy.mockResolvedValueOnce({
317
+ ok: false,
318
+ status: 401,
319
+ json: () => Promise.resolve({ success: false, error: "Authentication required" }),
320
+ } as Response);
321
+
322
+ try {
323
+ await client.list("posts");
324
+ expect.fail("Should have thrown");
325
+ } catch (e) {
326
+ expect(e).toBeInstanceOf(LocalAppError);
327
+ expect((e as LocalAppError).status).toBe(401);
328
+ expect((e as LocalAppError).message).toBe("Authentication required");
329
+ }
330
+ });
331
+
332
+ it("throws LocalAppError with status 403 on forbidden", async () => {
333
+ fetchSpy.mockResolvedValueOnce({
334
+ ok: false,
335
+ status: 403,
336
+ json: () => Promise.resolve({ success: false, error: "Access denied" }),
337
+ } as Response);
338
+
339
+ try {
340
+ await client.get("posts", 1);
341
+ expect.fail("Should have thrown");
342
+ } catch (e) {
343
+ expect(e).toBeInstanceOf(LocalAppError);
344
+ expect((e as LocalAppError).status).toBe(403);
345
+ }
346
+ });
347
+
348
+ it("throws LocalAppError with fallback message when no error field", async () => {
349
+ fetchSpy.mockResolvedValueOnce({
350
+ ok: false,
351
+ status: 500,
352
+ json: () => Promise.resolve({ success: false }),
353
+ } as Response);
354
+
355
+ try {
356
+ await client.me();
357
+ expect.fail("Should have thrown");
358
+ } catch (e) {
359
+ expect(e).toBeInstanceOf(LocalAppError);
360
+ expect((e as LocalAppError).status).toBe(500);
361
+ expect((e as LocalAppError).message).toBe("HTTP 500");
362
+ }
363
+ });
364
+
365
+ it("throws LocalAppError when an error response is not JSON", async () => {
366
+ fetchSpy.mockResolvedValueOnce({
367
+ ok: false,
368
+ status: 502,
369
+ json: () => Promise.reject(new SyntaxError("Unexpected token <")),
370
+ text: () => Promise.resolve("<html>bad gateway</html>"),
371
+ } as unknown as Response);
372
+
373
+ try {
374
+ await client.me();
375
+ expect.fail("Should have thrown");
376
+ } catch (e) {
377
+ expect(e).toBeInstanceOf(LocalAppError);
378
+ expect((e as LocalAppError).status).toBe(502);
379
+ expect((e as LocalAppError).message).toBe("HTTP 502");
380
+ }
381
+ });
382
+ });