primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +258 -186
- package/assets/skill/skills/primitive-platform/SKILL.md +93 -27
- package/dist/bin/primitive.js +15 -89
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.js +80 -17
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/agent-sessions.d.ts +129 -0
- package/dist/src/commands/agent-sessions.js +532 -20
- package/dist/src/commands/agent-sessions.js.map +1 -1
- package/dist/src/commands/analytics.js +207 -155
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps-children.js +3 -0
- package/dist/src/commands/apps-children.js.map +1 -1
- package/dist/src/commands/apps-transitions.d.ts +39 -0
- package/dist/src/commands/apps-transitions.js +198 -0
- package/dist/src/commands/apps-transitions.js.map +1 -0
- package/dist/src/commands/apps.d.ts +17 -0
- package/dist/src/commands/apps.js +108 -3
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth-sessions.js +2 -0
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +138 -44
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +2 -0
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/collections.js +318 -256
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/comparisons.js +2 -0
- package/dist/src/commands/comparisons.js.map +1 -1
- package/dist/src/commands/config.d.ts +2 -2
- package/dist/src/commands/config.js +59 -33
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/connections.js +2 -0
- package/dist/src/commands/connections.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +5 -3
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +6 -4
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +15 -0
- package/dist/src/commands/db3-types.js +159 -0
- package/dist/src/commands/db3-types.js.map +1 -0
- package/dist/src/commands/db3.d.ts +24 -0
- package/dist/src/commands/db3.js +1444 -0
- package/dist/src/commands/db3.js.map +1 -0
- package/dist/src/commands/documents.d.ts +110 -10
- package/dist/src/commands/documents.js +1012 -748
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.js +74 -0
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/env.js +8 -4
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/function-trigger-commands.d.ts +28 -0
- package/dist/src/commands/function-trigger-commands.js +341 -0
- package/dist/src/commands/function-trigger-commands.js.map +1 -0
- package/dist/src/commands/functions.js +376 -30
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/groups.js +168 -50
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.js +7 -5
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/hosting.d.ts +8 -0
- package/dist/src/commands/hosting.js +346 -0
- package/dist/src/commands/hosting.js.map +1 -0
- package/dist/src/commands/init.js +129 -38
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +82 -53
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/locks.d.ts +5 -3
- package/dist/src/commands/locks.js +19 -61
- package/dist/src/commands/locks.js.map +1 -1
- package/dist/src/commands/metadata-category-configs.d.ts +2 -2
- package/dist/src/commands/metadata-category-configs.js +4 -2
- package/dist/src/commands/metadata-category-configs.js.map +1 -1
- package/dist/src/commands/metadata.js +41 -0
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/prompts.js +75 -52
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rate-counters.d.ts +19 -0
- package/dist/src/commands/rate-counters.js +104 -0
- package/dist/src/commands/rate-counters.js.map +1 -0
- package/dist/src/commands/rule-sets.d.ts +1 -1
- package/dist/src/commands/rule-sets.js +2 -1
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/schemas.d.ts +15 -0
- package/dist/src/commands/schemas.js +122 -0
- package/dist/src/commands/schemas.js.map +1 -0
- package/dist/src/commands/scripts.d.ts +9 -17
- package/dist/src/commands/scripts.js +24 -479
- package/dist/src/commands/scripts.js.map +1 -1
- package/dist/src/commands/secrets.js +47 -3
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/sessions.js +2 -0
- package/dist/src/commands/sessions.js.map +1 -1
- package/dist/src/commands/skill.js +2 -0
- package/dist/src/commands/skill.js.map +1 -1
- package/dist/src/commands/sync-schemas.d.ts +202 -0
- package/dist/src/commands/sync-schemas.js +629 -0
- package/dist/src/commands/sync-schemas.js.map +1 -0
- package/dist/src/commands/sync-user-properties.d.ts +118 -0
- package/dist/src/commands/sync-user-properties.js +276 -0
- package/dist/src/commands/sync-user-properties.js.map +1 -0
- package/dist/src/commands/sync.d.ts +518 -546
- package/dist/src/commands/sync.js +3010 -4877
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/tokens.js +5 -3
- package/dist/src/commands/tokens.js.map +1 -1
- package/dist/src/commands/transitions.d.ts +54 -0
- package/dist/src/commands/transitions.js +418 -0
- package/dist/src/commands/transitions.js.map +1 -0
- package/dist/src/commands/usage.d.ts +18 -0
- package/dist/src/commands/usage.js +343 -0
- package/dist/src/commands/usage.js.map +1 -0
- package/dist/src/commands/user-properties.d.ts +14 -0
- package/dist/src/commands/user-properties.js +79 -0
- package/dist/src/commands/user-properties.js.map +1 -0
- package/dist/src/commands/users.js +911 -18
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/vars.js +2 -0
- package/dist/src/commands/vars.js.map +1 -1
- package/dist/src/commands/waitlist.js +39 -4
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/commands/workflows.d.ts +5 -83
- package/dist/src/commands/workflows.js +57 -2282
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/analytics-query.d.ts +58 -0
- package/dist/src/lib/analytics-query.js +134 -0
- package/dist/src/lib/analytics-query.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +1818 -438
- package/dist/src/lib/api-client.js +965 -544
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
- package/dist/src/lib/app-settings-descriptor.js +6 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-fixtures.d.ts +44 -0
- package/dist/src/lib/auth-fixtures.js +61 -0
- package/dist/src/lib/auth-fixtures.js.map +1 -0
- package/dist/src/lib/auth-flow.d.ts +34 -1
- package/dist/src/lib/auth-flow.js +429 -13
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/block-layout.d.ts +12 -23
- package/dist/src/lib/block-layout.js +26 -92
- package/dist/src/lib/block-layout.js.map +1 -1
- package/dist/src/lib/block-selector.d.ts +8 -14
- package/dist/src/lib/block-selector.js +8 -19
- package/dist/src/lib/block-selector.js.map +1 -1
- package/dist/src/lib/child-apps-local.d.ts +3 -1
- package/dist/src/lib/child-apps-local.js +9 -1
- package/dist/src/lib/child-apps-local.js.map +1 -1
- package/dist/src/lib/cli-manifest.d.ts +9 -0
- package/dist/src/lib/cli-manifest.js +10 -1
- package/dist/src/lib/cli-manifest.js.map +1 -1
- package/dist/src/lib/cli-version.d.ts +14 -0
- package/dist/src/lib/cli-version.js +38 -0
- package/dist/src/lib/cli-version.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
- package/dist/src/lib/collection-export.d.ts +76 -15
- package/dist/src/lib/collection-export.js +116 -23
- package/dist/src/lib/collection-export.js.map +1 -1
- package/dist/src/lib/collection-principal.d.ts +22 -0
- package/dist/src/lib/collection-principal.js +35 -0
- package/dist/src/lib/collection-principal.js.map +1 -0
- package/dist/src/lib/command-groups.d.ts +30 -0
- package/dist/src/lib/command-groups.js +109 -0
- package/dist/src/lib/command-groups.js.map +1 -0
- package/dist/src/lib/command-status.d.ts +147 -0
- package/dist/src/lib/command-status.js +266 -0
- package/dist/src/lib/command-status.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.d.ts +9 -22
- package/dist/src/lib/config-object-descriptor.js +107 -276
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-surface.d.ts +3 -7
- package/dist/src/lib/config-surface.js +9 -13
- package/dist/src/lib/config-surface.js.map +1 -1
- package/dist/src/lib/config-toml.d.ts +11 -2
- package/dist/src/lib/config-toml.js +25 -2
- package/dist/src/lib/config-toml.js.map +1 -1
- package/dist/src/lib/credentials-home.d.ts +7 -0
- package/dist/src/lib/credentials-home.js +45 -10
- package/dist/src/lib/credentials-home.js.map +1 -1
- package/dist/src/lib/credentials-lock.d.ts +14 -6
- package/dist/src/lib/credentials-lock.js +90 -10
- package/dist/src/lib/credentials-lock.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +123 -70
- package/dist/src/lib/credentials-store.js +358 -113
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/custodian.d.ts +8 -0
- package/dist/src/lib/custodian.js +18 -0
- package/dist/src/lib/custodian.js.map +1 -0
- package/dist/src/lib/data-input.d.ts +1 -1
- package/dist/src/lib/data-input.js +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +106 -0
- package/dist/src/lib/db-type-records.js +224 -0
- package/dist/src/lib/db-type-records.js.map +1 -0
- package/dist/src/lib/db3-export.d.ts +287 -0
- package/dist/src/lib/db3-export.js +647 -0
- package/dist/src/lib/db3-export.js.map +1 -0
- package/dist/src/lib/db3-index-output.d.ts +116 -0
- package/dist/src/lib/db3-index-output.js +223 -0
- package/dist/src/lib/db3-index-output.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +134 -0
- package/dist/src/lib/db3-type-models.js +452 -0
- package/dist/src/lib/db3-type-models.js.map +1 -0
- package/dist/src/lib/deprecation.d.ts +2 -2
- package/dist/src/lib/deprecation.js +2 -2
- package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
- package/dist/src/lib/document-ingest-artifact.js +36 -6
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/document-ingest-format2.d.ts +36 -0
- package/dist/src/lib/document-ingest-format2.js +78 -0
- package/dist/src/lib/document-ingest-format2.js.map +1 -0
- package/dist/src/lib/document-ingest-input.d.ts +9 -0
- package/dist/src/lib/document-ingest-input.js +28 -1
- package/dist/src/lib/document-ingest-input.js.map +1 -1
- package/dist/src/lib/document-ingest.d.ts +11 -1
- package/dist/src/lib/document-ingest.js +16 -0
- package/dist/src/lib/document-ingest.js.map +1 -1
- package/dist/src/lib/document-schema-rows.d.ts +42 -0
- package/dist/src/lib/document-schema-rows.js +53 -0
- package/dist/src/lib/document-schema-rows.js.map +1 -0
- package/dist/src/lib/experimental-apis.d.ts +36 -0
- package/dist/src/lib/experimental-apis.js +46 -0
- package/dist/src/lib/experimental-apis.js.map +1 -0
- package/dist/src/lib/file-attachment.d.ts +24 -0
- package/dist/src/lib/file-attachment.js +31 -0
- package/dist/src/lib/file-attachment.js.map +1 -0
- package/dist/src/lib/function-authorize-check.d.ts +142 -0
- package/dist/src/lib/function-authorize-check.js +311 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -0
- package/dist/src/lib/function-authorize-view.d.ts +27 -0
- package/dist/src/lib/function-authorize-view.js +88 -0
- package/dist/src/lib/function-authorize-view.js.map +1 -0
- package/dist/src/lib/function-bundle.d.ts +27 -5
- package/dist/src/lib/function-bundle.js +142 -7
- package/dist/src/lib/function-bundle.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +90 -12
- package/dist/src/lib/function-collect.js +482 -12
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.d.ts +65 -11
- package/dist/src/lib/function-db-types.js +297 -157
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-document-types.d.ts +19 -7
- package/dist/src/lib/function-document-types.js +24 -12
- package/dist/src/lib/function-document-types.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +57 -0
- package/dist/src/lib/function-lint.js +234 -0
- package/dist/src/lib/function-lint.js.map +1 -0
- package/dist/src/lib/function-log-row.js +21 -2
- package/dist/src/lib/function-log-row.js.map +1 -1
- package/dist/src/lib/function-run.d.ts +13 -21
- package/dist/src/lib/function-run.js +14 -27
- package/dist/src/lib/function-run.js.map +1 -1
- package/dist/src/lib/function-schema-codegen.d.ts +86 -22
- package/dist/src/lib/function-schema-codegen.js +194 -88
- package/dist/src/lib/function-schema-codegen.js.map +1 -1
- package/dist/src/lib/function-schema-refs.d.ts +98 -0
- package/dist/src/lib/function-schema-refs.js +177 -0
- package/dist/src/lib/function-schema-refs.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +109 -6
- package/dist/src/lib/function-sync.js +179 -26
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/function-trigger-listing.d.ts +11 -6
- package/dist/src/lib/function-trigger-listing.js +32 -11
- package/dist/src/lib/function-trigger-listing.js.map +1 -1
- package/dist/src/lib/function-typecheck.d.ts +52 -0
- package/dist/src/lib/function-typecheck.js +174 -54
- package/dist/src/lib/function-typecheck.js.map +1 -1
- package/dist/src/lib/function-versions.d.ts +2 -0
- package/dist/src/lib/function-versions.js +1 -0
- package/dist/src/lib/function-versions.js.map +1 -1
- package/dist/src/lib/generated-build-flags.d.ts +13 -0
- package/dist/src/lib/generated-build-flags.js +14 -0
- package/dist/src/lib/generated-build-flags.js.map +1 -0
- package/dist/src/lib/generated-command-status.d.ts +6 -0
- package/dist/src/lib/generated-command-status.js +469 -0
- package/dist/src/lib/generated-command-status.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +538 -141
- package/dist/src/lib/generated-config-surfaces.js +1772 -1854
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-build.d.ts +97 -0
- package/dist/src/lib/hosting-build.js +204 -0
- package/dist/src/lib/hosting-build.js.map +1 -0
- package/dist/src/lib/hosting-client.d.ts +167 -0
- package/dist/src/lib/hosting-client.js +340 -0
- package/dist/src/lib/hosting-client.js.map +1 -0
- package/dist/src/lib/hosting-environments.d.ts +32 -0
- package/dist/src/lib/hosting-environments.js +74 -0
- package/dist/src/lib/hosting-environments.js.map +1 -0
- package/dist/src/lib/hosting-errors.d.ts +30 -0
- package/dist/src/lib/hosting-errors.js +43 -0
- package/dist/src/lib/hosting-errors.js.map +1 -0
- package/dist/src/lib/hosting-token.d.ts +46 -0
- package/dist/src/lib/hosting-token.js +60 -0
- package/dist/src/lib/hosting-token.js.map +1 -0
- package/dist/src/lib/hosting-wait.d.ts +42 -0
- package/dist/src/lib/hosting-wait.js +84 -0
- package/dist/src/lib/hosting-wait.js.map +1 -0
- package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
- package/dist/src/lib/hosting-wfp-upload.js +149 -0
- package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
- package/dist/src/lib/init-assets.d.ts +2 -6
- package/dist/src/lib/init-assets.js +11 -27
- package/dist/src/lib/init-assets.js.map +1 -1
- package/dist/src/lib/init-ios-links.d.ts +11 -7
- package/dist/src/lib/init-ios-links.js +28 -22
- package/dist/src/lib/init-ios-links.js.map +1 -1
- package/dist/src/lib/init-login-note.d.ts +13 -0
- package/dist/src/lib/init-login-note.js +22 -0
- package/dist/src/lib/init-login-note.js.map +1 -0
- package/dist/src/lib/init-schema.d.ts +15 -0
- package/dist/src/lib/init-schema.js +54 -0
- package/dist/src/lib/init-schema.js.map +1 -1
- package/dist/src/lib/integration-test-request.d.ts +54 -0
- package/dist/src/lib/integration-test-request.js +207 -0
- package/dist/src/lib/integration-test-request.js.map +1 -0
- package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
- package/dist/src/lib/invoker-shared-enums.js +98 -0
- package/dist/src/lib/invoker-shared-enums.js.map +1 -0
- package/dist/src/lib/json-value.d.ts +6 -0
- package/dist/src/lib/json-value.js +13 -0
- package/dist/src/lib/json-value.js.map +1 -0
- package/dist/src/lib/load-routes.d.ts +33 -0
- package/dist/src/lib/load-routes.js +35 -0
- package/dist/src/lib/load-routes.js.map +1 -0
- package/dist/src/lib/log-inspection.d.ts +23 -4
- package/dist/src/lib/log-inspection.js +14 -5
- package/dist/src/lib/log-inspection.js.map +1 -1
- package/dist/src/lib/login-exchange-check.d.ts +18 -0
- package/dist/src/lib/login-exchange-check.js +27 -0
- package/dist/src/lib/login-exchange-check.js.map +1 -0
- package/dist/src/lib/login-scope-lines.d.ts +17 -7
- package/dist/src/lib/login-scope-lines.js +33 -10
- package/dist/src/lib/login-scope-lines.js.map +1 -1
- package/dist/src/lib/metadata-report.d.ts +85 -0
- package/dist/src/lib/metadata-report.js +81 -0
- package/dist/src/lib/metadata-report.js.map +1 -0
- package/dist/src/lib/object-status-filter.d.ts +9 -1
- package/dist/src/lib/object-status-filter.js +9 -1
- package/dist/src/lib/object-status-filter.js.map +1 -1
- package/dist/src/lib/output.d.ts +1 -1
- package/dist/src/lib/output.js +3 -1
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
- package/dist/src/lib/pin-refusal-hint.js +35 -0
- package/dist/src/lib/pin-refusal-hint.js.map +1 -0
- package/dist/src/lib/platform-owned.js +5 -0
- package/dist/src/lib/platform-owned.js.map +1 -1
- package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
- package/dist/src/lib/primitive-declaration-names.js +22 -0
- package/dist/src/lib/primitive-declaration-names.js.map +1 -0
- package/dist/src/lib/primitive-declaration.d.ts +174 -0
- package/dist/src/lib/primitive-declaration.js +792 -0
- package/dist/src/lib/primitive-declaration.js.map +1 -0
- package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
- package/dist/src/lib/primitive-env-plugin.js +408 -0
- package/dist/src/lib/primitive-env-plugin.js.map +1 -0
- package/dist/src/lib/project-login-apps.d.ts +8 -0
- package/dist/src/lib/project-login-apps.js +27 -0
- package/dist/src/lib/project-login-apps.js.map +1 -0
- package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
- package/dist/src/lib/prompt-schema-codegen.js +96 -100
- package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
- package/dist/src/lib/prompt-schema-document.d.ts +35 -0
- package/dist/src/lib/prompt-schema-document.js +92 -0
- package/dist/src/lib/prompt-schema-document.js.map +1 -0
- package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
- package/dist/src/lib/prompt-schema-refs.js +478 -0
- package/dist/src/lib/prompt-schema-refs.js.map +1 -0
- package/dist/src/lib/records-verbs.d.ts +79 -0
- package/dist/src/lib/records-verbs.js +45 -0
- package/dist/src/lib/records-verbs.js.map +1 -0
- package/dist/src/lib/register-commands.d.ts +36 -0
- package/dist/src/lib/register-commands.js +37 -0
- package/dist/src/lib/register-commands.js.map +1 -0
- package/dist/src/lib/retired-imports.d.ts +53 -0
- package/dist/src/lib/retired-imports.js +120 -0
- package/dist/src/lib/retired-imports.js.map +1 -0
- package/dist/src/lib/run-status.d.ts +1 -1
- package/dist/src/lib/run-status.generated.d.ts +2 -2
- package/dist/src/lib/run-status.generated.js +3 -1
- package/dist/src/lib/run-status.generated.js.map +1 -1
- package/dist/src/lib/run-status.js +1 -1
- package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
- package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
- package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
- package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
- package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
- package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
- package/dist/src/lib/schema-codegen/naming.js +83 -0
- package/dist/src/lib/schema-codegen/naming.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
- package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
- package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
- package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
- package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
- package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
- package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
- package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
- package/dist/src/lib/schema-family-index.d.ts +228 -0
- package/dist/src/lib/schema-family-index.js +813 -0
- package/dist/src/lib/schema-family-index.js.map +1 -0
- package/dist/src/lib/schema-pins.d.ts +82 -0
- package/dist/src/lib/schema-pins.js +198 -0
- package/dist/src/lib/schema-pins.js.map +1 -0
- package/dist/src/lib/schema-preview.d.ts +244 -0
- package/dist/src/lib/schema-preview.js +498 -0
- package/dist/src/lib/schema-preview.js.map +1 -0
- package/dist/src/lib/scope-request.d.ts +23 -11
- package/dist/src/lib/scope-request.js +69 -31
- package/dist/src/lib/scope-request.js.map +1 -1
- package/dist/src/lib/session-scope.d.ts +26 -0
- package/dist/src/lib/session-scope.js +58 -0
- package/dist/src/lib/session-scope.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +2 -2
- package/dist/src/lib/skill-installer.js +2 -21
- package/dist/src/lib/skill-installer.js.map +1 -1
- package/dist/src/lib/step-run-table.d.ts +1 -2
- package/dist/src/lib/step-run-table.js +1 -2
- package/dist/src/lib/step-run-table.js.map +1 -1
- package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
- package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
- package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
- package/dist/src/lib/swift-codegen/banners.js +12 -0
- package/dist/src/lib/swift-codegen/banners.js.map +1 -1
- package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
- package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
- package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
- package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
- package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
- package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +117 -31
- package/dist/src/lib/sync-resource-types.js +197 -189
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/sync-selectors.d.ts +7 -0
- package/dist/src/lib/sync-selectors.js +22 -2
- package/dist/src/lib/sync-selectors.js.map +1 -1
- package/dist/src/lib/template.d.ts +39 -3
- package/dist/src/lib/template.js +103 -14
- package/dist/src/lib/template.js.map +1 -1
- package/dist/src/lib/test-case-file-names.d.ts +3 -5
- package/dist/src/lib/test-case-file-names.js +3 -5
- package/dist/src/lib/test-case-file-names.js.map +1 -1
- package/dist/src/lib/test-runs.d.ts +45 -0
- package/dist/src/lib/test-runs.js +150 -0
- package/dist/src/lib/test-runs.js.map +1 -0
- package/dist/src/lib/test-users.d.ts +25 -0
- package/dist/src/lib/test-users.js +36 -0
- package/dist/src/lib/test-users.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +4 -2
- package/dist/src/lib/toml-database-config.js +11 -6
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/toml-scalar-edit.js +6 -4
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/transition-warnings.d.ts +21 -0
- package/dist/src/lib/transition-warnings.js +49 -0
- package/dist/src/lib/transition-warnings.js.map +1 -0
- package/dist/src/lib/user-index.d.ts +80 -0
- package/dist/src/lib/user-index.js +166 -0
- package/dist/src/lib/user-index.js.map +1 -0
- package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
- package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
- package/dist/src/lib/user-walk.d.ts +31 -0
- package/dist/src/lib/user-walk.js +102 -0
- package/dist/src/lib/user-walk.js.map +1 -0
- package/dist/src/lib/webhook-capture.d.ts +43 -0
- package/dist/src/lib/webhook-capture.js +91 -0
- package/dist/src/lib/webhook-capture.js.map +1 -0
- package/dist/src/lib/webhook-deliver.d.ts +18 -20
- package/dist/src/lib/webhook-deliver.js +34 -89
- package/dist/src/lib/webhook-deliver.js.map +1 -1
- package/dist/src/lib/webhook-test-run.d.ts +32 -0
- package/dist/src/lib/webhook-test-run.js +108 -0
- package/dist/src/lib/webhook-test-run.js.map +1 -0
- package/dist/src/lib/worker-perf-format.d.ts +22 -0
- package/dist/src/lib/worker-perf-format.js +27 -0
- package/dist/src/lib/worker-perf-format.js.map +1 -0
- package/dist/src/types/index.d.ts +20 -65
- package/dist/src/validators.d.ts +7 -55
- package/dist/src/validators.js +7 -53
- package/dist/src/validators.js.map +1 -1
- package/dist/src/vite.d.ts +17 -0
- package/dist/src/vite.js +18 -0
- package/dist/src/vite.js.map +1 -0
- package/package.json +20 -9
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `functions/primitive.d.ts` — the one generated declaration (#5544, project
|
|
3
|
+
* `unified-schemas` phase 10).
|
|
4
|
+
*
|
|
5
|
+
* It replaces four per-family files (`primitive-function-types.d.ts`,
|
|
6
|
+
* `primitive-prompt-types.d.ts`, `primitive-db3-types.d.ts`,
|
|
7
|
+
* `primitive-user-properties.d.ts`), which repeated a shape once per place it
|
|
8
|
+
* was inlined. One module-style file now holds, in order:
|
|
9
|
+
*
|
|
10
|
+
* - five namespaces, each always present: `Schemas` (every def of every
|
|
11
|
+
* `schemas/*.toml`), `Functions` (`<Key>Input`/`<Key>Output`), `Prompts`
|
|
12
|
+
* (`<Key>PromptOutput` and the agent types), `Db3` (each model the
|
|
13
|
+
* `ctx.db3` handle types, and each db3 projection some schema in the tree
|
|
14
|
+
* references) and `UserProperties`;
|
|
15
|
+
* - the top-level glue interfaces with the names the four files used
|
|
16
|
+
* (`PrimitiveFunctionSchemas`, …), maps of references into the namespaces;
|
|
17
|
+
* - one `declare module "primitive-functions"` block with every
|
|
18
|
+
* augmentation. The augmentations extend the top-level glue names, so no
|
|
19
|
+
* name inside the block can shadow a namespace.
|
|
20
|
+
*
|
|
21
|
+
* ── Each shape once ──────────────────────────────────────────────────────
|
|
22
|
+
*
|
|
23
|
+
* Every schema is rendered COMPILED, and a node the compiler inlined a ref at
|
|
24
|
+
* renders as a reference to the target's one declaration (`Schemas.Money`)
|
|
25
|
+
* when the reference is exact (`namedRefs.ts`): a sibling that overrides the
|
|
26
|
+
* target renders inline, so the type says what the validator enforces.
|
|
27
|
+
*
|
|
28
|
+
* ── Names ────────────────────────────────────────────────────────────────
|
|
29
|
+
*
|
|
30
|
+
* Every name comes from the compiled space (`compiledSpace.ts`), computed
|
|
31
|
+
* once for both languages: short when one party produces it, renamed
|
|
32
|
+
* `<Namespace>_<PascalKey>_<Name>` for every party to a collision, refused
|
|
33
|
+
* when a collision survives. The shared Swift file reads the same tree
|
|
34
|
+
* (`describeTreeTypes`), so a reader types the same name in either language.
|
|
35
|
+
*
|
|
36
|
+
* A db3 model's `<Model>Filter`, `<Model>Sort` (#5546) and `<Model>Unique`
|
|
37
|
+
* (#5895, a union of string literals) are not parties:
|
|
38
|
+
* they are named after the model's emitted name once the space is computed,
|
|
39
|
+
* so a renamed model's helpers follow it and no other name moves in either
|
|
40
|
+
* language. A helper named like another `Db3` declaration is refused. They
|
|
41
|
+
* reference the SDK's `Db3Filter` and `Db3Sort` through import types, which
|
|
42
|
+
* no declaration in the namespace can shadow, so the file imports nothing.
|
|
43
|
+
*
|
|
44
|
+
* The bytes depend on the tree only: every list is sorted by key and def name.
|
|
45
|
+
*/
|
|
46
|
+
import { describeAll as describeFunctionSet, describeFunctionSchemas, describeFunctionSchemaSet, FunctionSchemaCodegenError, functionSchemaSources, renderDeclaredType, renderTypeDecl, } from "./function-schema-codegen.js";
|
|
47
|
+
import { describeAll as describePromptSet, describePromptSchema, promptSchemaSources, renderAgentType, } from "./prompt-schema-codegen.js";
|
|
48
|
+
import { dbTypeRecords, db3TypeSources } from "./db-type-records.js";
|
|
49
|
+
import { atom, indent, PRINT_WIDTH, printedAtLevel, renderMember, renderTypeAlias, tsPropertyKey, tsStringLiteral, union } from "./codegen-shared/prettierStable.js";
|
|
50
|
+
import { loadSchemaFamilyIndex } from "./schema-family-index.js";
|
|
51
|
+
import { compiledSpace } from "./schema-codegen/compiledSpace.js";
|
|
52
|
+
import { namedReferences } from "./schema-codegen/namedRefs.js";
|
|
53
|
+
import { canonicalJsonText, pointerSegment } from "./schema-codegen/schemaIR.js";
|
|
54
|
+
import { workflowTypeBaseName } from "./schema-codegen/naming.js";
|
|
55
|
+
import { SWIFT_KEYWORDS, structTypeName } from "./swift-codegen/swiftNaming.js";
|
|
56
|
+
import { workflowSwiftTypeBaseName } from "./swift-codegen/swiftKeys.js";
|
|
57
|
+
import { renderUserPropertiesDeclarations, USER_PROPERTIES_FILE, userPropertiesSource, } from "./user-properties/user-properties-codegen.js";
|
|
58
|
+
export { PRIMITIVE_DECLARATION_FILE, PRIMITIVE_DECLARATION_SPECIFIER } from "./primitive-declaration-names.js";
|
|
59
|
+
/** Every input a tree has. */
|
|
60
|
+
export function primitiveDeclarationInputs(configDir) {
|
|
61
|
+
return {
|
|
62
|
+
functions: functionSchemaSources(configDir),
|
|
63
|
+
prompts: promptSchemaSources(configDir),
|
|
64
|
+
db3: db3TypeSources(configDir),
|
|
65
|
+
userProperties: userPropertiesSource(configDir)?.schema ?? null,
|
|
66
|
+
configDir,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export const functionTypeId = (key, part) => `fn:${key}#/$defs/${part}`;
|
|
70
|
+
export const promptTypeId = (key, target) => `prompt:${key}#/$defs/${target}`;
|
|
71
|
+
export const defTypeId = (file, name) => `schemas:${file}#/$defs/${pointerSegment(name)}`;
|
|
72
|
+
const modelTypeId = (type, model) => `db3model:${type}#${model}`;
|
|
73
|
+
const USER_PROPERTIES_KEY = "UserProperties";
|
|
74
|
+
export const USER_PROPERTIES_IDS = {
|
|
75
|
+
userProperties: "user-properties#UserProperties",
|
|
76
|
+
clientUserProperties: "user-properties#ClientUserProperties",
|
|
77
|
+
uniqueUserProperties: "user-properties#UniqueUserProperties",
|
|
78
|
+
};
|
|
79
|
+
/** The reserved party standing for TypeScript's `Record` in the compiled space; it declares nothing. */
|
|
80
|
+
const TS_RECORD_ID = "typescript#Record";
|
|
81
|
+
/** A def's name in Swift: the def name, a keyword lifted out with `_`. */
|
|
82
|
+
const swiftDefName = (name) => (SWIFT_KEYWORDS.has(name) ? `${name}_` : name);
|
|
83
|
+
/** Push's refusal of a `schemas/` file, as its preflight prints it (#5894). */
|
|
84
|
+
function schemaFileRefusal(local) {
|
|
85
|
+
return local.error ? new FunctionSchemaCodegenError(`${local.relative}: ${local.error}`) : null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* #5894 — refuse a tree holding any schema `config push` refuses: a function
|
|
89
|
+
* file, a prompt file or a `schemas/` file, each with push's own message.
|
|
90
|
+
* Throws the first as a `FunctionSchemaCodegenError`. `functions codegen`
|
|
91
|
+
* runs it before deciding there is nothing to generate, so a tree with no
|
|
92
|
+
* `functions/` directory, or one whose artifacts are client-only, cannot pass
|
|
93
|
+
* `--check` over a file push refuses.
|
|
94
|
+
*/
|
|
95
|
+
export function refuseTreeSchemasPushRefuses(configDir) {
|
|
96
|
+
for (const source of functionSchemaSources(configDir))
|
|
97
|
+
describeFunctionSchemas(source);
|
|
98
|
+
for (const source of promptSchemaSources(configDir))
|
|
99
|
+
describePromptSchema(source);
|
|
100
|
+
for (const local of loadSchemaFamilyIndex(configDir).locals) {
|
|
101
|
+
const refusal = schemaFileRefusal(local);
|
|
102
|
+
if (refusal)
|
|
103
|
+
throw refusal;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The tree's `schemas/` defs, each compiled. A file push would refuse is
|
|
108
|
+
* refused here with push's message (#5894), rather than leaving its defs out.
|
|
109
|
+
*/
|
|
110
|
+
function treeDefs(configDir) {
|
|
111
|
+
if (!configDir)
|
|
112
|
+
return [];
|
|
113
|
+
const defs = [];
|
|
114
|
+
for (const local of loadSchemaFamilyIndex(configDir).locals) {
|
|
115
|
+
const refusal = schemaFileRefusal(local);
|
|
116
|
+
if (refusal)
|
|
117
|
+
throw refusal;
|
|
118
|
+
const compile = local.compile;
|
|
119
|
+
if (!compile || "refusal" in compile)
|
|
120
|
+
continue;
|
|
121
|
+
for (const name of [...compile.names].sort()) {
|
|
122
|
+
defs.push({
|
|
123
|
+
id: defTypeId(local.file, name),
|
|
124
|
+
file: local.file,
|
|
125
|
+
name,
|
|
126
|
+
schema: compile.defs[name],
|
|
127
|
+
resolved: (compile.resolved?.[name] ?? []),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return defs;
|
|
132
|
+
}
|
|
133
|
+
/** A projection's identity: its schema without the root annotations naming its type. */
|
|
134
|
+
function projectionIdentity(schema) {
|
|
135
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema))
|
|
136
|
+
return canonicalJsonText(schema);
|
|
137
|
+
const { description: _d, $comment: _c, ...rest } = schema;
|
|
138
|
+
return canonicalJsonText(rest);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* #5896 — what a projection's Swift identity adds: its fields whose `ref` named a shared enum, each with the def's
|
|
142
|
+
* id, sorted by field; empty for a projection with none, so its identity is today's. Swift types such a field by the
|
|
143
|
+
* enum, so a ref-using and a hand-expanded declaration of one model are different declarations there, while
|
|
144
|
+
* TypeScript, which renders both as the same union, keeps one.
|
|
145
|
+
*/
|
|
146
|
+
function projectionEnumIdentity(projection, refs) {
|
|
147
|
+
const fields = refs.get(projection.type)?.get(projection.model);
|
|
148
|
+
const properties = projection.schema?.properties;
|
|
149
|
+
if (!fields || !properties)
|
|
150
|
+
return "";
|
|
151
|
+
const pairs = [...fields]
|
|
152
|
+
.filter(([field]) => Object.prototype.hasOwnProperty.call(properties, field))
|
|
153
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
154
|
+
.map(([field, ref]) => `${field}\u0001${defTypeId(ref.file, ref.name)}`);
|
|
155
|
+
return pairs.length === 0 ? "" : `\u0000${pairs.join("\u0000")}`;
|
|
156
|
+
}
|
|
157
|
+
/** Every db3 projection a chain step of `resolved` names, with the definition it inlined. */
|
|
158
|
+
function collectProjections(resolved, into) {
|
|
159
|
+
for (const entry of resolved) {
|
|
160
|
+
entry.chain.forEach((step, index) => {
|
|
161
|
+
if (!step.startsWith("db3:") || into.has(step))
|
|
162
|
+
return;
|
|
163
|
+
const match = /^db3:([^#]+)#\/\$defs\/(.+)\/(row|declared)$/.exec(step);
|
|
164
|
+
const schema = entry.definitions?.[index];
|
|
165
|
+
if (!match || schema === undefined)
|
|
166
|
+
return;
|
|
167
|
+
const model = match[2].replace(/~1/g, "/").replace(/~0/g, "~");
|
|
168
|
+
into.set(step, { id: step, type: match[1], model, projection: match[3], schema });
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Describe a tree's generated types and name them; see the module note.
|
|
174
|
+
* `language` picks the per-family refusals that language's generator makes
|
|
175
|
+
* (the TypeScript base-name check), and which collision refuses.
|
|
176
|
+
*/
|
|
177
|
+
export function describeTreeTypes(inputs, language) {
|
|
178
|
+
const functionSources = inputs.functions ?? [];
|
|
179
|
+
const functions = (language === "ts" ? describeFunctionSet(functionSources) : describeFunctionSchemaSet(functionSources)).map((entry) => entry.fn);
|
|
180
|
+
const prompts = describePromptSet(inputs.prompts ?? []).map((entry) => entry.prompt);
|
|
181
|
+
const defs = treeDefs(inputs.configDir);
|
|
182
|
+
const userProperties = inputs.userProperties ?? null;
|
|
183
|
+
const names = [];
|
|
184
|
+
const namespaces = new Map();
|
|
185
|
+
const add = (name, referable = true) => {
|
|
186
|
+
names.push(name);
|
|
187
|
+
if (referable)
|
|
188
|
+
namespaces.set(name.id, name.namespace);
|
|
189
|
+
};
|
|
190
|
+
for (const def of defs) {
|
|
191
|
+
add({
|
|
192
|
+
id: def.id,
|
|
193
|
+
namespace: "Schemas",
|
|
194
|
+
key: def.file,
|
|
195
|
+
source: `schemas/${def.file}.toml`,
|
|
196
|
+
short: { ts: def.name, swift: swiftDefName(def.name) },
|
|
197
|
+
suffix: def.name,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
for (const fn of functions) {
|
|
201
|
+
const swiftBase = workflowSwiftTypeBaseName(fn.key);
|
|
202
|
+
for (const [part, suffix] of [
|
|
203
|
+
["input", "Input"],
|
|
204
|
+
["output", "Output"],
|
|
205
|
+
]) {
|
|
206
|
+
add({
|
|
207
|
+
id: functionTypeId(fn.key, part),
|
|
208
|
+
namespace: "Functions",
|
|
209
|
+
key: fn.key,
|
|
210
|
+
source: fn.fileLabel,
|
|
211
|
+
short: { ts: `${fn.typeBaseName}${suffix}`, swift: `${swiftBase}${suffix}` },
|
|
212
|
+
suffix,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (const prompt of prompts) {
|
|
217
|
+
const base = prompt.typeBaseName;
|
|
218
|
+
const promptName = (target, typeName) => add({
|
|
219
|
+
id: promptTypeId(prompt.key, target),
|
|
220
|
+
namespace: "Prompts",
|
|
221
|
+
key: prompt.key,
|
|
222
|
+
source: prompt.fileLabel,
|
|
223
|
+
short: { ts: typeName, swift: typeName },
|
|
224
|
+
suffix: typeName.slice(base.length),
|
|
225
|
+
});
|
|
226
|
+
if (!prompt.agent) {
|
|
227
|
+
if (prompt.outputSchema !== undefined)
|
|
228
|
+
promptName("output", prompt.outputTypeName);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const agent = prompt.agent;
|
|
232
|
+
promptName("input", agent.variablesTypeName);
|
|
233
|
+
for (const tool of agent.clientTools) {
|
|
234
|
+
promptName(`tools/${tool.name}/input`, tool.input.typeName);
|
|
235
|
+
promptName(`tools/${tool.name}/output`, tool.output.typeName);
|
|
236
|
+
}
|
|
237
|
+
for (const presentation of agent.presentations)
|
|
238
|
+
promptName(`tools/${presentation.name}/input`, presentation.typeName);
|
|
239
|
+
for (const event of agent.events)
|
|
240
|
+
promptName(`events/${event.name}`, event.typeName);
|
|
241
|
+
}
|
|
242
|
+
// db3: each model the handle types, and each projection a rendered schema references.
|
|
243
|
+
const db3Types = [...(inputs.db3 ?? [])]
|
|
244
|
+
.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
|
|
245
|
+
.map((source) => ({
|
|
246
|
+
type: source.type,
|
|
247
|
+
models: dbTypeRecords({
|
|
248
|
+
key: source.type,
|
|
249
|
+
tomlPath: source.tomlPath,
|
|
250
|
+
tomlContent: source.tomlContent,
|
|
251
|
+
table: source.directory === "db3-types" ? "db3" : "database",
|
|
252
|
+
}, "required").map((record) => ({ id: modelTypeId(source.type, record.modelName), type: source.type, ...record })),
|
|
253
|
+
}));
|
|
254
|
+
for (const { type, models } of db3Types) {
|
|
255
|
+
for (const model of models) {
|
|
256
|
+
const short = workflowTypeBaseName(model.modelName);
|
|
257
|
+
add({
|
|
258
|
+
id: model.id,
|
|
259
|
+
namespace: "Db3",
|
|
260
|
+
key: type,
|
|
261
|
+
source: `db3 type ${type}`,
|
|
262
|
+
short: { ts: short, swift: structTypeName(model.modelName) },
|
|
263
|
+
suffix: short,
|
|
264
|
+
// Two types declaring one model identically are one party: its
|
|
265
|
+
// members (fields and the stamps the type applies) in any order, as
|
|
266
|
+
// the audit compares the model table's canonical JSON. A member's
|
|
267
|
+
// query kind (#5546) is left out, so the row's name is what it was
|
|
268
|
+
// before filters existed; `db3KindEntries` opens a member whose
|
|
269
|
+
// kind the parties sharing a name disagree on.
|
|
270
|
+
identity: canonicalJsonText(JSON.parse(JSON.stringify([...model.members]
|
|
271
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
272
|
+
.map(({ kind: _kind, ...member }) => member)))),
|
|
273
|
+
}, false);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const byProjection = new Map();
|
|
277
|
+
for (const fn of functions) {
|
|
278
|
+
collectProjections(fn.resolved.inputSchema, byProjection);
|
|
279
|
+
collectProjections(fn.resolved.outputSchema, byProjection);
|
|
280
|
+
}
|
|
281
|
+
for (const prompt of prompts) {
|
|
282
|
+
collectProjections(prompt.resolved.inputSchema, byProjection);
|
|
283
|
+
collectProjections(prompt.resolved.outputSchema, byProjection);
|
|
284
|
+
collectProjections(prompt.resolved.agent, byProjection);
|
|
285
|
+
}
|
|
286
|
+
for (const def of defs)
|
|
287
|
+
collectProjections(def.resolved, byProjection);
|
|
288
|
+
const projections = [...byProjection.values()].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
289
|
+
const db3EnumRefs = new Map();
|
|
290
|
+
for (const source of inputs.db3 ?? [])
|
|
291
|
+
if (source.enumRefs && !db3EnumRefs.has(source.type))
|
|
292
|
+
db3EnumRefs.set(source.type, source.enumRefs);
|
|
293
|
+
for (const projection of projections) {
|
|
294
|
+
const suffix = `${workflowTypeBaseName(projection.model)}${projection.projection === "row" ? "Row" : "Declared"}`;
|
|
295
|
+
add({
|
|
296
|
+
id: projection.id,
|
|
297
|
+
namespace: "Db3",
|
|
298
|
+
key: projection.type,
|
|
299
|
+
source: `db3 type ${projection.type}`,
|
|
300
|
+
short: { ts: suffix, swift: `${structTypeName(projection.model)}${projection.projection === "row" ? "Row" : "Declared"}` },
|
|
301
|
+
suffix,
|
|
302
|
+
identity: `${projection.projection}\u0000${projectionIdentity(projection.schema)}${language === "swift" ? projectionEnumIdentity(projection, db3EnumRefs) : ""}`,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
for (const [field, name] of [
|
|
306
|
+
["userProperties", "UserProperties"],
|
|
307
|
+
["clientUserProperties", "ClientUserProperties"],
|
|
308
|
+
["uniqueUserProperties", "UniqueUserProperties"],
|
|
309
|
+
]) {
|
|
310
|
+
add({
|
|
311
|
+
id: USER_PROPERTIES_IDS[field],
|
|
312
|
+
namespace: "UserProperties",
|
|
313
|
+
key: USER_PROPERTIES_KEY,
|
|
314
|
+
source: USER_PROPERTIES_FILE,
|
|
315
|
+
short: { ts: name, swift: name },
|
|
316
|
+
suffix: name,
|
|
317
|
+
}, false);
|
|
318
|
+
}
|
|
319
|
+
// TypeScript's `Record`, which the declarations write unqualified (an empty
|
|
320
|
+
// model, an open map): a def or a model named so would shadow it inside its
|
|
321
|
+
// namespace, so it is renamed as though another party produced the name.
|
|
322
|
+
add({
|
|
323
|
+
id: TS_RECORD_ID,
|
|
324
|
+
namespace: "Schemas",
|
|
325
|
+
key: "TypeScript",
|
|
326
|
+
source: "TypeScript's built-in `Record`",
|
|
327
|
+
short: { ts: "Record", swift: TS_RECORD_ID },
|
|
328
|
+
suffix: "Record",
|
|
329
|
+
}, false);
|
|
330
|
+
const space = compiledSpace(names);
|
|
331
|
+
const collision = space.collisions[language][0];
|
|
332
|
+
if (collision && language === "ts") {
|
|
333
|
+
throw new FunctionSchemaCodegenError(`${collision.sources[0]} and ${collision.sources[1]} both produce the generated type \`${collision.name}\` even ` +
|
|
334
|
+
"after the collision rename — rename one so the two differ");
|
|
335
|
+
}
|
|
336
|
+
if (language === "ts")
|
|
337
|
+
refuseDb3HelperCollisions(db3Types, projections, space);
|
|
338
|
+
return { functions, prompts, defs, db3Types, projections, userProperties, space, namespaces, db3EnumRefs };
|
|
339
|
+
}
|
|
340
|
+
/** The helpers each db3 model declares beside its interface (#5546), by the suffix on its emitted name. */
|
|
341
|
+
const DB3_HELPERS = [
|
|
342
|
+
["Filter", "filter"],
|
|
343
|
+
["Sort", "sort"],
|
|
344
|
+
["Unique", "unique names"],
|
|
345
|
+
];
|
|
346
|
+
/**
|
|
347
|
+
* Refuse a db3 model's filter or sort named like another declaration of the
|
|
348
|
+
* `Db3` namespace (a model or a projection), whatever their fields: the
|
|
349
|
+
* helpers are not parties of the compiled space, so nothing renames them.
|
|
350
|
+
*/
|
|
351
|
+
function refuseDb3HelperCollisions(db3Types, projections, space) {
|
|
352
|
+
const declared = new Map();
|
|
353
|
+
for (const { type, models } of db3Types) {
|
|
354
|
+
for (const model of models) {
|
|
355
|
+
const emitted = space.ts.get(model.id);
|
|
356
|
+
if (!declared.has(emitted))
|
|
357
|
+
declared.set(emitted, `db3 type ${type}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
for (const projection of projections) {
|
|
361
|
+
const emitted = space.ts.get(projection.id);
|
|
362
|
+
if (!declared.has(emitted))
|
|
363
|
+
declared.set(emitted, `db3 type ${projection.type}`);
|
|
364
|
+
}
|
|
365
|
+
for (const { type, models } of db3Types) {
|
|
366
|
+
for (const model of models) {
|
|
367
|
+
for (const [suffix, role] of DB3_HELPERS) {
|
|
368
|
+
const helper = `${space.ts.get(model.id)}${suffix}`;
|
|
369
|
+
const other = declared.get(helper);
|
|
370
|
+
if (other === undefined)
|
|
371
|
+
continue;
|
|
372
|
+
throw new FunctionSchemaCodegenError(`${other} and db3 type ${type} (the ${role} of ${model.modelName}) both produce the generated type \`${helper}\` ` +
|
|
373
|
+
"— rename one so the two differ");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* The name a reference to `ref` (a chain step: an explicit ref) renders in
|
|
380
|
+
* `language`, or null when the target has no generated declaration and
|
|
381
|
+
* renders inline: `Schemas.Money` in TypeScript, `Money` in Swift.
|
|
382
|
+
*/
|
|
383
|
+
export function treeNameOf(tree, language) {
|
|
384
|
+
return (ref) => {
|
|
385
|
+
const namespace = tree.namespaces.get(ref);
|
|
386
|
+
if (!namespace)
|
|
387
|
+
return null;
|
|
388
|
+
const emitted = (language === "ts" ? tree.space.ts : tree.space.swift).get(ref);
|
|
389
|
+
if (emitted === undefined)
|
|
390
|
+
return null;
|
|
391
|
+
return language === "ts" ? `${namespace}.${emitted}` : emitted;
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* The schema each referable declaration is rendered from, by id: what a
|
|
396
|
+
* reference to it must match to be exact (`namedRefs.ts`).
|
|
397
|
+
*/
|
|
398
|
+
export function treeTargetOf(tree) {
|
|
399
|
+
const known = targetsByTree.get(tree);
|
|
400
|
+
if (known)
|
|
401
|
+
return known;
|
|
402
|
+
const targets = new Map();
|
|
403
|
+
for (const def of tree.defs)
|
|
404
|
+
targets.set(def.id, def.schema);
|
|
405
|
+
for (const fn of tree.functions) {
|
|
406
|
+
targets.set(functionTypeId(fn.key, "input"), fn.inputSchema);
|
|
407
|
+
targets.set(functionTypeId(fn.key, "output"), fn.outputSchema);
|
|
408
|
+
}
|
|
409
|
+
for (const prompt of tree.prompts) {
|
|
410
|
+
const agent = prompt.agent;
|
|
411
|
+
if (!agent) {
|
|
412
|
+
targets.set(promptTypeId(prompt.key, "output"), prompt.outputSchema);
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
targets.set(promptTypeId(prompt.key, "input"), agent.inputSchema);
|
|
416
|
+
for (const tool of agent.clientTools) {
|
|
417
|
+
targets.set(promptTypeId(prompt.key, `tools/${tool.name}/input`), tool.input.schema);
|
|
418
|
+
targets.set(promptTypeId(prompt.key, `tools/${tool.name}/output`), tool.output.schema);
|
|
419
|
+
}
|
|
420
|
+
for (const presentation of agent.presentations)
|
|
421
|
+
targets.set(promptTypeId(prompt.key, `tools/${presentation.name}/input`), presentation.schema);
|
|
422
|
+
for (const event of agent.events)
|
|
423
|
+
targets.set(promptTypeId(prompt.key, `events/${event.name}`), event.schema);
|
|
424
|
+
}
|
|
425
|
+
for (const projection of tree.projections)
|
|
426
|
+
targets.set(projection.id, projection.schema);
|
|
427
|
+
const targetOf = (ref) => (targets.has(ref) ? { schema: targets.get(ref) } : undefined);
|
|
428
|
+
targetsByTree.set(tree, targetOf);
|
|
429
|
+
return targetOf;
|
|
430
|
+
}
|
|
431
|
+
const targetsByTree = new WeakMap();
|
|
432
|
+
/** The emitted (unqualified) name of an id. */
|
|
433
|
+
export function treeName(tree, language, id) {
|
|
434
|
+
return (language === "ts" ? tree.space.ts : tree.space.swift).get(id);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* The names `config diff`'s declaration preview reads (#5544): the tree's
|
|
438
|
+
* compiled space, as `primitive.d.ts` names and references; null when the
|
|
439
|
+
* tree's declaration cannot be described (the push reports why).
|
|
440
|
+
*/
|
|
441
|
+
export function previewNamesOf(configDir) {
|
|
442
|
+
let tree;
|
|
443
|
+
try {
|
|
444
|
+
tree = describeTreeTypes(primitiveDeclarationInputs(configDir), "ts");
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
const reference = treeNameOf(tree, "ts");
|
|
450
|
+
return {
|
|
451
|
+
reference,
|
|
452
|
+
target: treeTargetOf(tree),
|
|
453
|
+
declaration: (id, namespace, name) => `${namespace}.${tree.space.ts.get(id) ?? name}`,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* #5896 — a slot's `resolved` entries, plus one for each field of a db3 projection they inline whose `ref` named a
|
|
458
|
+
* shared enum: at `<pointer>/properties/<field>`, with the def's id after the projection entry's chain and its
|
|
459
|
+
* compiled schema after its definitions. The compile never reports such a field, because the db3 type was expanded
|
|
460
|
+
* before it saw one; the entries let `namedReferences` render an exact field by the enum's name, and an inexact one
|
|
461
|
+
* (a `max_length` beside the ref) inline. Nothing here reaches a compile's output or what push sends.
|
|
462
|
+
*/
|
|
463
|
+
export function withDb3EnumFieldEntries(tree, resolved) {
|
|
464
|
+
const refs = tree.db3EnumRefs;
|
|
465
|
+
if (!refs || refs.size === 0)
|
|
466
|
+
return [...resolved];
|
|
467
|
+
const defs = new Map(tree.defs.map((def) => [def.id, def]));
|
|
468
|
+
const out = [...resolved];
|
|
469
|
+
for (const entry of resolved) {
|
|
470
|
+
const last = entry.chain[entry.chain.length - 1];
|
|
471
|
+
const match = last === undefined ? null : /^db3:([^#]+)#\/\$defs\/(.+)\/(row|declared)$/.exec(last);
|
|
472
|
+
if (!match)
|
|
473
|
+
continue;
|
|
474
|
+
const model = match[2].replace(/~1/g, "/").replace(/~0/g, "~");
|
|
475
|
+
const fields = refs.get(match[1])?.get(model);
|
|
476
|
+
const projection = entry.definitions?.[entry.chain.length - 1];
|
|
477
|
+
if (!fields || !projection?.properties)
|
|
478
|
+
continue;
|
|
479
|
+
for (const [field, ref] of fields) {
|
|
480
|
+
const def = defs.get(defTypeId(ref.file, ref.name));
|
|
481
|
+
if (!def || !Object.prototype.hasOwnProperty.call(projection.properties, field))
|
|
482
|
+
continue;
|
|
483
|
+
out.push({
|
|
484
|
+
pointer: `${entry.pointer}/properties/${pointerSegment(field)}`,
|
|
485
|
+
chain: [...entry.chain, def.id],
|
|
486
|
+
definitions: [...(entry.definitions ?? entry.chain.map(() => undefined)), def.schema],
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* #5896 — the references a db3 projection's own declaration renders: each field whose `ref` named a shared enum, by
|
|
494
|
+
* the enum's name where the field is exactly the enum. Empty for a projection with none.
|
|
495
|
+
*/
|
|
496
|
+
export function projectionFieldReferences(tree, language, projection) {
|
|
497
|
+
const root = { pointer: "", chain: [projection.id], definitions: [projection.schema] };
|
|
498
|
+
const fields = withDb3EnumFieldEntries(tree, [root])
|
|
499
|
+
.slice(1)
|
|
500
|
+
.map((entry) => ({ pointer: entry.pointer, chain: entry.chain.slice(1), definitions: entry.definitions?.slice(1) }));
|
|
501
|
+
return treeReferences(tree, language, projection.schema, fields);
|
|
502
|
+
}
|
|
503
|
+
/** The references a slot's compiled schema renders, by pointer under the slot. */
|
|
504
|
+
export function treeReferences(tree, language, schema, resolved, prefix = "") {
|
|
505
|
+
return namedReferences(schema, resolved, treeNameOf(tree, language), prefix, treeTargetOf(tree)).named;
|
|
506
|
+
}
|
|
507
|
+
const HEADER = `// GENERATED by \`primitive config push\` from this tree's functions/, prompts/,
|
|
508
|
+
// schemas/, db3-types/, database-type-configs/ and user-properties.toml.
|
|
509
|
+
// DO NOT EDIT — your changes are overwritten on the next push.
|
|
510
|
+
//
|
|
511
|
+
// Import a namespace and name its types through it:
|
|
512
|
+
//
|
|
513
|
+
// import type { Functions, Schemas } from "./primitive";
|
|
514
|
+
// const price: Schemas.Money = input.price;
|
|
515
|
+
//
|
|
516
|
+
// \`Schemas\` holds every def of schemas/*.toml, \`Functions\` each function's
|
|
517
|
+
// \`<Key>Input\` and \`<Key>Output\`, \`Prompts\` each prompt's types, \`Db3\` the
|
|
518
|
+
// models \`ctx.db3\` types (each with a \`<Model>Filter\` and a \`<Model>Sort\`)
|
|
519
|
+
// and the projections a schema references, and \`UserProperties\` the user
|
|
520
|
+
// property types. A shape a ref reaches is declared once and referenced by
|
|
521
|
+
// name. The augmentation at the end types \`defineFunction\`,
|
|
522
|
+
// \`ctx.prompts.run\`, \`ctx.db3\` and \`ctx.users\`.
|
|
523
|
+
//
|
|
524
|
+
// A db3 type's timestamps are required on a read row, epoch milliseconds unless
|
|
525
|
+
// the model declares the field: the room stamps every write. A model outside the
|
|
526
|
+
// type's \`timestamps.models\` carries none.
|
|
527
|
+
// A row written before the db3 was typed may lack them.`;
|
|
528
|
+
/**
|
|
529
|
+
* `export namespace <name> { … }`, each declaration printed one level deep as
|
|
530
|
+
* Prettier prints it there, a blank line apart; `{}` with none.
|
|
531
|
+
*/
|
|
532
|
+
function namespaceBlock(name, decls) {
|
|
533
|
+
if (decls.length === 0)
|
|
534
|
+
return `export namespace ${name} {}`;
|
|
535
|
+
return [`export namespace ${name} {`, decls.map((render) => printedAtLevel(1, render)).join("\n\n"), "}"].join("\n");
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* A glue interface: its entries always expanded, which Prettier keeps; `{}`
|
|
539
|
+
* with none.
|
|
540
|
+
*/
|
|
541
|
+
function glue(name, entries) {
|
|
542
|
+
if (entries.length === 0)
|
|
543
|
+
return `export interface ${name} {}`;
|
|
544
|
+
return [`export interface ${name} {`, ...entries, "}"].join("\n");
|
|
545
|
+
}
|
|
546
|
+
/** `export interface <name> extends <base> {}`, the `extends` clause on its own line when the whole does not fit. */
|
|
547
|
+
function extendsGlue(name, base) {
|
|
548
|
+
const line = `export interface ${name} extends ${base} {}`;
|
|
549
|
+
return line.length <= 80 ? line : `export interface ${name}\n extends ${base} {}`;
|
|
550
|
+
}
|
|
551
|
+
/** An object type always expanded at `level`: one `key: value;` line per entry, `{}` with none. */
|
|
552
|
+
function expanded(level, entries) {
|
|
553
|
+
if (entries.length === 0)
|
|
554
|
+
return "{}";
|
|
555
|
+
const pad = " ".repeat(level + 1);
|
|
556
|
+
return ["{", ...entries.map(([key, value]) => `${pad}${tsPropertyKey(key)}: ${value};`), `${" ".repeat(level)}}`].join("\n");
|
|
557
|
+
}
|
|
558
|
+
/** A db3 model member, as Prettier prints it one level inside its interface. */
|
|
559
|
+
function db3MemberLines(member) {
|
|
560
|
+
const type = member.enum ? union(member.enum.map((value) => atom(tsStringLiteral(value)))) : atom(member.type);
|
|
561
|
+
return [...(member.comment ? [` /** ${member.comment} */`] : []), renderMember(1, tsPropertyKey(member.name), member.optional, type)];
|
|
562
|
+
}
|
|
563
|
+
/** The SDK helpers a model's filter and sort instantiate, as import types (#5546). */
|
|
564
|
+
const DB3_FILTER_HELPER = `import("primitive-functions").Db3Filter`;
|
|
565
|
+
const DB3_SORT_HELPER = `import("primitive-functions").Db3Sort`;
|
|
566
|
+
/**
|
|
567
|
+
* A model's filter's kinds map, member by member in the interface's order:
|
|
568
|
+
* `id` first when the model declares none, each member with a kind, nothing
|
|
569
|
+
* for a model with no members. `shared` is every model emitted under this
|
|
570
|
+
* name (one party, so the same members by name); a member whose kind they do
|
|
571
|
+
* not all agree on (`date` in one type, `string` in another) is left out, and
|
|
572
|
+
* so open, rather than typed by one of them.
|
|
573
|
+
*/
|
|
574
|
+
function db3KindEntries(members, shared) {
|
|
575
|
+
if (members.length === 0)
|
|
576
|
+
return [];
|
|
577
|
+
const agreed = (member) => shared.every((other) => other.find((candidate) => candidate.name === member.name)?.kind === member.kind);
|
|
578
|
+
const entries = [];
|
|
579
|
+
if (!members.some((member) => member.name === "id"))
|
|
580
|
+
entries.push(["id", "id"]);
|
|
581
|
+
for (const member of members)
|
|
582
|
+
if (member.kind && agreed(member))
|
|
583
|
+
entries.push([member.name, member.kind]);
|
|
584
|
+
return entries.map(([name, kind]) => [tsPropertyKey(name), tsStringLiteral(kind)]);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* `export type <name> = <helper><<arg>>;` as Prettier prints it one level
|
|
588
|
+
* inside a namespace: on one line when it fits; else a lone object argument
|
|
589
|
+
* hugs its brackets on the `=` line when that line reaches its `{`; else the
|
|
590
|
+
* right-hand side moves below the `=`, on one line when it fits there, its
|
|
591
|
+
* object broken open otherwise. `members` is the object argument's entries,
|
|
592
|
+
* or null for a plain type argument (which never breaks).
|
|
593
|
+
*/
|
|
594
|
+
function renderHelperAlias(name, helper, members, arg = "") {
|
|
595
|
+
const width = PRINT_WIDTH - 2;
|
|
596
|
+
const head = `export type ${name} =`;
|
|
597
|
+
const inlineArg = members === null ? arg : members.length === 0 ? "{}" : `{ ${members.map(([k, v]) => `${k}: ${v}`).join("; ")} }`;
|
|
598
|
+
const rhs = `${helper}<${inlineArg}>;`;
|
|
599
|
+
if (`${head} ${rhs}`.length <= width)
|
|
600
|
+
return `${head} ${rhs}`;
|
|
601
|
+
const broken = (level) => [`${helper}<{`, ...members.map(([k, v]) => `${" ".repeat(level + 1)}${k}: ${v};`), `${" ".repeat(level)}}>;`].join("\n");
|
|
602
|
+
const hugs = members !== null && members.length > 0;
|
|
603
|
+
if (hugs && `${head} ${helper}<{`.length <= width)
|
|
604
|
+
return `${head} ${broken(0)}`;
|
|
605
|
+
if (!hugs || ` ${rhs}`.length <= width)
|
|
606
|
+
return `${head}\n ${rhs}`;
|
|
607
|
+
return `${head}\n ${broken(1)}`;
|
|
608
|
+
}
|
|
609
|
+
/** A union of upsert names, `never` for none (#5895). */
|
|
610
|
+
function uniqueNode(uniqueNames) {
|
|
611
|
+
return uniqueNames.length === 0 ? atom("never") : union(uniqueNames.map((value) => atom(tsStringLiteral(value))));
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* A model's `<Model>Unique` (#5895): the names its upserts take, `never` for
|
|
615
|
+
* a model with none. A model several types emit under one name (their rows
|
|
616
|
+
* alike, their unique constraints not necessarily) takes the names every one
|
|
617
|
+
* of them declares; a type whose own names differ has them written into its
|
|
618
|
+
* `Db3Queries` entry instead (`db3UniqueQueryType`).
|
|
619
|
+
*/
|
|
620
|
+
function renderUniqueAlias(name, uniqueNames) {
|
|
621
|
+
if (uniqueNames.length === 0)
|
|
622
|
+
return `export type ${name} = never;`;
|
|
623
|
+
return renderTypeAlias(name, uniqueNode(uniqueNames));
|
|
624
|
+
}
|
|
625
|
+
/** The names every one of `sharers` declares, in the first one's order. */
|
|
626
|
+
function sharedUniqueNames(sharers) {
|
|
627
|
+
const [first, ...rest] = sharers;
|
|
628
|
+
return (first?.uniqueNames ?? []).filter((value) => rest.every((other) => other.uniqueNames.includes(value)));
|
|
629
|
+
}
|
|
630
|
+
/** True when `a` and `b` hold the same names, in any order. */
|
|
631
|
+
function sameNames(a, b) {
|
|
632
|
+
const set = new Set(a);
|
|
633
|
+
return set.size === new Set(b).size && b.every((value) => set.has(value));
|
|
634
|
+
}
|
|
635
|
+
/** A db3 model's `<Model>Filter`, `<Model>Sort` (#5546) and `<Model>Unique` (#5895), after its interface. */
|
|
636
|
+
function db3HelperDecls(emitted, members, shared, uniqueNames) {
|
|
637
|
+
return [
|
|
638
|
+
() => renderHelperAlias(`${emitted}Filter`, DB3_FILTER_HELPER, db3KindEntries(members, shared)),
|
|
639
|
+
() => renderHelperAlias(`${emitted}Sort`, DB3_SORT_HELPER, null, emitted),
|
|
640
|
+
() => renderUniqueAlias(`${emitted}Unique`, uniqueNames),
|
|
641
|
+
];
|
|
642
|
+
}
|
|
643
|
+
/** Render a declaration, naming the source and the slot when it cannot be. */
|
|
644
|
+
function renderNamed(where, render) {
|
|
645
|
+
try {
|
|
646
|
+
return render();
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
if (error instanceof FunctionSchemaCodegenError)
|
|
650
|
+
throw error;
|
|
651
|
+
throw new FunctionSchemaCodegenError(`${where} cannot be rendered as a TypeScript type (${error?.message ?? error})`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
/** The whole `functions/primitive.d.ts`; see the module note. A fixed point of Prettier's default config. */
|
|
655
|
+
export function renderPrimitiveDeclaration(inputs) {
|
|
656
|
+
const tree = describeTreeTypes(inputs, "ts");
|
|
657
|
+
const name = (id) => treeName(tree, "ts", id);
|
|
658
|
+
const refs = (schema, resolved, prefix = "") => ({
|
|
659
|
+
named: treeReferences(tree, "ts", schema, resolved, prefix),
|
|
660
|
+
});
|
|
661
|
+
const schemas = tree.defs.map((def) => () => renderNamed(`schemas/${def.file}.toml: def \`${def.name}\``, () => renderTypeDecl(name(def.id), def.schema, refs(def.schema, def.resolved))));
|
|
662
|
+
const functions = tree.functions.flatMap((fn) => [
|
|
663
|
+
() => renderDeclaredType(fn, "inputSchema", name(functionTypeId(fn.key, "input")), refs(fn.inputSchema, fn.resolved.inputSchema)),
|
|
664
|
+
() => renderDeclaredType(fn, "outputSchema", name(functionTypeId(fn.key, "output")), refs(fn.outputSchema, fn.resolved.outputSchema)),
|
|
665
|
+
]);
|
|
666
|
+
const prompts = [];
|
|
667
|
+
for (const prompt of tree.prompts) {
|
|
668
|
+
const agent = prompt.agent;
|
|
669
|
+
if (!agent) {
|
|
670
|
+
if (prompt.outputSchema === undefined)
|
|
671
|
+
continue;
|
|
672
|
+
prompts.push(() => renderAgentType(prompt, name(promptTypeId(prompt.key, "output")), prompt.outputSchema, "outputSchema", refs(prompt.outputSchema, prompt.resolved.outputSchema)));
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
const slot = (target, schema, path, pointer) => () => renderAgentType(prompt, name(promptTypeId(prompt.key, target)), schema, path, refs(schema, prompt.resolved.agent, pointer));
|
|
676
|
+
prompts.push(() => renderAgentType(prompt, name(promptTypeId(prompt.key, "input")), agent.inputSchema, "inputSchema", refs(agent.inputSchema, prompt.resolved.inputSchema)));
|
|
677
|
+
for (const tool of agent.clientTools) {
|
|
678
|
+
prompts.push(slot(`tools/${tool.name}/input`, tool.input.schema, `tools.${tool.name}.inputSchema`, tool.input.pointer));
|
|
679
|
+
prompts.push(slot(`tools/${tool.name}/output`, tool.output.schema, `tools.${tool.name}.outputSchema`, tool.output.pointer));
|
|
680
|
+
}
|
|
681
|
+
for (const presentation of agent.presentations) {
|
|
682
|
+
prompts.push(slot(`tools/${presentation.name}/input`, presentation.schema, `tools.${presentation.name}.inputSchema`, presentation.pointer));
|
|
683
|
+
}
|
|
684
|
+
for (const event of agent.events) {
|
|
685
|
+
prompts.push(slot(`events/${event.name}`, event.schema, `events.${event.name}.schema`, event.pointer));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
// Db3: one interface per model party (two types declaring a model
|
|
689
|
+
// identically share one), then each referenced projection.
|
|
690
|
+
const db3 = [];
|
|
691
|
+
const declaredDb3 = new Set();
|
|
692
|
+
const sharedUnique = new Map();
|
|
693
|
+
for (const { models } of tree.db3Types) {
|
|
694
|
+
for (const model of models) {
|
|
695
|
+
const emitted = name(model.id);
|
|
696
|
+
if (declaredDb3.has(emitted))
|
|
697
|
+
continue;
|
|
698
|
+
declaredDb3.add(emitted);
|
|
699
|
+
db3.push(() => model.members.length === 0
|
|
700
|
+
? `export type ${emitted} = Record<string, unknown>;`
|
|
701
|
+
: [`export interface ${emitted} {`, ...model.members.flatMap(db3MemberLines), "}"].join("\n"));
|
|
702
|
+
const sharers = tree.db3Types.flatMap(({ models: others }) => others.filter((other) => name(other.id) === emitted));
|
|
703
|
+
const shared = sharers.map((other) => other.members);
|
|
704
|
+
const uniqueNames = sharedUniqueNames(sharers);
|
|
705
|
+
sharedUnique.set(emitted, uniqueNames);
|
|
706
|
+
db3.push(...db3HelperDecls(emitted, model.members, shared, uniqueNames));
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
for (const projection of tree.projections) {
|
|
710
|
+
const emitted = name(projection.id);
|
|
711
|
+
if (declaredDb3.has(emitted))
|
|
712
|
+
continue;
|
|
713
|
+
declaredDb3.add(emitted);
|
|
714
|
+
db3.push(() => renderNamed(`db3 type ${projection.type}: the ${projection.projection} projection of \`${projection.model}\``, () => renderTypeDecl(emitted, projection.schema)));
|
|
715
|
+
}
|
|
716
|
+
const userPropertyNames = {
|
|
717
|
+
userProperties: name(USER_PROPERTIES_IDS.userProperties),
|
|
718
|
+
clientUserProperties: name(USER_PROPERTIES_IDS.clientUserProperties),
|
|
719
|
+
uniqueUserProperties: name(USER_PROPERTIES_IDS.uniqueUserProperties),
|
|
720
|
+
};
|
|
721
|
+
const functionEntries = tree.functions.map((fn) => ` ${tsPropertyKey(fn.key)}: ${expanded(1, [
|
|
722
|
+
["input", `Functions.${name(functionTypeId(fn.key, "input"))}`],
|
|
723
|
+
["output", `Functions.${name(functionTypeId(fn.key, "output"))}`],
|
|
724
|
+
])};`);
|
|
725
|
+
const promptEntries = tree.prompts.map((prompt) => {
|
|
726
|
+
const key = tsPropertyKey(prompt.key);
|
|
727
|
+
const ref = (target) => `Prompts.${name(promptTypeId(prompt.key, target))}`;
|
|
728
|
+
const agent = prompt.agent;
|
|
729
|
+
if (!agent) {
|
|
730
|
+
if (prompt.outputSchema === undefined)
|
|
731
|
+
return ` ${key}: {};`;
|
|
732
|
+
const inline = ` ${key}: { output: ${ref("output")} };`;
|
|
733
|
+
return inline.length <= 80 ? inline : ` ${key}: ${expanded(1, [["output", ref("output")]])};`;
|
|
734
|
+
}
|
|
735
|
+
const tools = expanded(3, agent.clientTools.map((tool) => [
|
|
736
|
+
tool.name,
|
|
737
|
+
expanded(4, [
|
|
738
|
+
["input", ref(`tools/${tool.name}/input`)],
|
|
739
|
+
["output", ref(`tools/${tool.name}/output`)],
|
|
740
|
+
]),
|
|
741
|
+
]));
|
|
742
|
+
const events = expanded(3, agent.events.map((event) => [event.name, ref(`events/${event.name}`)]));
|
|
743
|
+
const presentations = expanded(3, agent.presentations.map((p) => [p.name, ref(`tools/${p.name}/input`)]));
|
|
744
|
+
const body = expanded(2, [
|
|
745
|
+
["variables", ref("input")],
|
|
746
|
+
["clientTools", tools],
|
|
747
|
+
["events", events],
|
|
748
|
+
["presentations", presentations],
|
|
749
|
+
]);
|
|
750
|
+
return ` ${key}: ${expanded(1, [["agent", body]])};`;
|
|
751
|
+
});
|
|
752
|
+
const db3Entries = tree.db3Types.map(({ type, models }) => ` ${tsPropertyKey(type)}: ${expanded(1, models.map((model) => [model.modelName, `Db3.${name(model.id)}`]))};`);
|
|
753
|
+
// A model's `unique` is its own type's names: the shared `<Model>Unique`
|
|
754
|
+
// when they are the same, else written out, so a type never takes another
|
|
755
|
+
// type's names because their rows are alike.
|
|
756
|
+
const db3QueryEntry = (model) => {
|
|
757
|
+
const emitted = name(model.id);
|
|
758
|
+
const unique = sameNames(sharedUnique.get(emitted) ?? [], model.uniqueNames)
|
|
759
|
+
? `${indent(3)}unique: Db3.${emitted}Unique;`
|
|
760
|
+
: renderMember(3, "unique", false, uniqueNode(model.uniqueNames));
|
|
761
|
+
return ["{", `${indent(3)}filter: Db3.${emitted}Filter;`, `${indent(3)}sort: Db3.${emitted}Sort;`, unique, `${indent(2)}}`].join("\n");
|
|
762
|
+
};
|
|
763
|
+
const db3QueryEntries = tree.db3Types.map(({ type, models }) => ` ${tsPropertyKey(type)}: ${expanded(1, models.map((model) => [model.modelName, db3QueryEntry(model)]))};`);
|
|
764
|
+
const blocks = [
|
|
765
|
+
HEADER,
|
|
766
|
+
namespaceBlock("Schemas", schemas),
|
|
767
|
+
namespaceBlock("Functions", functions),
|
|
768
|
+
namespaceBlock("Prompts", prompts),
|
|
769
|
+
namespaceBlock("Db3", db3),
|
|
770
|
+
namespaceBlock("UserProperties", [0, 1, 2].map((index) => () => renderUserPropertiesDeclarations(tree.userProperties, userPropertyNames)[index])),
|
|
771
|
+
glue("PrimitiveFunctionSchemas", functionEntries),
|
|
772
|
+
glue("PrimitivePromptSchemas", promptEntries),
|
|
773
|
+
glue("PrimitiveDb3Schemas", db3Entries),
|
|
774
|
+
glue("PrimitiveDb3Queries", db3QueryEntries),
|
|
775
|
+
extendsGlue("PrimitiveUserProperties", `UserProperties.${userPropertyNames.userProperties}`),
|
|
776
|
+
extendsGlue("PrimitiveClientUserProperties", `UserProperties.${userPropertyNames.clientUserProperties}`),
|
|
777
|
+
extendsGlue("PrimitiveUserUniqueProperties", `UserProperties.${userPropertyNames.uniqueUserProperties}`),
|
|
778
|
+
[
|
|
779
|
+
`declare module "primitive-functions" {`,
|
|
780
|
+
` interface FunctionSchemas extends PrimitiveFunctionSchemas {}`,
|
|
781
|
+
` interface PromptSchemas extends PrimitivePromptSchemas {}`,
|
|
782
|
+
` interface Db3Schemas extends PrimitiveDb3Schemas {}`,
|
|
783
|
+
` interface Db3Queries extends PrimitiveDb3Queries {}`,
|
|
784
|
+
` interface UserProperties extends PrimitiveUserProperties {}`,
|
|
785
|
+
` interface ClientUserProperties extends PrimitiveClientUserProperties {}`,
|
|
786
|
+
` interface UserUniqueProperties extends PrimitiveUserUniqueProperties {}`,
|
|
787
|
+
`}`,
|
|
788
|
+
].join("\n"),
|
|
789
|
+
];
|
|
790
|
+
return blocks.join("\n\n") + "\n";
|
|
791
|
+
}
|
|
792
|
+
//# sourceMappingURL=primitive-declaration.js.map
|