primitive-admin 1.2.0-alpha.13 → 1.2.0-alpha.15

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 (324) hide show
  1. package/README.md +102 -78
  2. package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
  3. package/dist/bin/primitive.js +11 -82
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +79 -17
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/agent-sessions.js +2 -0
  8. package/dist/src/commands/agent-sessions.js.map +1 -1
  9. package/dist/src/commands/analytics.js +220 -18
  10. package/dist/src/commands/analytics.js.map +1 -1
  11. package/dist/src/commands/apps-children.js +2 -0
  12. package/dist/src/commands/apps-children.js.map +1 -1
  13. package/dist/src/commands/apps.js +19 -2
  14. package/dist/src/commands/apps.js.map +1 -1
  15. package/dist/src/commands/auth.js +11 -1
  16. package/dist/src/commands/auth.js.map +1 -1
  17. package/dist/src/commands/collections.js +13 -0
  18. package/dist/src/commands/collections.js.map +1 -1
  19. package/dist/src/commands/config.d.ts +1 -1
  20. package/dist/src/commands/config.js +40 -9
  21. package/dist/src/commands/config.js.map +1 -1
  22. package/dist/src/commands/connections.js +2 -0
  23. package/dist/src/commands/connections.js.map +1 -1
  24. package/dist/src/commands/database-type-configs.js +5 -3
  25. package/dist/src/commands/database-type-configs.js.map +1 -1
  26. package/dist/src/commands/databases.js +6 -4
  27. package/dist/src/commands/databases.js.map +1 -1
  28. package/dist/src/commands/db3-types.js +2 -0
  29. package/dist/src/commands/db3-types.js.map +1 -1
  30. package/dist/src/commands/db3.d.ts +12 -0
  31. package/dist/src/commands/db3.js +345 -11
  32. package/dist/src/commands/db3.js.map +1 -1
  33. package/dist/src/commands/documents.d.ts +52 -12
  34. package/dist/src/commands/documents.js +120 -29
  35. package/dist/src/commands/documents.js.map +1 -1
  36. package/dist/src/commands/email-templates.js +72 -0
  37. package/dist/src/commands/email-templates.js.map +1 -1
  38. package/dist/src/commands/functions.js +47 -10
  39. package/dist/src/commands/functions.js.map +1 -1
  40. package/dist/src/commands/groups.js +18 -3
  41. package/dist/src/commands/groups.js.map +1 -1
  42. package/dist/src/commands/init.js +7 -1
  43. package/dist/src/commands/init.js.map +1 -1
  44. package/dist/src/commands/integrations.js +80 -47
  45. package/dist/src/commands/integrations.js.map +1 -1
  46. package/dist/src/commands/metadata-category-configs.js +2 -0
  47. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  48. package/dist/src/commands/metadata.js +41 -0
  49. package/dist/src/commands/metadata.js.map +1 -1
  50. package/dist/src/commands/prompts.js +73 -47
  51. package/dist/src/commands/prompts.js.map +1 -1
  52. package/dist/src/commands/rule-sets.js +2 -0
  53. package/dist/src/commands/rule-sets.js.map +1 -1
  54. package/dist/src/commands/schemas.d.ts +15 -0
  55. package/dist/src/commands/schemas.js +122 -0
  56. package/dist/src/commands/schemas.js.map +1 -0
  57. package/dist/src/commands/secrets.js +45 -3
  58. package/dist/src/commands/secrets.js.map +1 -1
  59. package/dist/src/commands/sessions.js +2 -0
  60. package/dist/src/commands/sessions.js.map +1 -1
  61. package/dist/src/commands/sync-schemas.d.ts +202 -0
  62. package/dist/src/commands/sync-schemas.js +629 -0
  63. package/dist/src/commands/sync-schemas.js.map +1 -0
  64. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  65. package/dist/src/commands/sync-user-properties.js +276 -0
  66. package/dist/src/commands/sync-user-properties.js.map +1 -0
  67. package/dist/src/commands/sync.d.ts +243 -12
  68. package/dist/src/commands/sync.js +1474 -314
  69. package/dist/src/commands/sync.js.map +1 -1
  70. package/dist/src/commands/user-properties.d.ts +14 -0
  71. package/dist/src/commands/user-properties.js +79 -0
  72. package/dist/src/commands/user-properties.js.map +1 -0
  73. package/dist/src/commands/users.js +912 -18
  74. package/dist/src/commands/users.js.map +1 -1
  75. package/dist/src/commands/waitlist.js +39 -4
  76. package/dist/src/commands/waitlist.js.map +1 -1
  77. package/dist/src/lib/analytics-query.d.ts +58 -0
  78. package/dist/src/lib/analytics-query.js +134 -0
  79. package/dist/src/lib/analytics-query.js.map +1 -0
  80. package/dist/src/lib/api-client.d.ts +779 -95
  81. package/dist/src/lib/api-client.js +369 -166
  82. package/dist/src/lib/api-client.js.map +1 -1
  83. package/dist/src/lib/block-selector.d.ts +9 -15
  84. package/dist/src/lib/block-selector.js +9 -20
  85. package/dist/src/lib/block-selector.js.map +1 -1
  86. package/dist/src/lib/cli-manifest.d.ts +8 -0
  87. package/dist/src/lib/cli-manifest.js +10 -1
  88. package/dist/src/lib/cli-manifest.js.map +1 -1
  89. package/dist/src/lib/cli-version.d.ts +14 -0
  90. package/dist/src/lib/cli-version.js +38 -0
  91. package/dist/src/lib/cli-version.js.map +1 -0
  92. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  93. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  94. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  95. package/dist/src/lib/command-status.d.ts +110 -0
  96. package/dist/src/lib/command-status.js +184 -0
  97. package/dist/src/lib/command-status.js.map +1 -0
  98. package/dist/src/lib/config-object-descriptor.d.ts +6 -0
  99. package/dist/src/lib/config-object-descriptor.js +71 -0
  100. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  101. package/dist/src/lib/config-toml.d.ts +11 -2
  102. package/dist/src/lib/config-toml.js +25 -2
  103. package/dist/src/lib/config-toml.js.map +1 -1
  104. package/dist/src/lib/data-input.d.ts +1 -1
  105. package/dist/src/lib/data-input.js +1 -1
  106. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  107. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  108. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  109. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +11 -1
  110. package/dist/src/lib/db-codegen/dbTypeIR.js +11 -5
  111. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  112. package/dist/src/lib/db-type-records.d.ts +95 -0
  113. package/dist/src/lib/db-type-records.js +219 -0
  114. package/dist/src/lib/db-type-records.js.map +1 -0
  115. package/dist/src/lib/db3-export.d.ts +65 -9
  116. package/dist/src/lib/db3-export.js +159 -22
  117. package/dist/src/lib/db3-export.js.map +1 -1
  118. package/dist/src/lib/db3-index-output.d.ts +69 -3
  119. package/dist/src/lib/db3-index-output.js +142 -4
  120. package/dist/src/lib/db3-index-output.js.map +1 -1
  121. package/dist/src/lib/db3-type-models.d.ts +39 -7
  122. package/dist/src/lib/db3-type-models.js +138 -27
  123. package/dist/src/lib/db3-type-models.js.map +1 -1
  124. package/dist/src/lib/deprecation.d.ts +2 -2
  125. package/dist/src/lib/deprecation.js +2 -2
  126. package/dist/src/lib/experimental-apis.d.ts +36 -0
  127. package/dist/src/lib/experimental-apis.js +46 -0
  128. package/dist/src/lib/experimental-apis.js.map +1 -0
  129. package/dist/src/lib/file-attachment.d.ts +24 -0
  130. package/dist/src/lib/file-attachment.js +31 -0
  131. package/dist/src/lib/file-attachment.js.map +1 -0
  132. package/dist/src/lib/function-authorize-check.d.ts +1 -1
  133. package/dist/src/lib/function-authorize-check.js +2 -1
  134. package/dist/src/lib/function-authorize-check.js.map +1 -1
  135. package/dist/src/lib/function-authorize-view.js +4 -0
  136. package/dist/src/lib/function-authorize-view.js.map +1 -1
  137. package/dist/src/lib/function-bundle.d.ts +27 -5
  138. package/dist/src/lib/function-bundle.js +106 -7
  139. package/dist/src/lib/function-bundle.js.map +1 -1
  140. package/dist/src/lib/function-collect.d.ts +2 -0
  141. package/dist/src/lib/function-collect.js +36 -7
  142. package/dist/src/lib/function-collect.js.map +1 -1
  143. package/dist/src/lib/function-db-types.d.ts +57 -40
  144. package/dist/src/lib/function-db-types.js +246 -285
  145. package/dist/src/lib/function-db-types.js.map +1 -1
  146. package/dist/src/lib/function-document-types.d.ts +19 -7
  147. package/dist/src/lib/function-document-types.js +24 -12
  148. package/dist/src/lib/function-document-types.js.map +1 -1
  149. package/dist/src/lib/function-run.d.ts +1 -1
  150. package/dist/src/lib/function-run.js +1 -1
  151. package/dist/src/lib/function-run.js.map +1 -1
  152. package/dist/src/lib/function-schema-codegen.d.ts +58 -18
  153. package/dist/src/lib/function-schema-codegen.js +85 -74
  154. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  155. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  156. package/dist/src/lib/function-schema-refs.js +177 -0
  157. package/dist/src/lib/function-schema-refs.js.map +1 -0
  158. package/dist/src/lib/function-sync.d.ts +38 -4
  159. package/dist/src/lib/function-sync.js +83 -14
  160. package/dist/src/lib/function-sync.js.map +1 -1
  161. package/dist/src/lib/function-typecheck.d.ts +52 -0
  162. package/dist/src/lib/function-typecheck.js +171 -54
  163. package/dist/src/lib/function-typecheck.js.map +1 -1
  164. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  165. package/dist/src/lib/generated-build-flags.js +14 -0
  166. package/dist/src/lib/generated-build-flags.js.map +1 -0
  167. package/dist/src/lib/generated-config-surfaces.d.ts +211 -11
  168. package/dist/src/lib/generated-config-surfaces.js +579 -69
  169. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  170. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  171. package/dist/src/lib/generated-sdk-types.js +1 -1
  172. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  173. package/dist/src/lib/integration-test-request.d.ts +54 -0
  174. package/dist/src/lib/integration-test-request.js +207 -0
  175. package/dist/src/lib/integration-test-request.js.map +1 -0
  176. package/dist/src/lib/log-inspection.d.ts +3 -0
  177. package/dist/src/lib/log-inspection.js +1 -0
  178. package/dist/src/lib/log-inspection.js.map +1 -1
  179. package/dist/src/lib/metadata-report.d.ts +85 -0
  180. package/dist/src/lib/metadata-report.js +81 -0
  181. package/dist/src/lib/metadata-report.js.map +1 -0
  182. package/dist/src/lib/output.d.ts +1 -1
  183. package/dist/src/lib/output.js +1 -1
  184. package/dist/src/lib/platform-owned.js +5 -0
  185. package/dist/src/lib/platform-owned.js.map +1 -1
  186. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  187. package/dist/src/lib/primitive-declaration-names.js +22 -0
  188. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  189. package/dist/src/lib/primitive-declaration.d.ts +143 -0
  190. package/dist/src/lib/primitive-declaration.js +658 -0
  191. package/dist/src/lib/primitive-declaration.js.map +1 -0
  192. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  193. package/dist/src/lib/prompt-schema-codegen.js +82 -98
  194. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  195. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  196. package/dist/src/lib/prompt-schema-document.js +92 -0
  197. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  198. package/dist/src/lib/prompt-schema-refs.d.ts +164 -0
  199. package/dist/src/lib/prompt-schema-refs.js +452 -0
  200. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  201. package/dist/src/lib/records-verbs.d.ts +12 -2
  202. package/dist/src/lib/records-verbs.js +7 -2
  203. package/dist/src/lib/records-verbs.js.map +1 -1
  204. package/dist/src/lib/register-commands.d.ts +28 -0
  205. package/dist/src/lib/register-commands.js +101 -0
  206. package/dist/src/lib/register-commands.js.map +1 -0
  207. package/dist/src/lib/retired-imports.d.ts +53 -0
  208. package/dist/src/lib/retired-imports.js +120 -0
  209. package/dist/src/lib/retired-imports.js.map +1 -0
  210. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  211. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  212. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  213. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  214. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +221 -0
  215. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  216. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  217. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  218. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  219. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +209 -0
  220. package/dist/src/lib/schema-codegen/generated-field-grammar.js +379 -0
  221. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  222. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  223. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  224. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  225. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  226. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  227. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  228. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  229. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
  230. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
  231. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  232. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  233. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  234. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  235. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  236. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  237. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  238. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  239. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  240. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  241. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  242. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  243. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  244. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  245. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  246. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  247. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  248. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  249. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  250. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  251. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  252. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
  253. package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
  254. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  255. package/dist/src/lib/schema-codegen/valuesLists.d.ts +35 -0
  256. package/dist/src/lib/schema-codegen/valuesLists.js +128 -0
  257. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  258. package/dist/src/lib/schema-family-index.d.ts +228 -0
  259. package/dist/src/lib/schema-family-index.js +813 -0
  260. package/dist/src/lib/schema-family-index.js.map +1 -0
  261. package/dist/src/lib/schema-pins.d.ts +82 -0
  262. package/dist/src/lib/schema-pins.js +198 -0
  263. package/dist/src/lib/schema-pins.js.map +1 -0
  264. package/dist/src/lib/schema-preview.d.ts +244 -0
  265. package/dist/src/lib/schema-preview.js +498 -0
  266. package/dist/src/lib/schema-preview.js.map +1 -0
  267. package/dist/src/lib/skill-installer.d.ts +2 -2
  268. package/dist/src/lib/skill-installer.js +2 -21
  269. package/dist/src/lib/skill-installer.js.map +1 -1
  270. package/dist/src/lib/step-run-table.d.ts +1 -2
  271. package/dist/src/lib/step-run-table.js +1 -2
  272. package/dist/src/lib/step-run-table.js.map +1 -1
  273. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  274. package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
  275. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  276. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  277. package/dist/src/lib/swift-codegen/banners.js +12 -0
  278. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  279. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  280. package/dist/src/lib/swift-codegen/functionGenerator.js +167 -50
  281. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  282. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
  283. package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
  284. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  285. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  286. package/dist/src/lib/swift-codegen/sharedGenerator.js +120 -0
  287. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  288. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  289. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  290. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  291. package/dist/src/lib/sync-resource-types.d.ts +37 -5
  292. package/dist/src/lib/sync-resource-types.js +53 -5
  293. package/dist/src/lib/sync-resource-types.js.map +1 -1
  294. package/dist/src/lib/sync-selectors.d.ts +7 -0
  295. package/dist/src/lib/sync-selectors.js +22 -2
  296. package/dist/src/lib/sync-selectors.js.map +1 -1
  297. package/dist/src/lib/test-runs.d.ts +45 -0
  298. package/dist/src/lib/test-runs.js +150 -0
  299. package/dist/src/lib/test-runs.js.map +1 -0
  300. package/dist/src/lib/test-users.d.ts +25 -0
  301. package/dist/src/lib/test-users.js +36 -0
  302. package/dist/src/lib/test-users.js.map +1 -0
  303. package/dist/src/lib/toml-database-config.d.ts +2 -1
  304. package/dist/src/lib/toml-database-config.js +4 -3
  305. package/dist/src/lib/toml-database-config.js.map +1 -1
  306. package/dist/src/lib/toml-scalar-edit.js +6 -4
  307. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  308. package/dist/src/lib/user-index.d.ts +80 -0
  309. package/dist/src/lib/user-index.js +166 -0
  310. package/dist/src/lib/user-index.js.map +1 -0
  311. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  312. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  313. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  314. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  315. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  316. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  317. package/dist/src/lib/user-walk.d.ts +31 -0
  318. package/dist/src/lib/user-walk.js +102 -0
  319. package/dist/src/lib/user-walk.js.map +1 -0
  320. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  321. package/dist/src/lib/worker-perf-format.js +27 -0
  322. package/dist/src/lib/worker-perf-format.js.map +1 -0
  323. package/dist/src/types/index.d.ts +13 -34
  324. package/package.json +5 -3
@@ -19,22 +19,25 @@
19
19
  *
20
20
  * - `primitive-db-types.d.ts` — the app's database types, and the module
21
21
  * augmentation that binds them to `ctx.db`;
22
- * - `primitive-db3-types.d.ts` (#4803) — the app's db3 types, from
23
- * `db3-types/` and `database-type-configs/`, and the `Db3Schemas`
24
- * augmentation that types `ctx.db3(db3Id, "<type>").model("<Model>")`;
25
22
  * - `primitive-functions.d.ts` — the SDK's own types. The package is not on
26
23
  * npm yet, and even when it is, a config tree is not an npm project:
27
24
  * without this the bare `primitive-functions` specifier every function
28
25
  * imports would not resolve at all, and the augmentation would have
29
26
  * nothing to augment;
30
- * - `primitive-function-types.d.ts` (#3281, rendered by
31
- * `function-schema-codegen.ts`) — every function's `<Key>Input` and
32
- * `<Key>Output` from its declared schemas, and the `FunctionSchemas`
33
- * augmentation that types `defineFunction("<key>", handler)`;
27
+ * - `primitive.d.ts` (#5544, rendered by `primitive-declaration.ts`) —
28
+ * every `schemas/` def, function, prompt, db3 model and user property
29
+ * type under one namespace per family, and the augmentations that type
30
+ * `defineFunction`, `ctx.prompts.run`, `ctx.db3` and `ctx.users`. It
31
+ * replaced four per-family files (`RETIRED_DECLARATIONS`), which are
32
+ * removed;
34
33
  * - `primitive-document-types.d.ts` (#3281, rendered by
35
34
  * `function-document-types.ts`) — the project's document models from
36
35
  * `models/models.toml`, and the `DocumentSchemas` augmentation that types
37
- * `ctx.doc(documentId).model("<Model>")`; open when the project has none;
36
+ * `ctx.doc(documentId).model("<Model>")`; not written when the project has
37
+ * none (#5206), and dropped from an explicit tsconfig `files` list then.
38
+ * #5208 — inside a project it is typed from `models/models.toml` only,
39
+ * and the generated schema copy a pull or push once wrote beside it is
40
+ * removed (`plannedRemovals`);
38
41
  * - `generated/<key>.generated.ts` (#3281, same renderer) — the per-key
39
42
  * CLIENT invoker, carrying every verb since #3482. Excluded from
40
43
  * the scaffolded program (it imports `js-bao-wss-client`), and written to
@@ -58,18 +61,18 @@
58
61
  */
59
62
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "fs";
60
63
  import { basename, dirname, join, relative, resolve, sep } from "path";
61
- import { parseConfigToml, stringifyConfigToml } from "./config-toml.js";
62
- import { resolveDb3TypeModels } from "./db3-type-models.js";
63
- import { FUNCTION_INVOKERS_DIR, FUNCTION_TYPES_DECLARATION_FILE, GENERATED_FILE_SUFFIX, functionSchemaSources, renderFunctionInvokers, renderFunctionSchemasDeclaration, } from "./function-schema-codegen.js";
64
+ import { parseConfigToml } from "./config-toml.js";
65
+ import { FUNCTION_INVOKERS_DIR, FunctionSchemaCodegenError, GENERATED_FILE_SUFFIX, functionSchemaSources, renderFunctionInvokers, } from "./function-schema-codegen.js";
64
66
  import { DOCUMENT_TYPES_DECLARATION_FILE, DOCUMENT_SCHEMA_TREE_FILE, resolveDocumentSchema, renderDocumentTypesDeclaration, } from "./function-document-types.js";
65
- import { AGENT_CLIENT_FILE_SUFFIX, PROMPT_TYPES_DECLARATION_FILE, promptSchemaSources, renderAgentClientFiles, renderPromptSchemasDeclaration, } from "./prompt-schema-codegen.js";
66
- import { describeDbType } from "./db-codegen/dbTypeIR.js";
67
- import { tsTypeForDbFieldType } from "./db-codegen/dbTsTypes.js";
68
- import { objectPropertyKey } from "./db-codegen/dbNaming.js";
67
+ import { AGENT_CLIENT_FILE_SUFFIX, promptSchemaSources, renderAgentClientFiles, } from "./prompt-schema-codegen.js";
68
+ import { typeEntries } from "./db-type-records.js";
69
+ import { primitiveDeclarationInputs, renderPrimitiveDeclaration } from "./primitive-declaration.js";
70
+ import { PRIMITIVE_DECLARATION_FILE, PRIMITIVE_DECLARATION_SPECIFIER, RETIRED_DECLARATIONS, } from "./primitive-declaration-names.js";
69
71
  import { SDK_TYPES_SOURCE } from "./generated-sdk-types.js";
72
+ import { USER_PROPERTIES_CLIENT_FILE, USER_PROPERTIES_FILE, renderUserPropertiesClientTypes, treeHasUserProperties, userPropertiesSource, } from "./user-properties/user-properties-codegen.js";
73
+ export { db3TypeSources } from "./db-type-records.js";
74
+ export { PRIMITIVE_DECLARATION_FILE, RETIRED_DECLARATIONS } from "./primitive-declaration-names.js";
70
75
  export const DB_TYPES_DECLARATION_FILE = "primitive-db-types.d.ts";
71
- /** #4803 — the db3 types' declaration, binding `ctx.db3`. */
72
- export const DB3_TYPES_DECLARATION_FILE = "primitive-db3-types.d.ts";
73
76
  export const SDK_TYPES_FILE = "primitive-functions.d.ts";
74
77
  export const FUNCTIONS_TSCONFIG_FILE = "tsconfig.json";
75
78
  /**
@@ -82,14 +85,12 @@ export const FUNCTIONS_TSCONFIG_FILE = "tsconfig.json";
82
85
  export const REGENERATED_DECLARATIONS = [
83
86
  DB_TYPES_DECLARATION_FILE,
84
87
  SDK_TYPES_FILE,
85
- FUNCTION_TYPES_DECLARATION_FILE,
88
+ // #5544 — every function, prompt, schemas/ def, db3 and user property type.
89
+ PRIMITIVE_DECLARATION_FILE,
86
90
  DOCUMENT_TYPES_DECLARATION_FILE,
87
- // #3330 — the prompt output types, from the tree's `prompts/*.toml`.
88
- PROMPT_TYPES_DECLARATION_FILE,
89
- // #4803 — `ctx.db3`'s model types, from `db3-types/` and
90
- // `database-type-configs/`.
91
- DB3_TYPES_DECLARATION_FILE,
92
91
  ];
92
+ /** Every declaration codegen ever writes or once wrote. */
93
+ const ALL_DECLARATIONS = [...REGENERATED_DECLARATIONS, ...RETIRED_DECLARATIONS.map((retired) => retired.file)];
93
94
  /** The scaffold's exclusion for the client invokers (#3281). */
94
95
  export const GENERATED_EXCLUDE = `${FUNCTION_INVOKERS_DIR}/**`;
95
96
  const HEADER = `// GENERATED by \`primitive config push\` from database-type-configs/*.toml.
@@ -103,31 +104,6 @@ const HEADER = `// GENERATED by \`primitive config push\` from database-type-con
103
104
  // platform owns rather than the schema, added by the SDK's own row type, so it
104
105
  // is not repeated per model here whether or not a model declares one.
105
106
  `;
106
- function quote(value) {
107
- return JSON.stringify(value);
108
- }
109
- /**
110
- * A model or field name as a TYPE member key.
111
- *
112
- * Model and field names are whatever the TOML says — js-bao preserves them
113
- * verbatim — so `Order-Item` and `first-name` are ordinary schemas and are not
114
- * TypeScript identifiers. Emitting one raw makes the whole declaration a syntax
115
- * error, which breaks the editor and `tsc` wiring for every OTHER type in the
116
- * tree too. The client generators' own `objectPropertyKey` answers this,
117
- * except that its `__proto__` case is a computed key — legal in an object
118
- * literal, not in a type member — so that one is quoted instead.
119
- */
120
- function memberKey(name) {
121
- const key = objectPropertyKey(name);
122
- return key.startsWith("[") ? quote(name) : key;
123
- }
124
- /** A TS string-literal union, or `string` when there is nothing to narrow to. */
125
- function fieldType(type, enumValues) {
126
- if (type === "string" && Array.isArray(enumValues) && enumValues.length > 0) {
127
- return enumValues.map((v) => quote(v)).join(" | ");
128
- }
129
- return tsTypeForDbFieldType(type);
130
- }
131
107
  /**
132
108
  * The declaration for a whole config tree's database types.
133
109
  *
@@ -157,130 +133,9 @@ export function renderDbTypesDeclaration(sources) {
157
133
  }
158
134
  return lines.join("\n");
159
135
  }
160
- /**
161
- * One interface member per type, already sorted by the caller: the type's
162
- * models and their fields as `describeDbType` reads them. Shared by the
163
- * database declaration and the db3 one (#4803), so the two can never disagree
164
- * on what a type's TOML declares.
165
- *
166
- * `timestamps` is how a type's create and update stamps render (#5024): the
167
- * database declaration keeps them optional strings, as it always has; the db3
168
- * one makes them required on every model in the timestamps' scope, because a
169
- * db3 room writes them on every create and write there — epoch milliseconds,
170
- * so `number` unless the model declares the field.
171
- */
172
- function typeEntries(types, timestamps) {
173
- const lines = [];
174
- for (const source of types) {
175
- let records = [];
176
- try {
177
- const ir = describeDbType({
178
- databaseType: source.key,
179
- tomlPath: source.tomlPath,
180
- tomlContent: source.tomlContent,
181
- table: source.table,
182
- });
183
- records = [...ir.records]
184
- .sort((a, b) => (a.modelName < b.modelName ? -1 : 1))
185
- .map((record) => {
186
- const required = requiredStamps(ir.timestamps, record.modelName, timestamps);
187
- const declared = new Set();
188
- const members = [];
189
- for (const field of record.fields) {
190
- declared.add(field.name);
191
- members.push(` ${memberKey(field.name)}${field.required || required.has(field.name) ? "" : "?"}: ${fieldType(field.type, field.enum)};`);
192
- }
193
- // Server-stamped fields exist on a read row but not on one a
194
- // function just built, so they are optional — the same call the
195
- // client renderer makes — except a db3 type's timestamps, which
196
- // every row in scope carries. Writes take the SDK's write type,
197
- // which leaves every field optional.
198
- for (const stamped of [...ir.stampedFields].sort()) {
199
- if (declared.has(stamped))
200
- continue;
201
- declared.add(stamped);
202
- members.push(required.has(stamped)
203
- ? ` ${memberKey(stamped)}: number;`
204
- : ` ${memberKey(stamped)}?: string;`);
205
- }
206
- return { modelName: record.modelName, members };
207
- });
208
- }
209
- catch {
210
- // A type whose TOML this renderer cannot describe contributes no models
211
- // rather than failing the push: its own preflight reports the file, and
212
- // an untyped handle is what a schemaless type gets anyway.
213
- records = [];
214
- }
215
- if (records.length === 0) {
216
- lines.push(` ${quote(source.key)}: {};`);
217
- continue;
218
- }
219
- lines.push(` ${quote(source.key)}: {`);
220
- for (const record of records) {
221
- if (record.members.length === 0) {
222
- lines.push(` ${memberKey(record.modelName)}: Record<string, unknown>;`);
223
- continue;
224
- }
225
- lines.push(` ${memberKey(record.modelName)}: {`);
226
- lines.push(...record.members);
227
- lines.push(` };`);
228
- }
229
- lines.push(` };`);
230
- }
231
- return lines;
232
- }
233
- /** The stamp names a model's read rows always carry under this rendering. */
234
- function requiredStamps(stamps, modelName, timestamps) {
235
- if (timestamps === "optional")
236
- return new Set();
237
- if (stamps.models !== null && !stamps.models.includes(modelName))
238
- return new Set();
239
- return new Set([stamps.create, stamps.update].filter((name) => name !== null));
240
- }
241
- const DB3_HEADER = `// GENERATED by \`primitive config push\` from db3-types/*.toml and
242
- // database-type-configs/*.toml. DO NOT EDIT — your changes are overwritten on
243
- // the next push.
244
- //
245
- // It gives \`ctx.db3(db3Id, "<type>").model("<Model>")\` the model names and
246
- // field types this app's db3 types declare. The two directories are one
247
- // namespace: a name both hold is read from its db3-types/ file.
248
- //
249
- // A row a READ hands back also carries \`id: string\` — the record identity the
250
- // platform owns rather than the schema, added by the SDK's own row type.
251
- //
252
- // A type's timestamps are required on a read row, epoch milliseconds unless the
253
- // model declares the field: the room stamps every write. A row written
254
- // before the db3 was typed may lack them.
255
- `;
256
- /**
257
- * The declaration for a whole config tree's db3 types (#4803), rendered over
258
- * the same `describeDbType` IR the database declaration is, and sorted the
259
- * same way so the bytes depend on the schemas alone.
260
- */
261
- export function renderDb3TypesDeclaration(sources) {
262
- const types = [...sources].sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0));
263
- const lines = [DB3_HEADER, "export interface PrimitiveDb3Schemas {"];
264
- lines.push(...typeEntries(types.map((source) => ({
265
- key: source.type,
266
- tomlPath: source.tomlPath,
267
- tomlContent: source.tomlContent,
268
- table: source.directory === "db3-types" ? "db3" : "database",
269
- })), "required"));
270
- lines.push("}");
271
- lines.push("");
272
- // Only when there is something to bind, as for the database declaration:
273
- // an empty augmentation would close `ctx.db3`'s type key to nothing.
274
- if (types.length > 0) {
275
- lines.push(`declare module "primitive-functions" {`);
276
- lines.push(` interface Db3Schemas extends PrimitiveDb3Schemas {}`);
277
- lines.push(`}`);
278
- lines.push("");
279
- }
280
- return lines.join("\n");
281
- }
282
136
  /** The scaffolded compiler wiring. Written once; an author owns it after. */
283
137
  export function renderFunctionsTsconfig() {
138
+ const declarations = REGENERATED_DECLARATIONS;
284
139
  return (JSON.stringify({
285
140
  // Scaffolded by `primitive config push` (#3182). Yours to adjust — push
286
141
  // writes it once and then leaves it alone. What it must keep doing is
@@ -307,7 +162,7 @@ export function renderFunctionsTsconfig() {
307
162
  "primitive-functions": [`./${SDK_TYPES_FILE}`],
308
163
  },
309
164
  },
310
- include: ["**/*.ts", ...REGENERATED_DECLARATIONS.map((file) => `./${file}`)],
165
+ include: ["**/*.ts", ...declarations.map((file) => `./${file}`)],
311
166
  // The client invokers (#3281) import `js-bao-wss-client`, which a
312
167
  // config tree does not install: they are for the app's client code,
313
168
  // and an editor program that swept them in would report every one of
@@ -391,6 +246,10 @@ function isGlobEntry(entry) {
391
246
  function isDeclarationEntry(entry, file) {
392
247
  return entry === `./${file}` || entry === file;
393
248
  }
249
+ /** The retired declaration an entry names (#5544), or null. */
250
+ function retiredEntryOf(entry) {
251
+ return RETIRED_DECLARATIONS.find((retired) => isDeclarationEntry(entry, retired.file)) ?? null;
252
+ }
394
253
  /** `"./**\/*.ts"` and `"**\/*.ts"` name the same set; read them the same way. */
395
254
  function normalizeEntry(entry) {
396
255
  return entry.startsWith("./") ? entry.slice(2) : entry;
@@ -437,7 +296,7 @@ function coversSubdirectories(entry) {
437
296
  function isSourceEntry(entry) {
438
297
  if (typeof entry !== "string")
439
298
  return false;
440
- if (REGENERATED_DECLARATIONS.some((file) => isDeclarationEntry(entry, file))) {
299
+ if (ALL_DECLARATIONS.some((file) => isDeclarationEntry(entry, file))) {
441
300
  return false;
442
301
  }
443
302
  return isGlobEntry(entry) || entry.endsWith(".ts");
@@ -485,11 +344,17 @@ function tsconfigWiringGaps(parsed, context) {
485
344
  const declarationsCovered = listed.some(coversDeclarations);
486
345
  const reachesSubdirectories = listed.some(coversSubdirectories);
487
346
  const exclude = Array.isArray(parsed.exclude) ? parsed.exclude : [];
347
+ const absent = context.absentDeclarations ?? [];
488
348
  return {
489
349
  mapping: !mapped.includes(`./${SDK_TYPES_FILE}`),
490
350
  missingDeclarations: implicitlyAll || declarationsCovered
491
351
  ? []
492
- : REGENERATED_DECLARATIONS.filter((file) => !listed.some((entry) => isDeclarationEntry(entry, file))),
352
+ : REGENERATED_DECLARATIONS.filter((file) => !absent.includes(file) && !listed.some((entry) => isDeclarationEntry(entry, file))),
353
+ absentFiles: files.filter((entry) => typeof entry === "string" && absent.some((file) => isDeclarationEntry(entry, file))),
354
+ retiredEntries: [
355
+ ...include.filter((entry) => retiredEntryOf(entry)).map((entry) => ({ list: "include", entry: entry })),
356
+ ...files.filter((entry) => retiredEntryOf(entry)).map((entry) => ({ list: "files", entry: entry })),
357
+ ],
493
358
  sources: !implicitlyAll && !declarationsCovered && !listed.some(isSourceEntry),
494
359
  // Only a program that would SEE the directory needs the exclusion: an
495
360
  // explicit list that reaches no subdirectory never sweeps it in.
@@ -499,7 +364,12 @@ function tsconfigWiringGaps(parsed, context) {
499
364
  };
500
365
  }
501
366
  function hasGaps(gaps) {
502
- return (gaps.mapping || gaps.missingDeclarations.length > 0 || gaps.sources || gaps.generatedExclusion);
367
+ return (gaps.mapping ||
368
+ gaps.missingDeclarations.length > 0 ||
369
+ gaps.sources ||
370
+ gaps.generatedExclusion ||
371
+ gaps.absentFiles.length > 0 ||
372
+ gaps.retiredEntries.length > 0);
503
373
  }
504
374
  function describeGaps(gaps) {
505
375
  const problems = [];
@@ -519,6 +389,17 @@ function describeGaps(gaps) {
519
389
  problems.push(`\`exclude\` does not cover "${GENERATED_EXCLUDE}", so the generated client ` +
520
390
  "invokers (which import `js-bao-wss-client`) are swept into the program");
521
391
  }
392
+ if (gaps.absentFiles.length > 0) {
393
+ problems.push(`\`files\` names ${gaps.absentFiles
394
+ .map((entry) => `"${entry}"`)
395
+ .join(", ")}, which codegen no longer writes, so the compiler reports it missing`);
396
+ }
397
+ for (const { list, entry } of gaps.retiredEntries) {
398
+ const retired = retiredEntryOf(entry);
399
+ problems.push(`\`${list}\` names "${entry}", which codegen no longer writes: its types are in ` +
400
+ `"./${PRIMITIVE_DECLARATION_FILE}" under ${retired.namespace}, so remove the entry` +
401
+ (list === "files" ? ` and list "./${PRIMITIVE_DECLARATION_FILE}"` : ""));
402
+ }
522
403
  return problems;
523
404
  }
524
405
  /**
@@ -594,6 +475,20 @@ export function inspectFunctionsTsconfig(existing, context = { generatedDirExist
594
475
  : [];
595
476
  paths[SDK_MODULE_SPECIFIER] = [...mapped, `./${SDK_TYPES_FILE}`];
596
477
  }
478
+ if (gaps.retiredEntries.length > 0) {
479
+ // #5544 — a retired declaration's entry goes; its replacement comes back
480
+ // through the missing-declaration repair below, and a `files` list the
481
+ // removal empties goes with it, the sources then coming through `include`.
482
+ for (const list of ["include", "files"]) {
483
+ if (!Array.isArray(parsed[list]))
484
+ continue;
485
+ const kept = parsed[list].filter((entry) => !retiredEntryOf(entry));
486
+ if (list === "files" && kept.length === 0)
487
+ delete parsed.files;
488
+ else
489
+ parsed[list] = kept;
490
+ }
491
+ }
597
492
  if (gaps.missingDeclarations.length > 0 || gaps.sources) {
598
493
  const include = Array.isArray(parsed.include) ? parsed.include : [];
599
494
  const added = [];
@@ -613,6 +508,15 @@ export function inspectFunctionsTsconfig(existing, context = { generatedDirExist
613
508
  const exclude = Array.isArray(parsed.exclude) ? parsed.exclude : [];
614
509
  parsed.exclude = [...exclude, GENERATED_EXCLUDE];
615
510
  }
511
+ if (gaps.absentFiles.length > 0 && Array.isArray(parsed.files)) {
512
+ // #5206 — a root that no longer exists is dropped; an emptied list goes
513
+ // with it, since the sources then come through `include`.
514
+ const files = parsed.files.filter((entry) => !gaps.absentFiles.includes(entry));
515
+ if (files.length > 0)
516
+ parsed.files = files;
517
+ else
518
+ delete parsed.files;
519
+ }
616
520
  return { repaired: JSON.stringify(parsed, null, 2) + "\n", problems: [] };
617
521
  }
618
522
  /**
@@ -682,57 +586,6 @@ export function databaseTypeSources(configDir) {
682
586
  }
683
587
  return sources;
684
588
  }
685
- /**
686
- * Every db3 type a config tree declares (#4803): `db3-types/*.toml` (named by
687
- * `[type] name`, else the file name) and `database-type-configs/*.toml` (named
688
- * by `[type] databaseType`, else the file name), one namespace with one entry
689
- * per name. A `db3-types/` file naming models declared in another file of the
690
- * directory (`[type] models`) is read with them, resolved (#5025). A name both
691
- * directories hold is read from its `db3-types/` file:
692
- * `config push` refuses a pair that differ before anything is written, so the
693
- * two agree whenever this runs on a pushable tree.
694
- */
695
- export function db3TypeSources(configDir) {
696
- const byType = new Map();
697
- // #5025 — a db3 type naming models declared in another file of its
698
- // directory is typed with them: its content is the resolved document.
699
- const resolved = resolveDb3TypeModels(join(configDir, "db3-types"));
700
- const read = (directory, key) => {
701
- const dir = join(configDir, directory);
702
- if (!existsSync(dir))
703
- return;
704
- for (const file of readdirSync(dir).filter((f) => f.endsWith(".toml")).sort()) {
705
- const tomlPath = join(dir, file);
706
- let tomlContent;
707
- try {
708
- tomlContent = readFileSync(tomlPath, "utf-8");
709
- }
710
- catch {
711
- continue;
712
- }
713
- let declared = null;
714
- try {
715
- const parsed = parseConfigToml(tomlContent);
716
- if (parsed?.type?.[key])
717
- declared = String(parsed.type[key]);
718
- }
719
- catch {
720
- // Its own preflight reports a file that does not parse.
721
- }
722
- const type = declared || basename(file, ".toml");
723
- if (directory === "db3-types" && resolved.referencing.has(file)) {
724
- const document = resolved.documents.get(file);
725
- if (document)
726
- tomlContent = stringifyConfigToml(document);
727
- }
728
- if (!byType.has(type))
729
- byType.set(type, { type, tomlPath, tomlContent, directory });
730
- }
731
- };
732
- read("db3-types", "name");
733
- read("database-type-configs", "databaseType");
734
- return [...byType.values()];
735
- }
736
589
  /**
737
590
  * Whether the tree has a `functions/` directory of its own — one holding
738
591
  * anything besides the `generated/` directory codegen itself writes.
@@ -767,30 +620,58 @@ function planAgentClientArtifacts(configDir, options) {
767
620
  };
768
621
  });
769
622
  }
623
+ /**
624
+ * The app's client types of `user-properties.toml` (#5385), where the
625
+ * invokers go: client code needs them whether or not the tree has functions.
626
+ */
627
+ function planUserPropertiesClientArtifacts(configDir, options, userProperties) {
628
+ if (!userProperties)
629
+ return [];
630
+ const absolute = join(functionInvokerDir(configDir, options), USER_PROPERTIES_CLIENT_FILE);
631
+ return [
632
+ {
633
+ relative: reportedPath(configDir, absolute),
634
+ absolute,
635
+ contents: renderUserPropertiesClientTypes(userProperties),
636
+ regenerated: true,
637
+ source: USER_PROPERTIES_FILE,
638
+ },
639
+ ];
640
+ }
770
641
  /**
771
642
  * What push would write, without writing it.
772
643
  *
773
- * Only the agents' client artifacts when the tree has no `functions/`
774
- * directory (#3798, DSO-3798-005), and nothing at all when it has neither:
775
- * the other artifacts exist to type function sources, and a tree with none
776
- * needs no compiler wiring.
644
+ * Only the client artifacts — the agents' (#3798, DSO-3798-005) and the user
645
+ * property types (#5385) — when the tree has no `functions/` directory, and
646
+ * nothing at all when it has none of them: the other artifacts exist to type
647
+ * function sources, and a tree with none needs no compiler wiring.
777
648
  */
778
649
  export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
779
650
  const functionsDir = join(configDir, "functions");
780
651
  const agentArtifacts = planAgentClientArtifacts(configDir, options);
781
- if (!treeHasFunctionsDir(configDir))
782
- return agentArtifacts;
783
- // #3455 — one resolution for both the declaration below and the tree copy.
652
+ if (!treeHasFunctionsDir(configDir)) {
653
+ const clientArtifacts = [
654
+ ...planUserPropertiesClientArtifacts(configDir, options, userPropertiesSource(configDir)),
655
+ ...agentArtifacts,
656
+ ];
657
+ refuseSharedDestinations(clientArtifacts);
658
+ return clientArtifacts;
659
+ }
660
+ // #3455 — one resolution for the document declaration below.
784
661
  const documentSchema = resolveDocumentSchema(configDir);
785
662
  const declaration = renderDbTypesDeclaration(databaseTypeSources(configDir));
786
- // #3281 — the functions declaration and the per-key invokers, from the same
663
+ // #5544 — every function, prompt, schemas/ def, db3 and user property type
664
+ // in one declaration, and the per-key invokers from the same
787
665
  // `functions/*.toml`. A malformed schema throws naming the file: the honest
788
666
  // `unknown` is for an absent schema, and typing a broken one as anything
789
667
  // would be a declaration that lies.
790
668
  const functionSources = functionSchemaSources(configDir);
791
- const functionsDeclaration = renderFunctionSchemasDeclaration(functionSources);
669
+ const primitiveDeclaration = renderPrimitiveDeclaration(primitiveDeclarationInputs(configDir));
792
670
  const invokerDir = functionInvokerDir(configDir, options);
793
671
  const invokers = renderFunctionInvokers(functionSources);
672
+ // #5385 — the user property types, only for a tree that declares them. A
673
+ // file that does not parse throws naming it, like a malformed function schema.
674
+ const userProperties = userPropertiesSource(configDir);
794
675
  const artifacts = [
795
676
  {
796
677
  relative: `functions/${DB_TYPES_DECLARATION_FILE}`,
@@ -798,13 +679,6 @@ export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
798
679
  contents: declaration,
799
680
  regenerated: true,
800
681
  },
801
- // #4803 — `ctx.db3`'s model types, beside the database ones.
802
- {
803
- relative: `functions/${DB3_TYPES_DECLARATION_FILE}`,
804
- absolute: join(functionsDir, DB3_TYPES_DECLARATION_FILE),
805
- contents: renderDb3TypesDeclaration(db3TypeSources(configDir)),
806
- regenerated: true,
807
- },
808
682
  {
809
683
  relative: `functions/${SDK_TYPES_FILE}`,
810
684
  absolute: join(functionsDir, SDK_TYPES_FILE),
@@ -812,50 +686,37 @@ export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
812
686
  regenerated: true,
813
687
  },
814
688
  {
815
- relative: `functions/${FUNCTION_TYPES_DECLARATION_FILE}`,
816
- absolute: join(functionsDir, FUNCTION_TYPES_DECLARATION_FILE),
817
- contents: functionsDeclaration,
689
+ relative: `functions/${PRIMITIVE_DECLARATION_FILE}`,
690
+ absolute: join(functionsDir, PRIMITIVE_DECLARATION_FILE),
691
+ contents: primitiveDeclaration,
818
692
  regenerated: true,
819
693
  },
820
694
  // #3281 — the document handle's declaration, from the project's
821
- // `models/models.toml` (open when the project has none).
695
+ // `models/models.toml`.
822
696
  //
823
697
  // #3455 (D3455-009) — through the SAME resolution push and diff use, so a
824
698
  // tree pulled into a project with no `models/models.toml` is typed from
825
699
  // the schema its active version was pushed with rather than losing its
826
700
  // types the moment it is pulled.
827
- {
828
- relative: `functions/${DOCUMENT_TYPES_DECLARATION_FILE}`,
829
- absolute: join(functionsDir, DOCUMENT_TYPES_DECLARATION_FILE),
830
- contents: renderDocumentTypesDeclaration(documentSchema.declarationSource),
831
- regenerated: true,
832
- },
833
- // #3330 — `ctx.prompts.run`'s output types, from this tree's
834
- // `prompts/*.toml` (open when the tree declares none).
835
- {
836
- relative: `functions/${PROMPT_TYPES_DECLARATION_FILE}`,
837
- absolute: join(functionsDir, PROMPT_TYPES_DECLARATION_FILE),
838
- contents: renderPromptSchemasDeclaration(promptSchemaSources(configDir)),
839
- regenerated: true,
840
- },
841
- // #3455 (D3455-009) — the project's document schema, copied into the tree
842
- // so a fresh `config pull` into a project that has no `models/models.toml`
843
- // still rebuilds the same envelope and reads Synced.
844
701
  //
845
- // Regenerated from the PROJECT file whenever there is one, and otherwise
846
- // left exactly alone: when the copy is itself what the resolution answered
847
- // (rule 2) it IS the source, and rewriting a file from itself would be the
848
- // second source of truth the fixed precedence exists to avoid.
849
- ...(documentSchema.origin === "project" && documentSchema.source
702
+ // #5206 — none when no schema file resolves: an app with no documents
703
+ // gets no document declaration, and the one an earlier run wrote goes
704
+ // (`retiredFunctionTypeArtifacts`). The handle stays open without it.
705
+ ...(documentSchema.declarationSource
850
706
  ? [
851
707
  {
852
- relative: `functions/${DOCUMENT_SCHEMA_TREE_FILE}`,
853
- absolute: join(functionsDir, DOCUMENT_SCHEMA_TREE_FILE),
854
- contents: documentSchema.source.content,
708
+ relative: `functions/${DOCUMENT_TYPES_DECLARATION_FILE}`,
709
+ absolute: join(functionsDir, DOCUMENT_TYPES_DECLARATION_FILE),
710
+ contents: renderDocumentTypesDeclaration(documentSchema.declarationSource),
855
711
  regenerated: true,
856
712
  },
857
713
  ]
858
714
  : []),
715
+ // #5208 — the generated schema copy (D3455-009) is never planned: inside
716
+ // a project `models/models.toml` is the only document schema, so a copy
717
+ // there is a planned removal; outside one, a copy is itself the
718
+ // resolution (rule 2), and rewriting a file from itself would be a second
719
+ // source of truth.
859
720
  ...invokers.map((invoker) => {
860
721
  const absolute = join(invokerDir, invoker.fileName);
861
722
  return {
@@ -863,8 +724,12 @@ export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
863
724
  absolute,
864
725
  contents: invoker.content,
865
726
  regenerated: true,
727
+ source: `function ${invoker.fileName.slice(0, -GENERATED_FILE_SUFFIX.length)}`,
866
728
  };
867
729
  }),
730
+ // #5385 — `UserProperties` and `ClientUserProperties` for the app's client
731
+ // code (beside the invokers); the functions' are in `primitive.d.ts`.
732
+ ...planUserPropertiesClientArtifacts(configDir, options, userProperties),
868
733
  // #3798 — each agent's client-side types, beside the invokers and owned
869
734
  // by the same plan (so the orphan sweep keeps them while the agent does).
870
735
  ...agentArtifacts,
@@ -891,8 +756,27 @@ export function planFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
891
756
  regenerated: false,
892
757
  });
893
758
  }
759
+ refuseSharedDestinations(artifacts);
894
760
  return artifacts;
895
761
  }
762
+ /**
763
+ * Refuse a plan in which two artifacts name one file (#5385): a function
764
+ * keyed `user-properties` writes its invoker where the user property client
765
+ * types go, and either would silently overwrite the other. Judged on the
766
+ * absolute paths, so a `-o` directory is judged as written.
767
+ */
768
+ function refuseSharedDestinations(artifacts) {
769
+ const byPath = new Map();
770
+ for (const artifact of artifacts) {
771
+ const prior = byPath.get(artifact.absolute);
772
+ if (prior) {
773
+ throw new FunctionSchemaCodegenError(`${artifact.relative} would be generated twice — from ${prior.source ?? prior.relative} and from ` +
774
+ `${artifact.source ?? artifact.relative} — and one would overwrite the other. Rename the function ` +
775
+ "(its key names its generated file) so the two differ.");
776
+ }
777
+ byPath.set(artifact.absolute, artifact);
778
+ }
779
+ }
896
780
  /**
897
781
  * The tsconfig wiring push could not repair, phrased for the author.
898
782
  *
@@ -921,13 +805,18 @@ export function functionTypeWiringProblems(configDir, options = {}) {
921
805
  /**
922
806
  * What the inspection knows about the directory: whether `generated/` will
923
807
  * exist beside the tsconfig once this plan is written (it exists now, or this
924
- * plan writes an invoker into the default location).
808
+ * plan writes an invoker into the default location), and which declarations
809
+ * the plan leaves out (#5206).
925
810
  */
926
811
  function tsconfigContext(configDir, options) {
927
812
  const defaultDir = join(configDir, "functions", FUNCTION_INVOKERS_DIR);
813
+ const userProperties = treeHasUserProperties(configDir);
928
814
  const writesThere = functionInvokerDir(configDir, options) === defaultDir &&
929
- functionSchemaSources(configDir).length > 0;
930
- return { generatedDirExists: existsSync(defaultDir) || writesThere };
815
+ (functionSchemaSources(configDir).length > 0 || userProperties);
816
+ return {
817
+ generatedDirExists: existsSync(defaultDir) || writesThere,
818
+ absentDeclarations: resolveDocumentSchema(configDir).declarationSource ? [] : [DOCUMENT_TYPES_DECLARATION_FILE],
819
+ };
931
820
  }
932
821
  /**
933
822
  * Invokers in the plan's directory that the plan no longer writes — a
@@ -941,20 +830,84 @@ function orphanedInvokers(configDir, planned, options) {
941
830
  const keep = new Set(planned.map((a) => a.absolute));
942
831
  // #3798 (CSO-3798-003) — with no `functions/` at all, an agent's client
943
832
  // artifact is the only thing a run could have written here (an `-o`
944
- // directory the functions run never owned before), so only those are swept.
945
- const suffix = existsSync(join(configDir, "functions"))
946
- ? GENERATED_FILE_SUFFIX
947
- : AGENT_CLIENT_FILE_SUFFIX;
833
+ // directory the functions run never owned before), so only those are swept
834
+ // — and (#5385) the user property client types.
835
+ const owned = existsSync(join(configDir, "functions"))
836
+ ? (f) => f.endsWith(GENERATED_FILE_SUFFIX)
837
+ : (f) => f.endsWith(AGENT_CLIENT_FILE_SUFFIX) || f === USER_PROPERTIES_CLIENT_FILE;
948
838
  return readdirSync(dir)
949
- .filter((f) => f.endsWith(suffix))
839
+ .filter(owned)
950
840
  .map((f) => join(dir, f))
951
841
  .filter((absolute) => !keep.has(absolute));
952
842
  }
953
- /** Write them, and report the tree-relative paths that changed on disk. */
954
- export function writeFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
843
+ /**
844
+ * Declarations a plan may leave out (#5206): the document declaration exists
845
+ * only while a document schema resolves.
846
+ */
847
+ const OPTIONAL_DECLARATIONS = [DOCUMENT_TYPES_DECLARATION_FILE];
848
+ /**
849
+ * The generated files on disk that `planned` no longer writes: a document
850
+ * declaration an earlier run wrote, once the tree's document schema is gone
851
+ * (#5206), the four declarations `primitive.d.ts` replaced (#5544), and,
852
+ * inside a project, the generated schema copy no resolution there reads
853
+ * (#5208).
854
+ */
855
+ export function retiredFunctionTypeArtifacts(configDir, planned) {
856
+ if (!treeHasFunctionsDir(configDir))
857
+ return [];
858
+ const keep = new Set(planned.map((a) => a.absolute));
859
+ const staleCopy = resolveDocumentSchema(configDir).staleTreeCopy;
860
+ return [
861
+ ...OPTIONAL_DECLARATIONS.map((file) => join(configDir, "functions", file)),
862
+ ...RETIRED_DECLARATIONS.map((retired) => join(configDir, "functions", retired.file)),
863
+ ...(staleCopy ? [staleCopy] : []),
864
+ ].filter((absolute) => !keep.has(absolute) && existsSync(absolute));
865
+ }
866
+ /**
867
+ * Every file a write of `planned` removes, as absolute paths (#5208): the
868
+ * invokers of removed functions, and the retired generated files. The one
869
+ * list the write, `--check`, the dry-run typechecker and the removal lines
870
+ * all read, so they cannot disagree about what goes.
871
+ */
872
+ export function plannedRemovals(configDir, planned, options = {}) {
873
+ return [
874
+ ...orphanedInvokers(configDir, planned, options),
875
+ ...retiredFunctionTypeArtifacts(configDir, planned),
876
+ ];
877
+ }
878
+ /**
879
+ * The line a command prints for a file a write removed (#5208), given its
880
+ * tree-relative path. The schema copy's names where the document schema
881
+ * lives and how to get it back; it never sends the author to the copy.
882
+ */
883
+ export function functionTypeRemovalLine(relative) {
884
+ if (relative.endsWith(`/${DOCUMENT_SCHEMA_TREE_FILE}`)) {
885
+ return (`Removed ${relative}: inside a project the document schema is models/models.toml, and this ` +
886
+ "generated file is no longer read. To keep the schema, restore models/models.toml from version " +
887
+ "control (the generated file was committed beside your functions); the running version keeps " +
888
+ "the schema until a push without it.");
889
+ }
890
+ if (relative.endsWith(`/${DOCUMENT_TYPES_DECLARATION_FILE}`)) {
891
+ return `Removed ${relative}: no document schema resolves, so ctx.doc's models are untyped.`;
892
+ }
893
+ // #5544 — a declaration `primitive.d.ts` replaced names where its types went.
894
+ const retired = RETIRED_DECLARATIONS.find((entry) => relative.endsWith(`/${entry.file}`));
895
+ if (retired) {
896
+ return (`Removed ${relative}: its types are in functions/${PRIMITIVE_DECLARATION_FILE} under ${retired.namespace}; ` +
897
+ `import type { ${retired.namespace} } from "${PRIMITIVE_DECLARATION_SPECIFIER}".`);
898
+ }
899
+ // #5385 — the user property client types go with user-properties.toml.
900
+ if (relative.endsWith(`/${USER_PROPERTIES_CLIENT_FILE}`)) {
901
+ return `Removed ${relative}: the tree has no ${USER_PROPERTIES_FILE}, so UserProperties declares no field.`;
902
+ }
903
+ return `Removed ${relative}: no function declares it any more.`;
904
+ }
905
+ /** Write them, and report what was written and what was removed. */
906
+ export function applyFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
955
907
  // No early return for an empty plan (CSO-3798-003): removing a tree's last
956
908
  // agent (or its last function) plans nothing, and its artifacts still go.
957
909
  const artifacts = planFunctionTypeArtifacts(configDir, sdkTypes, options);
910
+ const removals = plannedRemovals(configDir, artifacts, options);
958
911
  const written = [];
959
912
  for (const artifact of artifacts) {
960
913
  const exists = existsSync(artifact.absolute);
@@ -969,10 +922,18 @@ export function writeFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
969
922
  // A removed function's invoker goes with it (#3281): a stale generated file
970
923
  // an app still imports is a compile error naming a function that no longer
971
924
  // exists, which is the right failure, but one left behind forever is not.
972
- for (const orphan of orphanedInvokers(configDir, artifacts, options)) {
973
- rmSync(orphan, { force: true });
925
+ const removed = [];
926
+ for (const absolute of removals) {
927
+ if (!existsSync(absolute))
928
+ continue;
929
+ rmSync(absolute, { force: true });
930
+ removed.push(reportedPath(configDir, absolute));
974
931
  }
975
- return written;
932
+ return { written, removed };
933
+ }
934
+ /** Write them, and report the tree-relative paths that changed on disk. */
935
+ export function writeFunctionTypeArtifacts(configDir, sdkTypes, options = {}) {
936
+ return applyFunctionTypeArtifacts(configDir, sdkTypes, options).written;
976
937
  }
977
938
  /**
978
939
  * The artifacts a `--check` run would rewrite: the freshness answer for CI and
@@ -995,8 +956,8 @@ export function staleFunctionTypeArtifacts(configDir, options = {}) {
995
956
  stale.push(artifact.relative);
996
957
  }
997
958
  }
998
- for (const orphan of orphanedInvokers(configDir, planned, options)) {
999
- stale.push(reportedPath(configDir, orphan));
959
+ for (const removal of plannedRemovals(configDir, planned, options)) {
960
+ stale.push(reportedPath(configDir, removal));
1000
961
  }
1001
962
  return stale;
1002
963
  }