@happyvertical/smrt-core 0.30.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/AGENTS.md +124 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +265 -0
- package/bin/smrt-prebuild.js +26 -0
- package/dist/__tests__/fixtures/advisor-test-classes.d.ts +28 -0
- package/dist/__tests__/fixtures/advisor-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts +12 -0
- package/dist/__tests__/fixtures/collection-coverage-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts +28 -0
- package/dist/__tests__/fixtures/inheritance-resolver-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/inheritance-test-classes.d.ts +43 -0
- package/dist/__tests__/fixtures/inheritance-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/mcp-integration-test-classes.d.ts +18 -0
- package/dist/__tests__/fixtures/mcp-integration-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts +15 -0
- package/dist/__tests__/fixtures/object-ai-memory-fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures/object-spec-test-classes.d.ts +13 -0
- package/dist/__tests__/fixtures/object-spec-test-classes.d.ts.map +1 -0
- package/dist/__tests__/fixtures/registry-test-classes.d.ts +23 -0
- package/dist/__tests__/fixtures/registry-test-classes.d.ts.map +1 -0
- package/dist/adapters/ai-usage.d.ts +23 -0
- package/dist/adapters/ai-usage.d.ts.map +1 -0
- package/dist/adapters/ai-usage.js +105 -0
- package/dist/adapters/ai-usage.js.map +1 -0
- package/dist/adapters/cost-rates.d.ts +20 -0
- package/dist/adapters/cost-rates.d.ts.map +1 -0
- package/dist/adapters/cost-rates.js +40 -0
- package/dist/adapters/cost-rates.js.map +1 -0
- package/dist/adapters/index.d.ts +19 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/metrics.d.ts +111 -0
- package/dist/adapters/metrics.d.ts.map +1 -0
- package/dist/adapters/metrics.js +169 -0
- package/dist/adapters/metrics.js.map +1 -0
- package/dist/adapters/pubsub.d.ts +124 -0
- package/dist/adapters/pubsub.d.ts.map +1 -0
- package/dist/adapters/pubsub.js +121 -0
- package/dist/adapters/pubsub.js.map +1 -0
- package/dist/browser.d.ts +32 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +68 -0
- package/dist/browser.js.map +1 -0
- package/dist/child-accessors.d.ts +27 -0
- package/dist/child-accessors.d.ts.map +1 -0
- package/dist/child-accessors.js +35 -0
- package/dist/child-accessors.js.map +1 -0
- package/dist/class.d.ts +313 -0
- package/dist/class.d.ts.map +1 -0
- package/dist/class.js +896 -0
- package/dist/class.js.map +1 -0
- package/dist/collection-cache.d.ts +110 -0
- package/dist/collection-cache.d.ts.map +1 -0
- package/dist/collection-cache.js +187 -0
- package/dist/collection-cache.js.map +1 -0
- package/dist/collection.d.ts +894 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +1987 -0
- package/dist/collection.js.map +1 -0
- package/dist/config/global-config.d.ts +3 -0
- package/dist/config/global-config.d.ts.map +1 -0
- package/dist/config/global-config.js +19 -0
- package/dist/config/global-config.js.map +1 -0
- package/dist/config.d.ts +145 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +57 -0
- package/dist/config.js.map +1 -0
- package/dist/consumer-plugin/index.d.ts +22 -0
- package/dist/consumer-plugin/index.d.ts.map +1 -0
- package/dist/consumer-plugin/index.js +452 -0
- package/dist/consumer-plugin/index.js.map +1 -0
- package/dist/consumer-plugin.d.ts +8 -0
- package/dist/consumer-plugin.d.ts.map +1 -0
- package/dist/consumer-plugin.js +5 -0
- package/dist/consumer-plugin.js.map +1 -0
- package/dist/database.d.ts +95 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +32 -0
- package/dist/database.js.map +1 -0
- package/dist/decorators/compatibility.d.ts +14 -0
- package/dist/decorators/compatibility.d.ts.map +1 -0
- package/dist/decorators/compatibility.js +111 -0
- package/dist/decorators/compatibility.js.map +1 -0
- package/dist/decorators/index.d.ts +381 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +104 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/dispatch/bus.d.ts +306 -0
- package/dist/dispatch/bus.d.ts.map +1 -0
- package/dist/dispatch/bus.js +583 -0
- package/dist/dispatch/bus.js.map +1 -0
- package/dist/dispatch/collections/DispatchSubscriptions.d.ts +79 -0
- package/dist/dispatch/collections/DispatchSubscriptions.d.ts.map +1 -0
- package/dist/dispatch/collections/DispatchSubscriptions.js +243 -0
- package/dist/dispatch/collections/DispatchSubscriptions.js.map +1 -0
- package/dist/dispatch/collections/Dispatches.d.ts +98 -0
- package/dist/dispatch/collections/Dispatches.d.ts.map +1 -0
- package/dist/dispatch/collections/Dispatches.js +358 -0
- package/dist/dispatch/collections/Dispatches.js.map +1 -0
- package/dist/dispatch/index.d.ts +47 -0
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/dispatch/models/Dispatch.d.ts +101 -0
- package/dist/dispatch/models/Dispatch.d.ts.map +1 -0
- package/dist/dispatch/models/Dispatch.js +162 -0
- package/dist/dispatch/models/Dispatch.js.map +1 -0
- package/dist/dispatch/models/DispatchSubscription.d.ts +83 -0
- package/dist/dispatch/models/DispatchSubscription.d.ts.map +1 -0
- package/dist/dispatch/models/DispatchSubscription.js +112 -0
- package/dist/dispatch/models/DispatchSubscription.js.map +1 -0
- package/dist/dispatch/tenant-resolver.d.ts +98 -0
- package/dist/dispatch/tenant-resolver.d.ts.map +1 -0
- package/dist/dispatch/tenant-resolver.js +32 -0
- package/dist/dispatch/tenant-resolver.js.map +1 -0
- package/dist/dispatch/types.d.ts +149 -0
- package/dist/dispatch/types.d.ts.map +1 -0
- package/dist/embeddings/hash.d.ts +33 -0
- package/dist/embeddings/hash.d.ts.map +1 -0
- package/dist/embeddings/hash.js +37 -0
- package/dist/embeddings/hash.js.map +1 -0
- package/dist/embeddings/index.d.ts +36 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/provider.d.ts +75 -0
- package/dist/embeddings/provider.d.ts.map +1 -0
- package/dist/embeddings/provider.js +170 -0
- package/dist/embeddings/provider.js.map +1 -0
- package/dist/embeddings/similarity.d.ts +47 -0
- package/dist/embeddings/similarity.d.ts.map +1 -0
- package/dist/embeddings/similarity.js +64 -0
- package/dist/embeddings/similarity.js.map +1 -0
- package/dist/embeddings/storage.d.ts +125 -0
- package/dist/embeddings/storage.d.ts.map +1 -0
- package/dist/embeddings/storage.js +283 -0
- package/dist/embeddings/storage.js.map +1 -0
- package/dist/embeddings/types.d.ts +250 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/errors.d.ts +363 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +669 -0
- package/dist/errors.js.map +1 -0
- package/dist/generators/cli.d.ts +162 -0
- package/dist/generators/cli.d.ts.map +1 -0
- package/dist/generators/cli.js +462 -0
- package/dist/generators/cli.js.map +1 -0
- package/dist/generators/index.d.ts +13 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/mcp-runtime-template.d.ts +60 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -0
- package/dist/generators/mcp-runtime-template.js +509 -0
- package/dist/generators/mcp-runtime-template.js.map +1 -0
- package/dist/generators/mcp.d.ts +231 -0
- package/dist/generators/mcp.d.ts.map +1 -0
- package/dist/generators/mcp.js +1220 -0
- package/dist/generators/mcp.js.map +1 -0
- package/dist/generators/rest.d.ts +171 -0
- package/dist/generators/rest.d.ts.map +1 -0
- package/dist/generators/rest.js +591 -0
- package/dist/generators/rest.js.map +1 -0
- package/dist/generators/swagger.d.ts +21 -0
- package/dist/generators/swagger.d.ts.map +1 -0
- package/dist/generators/swagger.js +307 -0
- package/dist/generators/swagger.js.map +1 -0
- package/dist/generators/tenant-gate.d.ts +74 -0
- package/dist/generators/tenant-gate.d.ts.map +1 -0
- package/dist/generators/tenant-gate.js +15 -0
- package/dist/generators/tenant-gate.js.map +1 -0
- package/dist/generators.d.ts +8 -0
- package/dist/generators.d.ts.map +1 -0
- package/dist/generators.js +19 -0
- package/dist/generators.js.map +1 -0
- package/dist/hierarchical.d.ts +103 -0
- package/dist/hierarchical.d.ts.map +1 -0
- package/dist/hierarchical.js +184 -0
- package/dist/hierarchical.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +202 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors.d.ts +251 -0
- package/dist/interceptors.d.ts.map +1 -0
- package/dist/interceptors.js +259 -0
- package/dist/interceptors.js.map +1 -0
- package/dist/junction.d.ts +99 -0
- package/dist/junction.d.ts.map +1 -0
- package/dist/junction.js +136 -0
- package/dist/junction.js.map +1 -0
- package/dist/knowledge.d.ts +11 -0
- package/dist/knowledge.d.ts.map +1 -0
- package/dist/knowledge.js +310 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/lazy-config.d.ts +160 -0
- package/dist/lazy-config.d.ts.map +1 -0
- package/dist/lazy-config.js +146 -0
- package/dist/lazy-config.js.map +1 -0
- package/dist/manifest/discover-base-classes.d.ts +78 -0
- package/dist/manifest/discover-base-classes.d.ts.map +1 -0
- package/dist/manifest/discover-base-classes.js +85 -0
- package/dist/manifest/discover-base-classes.js.map +1 -0
- package/dist/manifest/discover-smrt-packages.d.ts +48 -0
- package/dist/manifest/discover-smrt-packages.d.ts.map +1 -0
- package/dist/manifest/discover-smrt-packages.js +361 -0
- package/dist/manifest/discover-smrt-packages.js.map +1 -0
- package/dist/manifest/generator.d.ts +93 -0
- package/dist/manifest/generator.d.ts.map +1 -0
- package/dist/manifest/generator.js +380 -0
- package/dist/manifest/generator.js.map +1 -0
- package/dist/manifest/index.d.ts +16 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +51 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manager.d.ts +51 -0
- package/dist/manifest/manager.d.ts.map +1 -0
- package/dist/manifest/manager.js +89 -0
- package/dist/manifest/manager.js.map +1 -0
- package/dist/manifest/manifest-loader.d.ts +187 -0
- package/dist/manifest/manifest-loader.d.ts.map +1 -0
- package/dist/manifest/manifest-loader.js +847 -0
- package/dist/manifest/manifest-loader.js.map +1 -0
- package/dist/manifest/sources/composite.d.ts +22 -0
- package/dist/manifest/sources/composite.d.ts.map +1 -0
- package/dist/manifest/sources/composite.js +60 -0
- package/dist/manifest/sources/composite.js.map +1 -0
- package/dist/manifest/sources/embedded.d.ts +7 -0
- package/dist/manifest/sources/embedded.d.ts.map +1 -0
- package/dist/manifest/sources/embedded.js +30 -0
- package/dist/manifest/sources/embedded.js.map +1 -0
- package/dist/manifest/sources/explicit-paths.d.ts +17 -0
- package/dist/manifest/sources/explicit-paths.d.ts.map +1 -0
- package/dist/manifest/sources/explicit-paths.js +35 -0
- package/dist/manifest/sources/explicit-paths.js.map +1 -0
- package/dist/manifest/sources/fallback.d.ts +25 -0
- package/dist/manifest/sources/fallback.d.ts.map +1 -0
- package/dist/manifest/sources/fallback.js +63 -0
- package/dist/manifest/sources/fallback.js.map +1 -0
- package/dist/manifest/sources/index.d.ts +17 -0
- package/dist/manifest/sources/index.d.ts.map +1 -0
- package/dist/manifest/sources/local-test.d.ts +7 -0
- package/dist/manifest/sources/local-test.d.ts.map +1 -0
- package/dist/manifest/sources/local-test.js +21 -0
- package/dist/manifest/sources/local-test.js.map +1 -0
- package/dist/manifest/sources/static.d.ts +7 -0
- package/dist/manifest/sources/static.d.ts.map +1 -0
- package/dist/manifest/sources/static.js +19 -0
- package/dist/manifest/sources/static.js.map +1 -0
- package/dist/manifest/sources/test.d.ts +7 -0
- package/dist/manifest/sources/test.d.ts.map +1 -0
- package/dist/manifest/sources/test.js +21 -0
- package/dist/manifest/sources/test.js.map +1 -0
- package/dist/manifest/sources/types.d.ts +79 -0
- package/dist/manifest/sources/types.d.ts.map +1 -0
- package/dist/manifest/sources/types.js +61 -0
- package/dist/manifest/sources/types.js.map +1 -0
- package/dist/manifest/static-manifest.d.ts +4 -0
- package/dist/manifest/static-manifest.d.ts.map +1 -0
- package/dist/manifest/static-manifest.js +1535 -0
- package/dist/manifest/static-manifest.js.map +1 -0
- package/dist/manifest/store.d.ts +111 -0
- package/dist/manifest/store.d.ts.map +1 -0
- package/dist/manifest/store.js +431 -0
- package/dist/manifest/store.js.map +1 -0
- package/dist/manifest/test-manifest-loader.d.ts +3 -0
- package/dist/manifest/test-manifest-loader.d.ts.map +1 -0
- package/dist/manifest/test-manifest-stub.d.ts +4 -0
- package/dist/manifest/test-manifest-stub.d.ts.map +1 -0
- package/dist/manifest/test-manifest-stub.js +80013 -0
- package/dist/manifest/test-manifest-stub.js.map +1 -0
- package/dist/manifest.d.ts +8 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +20 -0
- package/dist/manifest.js.map +1 -0
- package/dist/manifest.json +1489 -0
- package/dist/mcp-advisor/index.d.ts +499 -0
- package/dist/mcp-advisor/index.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/add-ai-methods.d.ts +6 -0
- package/dist/mcp-advisor/tools/add-ai-methods.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/configure-decorators.d.ts +6 -0
- package/dist/mcp-advisor/tools/configure-decorators.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-collection.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-collection.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-field-definitions.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-field-definitions.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/generate-smrt-class.d.ts +6 -0
- package/dist/mcp-advisor/tools/generate-smrt-class.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/get-object-config.d.ts +6 -0
- package/dist/mcp-advisor/tools/get-object-config.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/get-object-schema.d.ts +10 -0
- package/dist/mcp-advisor/tools/get-object-schema.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/list-registered-objects.d.ts +9 -0
- package/dist/mcp-advisor/tools/list-registered-objects.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/preview-api-endpoints.d.ts +9 -0
- package/dist/mcp-advisor/tools/preview-api-endpoints.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/preview-mcp-tools.d.ts +9 -0
- package/dist/mcp-advisor/tools/preview-mcp-tools.d.ts.map +1 -0
- package/dist/mcp-advisor/tools/validate-smrt-object.d.ts +6 -0
- package/dist/mcp-advisor/tools/validate-smrt-object.d.ts.map +1 -0
- package/dist/mcp-advisor/types.d.ts +209 -0
- package/dist/mcp-advisor/types.d.ts.map +1 -0
- package/dist/migrations/backfill-tracker.d.ts +84 -0
- package/dist/migrations/backfill-tracker.d.ts.map +1 -0
- package/dist/migrations/backfill-tracker.js +118 -0
- package/dist/migrations/backfill-tracker.js.map +1 -0
- package/dist/migrations/checksum.d.ts +43 -0
- package/dist/migrations/checksum.d.ts.map +1 -0
- package/dist/migrations/checksum.js +32 -0
- package/dist/migrations/checksum.js.map +1 -0
- package/dist/migrations/differ.d.ts +186 -0
- package/dist/migrations/differ.d.ts.map +1 -0
- package/dist/migrations/differ.js +601 -0
- package/dist/migrations/differ.js.map +1 -0
- package/dist/migrations/generator.d.ts +133 -0
- package/dist/migrations/generator.d.ts.map +1 -0
- package/dist/migrations/generator.js +328 -0
- package/dist/migrations/generator.js.map +1 -0
- package/dist/migrations/index.d.ts +20 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/orchestrate.d.ts +148 -0
- package/dist/migrations/orchestrate.d.ts.map +1 -0
- package/dist/migrations/orchestrate.js +118 -0
- package/dist/migrations/orchestrate.js.map +1 -0
- package/dist/migrations/tracker.d.ts +134 -0
- package/dist/migrations/tracker.d.ts.map +1 -0
- package/dist/migrations/tracker.js +624 -0
- package/dist/migrations/tracker.js.map +1 -0
- package/dist/migrations/types.d.ts +221 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations.d.ts +7 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +26 -0
- package/dist/migrations.js.map +1 -0
- package/dist/node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js +56 -0
- package/dist/node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js +163 -0
- package/dist/node_modules/.pnpm/brace-expansion@5.0.5/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js +13 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/ast.js +654 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/ast.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/brace-expressions.js +111 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/escape.js +10 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/escape.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/index.js +824 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/unescape.js +10 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/unescape.js.map +1 -0
- package/dist/object.d.ts +1202 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +2731 -0
- package/dist/object.js.map +1 -0
- package/dist/polymorphic-association.d.ts +69 -0
- package/dist/polymorphic-association.d.ts.map +1 -0
- package/dist/polymorphic-association.js +96 -0
- package/dist/polymorphic-association.js.map +1 -0
- package/dist/prebuild/cli.d.ts +7 -0
- package/dist/prebuild/cli.d.ts.map +1 -0
- package/dist/prebuild/cli.js +29 -0
- package/dist/prebuild/cli.js.map +1 -0
- package/dist/prebuild/index.d.ts +22 -0
- package/dist/prebuild/index.d.ts.map +1 -0
- package/dist/prebuild/index.js +239 -0
- package/dist/prebuild/index.js.map +1 -0
- package/dist/prebuild.d.ts +8 -0
- package/dist/prebuild.d.ts.map +1 -0
- package/dist/prebuild.js +6 -0
- package/dist/prebuild.js.map +1 -0
- package/dist/registry/cache-config.d.ts +13 -0
- package/dist/registry/cache-config.d.ts.map +1 -0
- package/dist/registry/cache-config.js +17 -0
- package/dist/registry/cache-config.js.map +1 -0
- package/dist/registry/class-registration.d.ts +31 -0
- package/dist/registry/class-registration.d.ts.map +1 -0
- package/dist/registry/class-registration.js +1074 -0
- package/dist/registry/class-registration.js.map +1 -0
- package/dist/registry/collection-resolution.d.ts +45 -0
- package/dist/registry/collection-resolution.d.ts.map +1 -0
- package/dist/registry/collection-resolution.js +121 -0
- package/dist/registry/collection-resolution.js.map +1 -0
- package/dist/registry/collision-policy.d.ts +179 -0
- package/dist/registry/collision-policy.d.ts.map +1 -0
- package/dist/registry/collision-policy.js +153 -0
- package/dist/registry/collision-policy.js.map +1 -0
- package/dist/registry/diagnostics.d.ts +58 -0
- package/dist/registry/diagnostics.d.ts.map +1 -0
- package/dist/registry/diagnostics.js +54 -0
- package/dist/registry/diagnostics.js.map +1 -0
- package/dist/registry/embedding-manager.d.ts +23 -0
- package/dist/registry/embedding-manager.d.ts.map +1 -0
- package/dist/registry/embedding-manager.js +62 -0
- package/dist/registry/embedding-manager.js.map +1 -0
- package/dist/registry/index.d.ts +13 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/inheritance-resolver.d.ts +13 -0
- package/dist/registry/inheritance-resolver.d.ts.map +1 -0
- package/dist/registry/inheritance-resolver.js +244 -0
- package/dist/registry/inheritance-resolver.js.map +1 -0
- package/dist/registry/manifest-field-merge.d.ts +4 -0
- package/dist/registry/manifest-field-merge.d.ts.map +1 -0
- package/dist/registry/manifest-field-merge.js +82 -0
- package/dist/registry/manifest-field-merge.js.map +1 -0
- package/dist/registry/name-resolver.d.ts +102 -0
- package/dist/registry/name-resolver.d.ts.map +1 -0
- package/dist/registry/name-resolver.js +241 -0
- package/dist/registry/name-resolver.js.map +1 -0
- package/dist/registry/relationship-graph.d.ts +16 -0
- package/dist/registry/relationship-graph.d.ts.map +1 -0
- package/dist/registry/relationship-graph.js +79 -0
- package/dist/registry/relationship-graph.js.map +1 -0
- package/dist/registry/schema-builder.d.ts +113 -0
- package/dist/registry/schema-builder.d.ts.map +1 -0
- package/dist/registry/schema-builder.js +474 -0
- package/dist/registry/schema-builder.js.map +1 -0
- package/dist/registry/shared-state.d.ts +62 -0
- package/dist/registry/shared-state.d.ts.map +1 -0
- package/dist/registry/shared-state.js +135 -0
- package/dist/registry/shared-state.js.map +1 -0
- package/dist/registry/types.d.ts +667 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/validator.d.ts +13 -0
- package/dist/registry/validator.d.ts.map +1 -0
- package/dist/registry/validator.js +138 -0
- package/dist/registry/validator.js.map +1 -0
- package/dist/registry.d.ts +1358 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +2301 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtime/client.d.ts +34 -0
- package/dist/runtime/client.d.ts.map +1 -0
- package/dist/runtime/client.js +104 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/mcp.d.ts +47 -0
- package/dist/runtime/mcp.d.ts.map +1 -0
- package/dist/runtime/mcp.js +72 -0
- package/dist/runtime/mcp.js.map +1 -0
- package/dist/runtime/server.d.ts +92 -0
- package/dist/runtime/server.d.ts.map +1 -0
- package/dist/runtime/server.js +390 -0
- package/dist/runtime/server.js.map +1 -0
- package/dist/runtime/types.d.ts +58 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +10 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scanner/import-scanner.d.ts +7 -0
- package/dist/scanner/import-scanner.d.ts.map +1 -0
- package/dist/scanner/index.d.ts +12 -0
- package/dist/scanner/index.d.ts.map +1 -0
- package/dist/scanner/manifest-generator.d.ts +304 -0
- package/dist/scanner/manifest-generator.d.ts.map +1 -0
- package/dist/scanner/manifest-generator.js +1707 -0
- package/dist/scanner/manifest-generator.js.map +1 -0
- package/dist/scanner/test-file-patterns.d.ts +18 -0
- package/dist/scanner/test-file-patterns.d.ts.map +1 -0
- package/dist/scanner/test-file-patterns.js +16 -0
- package/dist/scanner/test-file-patterns.js.map +1 -0
- package/dist/scanner/types.d.ts +313 -0
- package/dist/scanner/types.d.ts.map +1 -0
- package/dist/scanner/types.js +2 -0
- package/dist/scanner/types.js.map +1 -0
- package/dist/scanner.d.ts +6 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +6 -0
- package/dist/scanner.js.map +1 -0
- package/dist/schema/code-generator.d.ts +53 -0
- package/dist/schema/code-generator.d.ts.map +1 -0
- package/dist/schema/ddl/base-strategy.d.ts +80 -0
- package/dist/schema/ddl/base-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/base-strategy.js +240 -0
- package/dist/schema/ddl/base-strategy.js.map +1 -0
- package/dist/schema/ddl/duckdb-strategy.d.ts +33 -0
- package/dist/schema/ddl/duckdb-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/duckdb-strategy.js +74 -0
- package/dist/schema/ddl/duckdb-strategy.js.map +1 -0
- package/dist/schema/ddl/index.d.ts +53 -0
- package/dist/schema/ddl/index.d.ts.map +1 -0
- package/dist/schema/ddl/index.js +80 -0
- package/dist/schema/ddl/index.js.map +1 -0
- package/dist/schema/ddl/json-duckdb-strategy.d.ts +8 -0
- package/dist/schema/ddl/json-duckdb-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/json-duckdb-strategy.js +14 -0
- package/dist/schema/ddl/json-duckdb-strategy.js.map +1 -0
- package/dist/schema/ddl/postgres-strategy.d.ts +29 -0
- package/dist/schema/ddl/postgres-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/postgres-strategy.js +102 -0
- package/dist/schema/ddl/postgres-strategy.js.map +1 -0
- package/dist/schema/ddl/sqlite-strategy.d.ts +38 -0
- package/dist/schema/ddl/sqlite-strategy.d.ts.map +1 -0
- package/dist/schema/ddl/sqlite-strategy.js +74 -0
- package/dist/schema/ddl/sqlite-strategy.js.map +1 -0
- package/dist/schema/ddl/types.d.ts +114 -0
- package/dist/schema/ddl/types.d.ts.map +1 -0
- package/dist/schema/generator.d.ts +176 -0
- package/dist/schema/generator.d.ts.map +1 -0
- package/dist/schema/generator.js +1076 -0
- package/dist/schema/generator.js.map +1 -0
- package/dist/schema/index-utils.d.ts +19 -0
- package/dist/schema/index-utils.d.ts.map +1 -0
- package/dist/schema/index-utils.js +32 -0
- package/dist/schema/index-utils.js.map +1 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/override-system.d.ts +43 -0
- package/dist/schema/override-system.d.ts.map +1 -0
- package/dist/schema/schema-aggregator.d.ts +112 -0
- package/dist/schema/schema-aggregator.d.ts.map +1 -0
- package/dist/schema/schema-manager.d.ts +95 -0
- package/dist/schema/schema-manager.d.ts.map +1 -0
- package/dist/schema/schema-manager.js +283 -0
- package/dist/schema/schema-manager.js.map +1 -0
- package/dist/schema/sql-identifiers.d.ts +107 -0
- package/dist/schema/sql-identifiers.d.ts.map +1 -0
- package/dist/schema/sql-identifiers.js +190 -0
- package/dist/schema/sql-identifiers.js.map +1 -0
- package/dist/schema/table-verifier.d.ts +10 -0
- package/dist/schema/table-verifier.d.ts.map +1 -0
- package/dist/schema/table-verifier.js +37 -0
- package/dist/schema/table-verifier.js.map +1 -0
- package/dist/schema/types.d.ts +241 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/utils.d.ts +32 -0
- package/dist/schema/utils.d.ts.map +1 -0
- package/dist/schema/utils.js +134 -0
- package/dist/schema/utils.js.map +1 -0
- package/dist/scripts/create-wrappers.js +89 -0
- package/dist/scripts/generate-manifest.js +155 -0
- package/dist/scripts/generate-test-manifest.js +77 -0
- package/dist/scripts/migrate-datetime-to-timestamp.ts +310 -0
- package/dist/scripts/prepack.js +49 -0
- package/dist/signals/bus.d.ts +64 -0
- package/dist/signals/bus.d.ts.map +1 -0
- package/dist/signals/bus.js +102 -0
- package/dist/signals/bus.js.map +1 -0
- package/dist/signals/index.d.ts +11 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/sanitizer.d.ts +54 -0
- package/dist/signals/sanitizer.d.ts.map +1 -0
- package/dist/signals/sanitizer.js +111 -0
- package/dist/signals/sanitizer.js.map +1 -0
- package/dist/smrt-knowledge.json +335 -0
- package/dist/system/compatibility.d.ts +8 -0
- package/dist/system/compatibility.d.ts.map +1 -0
- package/dist/system/compatibility.js +409 -0
- package/dist/system/compatibility.js.map +1 -0
- package/dist/system/index.d.ts +9 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/schema.d.ts +69 -0
- package/dist/system/schema.d.ts.map +1 -0
- package/dist/system/schema.js +271 -0
- package/dist/system/schema.js.map +1 -0
- package/dist/system/types.d.ts +135 -0
- package/dist/system/types.d.ts.map +1 -0
- package/dist/system-fields.d.ts +44 -0
- package/dist/system-fields.d.ts.map +1 -0
- package/dist/system-fields.js +55 -0
- package/dist/system-fields.js.map +1 -0
- package/dist/table-cache.d.ts +28 -0
- package/dist/table-cache.d.ts.map +1 -0
- package/dist/table-cache.js +21 -0
- package/dist/table-cache.js.map +1 -0
- package/dist/test-utils.d.ts +140 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/testing/database.d.ts +73 -0
- package/dist/testing/database.d.ts.map +1 -0
- package/dist/testing/database.js +204 -0
- package/dist/testing/database.js.map +1 -0
- package/dist/testing/index.d.ts +21 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +5 -0
- package/dist/testing.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/tool-executor.d.ts +101 -0
- package/dist/tools/tool-executor.d.ts.map +1 -0
- package/dist/tools/tool-executor.js +142 -0
- package/dist/tools/tool-executor.js.map +1 -0
- package/dist/tools/tool-generator.d.ts +54 -0
- package/dist/tools/tool-generator.d.ts.map +1 -0
- package/dist/tools/tool-generator.js +121 -0
- package/dist/tools/tool-generator.js.map +1 -0
- package/dist/utils/chunk.d.ts +32 -0
- package/dist/utils/chunk.d.ts.map +1 -0
- package/dist/utils/chunk.js +14 -0
- package/dist/utils/chunk.js.map +1 -0
- package/dist/utils/import-workspace-module.d.ts +8 -0
- package/dist/utils/import-workspace-module.d.ts.map +1 -0
- package/dist/utils/import-workspace-module.js +81 -0
- package/dist/utils/import-workspace-module.js.map +1 -0
- package/dist/utils/json.d.ts +102 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +43 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lru-cache.d.ts +69 -0
- package/dist/utils/lru-cache.d.ts.map +1 -0
- package/dist/utils/lru-cache.js +100 -0
- package/dist/utils/lru-cache.js.map +1 -0
- package/dist/utils/naming.d.ts +16 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/dist/utils/naming.js +23 -0
- package/dist/utils/naming.js.map +1 -0
- package/dist/utils/qualified-names.d.ts +122 -0
- package/dist/utils/qualified-names.d.ts.map +1 -0
- package/dist/utils/qualified-names.js +82 -0
- package/dist/utils/qualified-names.js.map +1 -0
- package/dist/utils/scanner-module.d.ts +37 -0
- package/dist/utils/scanner-module.d.ts.map +1 -0
- package/dist/utils.d.ts +177 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +185 -0
- package/dist/utils.js.map +1 -0
- package/dist/vite-plugin/import-build-aware.d.ts +68 -0
- package/dist/vite-plugin/import-build-aware.d.ts.map +1 -0
- package/dist/vite-plugin/import-build-aware.js +72 -0
- package/dist/vite-plugin/import-build-aware.js.map +1 -0
- package/dist/vite-plugin/index.d.ts +59 -0
- package/dist/vite-plugin/index.d.ts.map +1 -0
- package/dist/vite-plugin/index.js +1400 -0
- package/dist/vite-plugin/index.js.map +1 -0
- package/dist/vite-plugin/sveltekit-generator.d.ts +66 -0
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -0
- package/dist/vite-plugin/sveltekit-generator.js +1375 -0
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -0
- package/dist/vite-plugin/templates/default-ui.ts +432 -0
- package/dist/vite-plugin/templates/default.html +206 -0
- package/dist/vite-plugin.d.ts +8 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +11 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +208 -0
|
@@ -0,0 +1,1400 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { buildDomainKnowledgeManifest } from "../knowledge.js";
|
|
5
|
+
import { discoverSmrtPackages } from "../manifest/discover-smrt-packages.js";
|
|
6
|
+
import { importWorkspaceModule } from "../utils/import-workspace-module.js";
|
|
7
|
+
import { importBuildAwareModule } from "./import-build-aware.js";
|
|
8
|
+
import { generateSvelteKitRoutes, validateCliIncludeAgainstApi, resolveApiActionSet, findCliApiCoherenceViolations, methodNameToKebab } from "./sveltekit-generator.js";
|
|
9
|
+
const VIRTUAL_MODULES = {
|
|
10
|
+
"@happyvertical/smrt-virt-routes": "smrt:routes",
|
|
11
|
+
"@happyvertical/smrt-virt-client": "smrt:client",
|
|
12
|
+
"@happyvertical/smrt-virt-mcp": "smrt:mcp",
|
|
13
|
+
"@happyvertical/smrt-virt-types": "smrt:types",
|
|
14
|
+
"@happyvertical/smrt-virt-manifest": "smrt:manifest",
|
|
15
|
+
"@happyvertical/smrt-virt-schema": "smrt:schema",
|
|
16
|
+
"@happyvertical/smrt-virt-ui": "smrt:ui",
|
|
17
|
+
"@happyvertical/smrt-virt-cli": "smrt:cli"
|
|
18
|
+
};
|
|
19
|
+
async function importScanner() {
|
|
20
|
+
return importWorkspaceModule({
|
|
21
|
+
packageName: "@happyvertical/smrt-scanner",
|
|
22
|
+
distEntry: "packages/scanner/dist/index.js",
|
|
23
|
+
sourceEntry: "packages/scanner/src/index.ts",
|
|
24
|
+
purpose: "Vite manifest scanning"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function smrtPlugin(options = {}) {
|
|
28
|
+
const {
|
|
29
|
+
include = ["src/**/*.ts", "src/**/*.js"],
|
|
30
|
+
exclude = ["**/*.test.ts", "**/*.spec.ts", "**/node_modules/**"],
|
|
31
|
+
hmr = true,
|
|
32
|
+
watch = true,
|
|
33
|
+
generateTypes = true,
|
|
34
|
+
baseClasses = ["SmrtObject", "SmartObject"],
|
|
35
|
+
followImports = true,
|
|
36
|
+
// Default true: needed for multi-package inheritance
|
|
37
|
+
typeDeclarationsPath = "src/types",
|
|
38
|
+
mode = "auto",
|
|
39
|
+
svelteKit = {
|
|
40
|
+
enabled: false,
|
|
41
|
+
routesDir: "src/routes/api",
|
|
42
|
+
objectsDir: "src/lib/objects",
|
|
43
|
+
configPath: "src/lib/server",
|
|
44
|
+
configFileName: "smrt.ts"
|
|
45
|
+
},
|
|
46
|
+
knowledge,
|
|
47
|
+
validateCliApiCoherence = true
|
|
48
|
+
} = options;
|
|
49
|
+
function warnCliApiCoherenceViolations(m) {
|
|
50
|
+
if (!validateCliApiCoherence) return;
|
|
51
|
+
const violations = findCliApiCoherenceViolations(m);
|
|
52
|
+
if (violations.length === 0) return;
|
|
53
|
+
for (const { className, unreachable } of violations) {
|
|
54
|
+
for (const action of unreachable) {
|
|
55
|
+
console.warn(
|
|
56
|
+
`[smrt] ${className}.${action} is declared in cli.include but is not exposed via the api. Build will fail until this is resolved.
|
|
57
|
+
Either:
|
|
58
|
+
- Add '${action}' to api.include, or
|
|
59
|
+
- Remove '${action}' from cli.include.
|
|
60
|
+
The CLI invokes methods over HTTP; methods without API routes are unreachable.
|
|
61
|
+
If this CLI is intentionally invoked in-process (no HTTP), set
|
|
62
|
+
\`cli: { skipApiCheck: true }\` on the @smrt() decorator to acknowledge.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let server;
|
|
68
|
+
let manifest = null;
|
|
69
|
+
let pluginMode = "server";
|
|
70
|
+
let projectRoot = process.cwd();
|
|
71
|
+
let config = null;
|
|
72
|
+
let resolvedPluginNames = [];
|
|
73
|
+
async function writeLocalManifest(m, rootDir) {
|
|
74
|
+
try {
|
|
75
|
+
const { writeFileSync, mkdirSync } = await import("node:fs");
|
|
76
|
+
const { resolve } = await import("node:path");
|
|
77
|
+
const smrtDir = resolve(rootDir, ".smrt");
|
|
78
|
+
mkdirSync(smrtDir, { recursive: true });
|
|
79
|
+
const manifestPath = resolve(smrtDir, "manifest.json");
|
|
80
|
+
writeFileSync(manifestPath, JSON.stringify(m, null, 2), "utf-8");
|
|
81
|
+
await writeDomainKnowledgeArtifact(
|
|
82
|
+
m,
|
|
83
|
+
rootDir,
|
|
84
|
+
resolve(smrtDir, "smrt-knowledge.json"),
|
|
85
|
+
manifestPath
|
|
86
|
+
);
|
|
87
|
+
const objectCount = Object.keys(m.objects).length;
|
|
88
|
+
console.log(
|
|
89
|
+
`[smrt] Wrote local manifest with ${objectCount} objects to .smrt/manifest.json`
|
|
90
|
+
);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("[smrt] Error writing local manifest:", error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function writeDomainKnowledgeArtifact(m, rootDir, outputPath, manifestPath) {
|
|
96
|
+
const resolvedKnowledge = await resolveKnowledgeConfig(rootDir, m);
|
|
97
|
+
if (resolvedKnowledge.enabled === false) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const { mkdirSync, writeFileSync } = await import("node:fs");
|
|
101
|
+
const { dirname: dirname2 } = await import("node:path");
|
|
102
|
+
mkdirSync(dirname2(outputPath), { recursive: true });
|
|
103
|
+
const artifact = buildDomainKnowledgeManifest({
|
|
104
|
+
manifest: m,
|
|
105
|
+
rootDir,
|
|
106
|
+
manifestPath,
|
|
107
|
+
config: resolvedKnowledge
|
|
108
|
+
});
|
|
109
|
+
writeFileSync(
|
|
110
|
+
outputPath,
|
|
111
|
+
JSON.stringify(
|
|
112
|
+
preserveKnowledgeGeneratedAt(outputPath, artifact),
|
|
113
|
+
null,
|
|
114
|
+
2
|
|
115
|
+
),
|
|
116
|
+
"utf-8"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
async function resolveKnowledgeConfig(rootDir, m) {
|
|
120
|
+
if (knowledge === false) return { enabled: false };
|
|
121
|
+
const packageName = m.packageName ?? readPackageName(rootDir);
|
|
122
|
+
const defaults = {
|
|
123
|
+
enabled: true,
|
|
124
|
+
api: {
|
|
125
|
+
enabled: false,
|
|
126
|
+
basePath: "/__smrt/knowledge",
|
|
127
|
+
requireAdmin: true,
|
|
128
|
+
includeDocs: false,
|
|
129
|
+
includePrompts: false
|
|
130
|
+
},
|
|
131
|
+
includeDocs: true,
|
|
132
|
+
includePrompts: true
|
|
133
|
+
};
|
|
134
|
+
let fileKnowledge = {};
|
|
135
|
+
let packageKnowledge = {};
|
|
136
|
+
try {
|
|
137
|
+
const previousCwd = process.cwd();
|
|
138
|
+
process.chdir(rootDir);
|
|
139
|
+
try {
|
|
140
|
+
const { loadConfig } = await import("@happyvertical/smrt-config");
|
|
141
|
+
const config2 = await loadConfig({ cache: false });
|
|
142
|
+
fileKnowledge = config2.knowledge ?? {};
|
|
143
|
+
packageKnowledge = packageName ? config2.packages?.[packageName]?.knowledge ?? {} : {};
|
|
144
|
+
} finally {
|
|
145
|
+
process.chdir(previousCwd);
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
fileKnowledge = {};
|
|
149
|
+
packageKnowledge = {};
|
|
150
|
+
}
|
|
151
|
+
return mergeKnowledgeConfig(
|
|
152
|
+
defaults,
|
|
153
|
+
fileKnowledge,
|
|
154
|
+
packageKnowledge,
|
|
155
|
+
knowledge || {}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
function mergeKnowledgeConfig(...configs) {
|
|
159
|
+
const merged = {};
|
|
160
|
+
for (const next of configs) {
|
|
161
|
+
if (!next) continue;
|
|
162
|
+
const hasApi = Boolean(merged.api || next.api);
|
|
163
|
+
const api = hasApi ? { ...merged.api ?? {}, ...next.api ?? {} } : void 0;
|
|
164
|
+
Object.assign(merged, next);
|
|
165
|
+
if (api) merged.api = api;
|
|
166
|
+
}
|
|
167
|
+
return merged;
|
|
168
|
+
}
|
|
169
|
+
function preserveKnowledgeGeneratedAt(outputPath, nextKnowledge) {
|
|
170
|
+
if (!existsSync(outputPath)) return nextKnowledge;
|
|
171
|
+
try {
|
|
172
|
+
const current = JSON.parse(readFileSync(outputPath, "utf8"));
|
|
173
|
+
if (semanticKnowledgeJson(current) === semanticKnowledgeJson(nextKnowledge)) {
|
|
174
|
+
return {
|
|
175
|
+
...nextKnowledge,
|
|
176
|
+
generatedAt: current.generatedAt
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
return nextKnowledge;
|
|
182
|
+
}
|
|
183
|
+
function semanticKnowledgeJson(artifact) {
|
|
184
|
+
const { generatedAt: _generatedAt, ...rest } = artifact ?? {};
|
|
185
|
+
return JSON.stringify(sortJson(rest));
|
|
186
|
+
}
|
|
187
|
+
function sortJson(value) {
|
|
188
|
+
if (Array.isArray(value)) return value.map(sortJson);
|
|
189
|
+
if (value && typeof value === "object") {
|
|
190
|
+
return Object.fromEntries(
|
|
191
|
+
Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, sortJson(entry)])
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
function readPackageName(rootDir) {
|
|
197
|
+
try {
|
|
198
|
+
const pkg = JSON.parse(
|
|
199
|
+
readFileSync(join(rootDir, "package.json"), "utf8")
|
|
200
|
+
);
|
|
201
|
+
return typeof pkg.name === "string" ? pkg.name : void 0;
|
|
202
|
+
} catch {
|
|
203
|
+
return void 0;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function validateConsumerPluginSetup(m, context) {
|
|
207
|
+
if (config?.mode === "test") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (config?.build?.lib) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const consumerDependencies = (m.smrtDependencies || []).filter(
|
|
214
|
+
(dependency) => dependency !== "@happyvertical/smrt-core"
|
|
215
|
+
);
|
|
216
|
+
if (consumerDependencies.length === 0) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const hasConsumerPlugin = resolvedPluginNames.some(
|
|
220
|
+
(name) => name === "smrt-consumer"
|
|
221
|
+
);
|
|
222
|
+
if (hasConsumerPlugin) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const dependencySummary = consumerDependencies.length <= 4 ? consumerDependencies.join(", ") : `${consumerDependencies.slice(0, 4).join(", ")}, +${consumerDependencies.length - 4} more`;
|
|
226
|
+
throw new Error(
|
|
227
|
+
`[smrt] Consumer project misconfiguration detected during ${context}: found external SMRT dependencies (${dependencySummary}) but vite.config is missing smrtConsumer(). Add "import { smrtConsumer } from '@happyvertical/smrt-core/consumer-plugin'" and register it alongside smrtPlugin() so .smrt/register.js is generated for CLI/runtime class loading.`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function validateLibraryMinifySetup(m, context) {
|
|
231
|
+
if (!config?.build?.lib) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (Object.keys(m.objects || {}).length === 0) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (config.build.minify === false) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
throw new Error(
|
|
241
|
+
`[smrt] Library package misconfiguration detected during ${context}: packages that publish SMRT objects must set Vite build.minify = false. Minification rewrites runtime class names and breaks manifest registration, STI resolution, and collection queries in downstream apps.`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
name: "smrt-auto-service",
|
|
246
|
+
// Expose options for external access (e.g., test manifest generation)
|
|
247
|
+
api: {
|
|
248
|
+
options: {
|
|
249
|
+
baseClasses,
|
|
250
|
+
followImports,
|
|
251
|
+
include,
|
|
252
|
+
exclude
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
async configResolved(resolvedConfig) {
|
|
256
|
+
config = resolvedConfig;
|
|
257
|
+
resolvedPluginNames = (resolvedConfig.plugins || []).map(
|
|
258
|
+
(plugin) => plugin?.name || ""
|
|
259
|
+
);
|
|
260
|
+
projectRoot = resolvedConfig.root;
|
|
261
|
+
if (mode === "auto") {
|
|
262
|
+
const isSSRBuild = resolvedConfig.build?.ssr;
|
|
263
|
+
const isFederationBuild = resolvedConfig.plugins.some(
|
|
264
|
+
(p) => p.name?.includes("federation")
|
|
265
|
+
);
|
|
266
|
+
const isClientBuild = isFederationBuild || !isSSRBuild && resolvedConfig.build?.target === "esnext";
|
|
267
|
+
pluginMode = isClientBuild ? "client" : "server";
|
|
268
|
+
} else {
|
|
269
|
+
pluginMode = mode;
|
|
270
|
+
}
|
|
271
|
+
console.log(`[smrt] Running in ${pluginMode} mode`);
|
|
272
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
273
|
+
if (manifest) {
|
|
274
|
+
await writeLocalManifest(manifest, projectRoot);
|
|
275
|
+
validateLibraryMinifySetup(manifest, "configResolved");
|
|
276
|
+
validateConsumerPluginSetup(manifest, "configResolved");
|
|
277
|
+
if (validateCliApiCoherence) {
|
|
278
|
+
validateCliIncludeAgainstApi(manifest);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (svelteKit.enabled && manifest) {
|
|
282
|
+
await generateSvelteKitRoutes(resolvedConfig.root, manifest, {
|
|
283
|
+
enabled: svelteKit.enabled,
|
|
284
|
+
routesDir: svelteKit.routesDir || "src/routes/api",
|
|
285
|
+
objectsDir: svelteKit.objectsDir || "src/lib/objects",
|
|
286
|
+
configPath: svelteKit.configPath || "src/lib/server",
|
|
287
|
+
configFileName: svelteKit.configFileName || "smrt.ts",
|
|
288
|
+
kebabRoutes: svelteKit.kebabRoutes ?? false,
|
|
289
|
+
knowledge: await resolveKnowledgeConfig(
|
|
290
|
+
resolvedConfig.root,
|
|
291
|
+
manifest
|
|
292
|
+
)
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
async buildStart() {
|
|
297
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
298
|
+
if (manifest) {
|
|
299
|
+
await writeLocalManifest(manifest, projectRoot);
|
|
300
|
+
validateLibraryMinifySetup(manifest, "buildStart");
|
|
301
|
+
validateConsumerPluginSetup(manifest, "buildStart");
|
|
302
|
+
if (validateCliApiCoherence) {
|
|
303
|
+
validateCliIncludeAgainstApi(manifest);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
configureServer(devServer) {
|
|
308
|
+
server = devServer;
|
|
309
|
+
devServer.middlewares.use(async (req, res, next) => {
|
|
310
|
+
if (svelteKit.enabled) {
|
|
311
|
+
return next();
|
|
312
|
+
}
|
|
313
|
+
if (req.url === "/" || req.url === "/index.html") {
|
|
314
|
+
try {
|
|
315
|
+
const { existsSync: existsSync2 } = await import("node:fs");
|
|
316
|
+
const { join: join2 } = await import("node:path");
|
|
317
|
+
const projectRoot2 = devServer.config.root;
|
|
318
|
+
const indexPath = join2(projectRoot2, "index.html");
|
|
319
|
+
if (existsSync2(indexPath)) {
|
|
320
|
+
return next();
|
|
321
|
+
}
|
|
322
|
+
console.log("[smrt] Serving default UI (no index.html found)");
|
|
323
|
+
let html = getDefaultHTML();
|
|
324
|
+
html = await devServer.transformIndexHtml("/", html);
|
|
325
|
+
res.setHeader("Content-Type", "text/html");
|
|
326
|
+
res.end(html);
|
|
327
|
+
return;
|
|
328
|
+
} catch (error) {
|
|
329
|
+
console.error("[smrt] Error serving default HTML:", error);
|
|
330
|
+
return next();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
next();
|
|
334
|
+
});
|
|
335
|
+
if (watch && hmr) {
|
|
336
|
+
const watcher = devServer.watcher;
|
|
337
|
+
watcher.on("change", async (file) => {
|
|
338
|
+
try {
|
|
339
|
+
if (await shouldRescan(file)) {
|
|
340
|
+
console.log(`[smrt] Rescanning due to change in ${file}`);
|
|
341
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
342
|
+
if (manifest) {
|
|
343
|
+
await writeLocalManifest(manifest, projectRoot);
|
|
344
|
+
warnCliApiCoherenceViolations(manifest);
|
|
345
|
+
}
|
|
346
|
+
if (svelteKit.enabled && manifest && server) {
|
|
347
|
+
await generateSvelteKitRoutes(server.config.root, manifest, {
|
|
348
|
+
enabled: svelteKit.enabled,
|
|
349
|
+
routesDir: svelteKit.routesDir || "src/routes/api",
|
|
350
|
+
objectsDir: svelteKit.objectsDir || "src/lib/objects",
|
|
351
|
+
configPath: svelteKit.configPath || "src/lib/server",
|
|
352
|
+
configFileName: svelteKit.configFileName || "smrt.ts",
|
|
353
|
+
kebabRoutes: svelteKit.kebabRoutes ?? false,
|
|
354
|
+
knowledge: await resolveKnowledgeConfig(
|
|
355
|
+
server.config.root,
|
|
356
|
+
manifest
|
|
357
|
+
)
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
Object.values(VIRTUAL_MODULES).forEach((id) => {
|
|
361
|
+
const module = server?.moduleGraph.getModuleById(id);
|
|
362
|
+
if (module) {
|
|
363
|
+
server?.reloadModule(module);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.error(
|
|
369
|
+
`[smrt] Failed to rescan after change in ${file}:`,
|
|
370
|
+
error
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
watcher.on("add", async (file) => {
|
|
375
|
+
try {
|
|
376
|
+
if (await shouldRescan(file)) {
|
|
377
|
+
console.log(`[smrt] Rescanning due to new file ${file}`);
|
|
378
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
379
|
+
if (manifest) {
|
|
380
|
+
await writeLocalManifest(manifest, projectRoot);
|
|
381
|
+
warnCliApiCoherenceViolations(manifest);
|
|
382
|
+
}
|
|
383
|
+
if (svelteKit.enabled && manifest && server) {
|
|
384
|
+
await generateSvelteKitRoutes(server.config.root, manifest, {
|
|
385
|
+
enabled: svelteKit.enabled,
|
|
386
|
+
routesDir: svelteKit.routesDir || "src/routes/api",
|
|
387
|
+
objectsDir: svelteKit.objectsDir || "src/lib/objects",
|
|
388
|
+
configPath: svelteKit.configPath || "src/lib/server",
|
|
389
|
+
configFileName: svelteKit.configFileName || "smrt.ts",
|
|
390
|
+
kebabRoutes: svelteKit.kebabRoutes ?? false,
|
|
391
|
+
knowledge: await resolveKnowledgeConfig(
|
|
392
|
+
server.config.root,
|
|
393
|
+
manifest
|
|
394
|
+
)
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
} catch (error) {
|
|
399
|
+
console.error(
|
|
400
|
+
`[smrt] Failed to rescan after adding ${file}:`,
|
|
401
|
+
error
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
watcher.on("unlink", async (file) => {
|
|
406
|
+
try {
|
|
407
|
+
if (await shouldRescan(file)) {
|
|
408
|
+
console.log(`[smrt] Rescanning due to removed file ${file}`);
|
|
409
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
410
|
+
if (manifest) {
|
|
411
|
+
await writeLocalManifest(manifest, projectRoot);
|
|
412
|
+
warnCliApiCoherenceViolations(manifest);
|
|
413
|
+
}
|
|
414
|
+
if (svelteKit.enabled && manifest && server) {
|
|
415
|
+
await generateSvelteKitRoutes(server.config.root, manifest, {
|
|
416
|
+
enabled: svelteKit.enabled,
|
|
417
|
+
routesDir: svelteKit.routesDir || "src/routes/api",
|
|
418
|
+
objectsDir: svelteKit.objectsDir || "src/lib/objects",
|
|
419
|
+
configPath: svelteKit.configPath || "src/lib/server",
|
|
420
|
+
configFileName: svelteKit.configFileName || "smrt.ts",
|
|
421
|
+
kebabRoutes: svelteKit.kebabRoutes ?? false,
|
|
422
|
+
knowledge: await resolveKnowledgeConfig(
|
|
423
|
+
server.config.root,
|
|
424
|
+
manifest
|
|
425
|
+
)
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
} catch (error) {
|
|
430
|
+
console.error(
|
|
431
|
+
`[smrt] Failed to rescan after removing ${file}:`,
|
|
432
|
+
error
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
resolveId(id) {
|
|
439
|
+
if (id in VIRTUAL_MODULES) {
|
|
440
|
+
return `\0${VIRTUAL_MODULES[id]}`;
|
|
441
|
+
}
|
|
442
|
+
if (id === "/index.html" && server) {
|
|
443
|
+
return `\0smrt:index-html`;
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
},
|
|
447
|
+
async load(id) {
|
|
448
|
+
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
449
|
+
if (!manifest) {
|
|
450
|
+
manifest = await scanAndGenerateManifest(projectRoot);
|
|
451
|
+
}
|
|
452
|
+
switch (cleanId) {
|
|
453
|
+
case "smrt:routes":
|
|
454
|
+
return await generateRoutesModule(manifest);
|
|
455
|
+
case "smrt:client":
|
|
456
|
+
return generateClientModule(manifest, {
|
|
457
|
+
kebabRoutes: svelteKit.kebabRoutes ?? false
|
|
458
|
+
});
|
|
459
|
+
case "smrt:mcp":
|
|
460
|
+
return await generateMCPModule(manifest);
|
|
461
|
+
case "smrt:types":
|
|
462
|
+
return await generateTypesModule(manifest, pluginMode);
|
|
463
|
+
case "smrt:manifest":
|
|
464
|
+
return generateManifestModule(manifest);
|
|
465
|
+
case "smrt:schema":
|
|
466
|
+
return await generateSchemaModule(manifest);
|
|
467
|
+
case "smrt:ui":
|
|
468
|
+
return await loadDefaultUI();
|
|
469
|
+
case "smrt:index-html":
|
|
470
|
+
return await loadDefaultHTML();
|
|
471
|
+
case "smrt:cli":
|
|
472
|
+
return await generateCLIModule(manifest);
|
|
473
|
+
default:
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
transformIndexHtml: {
|
|
478
|
+
order: "pre",
|
|
479
|
+
handler: async (html, _ctx) => {
|
|
480
|
+
if (!server) return html;
|
|
481
|
+
try {
|
|
482
|
+
const { existsSync: existsSync2 } = await import("node:fs");
|
|
483
|
+
const { join: join2 } = await import("node:path");
|
|
484
|
+
const projectRoot2 = server.config.root;
|
|
485
|
+
const indexPath = join2(projectRoot2, "index.html");
|
|
486
|
+
if (existsSync2(indexPath)) {
|
|
487
|
+
return html;
|
|
488
|
+
}
|
|
489
|
+
return await loadDefaultHTML();
|
|
490
|
+
} catch (error) {
|
|
491
|
+
console.error("[smrt] Error checking for index.html:", error);
|
|
492
|
+
return html;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
async closeBundle() {
|
|
497
|
+
if (!manifest || !config.build?.lib) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
const { writeFileSync, mkdirSync } = await import("node:fs");
|
|
502
|
+
const { resolve, dirname: dirname2 } = await import("node:path");
|
|
503
|
+
const outDir = config.build?.rollupOptions?.output?.dir || config.build?.outDir || "dist";
|
|
504
|
+
const manifestPath = resolve(projectRoot, outDir, "manifest.json");
|
|
505
|
+
const knowledgePath = resolve(
|
|
506
|
+
projectRoot,
|
|
507
|
+
outDir,
|
|
508
|
+
"smrt-knowledge.json"
|
|
509
|
+
);
|
|
510
|
+
mkdirSync(dirname2(manifestPath), { recursive: true });
|
|
511
|
+
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), "utf-8");
|
|
512
|
+
await writeDomainKnowledgeArtifact(
|
|
513
|
+
manifest,
|
|
514
|
+
projectRoot,
|
|
515
|
+
knowledgePath,
|
|
516
|
+
manifestPath
|
|
517
|
+
);
|
|
518
|
+
const objectCount = Object.keys(manifest.objects).length;
|
|
519
|
+
console.log(
|
|
520
|
+
`[smrt] Wrote manifest with ${objectCount} objects to ${manifestPath}`
|
|
521
|
+
);
|
|
522
|
+
} catch (error) {
|
|
523
|
+
console.error("[smrt] Error writing manifest file:", error);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
async function scanAndGenerateManifest(rootDir) {
|
|
528
|
+
try {
|
|
529
|
+
return await scanWithOxc(rootDir);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (error instanceof Error && error.message.includes("Cannot find package")) {
|
|
532
|
+
console.error(
|
|
533
|
+
"[smrt] @happyvertical/smrt-scanner is required but not installed."
|
|
534
|
+
);
|
|
535
|
+
console.error(
|
|
536
|
+
"[smrt] Install it: pnpm add @happyvertical/smrt-scanner"
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
console.error("[smrt] Error scanning files:", error);
|
|
540
|
+
throw error;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
async function scanWithOxc(rootDir) {
|
|
544
|
+
const startTime = performance.now();
|
|
545
|
+
try {
|
|
546
|
+
const { OxcScanner, ManifestAdapter } = await importScanner();
|
|
547
|
+
console.log(`[smrt] Using experimental OXC scanner for faster builds`);
|
|
548
|
+
const safeExclude = [...exclude || [], "**/*.svelte"];
|
|
549
|
+
const scanner = new OxcScanner({
|
|
550
|
+
cwd: rootDir,
|
|
551
|
+
include,
|
|
552
|
+
exclude: safeExclude
|
|
553
|
+
});
|
|
554
|
+
const { results, resolved } = await scanner.scanAndResolve();
|
|
555
|
+
if (results.errors.length > 0) {
|
|
556
|
+
console.error(
|
|
557
|
+
`
|
|
558
|
+
[smrt] ❌ Build failed: ${results.errors.length} error(s) during scanning:
|
|
559
|
+
`
|
|
560
|
+
);
|
|
561
|
+
for (const error of results.errors) {
|
|
562
|
+
console.error(
|
|
563
|
+
` ${error.filePath}:${error.line || "?"}: ${error.message}
|
|
564
|
+
`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
throw new Error(
|
|
568
|
+
"[smrt] Build aborted due to scan errors. See above for details."
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
let packageName;
|
|
572
|
+
let packageVersion;
|
|
573
|
+
let packageJson;
|
|
574
|
+
try {
|
|
575
|
+
const { readFileSync: readFileSync2 } = await import("node:fs");
|
|
576
|
+
const { join: join2 } = await import("node:path");
|
|
577
|
+
const pkgPath = join2(rootDir, "package.json");
|
|
578
|
+
const pkgContent = readFileSync2(pkgPath, "utf-8");
|
|
579
|
+
packageJson = JSON.parse(pkgContent);
|
|
580
|
+
packageName = packageJson.name || void 0;
|
|
581
|
+
packageVersion = packageJson.version || void 0;
|
|
582
|
+
} catch {
|
|
583
|
+
console.warn(
|
|
584
|
+
"[smrt] Warning: package.json not found. Qualified names will not be generated."
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
const adapter = new ManifestAdapter();
|
|
588
|
+
const newManifest = adapter.toManifest(resolved, {
|
|
589
|
+
packageName,
|
|
590
|
+
packageVersion,
|
|
591
|
+
typeAliases: results.typeAliases
|
|
592
|
+
});
|
|
593
|
+
newManifest.moduleType = "smrt";
|
|
594
|
+
const smrtDependencies = discoverSmrtPackages({ baseDir: rootDir });
|
|
595
|
+
if (smrtDependencies.length > 0) {
|
|
596
|
+
newManifest.smrtDependencies = smrtDependencies;
|
|
597
|
+
console.log(
|
|
598
|
+
`[smrt] Found ${smrtDependencies.length} SMRT dependencies: ${smrtDependencies.join(", ")}`
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
const { ManifestGenerator } = await importBuildAwareModule({
|
|
602
|
+
source: "../scanner/index.ts",
|
|
603
|
+
dist: "../scanner.js"
|
|
604
|
+
});
|
|
605
|
+
const manifestGen = new ManifestGenerator();
|
|
606
|
+
manifestGen.injectTenantScopedFields(newManifest);
|
|
607
|
+
manifestGen.mergeInheritedFields(newManifest);
|
|
608
|
+
manifestGen.generateValidationRules(newManifest);
|
|
609
|
+
manifestGen.generateSchemas(newManifest);
|
|
610
|
+
manifestGen.assertTenantScopedSchemaContract(newManifest);
|
|
611
|
+
manifestGen.generateAgentManifests(newManifest, packageName, packageJson);
|
|
612
|
+
const elapsed = performance.now() - startTime;
|
|
613
|
+
const objectCount = Object.keys(newManifest.objects).length;
|
|
614
|
+
if (objectCount > 0) {
|
|
615
|
+
const names = Object.keys(newManifest.objects).join(", ");
|
|
616
|
+
console.log(`[smrt] Found ${objectCount} SMRT objects: ${names}`);
|
|
617
|
+
} else {
|
|
618
|
+
console.log("[smrt] No SMRT objects found");
|
|
619
|
+
}
|
|
620
|
+
console.log(`[smrt] OXC scan completed in ${elapsed.toFixed(2)}ms`);
|
|
621
|
+
if (generateTypes && server) {
|
|
622
|
+
await generateTypeDeclarationFile(
|
|
623
|
+
newManifest,
|
|
624
|
+
rootDir,
|
|
625
|
+
typeDeclarationsPath
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
return newManifest;
|
|
629
|
+
} catch (error) {
|
|
630
|
+
console.error("[smrt] Error in OXC scanner:", error);
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
async function shouldRescan(file) {
|
|
635
|
+
if (pluginMode === "client") {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
try {
|
|
639
|
+
const { minimatch } = await import("../node_modules/.pnpm/minimatch@10.2.3/node_modules/minimatch/dist/esm/index.js");
|
|
640
|
+
const isIncluded = include.some((pattern) => minimatch(file, pattern));
|
|
641
|
+
const isExcluded = exclude.some((pattern) => minimatch(file, pattern));
|
|
642
|
+
return isIncluded && !isExcluded;
|
|
643
|
+
} catch (error) {
|
|
644
|
+
console.warn("[smrt] Error checking file patterns:", error);
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
async function generateRoutesModule(manifest) {
|
|
650
|
+
try {
|
|
651
|
+
const { ManifestGenerator } = await importBuildAwareModule({
|
|
652
|
+
source: "../scanner/index.ts",
|
|
653
|
+
dist: "../scanner.js"
|
|
654
|
+
});
|
|
655
|
+
const generator = new ManifestGenerator();
|
|
656
|
+
const routes = generator.generateRestEndpoints(manifest);
|
|
657
|
+
return `
|
|
658
|
+
// Auto-generated REST routes from SMRT objects
|
|
659
|
+
// This file is generated automatically - do not edit
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Setup routes on an Express-like app
|
|
663
|
+
*
|
|
664
|
+
* NOTE: This virtual module function is for documentation only.
|
|
665
|
+
* For actual route registration, use:
|
|
666
|
+
* - import { startRestServer } from '@happyvertical/smrt-core'
|
|
667
|
+
* - Or APIGenerator from '@happyvertical/smrt-core/generators'
|
|
668
|
+
*
|
|
669
|
+
* @param app - Express-like app instance
|
|
670
|
+
* @param options - Route configuration options
|
|
671
|
+
* @param options.basePath - Base path for all routes (default: '/api/v1')
|
|
672
|
+
*/
|
|
673
|
+
export function setupRoutes(app, options = {}) {
|
|
674
|
+
const basePath = options.basePath || '/api/v1';
|
|
675
|
+
|
|
676
|
+
console.warn('[smrt] setupRoutes is a documentation function only.');
|
|
677
|
+
console.warn('[smrt] Use startRestServer() or APIGenerator for actual route registration.');
|
|
678
|
+
console.warn('[smrt] Available endpoints:');
|
|
679
|
+
${routes.split("\\n").map((line) => ` console.warn(\` \${basePath}${line.trim()}\`);`).join("\\n")}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
export { setupRoutes as default };
|
|
683
|
+
`;
|
|
684
|
+
} catch (error) {
|
|
685
|
+
console.warn("[smrt] Error generating routes module:", error);
|
|
686
|
+
return 'export function setupRoutes(app, options = {}) { console.warn("Routes generation failed"); }';
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function lowerFirst(value) {
|
|
690
|
+
return value ? value[0].toLowerCase() + value.slice(1) : value;
|
|
691
|
+
}
|
|
692
|
+
function uniqueApiClientEntries(objects) {
|
|
693
|
+
const usedKeys = /* @__PURE__ */ new Set();
|
|
694
|
+
return objects.map(([objectName, obj]) => {
|
|
695
|
+
let clientKey = obj.collection;
|
|
696
|
+
if (usedKeys.has(clientKey)) {
|
|
697
|
+
clientKey = lowerFirst(obj.className);
|
|
698
|
+
}
|
|
699
|
+
const baseClientKey = clientKey;
|
|
700
|
+
let suffix = 2;
|
|
701
|
+
while (usedKeys.has(clientKey)) {
|
|
702
|
+
clientKey = `${baseClientKey}${suffix}`;
|
|
703
|
+
suffix += 1;
|
|
704
|
+
}
|
|
705
|
+
usedKeys.add(clientKey);
|
|
706
|
+
return { objectName, obj, clientKey };
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
function generateClientModule(manifest, options = {}) {
|
|
710
|
+
const objects = uniqueApiClientEntries(Object.entries(manifest.objects));
|
|
711
|
+
const clientMethods = objects.map(({ obj, clientKey }) => {
|
|
712
|
+
const { collection, methods = {} } = obj;
|
|
713
|
+
const exposedActions = resolveApiActionSet(obj);
|
|
714
|
+
const apiConfig = obj.decoratorConfig?.api;
|
|
715
|
+
const apiRoutes = apiConfig && typeof apiConfig === "object" ? apiConfig.routes ?? {} : {};
|
|
716
|
+
const customMethods = Object.entries(methods).filter(
|
|
717
|
+
([name, method]) => method.isPublic && exposedActions.has(name)
|
|
718
|
+
);
|
|
719
|
+
const segmentFor = (methodName) => {
|
|
720
|
+
const overridePath = apiRoutes[methodName]?.path;
|
|
721
|
+
if (overridePath) {
|
|
722
|
+
const trimmed = overridePath.split("/").map((s) => s.trim()).filter(Boolean).join("/");
|
|
723
|
+
if (trimmed.length > 0) return trimmed;
|
|
724
|
+
}
|
|
725
|
+
return options.kebabRoutes ? methodNameToKebab(methodName) : methodName;
|
|
726
|
+
};
|
|
727
|
+
const customMethodImpls = customMethods.map(([methodName, _method]) => {
|
|
728
|
+
const urlSegment = segmentFor(methodName);
|
|
729
|
+
return ` ${methodName}: (id, options) => fetch(basePath + '/${collection}/' + id + '/${urlSegment}', {
|
|
730
|
+
method: 'POST',
|
|
731
|
+
headers: { 'Content-Type': 'application/json' },
|
|
732
|
+
body: JSON.stringify(options || {})
|
|
733
|
+
}).then(r => r.json())`;
|
|
734
|
+
}).join(",\n");
|
|
735
|
+
const customMethodsBlock = customMethods.length > 0 ? `,
|
|
736
|
+
${customMethodImpls}` : "";
|
|
737
|
+
return `
|
|
738
|
+
${clientKey}: {
|
|
739
|
+
list: (params) => fetch(basePath + '/${collection}', {
|
|
740
|
+
method: 'GET',
|
|
741
|
+
headers: { 'Content-Type': 'application/json' }
|
|
742
|
+
}).then(r => r.json()),
|
|
743
|
+
|
|
744
|
+
get: (id) => fetch(basePath + '/${collection}/' + id, {
|
|
745
|
+
method: 'GET',
|
|
746
|
+
headers: { 'Content-Type': 'application/json' }
|
|
747
|
+
}).then(r => r.json()),
|
|
748
|
+
|
|
749
|
+
create: (data) => fetch(basePath + '/${collection}', {
|
|
750
|
+
method: 'POST',
|
|
751
|
+
headers: { 'Content-Type': 'application/json' },
|
|
752
|
+
body: JSON.stringify(data)
|
|
753
|
+
}).then(r => r.json()),
|
|
754
|
+
|
|
755
|
+
update: (id, data) => fetch(basePath + '/${collection}/' + id, {
|
|
756
|
+
method: 'PUT',
|
|
757
|
+
headers: { 'Content-Type': 'application/json' },
|
|
758
|
+
body: JSON.stringify(data)
|
|
759
|
+
}).then(r => r.json()),
|
|
760
|
+
|
|
761
|
+
delete: (id) => fetch(basePath + '/${collection}/' + id, {
|
|
762
|
+
method: 'DELETE',
|
|
763
|
+
headers: { 'Content-Type': 'application/json' }
|
|
764
|
+
}).then(r => r.ok),
|
|
765
|
+
|
|
766
|
+
search: (query) => fetch(basePath + '/${collection}/search?q=' + encodeURIComponent(query), {
|
|
767
|
+
method: 'GET',
|
|
768
|
+
headers: { 'Content-Type': 'application/json' }
|
|
769
|
+
}).then(r => r.json())${customMethodsBlock}
|
|
770
|
+
}`;
|
|
771
|
+
}).join(",");
|
|
772
|
+
return `
|
|
773
|
+
// Auto-generated API client from SMRT objects
|
|
774
|
+
// This file is generated automatically - do not edit
|
|
775
|
+
|
|
776
|
+
export function createClient(basePath = '/api/v1') {
|
|
777
|
+
return {${clientMethods}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
export { createClient as default };
|
|
782
|
+
`;
|
|
783
|
+
}
|
|
784
|
+
async function generateMCPModule(manifest) {
|
|
785
|
+
try {
|
|
786
|
+
const { ManifestGenerator } = await importBuildAwareModule({
|
|
787
|
+
source: "../scanner/index.ts",
|
|
788
|
+
dist: "../scanner.js"
|
|
789
|
+
});
|
|
790
|
+
const generator = new ManifestGenerator();
|
|
791
|
+
const tools = generator.generateMCPTools(manifest);
|
|
792
|
+
return `
|
|
793
|
+
// Auto-generated MCP tools from SMRT objects
|
|
794
|
+
// This file is generated automatically - do not edit
|
|
795
|
+
|
|
796
|
+
import { SmrtMCPServer } from '@happyvertical/smrt-core/runtime';
|
|
797
|
+
|
|
798
|
+
export const tools = ${tools};
|
|
799
|
+
|
|
800
|
+
export function createMCPServer(options = {}) {
|
|
801
|
+
const server = new SmrtMCPServer({
|
|
802
|
+
name: options.name || 'smrt-auto-generated',
|
|
803
|
+
version: options.version || '1.0.0',
|
|
804
|
+
...options
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
// Add all generated tools to the server
|
|
808
|
+
for (const tool of tools) {
|
|
809
|
+
server.addTool(tool, async (params) => {
|
|
810
|
+
// Tool execution will be handled by the application
|
|
811
|
+
throw new Error(\`Tool '\${tool.name}' handler must be provided by application\`);
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return server;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
export { createMCPServer as default };
|
|
819
|
+
`;
|
|
820
|
+
} catch (error) {
|
|
821
|
+
console.warn("[smrt] Error generating MCP module:", error);
|
|
822
|
+
return `
|
|
823
|
+
import { SmrtMCPServer } from '@happyvertical/smrt-core/runtime';
|
|
824
|
+
export const tools = [];
|
|
825
|
+
export function createMCPServer(options = {}) {
|
|
826
|
+
console.warn("MCP generation failed");
|
|
827
|
+
return new SmrtMCPServer({
|
|
828
|
+
name: options.name || 'smrt-client',
|
|
829
|
+
version: options.version || '1.0.0',
|
|
830
|
+
...options
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
`;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function generateClientModeTypes(manifest) {
|
|
837
|
+
const typeDefinitions = [];
|
|
838
|
+
for (const [objectName, objectMeta] of Object.entries(manifest.objects)) {
|
|
839
|
+
const fields = objectMeta.fields || {};
|
|
840
|
+
const propertyLines = [];
|
|
841
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
842
|
+
let type = "any";
|
|
843
|
+
switch (fieldDef.type) {
|
|
844
|
+
case "text":
|
|
845
|
+
type = "string";
|
|
846
|
+
break;
|
|
847
|
+
case "decimal":
|
|
848
|
+
case "integer":
|
|
849
|
+
type = "number";
|
|
850
|
+
break;
|
|
851
|
+
case "boolean":
|
|
852
|
+
type = "boolean";
|
|
853
|
+
break;
|
|
854
|
+
case "datetime":
|
|
855
|
+
type = "string";
|
|
856
|
+
break;
|
|
857
|
+
case "json":
|
|
858
|
+
type = "any";
|
|
859
|
+
break;
|
|
860
|
+
case "foreignKey":
|
|
861
|
+
type = "string";
|
|
862
|
+
break;
|
|
863
|
+
default:
|
|
864
|
+
type = "any";
|
|
865
|
+
}
|
|
866
|
+
const optional = !fieldDef.required ? "?" : "";
|
|
867
|
+
propertyLines.push(` ${fieldName}${optional}: ${type};`);
|
|
868
|
+
}
|
|
869
|
+
propertyLines.unshift(
|
|
870
|
+
" id?: string;",
|
|
871
|
+
" created_at?: string;",
|
|
872
|
+
" updated_at?: string;"
|
|
873
|
+
);
|
|
874
|
+
const interfaceDef = `export interface ${objectName}Data {
|
|
875
|
+
${propertyLines.join("\n")}
|
|
876
|
+
}`;
|
|
877
|
+
typeDefinitions.push(interfaceDef);
|
|
878
|
+
}
|
|
879
|
+
return typeDefinitions.join("\n\n");
|
|
880
|
+
}
|
|
881
|
+
async function generateTypesModule(manifest, mode = "server") {
|
|
882
|
+
let interfaces = "";
|
|
883
|
+
try {
|
|
884
|
+
if (mode !== "client") {
|
|
885
|
+
const { ManifestGenerator } = await importBuildAwareModule({
|
|
886
|
+
source: "../scanner/index.ts",
|
|
887
|
+
dist: "../scanner.js"
|
|
888
|
+
});
|
|
889
|
+
const generator = new ManifestGenerator();
|
|
890
|
+
interfaces = generator.generateTypeDefinitions(manifest);
|
|
891
|
+
} else {
|
|
892
|
+
interfaces = generateClientModeTypes(manifest);
|
|
893
|
+
}
|
|
894
|
+
return `
|
|
895
|
+
// Auto-generated TypeScript types from SMRT objects
|
|
896
|
+
// This file is generated automatically - do not edit
|
|
897
|
+
|
|
898
|
+
${interfaces}
|
|
899
|
+
|
|
900
|
+
export interface Request {
|
|
901
|
+
params: Record<string, string>;
|
|
902
|
+
query: Record<string, any>;
|
|
903
|
+
json(): Promise<any>;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
export interface Response {
|
|
907
|
+
json(data: any, init?: { status?: number }): Response;
|
|
908
|
+
status(code: number): Response;
|
|
909
|
+
}
|
|
910
|
+
`;
|
|
911
|
+
} catch (error) {
|
|
912
|
+
console.warn("[smrt] Error generating types module:", error);
|
|
913
|
+
return `
|
|
914
|
+
// Auto-generated TypeScript types from SMRT objects (fallback)
|
|
915
|
+
// This file is generated automatically - do not edit
|
|
916
|
+
|
|
917
|
+
export interface Request {
|
|
918
|
+
params: Record<string, string>;
|
|
919
|
+
query: Record<string, any>;
|
|
920
|
+
json(): Promise<any>;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export interface Response {
|
|
924
|
+
json(data: any, init?: { status?: number }): Response;
|
|
925
|
+
status(code: number): Response;
|
|
926
|
+
}
|
|
927
|
+
`;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function generateManifestModule(manifest) {
|
|
931
|
+
return `
|
|
932
|
+
// Auto-generated manifest from SMRT objects
|
|
933
|
+
// This file is generated automatically - do not edit
|
|
934
|
+
|
|
935
|
+
export const manifest = ${JSON.stringify(manifest, null, 2)};
|
|
936
|
+
|
|
937
|
+
export { manifest as default };
|
|
938
|
+
`;
|
|
939
|
+
}
|
|
940
|
+
async function generateTypeDeclarationFile(manifest, projectRoot, typeDeclarationsPath) {
|
|
941
|
+
try {
|
|
942
|
+
const [{ join: join2 }, { existsSync: existsSync2, mkdirSync, writeFileSync }] = await Promise.all([import("node:path"), import("node:fs")]);
|
|
943
|
+
const declarationsDir = join2(projectRoot, typeDeclarationsPath);
|
|
944
|
+
const declarationsFile = join2(declarationsDir, "virtual-modules.d.ts");
|
|
945
|
+
if (!existsSync2(declarationsDir)) {
|
|
946
|
+
mkdirSync(declarationsDir, { recursive: true });
|
|
947
|
+
}
|
|
948
|
+
const objectInterfaces = Object.entries(manifest.objects).map(([_name, obj]) => {
|
|
949
|
+
const interfaceName = `${obj.className}Data`;
|
|
950
|
+
const fields = Object.entries(obj.fields).map(([fieldName, field]) => {
|
|
951
|
+
const optional = field.required === false ? "?" : "";
|
|
952
|
+
const type = mapTypeScriptType(field.type);
|
|
953
|
+
return ` ${fieldName}${optional}: ${type};`;
|
|
954
|
+
}).join("\n");
|
|
955
|
+
return ` export interface ${interfaceName} {
|
|
956
|
+
id?: string;
|
|
957
|
+
${fields}
|
|
958
|
+
createdAt?: string;
|
|
959
|
+
updatedAt?: string;
|
|
960
|
+
}`;
|
|
961
|
+
}).join("\n\n");
|
|
962
|
+
const apiClientInterface = uniqueApiClientEntries(
|
|
963
|
+
Object.entries(manifest.objects)
|
|
964
|
+
).map(({ obj, clientKey }) => {
|
|
965
|
+
const { className, methods = {} } = obj;
|
|
966
|
+
const interfaceName = `${className}Data`;
|
|
967
|
+
const exposedActions = resolveApiActionSet(obj);
|
|
968
|
+
const customMethods = Object.entries(methods).filter(
|
|
969
|
+
([name, method]) => method.isPublic && exposedActions.has(name)
|
|
970
|
+
);
|
|
971
|
+
const customMethodSignatures = customMethods.map(([methodName, method]) => {
|
|
972
|
+
const params = method.parameters || [];
|
|
973
|
+
const optionsSignature = params.length > 0 ? `, options?: { ${params.map((p) => `${p.name}?: ${mapTypeScriptType(p.type)}`).join("; ")} }` : "";
|
|
974
|
+
return ` ${methodName}(id: string${optionsSignature}): Promise<any>;`;
|
|
975
|
+
}).join("\n");
|
|
976
|
+
if (customMethods.length > 0) {
|
|
977
|
+
return ` ${clientKey}: CrudOperations<${interfaceName}> & {
|
|
978
|
+
${customMethodSignatures}
|
|
979
|
+
};`;
|
|
980
|
+
} else {
|
|
981
|
+
return ` ${clientKey}: CrudOperations<${interfaceName}>;`;
|
|
982
|
+
}
|
|
983
|
+
}).join("\n");
|
|
984
|
+
const _mcpTools = Object.entries(manifest.objects).flatMap(
|
|
985
|
+
([_name, obj]) => Object.entries(obj.methods).map(([methodName, method]) => ({
|
|
986
|
+
name: `${methodName}_${obj.collection}`,
|
|
987
|
+
description: `${method.name} operation on ${obj.collection}`,
|
|
988
|
+
inputSchema: {
|
|
989
|
+
type: "object",
|
|
990
|
+
properties: Object.fromEntries(
|
|
991
|
+
method.parameters.map((param) => [
|
|
992
|
+
param.name,
|
|
993
|
+
{ type: mapJsonSchemaType(param.type) }
|
|
994
|
+
])
|
|
995
|
+
),
|
|
996
|
+
required: method.parameters.filter((p) => p.optional !== true).map((p) => p.name)
|
|
997
|
+
}
|
|
998
|
+
}))
|
|
999
|
+
);
|
|
1000
|
+
const typeDeclarations = `/**
|
|
1001
|
+
* Auto-generated TypeScript declarations for SMRT virtual modules
|
|
1002
|
+
* Generated from discovered @smrt() decorated classes
|
|
1003
|
+
*
|
|
1004
|
+
* DO NOT EDIT THIS FILE MANUALLY
|
|
1005
|
+
* This file is automatically regenerated when SMRT objects change
|
|
1006
|
+
*/
|
|
1007
|
+
|
|
1008
|
+
// Manifest module - Contains discovered SMRT objects metadata
|
|
1009
|
+
declare module '@happyvertical/smrt-virt-manifest' {
|
|
1010
|
+
export interface SmrtObjectField {
|
|
1011
|
+
type: string;
|
|
1012
|
+
required?: boolean;
|
|
1013
|
+
default?: any;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
export interface SmrtObjectMethod {
|
|
1017
|
+
name: string;
|
|
1018
|
+
parameters: Array<{
|
|
1019
|
+
name: string;
|
|
1020
|
+
type: string;
|
|
1021
|
+
required?: boolean;
|
|
1022
|
+
}>;
|
|
1023
|
+
returnType: string;
|
|
1024
|
+
isAsync: boolean;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
export interface SmrtObjectDefinition {
|
|
1028
|
+
className: string;
|
|
1029
|
+
collection: string;
|
|
1030
|
+
fields: Record<string, SmrtObjectField>;
|
|
1031
|
+
methods: Record<string, SmrtObjectMethod>;
|
|
1032
|
+
decoratorConfig: any;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
export interface SmrtManifest {
|
|
1036
|
+
version: string;
|
|
1037
|
+
timestamp: number;
|
|
1038
|
+
objects: Record<string, SmrtObjectDefinition>;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
export const manifest: SmrtManifest;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Routes module - Auto-generated REST route setup
|
|
1045
|
+
declare module '@happyvertical/smrt-virt-routes' {
|
|
1046
|
+
export interface RouteApp {
|
|
1047
|
+
get(path: string, handler: (req: any, res: any) => void): void;
|
|
1048
|
+
post(path: string, handler: (req: any, res: any) => void): void;
|
|
1049
|
+
put(path: string, handler: (req: any, res: any) => void): void;
|
|
1050
|
+
delete(path: string, handler: (req: any, res: any) => void): void;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
export interface RouteOptions {
|
|
1054
|
+
basePath?: string;
|
|
1055
|
+
[key: string]: any;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
export function setupRoutes(app: RouteApp, options?: RouteOptions): void;
|
|
1059
|
+
export default setupRoutes;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// Client module - Auto-generated API client
|
|
1063
|
+
declare module '@happyvertical/smrt-virt-client' {
|
|
1064
|
+
export interface ApiResponse<T = any> {
|
|
1065
|
+
id?: string;
|
|
1066
|
+
data?: T;
|
|
1067
|
+
error?: string;
|
|
1068
|
+
message?: string;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
export interface CrudOperations<T = any> {
|
|
1072
|
+
list(params?: Record<string, any>): Promise<T[]>;
|
|
1073
|
+
get(id: string): Promise<T>;
|
|
1074
|
+
create(data: Partial<T>): Promise<T>;
|
|
1075
|
+
update(id: string, data: Partial<T>): Promise<T>;
|
|
1076
|
+
delete(id: string): Promise<boolean>;
|
|
1077
|
+
search(query: string): Promise<T[]>;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export interface ApiClient {
|
|
1081
|
+
${apiClientInterface}
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
export function createClient(basePath?: string): ApiClient;
|
|
1085
|
+
export default createClient;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// MCP module - Auto-generated Model Context Protocol tools
|
|
1089
|
+
declare module '@happyvertical/smrt-virt-mcp' {
|
|
1090
|
+
import type { SmrtMCPServer, MCPServerOptions } from '@happyvertical/smrt-core/runtime';
|
|
1091
|
+
|
|
1092
|
+
export interface McpTool {
|
|
1093
|
+
name: string;
|
|
1094
|
+
description: string;
|
|
1095
|
+
inputSchema: {
|
|
1096
|
+
type: string;
|
|
1097
|
+
properties: Record<string, any>;
|
|
1098
|
+
required?: string[];
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export const tools: McpTool[];
|
|
1103
|
+
export function createMCPServer(options?: MCPServerOptions): SmrtMCPServer;
|
|
1104
|
+
export default createMCPServer;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// Types module - Auto-generated TypeScript interfaces
|
|
1108
|
+
declare module '@happyvertical/smrt-virt-types' {
|
|
1109
|
+
export const types: string;
|
|
1110
|
+
|
|
1111
|
+
// Auto-generated interfaces for discovered SMRT objects
|
|
1112
|
+
${objectInterfaces}
|
|
1113
|
+
|
|
1114
|
+
export default types;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// CLI module - Auto-generated command-line interface
|
|
1118
|
+
declare module '@happyvertical/smrt-virt-cli' {
|
|
1119
|
+
export interface CLIConfig {
|
|
1120
|
+
name?: string;
|
|
1121
|
+
version?: string;
|
|
1122
|
+
description?: string;
|
|
1123
|
+
prompt?: boolean;
|
|
1124
|
+
colors?: boolean;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
export interface CLIContext {
|
|
1128
|
+
db?: any;
|
|
1129
|
+
ai?: any;
|
|
1130
|
+
user?: {
|
|
1131
|
+
id: string;
|
|
1132
|
+
roles?: string[];
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
export interface CLICommandMap {
|
|
1137
|
+
[objectName: string]: {
|
|
1138
|
+
collection: string;
|
|
1139
|
+
commands: string[];
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
export const cliCommands: CLICommandMap;
|
|
1144
|
+
|
|
1145
|
+
export function setupCLI(config?: CLIConfig, context?: CLIContext): {
|
|
1146
|
+
run: (argv: string[]) => Promise<void>;
|
|
1147
|
+
generator: any;
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
export function getCLIHandler(config?: CLIConfig, context?: CLIContext): (argv: string[]) => Promise<void>;
|
|
1151
|
+
|
|
1152
|
+
export default setupCLI;
|
|
1153
|
+
}`;
|
|
1154
|
+
writeFileSync(declarationsFile, typeDeclarations);
|
|
1155
|
+
console.log(
|
|
1156
|
+
`[smrt] Generated TypeScript declarations: ${declarationsFile}`
|
|
1157
|
+
);
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
console.error("[smrt] Error generating TypeScript declarations:", error);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
function mapTypeScriptType(smrtType) {
|
|
1163
|
+
const typeMap = {
|
|
1164
|
+
string: "string",
|
|
1165
|
+
number: "number",
|
|
1166
|
+
boolean: "boolean",
|
|
1167
|
+
array: "any[]",
|
|
1168
|
+
object: "Record<string, any>",
|
|
1169
|
+
date: "string",
|
|
1170
|
+
Date: "string"
|
|
1171
|
+
};
|
|
1172
|
+
return typeMap[smrtType] || "any";
|
|
1173
|
+
}
|
|
1174
|
+
function mapJsonSchemaType(tsType) {
|
|
1175
|
+
const typeMap = {
|
|
1176
|
+
string: "string",
|
|
1177
|
+
number: "number",
|
|
1178
|
+
boolean: "boolean",
|
|
1179
|
+
array: "array",
|
|
1180
|
+
object: "object",
|
|
1181
|
+
any: "string"
|
|
1182
|
+
};
|
|
1183
|
+
return typeMap[tsType] || "string";
|
|
1184
|
+
}
|
|
1185
|
+
function getDefaultHTML() {
|
|
1186
|
+
const uiScript = getDefaultUIModule();
|
|
1187
|
+
return '<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>SMRT Development UI</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body {\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n background: #f5f5f5;\n color: #333;\n }\n .container { max-width: 1200px; margin: 0 auto; padding: 20px; }\n header {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n padding: 40px 0;\n margin-bottom: 40px;\n box-shadow: 0 4px 6px rgba(0,0,0,0.1);\n }\n header h1 { font-size: 2.5em; font-weight: 700; margin-bottom: 10px; }\n .subtitle { font-size: 1.1em; opacity: 0.9; }\n .stats {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n gap: 20px;\n margin-bottom: 40px;\n }\n .stat-card {\n background: white;\n padding: 20px;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n text-align: center;\n }\n .stat-value { font-size: 2.5em; font-weight: 700; color: #667eea; margin-bottom: 5px; }\n .stat-label { font-size: 0.9em; color: #666; text-transform: uppercase; letter-spacing: 1px; }\n .collections { display: grid; gap: 30px; }\n .collection-card {\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n overflow: hidden;\n }\n .collection-header {\n background: #667eea;\n color: white;\n padding: 15px 20px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n .collection-title { font-size: 1.3em; font-weight: 600; }\n .collection-count {\n background: rgba(255,255,255,0.2);\n padding: 5px 15px;\n border-radius: 20px;\n font-size: 0.9em;\n }\n .collection-body { padding: 20px; }\n .field-list {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));\n gap: 15px;\n margin-bottom: 20px;\n }\n .field {\n padding: 10px;\n background: #f8f9fa;\n border-radius: 4px;\n border-left: 3px solid #667eea;\n }\n .field-name { font-weight: 600; color: #333; margin-bottom: 3px; }\n .field-type { font-size: 0.85em; color: #666; }\n .actions { display: flex; gap: 10px; flex-wrap: wrap; }\n .btn {\n padding: 10px 20px;\n border: none;\n border-radius: 4px;\n font-size: 0.9em;\n cursor: pointer;\n transition: all 0.2s;\n text-decoration: none;\n display: inline-block;\n }\n .btn-primary { background: #667eea; color: white; }\n .btn-primary:hover { background: #5568d3; transform: translateY(-1px); }\n .btn-secondary { background: #e0e0e0; color: #333; }\n .btn-secondary:hover { background: #d0d0d0; }\n .loading { text-align: center; padding: 40px; color: #666; }\n .error {\n background: #fee;\n border: 1px solid #fcc;\n color: #c33;\n padding: 15px;\n border-radius: 4px;\n margin-bottom: 20px;\n }\n .empty-state { text-align: center; padding: 60px 20px; color: #999; }\n .empty-state svg { width: 100px; height: 100px; margin-bottom: 20px; opacity: 0.3; }\n </style>\n</head>\n<body>\n <div id="app">\n <div class="loading">Loading SMRT UI...</div>\n </div>\n <script type="module">\n' + uiScript + "\n <\/script>\n</body>\n</html>";
|
|
1188
|
+
}
|
|
1189
|
+
function getDefaultUIModule() {
|
|
1190
|
+
try {
|
|
1191
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
1192
|
+
const templatePath = join(__dirname, "templates/default-ui.js");
|
|
1193
|
+
return readFileSync(templatePath, "utf-8").trim();
|
|
1194
|
+
} catch (error) {
|
|
1195
|
+
console.error("[smrt] Error loading UI template:", error);
|
|
1196
|
+
return `
|
|
1197
|
+
async function createUI() {
|
|
1198
|
+
const app = document.getElementById('app');
|
|
1199
|
+
if (!app) return;
|
|
1200
|
+
app.innerHTML = '<div class="container" style="padding:40px;text-align:center;"><h1>🎯 SMRT Development UI</h1><p>Template file not found. UI code could not be loaded.</p></div>';
|
|
1201
|
+
}
|
|
1202
|
+
createUI();
|
|
1203
|
+
`;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
async function loadDefaultHTML() {
|
|
1207
|
+
return getDefaultHTML();
|
|
1208
|
+
}
|
|
1209
|
+
async function loadDefaultUI() {
|
|
1210
|
+
return getDefaultUIModule();
|
|
1211
|
+
}
|
|
1212
|
+
async function generateCLIModule(manifest) {
|
|
1213
|
+
try {
|
|
1214
|
+
const commands = [];
|
|
1215
|
+
const objectImports = [];
|
|
1216
|
+
for (const [className, objectDef] of Object.entries(manifest.objects)) {
|
|
1217
|
+
const config = objectDef.decoratorConfig;
|
|
1218
|
+
const cliConfig = config?.cli;
|
|
1219
|
+
if (cliConfig === false) continue;
|
|
1220
|
+
const excluded = (typeof cliConfig === "object" ? cliConfig.exclude : []) || [];
|
|
1221
|
+
const included = typeof cliConfig === "object" ? cliConfig.include : null;
|
|
1222
|
+
const shouldInclude = (command) => {
|
|
1223
|
+
if (included && !included.includes(command)) return false;
|
|
1224
|
+
if (excluded.includes(command)) return false;
|
|
1225
|
+
return true;
|
|
1226
|
+
};
|
|
1227
|
+
const collectionName = objectDef.collection;
|
|
1228
|
+
const commandName = (objectDef.className || className).toLowerCase();
|
|
1229
|
+
objectImports.push(
|
|
1230
|
+
`// Import ${className} and ${className}Collection for CLI operations`
|
|
1231
|
+
);
|
|
1232
|
+
const availableCommands = [];
|
|
1233
|
+
if (shouldInclude("list"))
|
|
1234
|
+
availableCommands.push(`'${commandName}:list'`);
|
|
1235
|
+
if (shouldInclude("get")) availableCommands.push(`'${commandName}:get'`);
|
|
1236
|
+
if (shouldInclude("create"))
|
|
1237
|
+
availableCommands.push(`'${commandName}:create'`);
|
|
1238
|
+
if (shouldInclude("update"))
|
|
1239
|
+
availableCommands.push(`'${commandName}:update'`);
|
|
1240
|
+
if (shouldInclude("delete"))
|
|
1241
|
+
availableCommands.push(`'${commandName}:delete'`);
|
|
1242
|
+
for (const [methodName, _method] of Object.entries(objectDef.methods)) {
|
|
1243
|
+
if (methodName.startsWith("_") || ["list", "get", "create", "update", "delete", "save"].includes(
|
|
1244
|
+
methodName
|
|
1245
|
+
))
|
|
1246
|
+
continue;
|
|
1247
|
+
if (shouldInclude(methodName)) {
|
|
1248
|
+
availableCommands.push(`'${commandName}:${methodName}'`);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (availableCommands.length > 0) {
|
|
1252
|
+
commands.push(`
|
|
1253
|
+
// ${className} commands
|
|
1254
|
+
${className}: {
|
|
1255
|
+
collection: '${collectionName}',
|
|
1256
|
+
commands: [${availableCommands.join(", ")}]
|
|
1257
|
+
}`);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return `
|
|
1261
|
+
// Auto-generated CLI module from SMRT objects
|
|
1262
|
+
// This file is generated automatically - do not edit
|
|
1263
|
+
|
|
1264
|
+
import { CLIGenerator } from '@happyvertical/smrt-core/generators/cli';
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* @typedef {import('@happyvertical/smrt-core/generators/cli').CLIConfig} CLIConfig
|
|
1268
|
+
* @typedef {import('@happyvertical/smrt-core/generators/cli').CLIContext} CLIContext
|
|
1269
|
+
*/
|
|
1270
|
+
|
|
1271
|
+
${objectImports.join("\n")}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* Available CLI commands by object
|
|
1275
|
+
*/
|
|
1276
|
+
export const cliCommands = {${commands.join(",\n")}
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* Setup CLI with auto-generated commands
|
|
1281
|
+
*
|
|
1282
|
+
* @param {CLIConfig} [config={}] - CLI configuration
|
|
1283
|
+
* @param {CLIContext} [context={}] - CLI context
|
|
1284
|
+
* @returns {{run: function(string[]): Promise<void>, generator: *}}
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* import { setupCLI } from '@happyvertical/smrt-virt-cli';
|
|
1288
|
+
*
|
|
1289
|
+
* const cli = setupCLI({
|
|
1290
|
+
* name: 'my-app',
|
|
1291
|
+
* version: '1.0.0'
|
|
1292
|
+
* });
|
|
1293
|
+
*
|
|
1294
|
+
* cli.run(process.argv);
|
|
1295
|
+
*/
|
|
1296
|
+
export function setupCLI(config = {}, context = {}) {
|
|
1297
|
+
const generator = new CLIGenerator(config, context);
|
|
1298
|
+
return {
|
|
1299
|
+
run: async (argv) => {
|
|
1300
|
+
const handler = generator.generateHandler();
|
|
1301
|
+
await handler(argv.slice(2)); // Remove 'node' and script name
|
|
1302
|
+
},
|
|
1303
|
+
generator
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* Get CLI handler directly
|
|
1309
|
+
*
|
|
1310
|
+
* @param {CLIConfig} [config={}] - CLI configuration
|
|
1311
|
+
* @param {CLIContext} [context={}] - CLI context
|
|
1312
|
+
* @returns {function(string[]): Promise<void>}
|
|
1313
|
+
*/
|
|
1314
|
+
export function getCLIHandler(config = {}, context = {}) {
|
|
1315
|
+
const generator = new CLIGenerator(config, context);
|
|
1316
|
+
return generator.generateHandler();
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
export default setupCLI;
|
|
1320
|
+
`;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
console.warn("[smrt] Error generating CLI module:", error);
|
|
1323
|
+
return `
|
|
1324
|
+
// Error generating CLI module
|
|
1325
|
+
export const cliCommands = {};
|
|
1326
|
+
export function setupCLI() {
|
|
1327
|
+
console.warn("CLI generation failed");
|
|
1328
|
+
return { run: async () => {} };
|
|
1329
|
+
}
|
|
1330
|
+
export function getCLIHandler() {
|
|
1331
|
+
return async () => console.warn("CLI generation failed");
|
|
1332
|
+
}
|
|
1333
|
+
export default setupCLI;
|
|
1334
|
+
`;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
async function generateSchemaModule(manifest) {
|
|
1338
|
+
try {
|
|
1339
|
+
const { SchemaGenerator } = await importBuildAwareModule({
|
|
1340
|
+
source: "../schema/generator.ts",
|
|
1341
|
+
dist: "../schema/generator.js"
|
|
1342
|
+
});
|
|
1343
|
+
const schemaGenerator = new SchemaGenerator();
|
|
1344
|
+
const schemas = {};
|
|
1345
|
+
for (const [className, objectDef] of Object.entries(manifest.objects)) {
|
|
1346
|
+
const schema = schemaGenerator.generateSchema(objectDef);
|
|
1347
|
+
schemas[className] = schema;
|
|
1348
|
+
}
|
|
1349
|
+
const schemaManifest = {
|
|
1350
|
+
version: "1.0.0",
|
|
1351
|
+
timestamp: Date.now(),
|
|
1352
|
+
packageName: manifest.packageName || "unknown",
|
|
1353
|
+
schemas,
|
|
1354
|
+
dependencies: Array.from(
|
|
1355
|
+
new Set(
|
|
1356
|
+
Object.values(schemas).flatMap((s) => s.dependencies || [])
|
|
1357
|
+
)
|
|
1358
|
+
)
|
|
1359
|
+
};
|
|
1360
|
+
return `// Auto-generated schema manifest from SMRT objects
|
|
1361
|
+
// This file is generated automatically - do not edit
|
|
1362
|
+
|
|
1363
|
+
// Schema manifest as JSON for SQL adapters
|
|
1364
|
+
export const schemaManifest = ${JSON.stringify(schemaManifest, null, 2)};
|
|
1365
|
+
|
|
1366
|
+
// Schema registry for runtime access
|
|
1367
|
+
export const schemas = schemaManifest.schemas;
|
|
1368
|
+
|
|
1369
|
+
// Schema lookup function
|
|
1370
|
+
export function getSchema(className: string) {
|
|
1371
|
+
return schemas[className];
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// All schemas as array for dependency resolution
|
|
1375
|
+
export const allSchemas = Object.values(schemas);
|
|
1376
|
+
|
|
1377
|
+
// Package information
|
|
1378
|
+
export const packageName = schemaManifest.packageName;
|
|
1379
|
+
export const dependencies = schemaManifest.dependencies;
|
|
1380
|
+
|
|
1381
|
+
export default schemaManifest;`;
|
|
1382
|
+
} catch (error) {
|
|
1383
|
+
console.error("[smrt] Error generating schema module:", error);
|
|
1384
|
+
return `// Error generating schema module
|
|
1385
|
+
export const schemaManifest = { schemas: {}, dependencies: [] };
|
|
1386
|
+
export const schemas = {};
|
|
1387
|
+
export function getSchema() { return null; }
|
|
1388
|
+
export const allSchemas = [];
|
|
1389
|
+
export default {};`;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
export {
|
|
1393
|
+
findCliApiCoherenceViolations,
|
|
1394
|
+
generateSvelteKitRoutes,
|
|
1395
|
+
methodNameToKebab,
|
|
1396
|
+
resolveApiActionSet,
|
|
1397
|
+
smrtPlugin,
|
|
1398
|
+
validateCliIncludeAgainstApi
|
|
1399
|
+
};
|
|
1400
|
+
//# sourceMappingURL=index.js.map
|