@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
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,1202 @@
|
|
|
1
|
+
import { AITool } from '@happyvertical/ai';
|
|
2
|
+
import { SmrtClassOptions, SmrtClass } from './class';
|
|
3
|
+
import { GenerateEmbeddingsOptions } from './embeddings/types';
|
|
4
|
+
import { ToolCall, ToolCallResult } from './tools/tool-executor';
|
|
5
|
+
/**
|
|
6
|
+
* Options for SmrtObject initialization
|
|
7
|
+
*/
|
|
8
|
+
export interface SmrtObjectOptions extends SmrtClassOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Unique identifier for the object
|
|
11
|
+
*/
|
|
12
|
+
id?: string;
|
|
13
|
+
/**
|
|
14
|
+
* URL-friendly identifier
|
|
15
|
+
*/
|
|
16
|
+
slug?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional context to scope the slug (could be a path, domain, etc.)
|
|
19
|
+
*/
|
|
20
|
+
context?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Creation timestamp
|
|
23
|
+
*/
|
|
24
|
+
created_at?: Date;
|
|
25
|
+
/**
|
|
26
|
+
* Last update timestamp
|
|
27
|
+
*/
|
|
28
|
+
updated_at?: Date;
|
|
29
|
+
/**
|
|
30
|
+
* Flag to skip automatic field extraction (internal use)
|
|
31
|
+
*/
|
|
32
|
+
_extractingFields?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Flag to skip database loading (internal use)
|
|
35
|
+
*/
|
|
36
|
+
_skipLoad?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Flag to skip save-time embedding auto-generation (internal use).
|
|
39
|
+
*
|
|
40
|
+
* This is used when framework code will generate embeddings explicitly after
|
|
41
|
+
* saving and wants to avoid racing a duplicate background generation.
|
|
42
|
+
*/
|
|
43
|
+
_skipAutoEmbeddings?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Allow arbitrary field values to be passed
|
|
46
|
+
*/
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for the relationship loaders {@link SmrtObject.loadRelated},
|
|
51
|
+
* {@link SmrtObject.loadRelatedMany}, and {@link SmrtObject.getRelated}.
|
|
52
|
+
*/
|
|
53
|
+
export interface LoadRelatedOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Bypass the cross-tenant isolation guard.
|
|
56
|
+
*
|
|
57
|
+
* By default, resolving a relationship from a tenant-scoped object to an
|
|
58
|
+
* object in a *different*, non-null tenant throws a `TenantIsolationError`.
|
|
59
|
+
* Set this to `true` for deliberate cross-tenant flows (admin tooling,
|
|
60
|
+
* migrations, super-admin bypass paths) where the access is intentional.
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
allowCrossTenant?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Base class for all persistent SMRT domain objects.
|
|
68
|
+
*
|
|
69
|
+
* Provides a full ORM lifecycle: construct with options, call `initialize()`,
|
|
70
|
+
* then use `save()` / `delete()` for persistence. Objects are identified by a
|
|
71
|
+
* UUID `id` and an optional URL-friendly `slug` (auto-generated from `name`,
|
|
72
|
+
* `title`, `label`, or `id` if not provided).
|
|
73
|
+
*
|
|
74
|
+
* Key capabilities:
|
|
75
|
+
* - **Persistence**: `save()` (upsert with retry), `delete()` (with hooks)
|
|
76
|
+
* - **Loading**: `loadFromId()`, `loadFromSlug()` (called automatically by `initialize()`)
|
|
77
|
+
* - **AI operations**: `is()` (boolean criteria check), `do()` (freeform instruction)
|
|
78
|
+
* - **Relationships**: `loadRelated()` (foreignKey), `loadRelatedMany()` (oneToMany)
|
|
79
|
+
* - **Context memory**: `remember()` / `recall()` / `recallAll()` / `forget()` / `forgetScope()`
|
|
80
|
+
* - **STI support**: `_meta_type` discriminator, `_meta_data` JSONB for child fields
|
|
81
|
+
* - **Serialization**: `toJSON()` (framework-managed, handles STI), `transformJSON()` (override hook)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* @smrt()
|
|
86
|
+
* class Product extends SmrtObject {
|
|
87
|
+
* name: string = '';
|
|
88
|
+
* price: number = 0.0;
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* const product = new Product({ db: myDb, name: 'Widget', price: 9.99 });
|
|
92
|
+
* await product.initialize();
|
|
93
|
+
* await product.save();
|
|
94
|
+
* console.log(product.id); // auto-generated UUID
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare class SmrtObject extends SmrtClass {
|
|
98
|
+
/**
|
|
99
|
+
* Database table name for this object
|
|
100
|
+
*/
|
|
101
|
+
_tableName: string;
|
|
102
|
+
/**
|
|
103
|
+
* Cache for loaded relationships to avoid repeated database queries
|
|
104
|
+
* Maps fieldName to loaded object(s)
|
|
105
|
+
*/
|
|
106
|
+
private _loadedRelationships;
|
|
107
|
+
/**
|
|
108
|
+
* Whether this object is backed by an existing database row.
|
|
109
|
+
*
|
|
110
|
+
* Set when the object is hydrated from the database (collection
|
|
111
|
+
* get/list/query, `loadFromId()`, `loadFromSlug()`) and after a successful
|
|
112
|
+
* `save()`. `save()` uses it to target the primary key on upsert instead
|
|
113
|
+
* of the natural-key conflict columns, so natural-key edits (e.g. renaming
|
|
114
|
+
* a slug) update the existing row rather than colliding on `*_pkey`
|
|
115
|
+
* (issue #1472).
|
|
116
|
+
*/
|
|
117
|
+
private _persisted;
|
|
118
|
+
/**
|
|
119
|
+
* Override options with SmrtObjectOptions type for proper type narrowing.
|
|
120
|
+
* Initialized by parent constructor via super() call.
|
|
121
|
+
*/
|
|
122
|
+
options: SmrtObjectOptions;
|
|
123
|
+
/**
|
|
124
|
+
* Unique identifier for the object
|
|
125
|
+
*/
|
|
126
|
+
protected _id: string | null | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* URL-friendly identifier
|
|
129
|
+
*/
|
|
130
|
+
protected _slug: string | null | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Optional context to scope the slug
|
|
133
|
+
*/
|
|
134
|
+
protected _context: string | null | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Creation timestamp
|
|
137
|
+
*/
|
|
138
|
+
created_at: Date | null | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Last update timestamp
|
|
141
|
+
*/
|
|
142
|
+
updated_at: Date | null | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a new SmrtObject instance
|
|
145
|
+
*
|
|
146
|
+
* @param options - Configuration options including identifiers and metadata
|
|
147
|
+
* @throws Error if options is null
|
|
148
|
+
*/
|
|
149
|
+
constructor(options?: SmrtObjectOptions);
|
|
150
|
+
private getRegisteredClassInfo;
|
|
151
|
+
protected getResolvedClassName(): string;
|
|
152
|
+
protected getResolvedQualifiedName(): string;
|
|
153
|
+
private getCurrentMetaType;
|
|
154
|
+
private isLegacySTIDiscriminatorUpgrade;
|
|
155
|
+
private planPersistenceWrite;
|
|
156
|
+
/**
|
|
157
|
+
* Protected setter for ID to maintain type safety
|
|
158
|
+
* Used internally by collection.create() and other framework code
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
protected setId(id: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Whether this object is backed by an existing database row.
|
|
164
|
+
*
|
|
165
|
+
* True after hydration from the database (collection get/list/query,
|
|
166
|
+
* `loadFromId()`, `loadFromSlug()`) or after a successful `save()`.
|
|
167
|
+
*/
|
|
168
|
+
get isPersisted(): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Marks this object as backed by an existing database row, so `save()`
|
|
171
|
+
* targets the primary key instead of the natural-key conflict columns.
|
|
172
|
+
* Called by framework hydration paths (issue #1472).
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
markAsPersisted(): void;
|
|
176
|
+
protected verifyStorageReady(): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Protected setter for STI discriminator to maintain type safety
|
|
179
|
+
* Used internally for Single Table Inheritance support
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
protected setMetaType(metaType: string): void;
|
|
183
|
+
/**
|
|
184
|
+
* Smart clone helper to avoid array/object aliasing (Issue #22)
|
|
185
|
+
*
|
|
186
|
+
* Clones values to prevent shared references between options and instance properties:
|
|
187
|
+
* - Primitives (string, number, boolean, null, undefined): No clone needed
|
|
188
|
+
* - Dates: No clone needed (immutable)
|
|
189
|
+
* - Field instances: No clone needed (framework objects)
|
|
190
|
+
* - Arrays: Shallow clone
|
|
191
|
+
* - Plain objects: Shallow clone
|
|
192
|
+
* - Other objects: Pass through (class instances, etc.)
|
|
193
|
+
*
|
|
194
|
+
* @param value - Value to clone
|
|
195
|
+
* @returns Cloned value or original if no cloning needed
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
private cloneValue;
|
|
199
|
+
/**
|
|
200
|
+
* Initialize properties from options after field initializers have run
|
|
201
|
+
* This ensures option values take precedence over default field initializer values
|
|
202
|
+
* Uses smart cloning to prevent array/object aliasing (Issue #22)
|
|
203
|
+
*/
|
|
204
|
+
private initializePropertiesFromOptions;
|
|
205
|
+
/**
|
|
206
|
+
* Gets the unique identifier for this object
|
|
207
|
+
*/
|
|
208
|
+
get id(): string | null | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Sets the unique identifier for this object
|
|
211
|
+
*
|
|
212
|
+
* @param value - The ID to set
|
|
213
|
+
* @throws Error if the value is invalid
|
|
214
|
+
*/
|
|
215
|
+
set id(value: string | null | undefined);
|
|
216
|
+
/**
|
|
217
|
+
* Gets the URL-friendly slug for this object
|
|
218
|
+
*/
|
|
219
|
+
get slug(): string | null | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* Sets the URL-friendly slug for this object
|
|
222
|
+
*
|
|
223
|
+
* @param value - The slug to set
|
|
224
|
+
* @throws Error if the value is invalid
|
|
225
|
+
*/
|
|
226
|
+
set slug(value: string | null | undefined);
|
|
227
|
+
/**
|
|
228
|
+
* Gets the context that scopes this object's slug
|
|
229
|
+
*/
|
|
230
|
+
get context(): string;
|
|
231
|
+
/**
|
|
232
|
+
* Sets the context that scopes this object's slug
|
|
233
|
+
*
|
|
234
|
+
* @param value - The context to set
|
|
235
|
+
* @throws Error if the value is invalid
|
|
236
|
+
*/
|
|
237
|
+
set context(value: string | null | undefined);
|
|
238
|
+
/**
|
|
239
|
+
* Initializes this object and optionally loads its data from the database.
|
|
240
|
+
*
|
|
241
|
+
* Initialization order:
|
|
242
|
+
* 1. Runs TypeScript field initializers (class property defaults)
|
|
243
|
+
* 2. Applies `options` values on top of defaults (options win)
|
|
244
|
+
* 3. If `options.id` is set, calls `loadFromId()` to hydrate from DB
|
|
245
|
+
* 4. If `options.slug` is set (and no id), calls `loadFromSlug()` instead
|
|
246
|
+
*
|
|
247
|
+
* Runtime schema verification is deferred until the first actual DB
|
|
248
|
+
* operation, which keeps initialization safe for SSR and prerendering
|
|
249
|
+
* without mutating application schema.
|
|
250
|
+
*
|
|
251
|
+
* Called automatically by collection methods. Call manually only when
|
|
252
|
+
* constructing objects outside of a collection.
|
|
253
|
+
*
|
|
254
|
+
* @returns This instance, ready to use (enables chaining)
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const product = new Product({ db: myDb, id: 'existing-uuid' });
|
|
259
|
+
* await product.initialize(); // loads product data from DB
|
|
260
|
+
* console.log(product.name);
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
initialize(): Promise<this>;
|
|
264
|
+
/**
|
|
265
|
+
* Determines if this class needs automatic property initialization from options
|
|
266
|
+
*
|
|
267
|
+
* Decorator-based classes handle property assignment in their constructor,
|
|
268
|
+
* so they don't need the automatic property initialization logic.
|
|
269
|
+
* This optimization avoids redundant work and Field instance handling.
|
|
270
|
+
*
|
|
271
|
+
* @returns True if property initialization is needed, false otherwise
|
|
272
|
+
* @private
|
|
273
|
+
*/
|
|
274
|
+
private needsPropertyInitialization;
|
|
275
|
+
/**
|
|
276
|
+
* Loads data from a database row into this object's properties
|
|
277
|
+
*
|
|
278
|
+
* STI Support: If using Single Table Inheritance (tableStrategy: 'sti'):
|
|
279
|
+
* - Merges _meta_data JSONB fields into the main data object
|
|
280
|
+
* - Validates _meta_type discriminator matches class name
|
|
281
|
+
*
|
|
282
|
+
* @param data - Database row data (with snake_case column names)
|
|
283
|
+
* @throws Error if STI validation fails
|
|
284
|
+
*/
|
|
285
|
+
loadDataFromDb(data: any): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Gets the database table name for this object
|
|
288
|
+
*/
|
|
289
|
+
get tableName(): string;
|
|
290
|
+
/**
|
|
291
|
+
* Gets field definitions and current values for this object
|
|
292
|
+
*
|
|
293
|
+
* @returns Object containing field definitions with current values
|
|
294
|
+
*/
|
|
295
|
+
getFields(): Promise<Record<string, any>>;
|
|
296
|
+
/**
|
|
297
|
+
* Override hook for customizing JSON serialization output.
|
|
298
|
+
*
|
|
299
|
+
* This is the **only safe way** to customize serialization. Do **not** override
|
|
300
|
+
* `toJSON()` directly — it manages STI discriminator assignment (`_meta_type`),
|
|
301
|
+
* meta-field extraction into `_meta_data`, and manifest-driven field enumeration.
|
|
302
|
+
* Overriding it will silently break STI persistence.
|
|
303
|
+
*
|
|
304
|
+
* The `data` argument already contains all persisted fields. Return a new object
|
|
305
|
+
* (spread `data` and add/modify/remove keys) to change what is serialized.
|
|
306
|
+
* Non-persisted computed properties added here are excluded from `save()` because
|
|
307
|
+
* the DB write path uses `toJSON()` output, not this hook's additions — unless
|
|
308
|
+
* those keys also correspond to real schema columns.
|
|
309
|
+
*
|
|
310
|
+
* @param data - Fully serialized object produced by the framework's `toJSON()` logic
|
|
311
|
+
* @returns Transformed data to use as the final serialization result
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* class Article extends SmrtObject {
|
|
316
|
+
* body: string = '';
|
|
317
|
+
*
|
|
318
|
+
* protected transformJSON(data: any): any {
|
|
319
|
+
* return {
|
|
320
|
+
* ...data,
|
|
321
|
+
* wordCount: this.body.split(/\s+/).length,
|
|
322
|
+
* preview: this.body.substring(0, 100),
|
|
323
|
+
* };
|
|
324
|
+
* }
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @see {@link toJSON} for the framework implementation (do not override)
|
|
329
|
+
*/
|
|
330
|
+
protected transformJSON(data: any): any;
|
|
331
|
+
/**
|
|
332
|
+
* Custom JSON serialization
|
|
333
|
+
* Returns a plain object with all field values for proper JSON.stringify() behavior
|
|
334
|
+
* Field instances automatically call their toJSON() method during serialization
|
|
335
|
+
*
|
|
336
|
+
* Issue #205: Filters out undefined values to prevent database errors
|
|
337
|
+
*
|
|
338
|
+
* Note: This method cannot be async because JSON.stringify() expects synchronous toJSON()
|
|
339
|
+
* It uses direct property access instead of getFields() to avoid async issues
|
|
340
|
+
*
|
|
341
|
+
* STI Support: If using Single Table Inheritance (tableStrategy: 'sti'):
|
|
342
|
+
* - Sets _meta_type discriminator to class name
|
|
343
|
+
* - Extracts meta fields to _meta_data JSONB column
|
|
344
|
+
*
|
|
345
|
+
* **Customization:** Override `transformJSON()` instead of this method.
|
|
346
|
+
* See transformJSON() documentation for safe customization patterns.
|
|
347
|
+
*/
|
|
348
|
+
toJSON(): any;
|
|
349
|
+
/**
|
|
350
|
+
* Converts this object to a plain JavaScript object (POJO)
|
|
351
|
+
*
|
|
352
|
+
* Unlike toJSON() which returns an object that can still be a class instance,
|
|
353
|
+
* this method returns a true plain object suitable for:
|
|
354
|
+
* - SvelteKit's load function returns (requires serializable data)
|
|
355
|
+
* - Passing data through web workers
|
|
356
|
+
* - Any context requiring non-class objects
|
|
357
|
+
*
|
|
358
|
+
* @returns Plain JavaScript object with all field values
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* // In a SvelteKit +page.server.ts load function:
|
|
363
|
+
* const users = await userCollection.list();
|
|
364
|
+
* return {
|
|
365
|
+
* users: users.map(u => u.toPlainObject())
|
|
366
|
+
* };
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
toPlainObject(): Record<string, unknown>;
|
|
370
|
+
/**
|
|
371
|
+
* Collects the property names of fields marked `@field({ sensitive: true })`
|
|
372
|
+
* for this instance's class (and, under STI, every member of its hierarchy,
|
|
373
|
+
* since `toJSON()` merges sibling fields into the serialized payload).
|
|
374
|
+
*
|
|
375
|
+
* Reads both the first-class `sensitive` flag and the `_meta.sensitive`
|
|
376
|
+
* mirror so it works regardless of whether the field metadata came from the
|
|
377
|
+
* AST manifest or a runtime `@field()` decorator registration.
|
|
378
|
+
*/
|
|
379
|
+
private getSensitiveFieldNames;
|
|
380
|
+
/**
|
|
381
|
+
* Public-safe serialization for network surfaces.
|
|
382
|
+
*
|
|
383
|
+
* Returns the same shape as `toJSON()` but with every `sensitive` field
|
|
384
|
+
* removed (including STI meta fields nested under `_meta_data`). This is the
|
|
385
|
+
* serializer used by the generated REST / MCP / SvelteKit routes so that
|
|
386
|
+
* secret columns (API secrets, credentials, tax IDs) are never returned over
|
|
387
|
+
* the wire, while `toJSON()` continues to carry them for database persistence.
|
|
388
|
+
*
|
|
389
|
+
* @returns A plain object safe to send to API consumers.
|
|
390
|
+
*/
|
|
391
|
+
toPublicJSON(): Record<string, unknown>;
|
|
392
|
+
/**
|
|
393
|
+
* Gets or generates a unique ID for this object
|
|
394
|
+
*
|
|
395
|
+
* @returns Promise resolving to the object's ID
|
|
396
|
+
*/
|
|
397
|
+
getId(): Promise<string>;
|
|
398
|
+
/**
|
|
399
|
+
* Returns the slug for this object, generating one if not already set.
|
|
400
|
+
*
|
|
401
|
+
* Generation falls back through the following fields in order:
|
|
402
|
+
* `name` → `title` → `label` → `id`
|
|
403
|
+
*
|
|
404
|
+
* The generated slug is lowercased, with non-alphanumeric characters
|
|
405
|
+
* replaced by hyphens and leading/trailing hyphens stripped.
|
|
406
|
+
*
|
|
407
|
+
* Called automatically by `save()` when no slug is present.
|
|
408
|
+
*
|
|
409
|
+
* @returns The existing slug or a newly generated one (may be `null` if
|
|
410
|
+
* none of the fallback fields and `id` are set)
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* const product = new Product({ name: 'My Widget' });
|
|
415
|
+
* console.log(await product.getSlug()); // 'my-widget'
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
getSlug(): Promise<string | null | undefined>;
|
|
419
|
+
/**
|
|
420
|
+
* Gets the ID of this object if it's already saved in the database
|
|
421
|
+
*
|
|
422
|
+
* @returns Promise resolving to the saved ID or null if not saved
|
|
423
|
+
*/
|
|
424
|
+
getSavedId(): Promise<any>;
|
|
425
|
+
/**
|
|
426
|
+
* Checks if this object is already saved in the database
|
|
427
|
+
*
|
|
428
|
+
* @returns Promise resolving to true if saved, false otherwise
|
|
429
|
+
*/
|
|
430
|
+
isSaved(): Promise<boolean>;
|
|
431
|
+
/**
|
|
432
|
+
* Resolve the set of snake_case column names whose database type is `UUID`
|
|
433
|
+
* for the table this object writes to.
|
|
434
|
+
*
|
|
435
|
+
* Declared foreign keys (`@foreignKey()`) and cross-package references
|
|
436
|
+
* (`@crossPackageRef()`) generate native `UUID` columns (R11). Their default
|
|
437
|
+
* declared value in TypeScript is the empty string (`''`), which is not a
|
|
438
|
+
* valid UUID literal. Postgres rejects `''` on a `uuid` column with
|
|
439
|
+
* `invalid input syntax for type uuid`, so any optional/unset declared FK
|
|
440
|
+
* (a root entity's self-reference, an optional cross-package link, etc.)
|
|
441
|
+
* would fail to insert. We coerce `''` → `NULL` for these columns before
|
|
442
|
+
* binding (see {@link coerceEmptyUuidValuesToNull}); this method tells that
|
|
443
|
+
* coercion which columns are UUID-typed.
|
|
444
|
+
*
|
|
445
|
+
* Resolution prefers the built schema (`getSchema().columns`), which already
|
|
446
|
+
* reflects all reconciliation — e.g. a `@foreignKey()` whose target class
|
|
447
|
+
* uses `idType: 'text'` is downgraded to `TEXT` and is therefore correctly
|
|
448
|
+
* excluded here. For STI children, columns live on the STI base table, so we
|
|
449
|
+
* union the base schema's columns. When no built schema is available (pure
|
|
450
|
+
* runtime-registered classes without a manifest) we fall back to field
|
|
451
|
+
* metadata, mirroring the schema-builder's field→SQL mapping.
|
|
452
|
+
*/
|
|
453
|
+
private resolveUuidColumnNames;
|
|
454
|
+
/**
|
|
455
|
+
* Coerce empty-string values to `NULL` for UUID-typed columns in the
|
|
456
|
+
* snake_cased write payload.
|
|
457
|
+
*
|
|
458
|
+
* Framework-level fix for the whole class of bug where a declared FK field
|
|
459
|
+
* defaults to `''` (the natural TypeScript default for `string`) and is left
|
|
460
|
+
* unset on insert — e.g. creating a ROOT entity whose optional self-reference
|
|
461
|
+
* (`previousFactId`, `parentPartnerId`, …) is empty. On Postgres `uuid`
|
|
462
|
+
* columns, `''` raises `invalid input syntax for type uuid`. Coercing to
|
|
463
|
+
* `NULL` here fixes every such field uniformly without per-field type churn
|
|
464
|
+
* or consumer-facing type changes. Mutates `data` in place.
|
|
465
|
+
*/
|
|
466
|
+
private coerceEmptyUuidValuesToNull;
|
|
467
|
+
/**
|
|
468
|
+
* Persists this object to the database using an upsert (insert or update).
|
|
469
|
+
*
|
|
470
|
+
* Steps performed on every save:
|
|
471
|
+
* 1. Runs field-level validation (`validateBeforeSave()`)
|
|
472
|
+
* 2. Executes `beforeSave` interceptors (e.g. tenant injection)
|
|
473
|
+
* 3. Assigns a UUID `id` if not already set
|
|
474
|
+
* 4. Generates a `slug` via `getSlug()` if not already set
|
|
475
|
+
* 5. Updates `updated_at` (and sets `created_at` on first save)
|
|
476
|
+
* 6. Upserts the row with automatic retry (3 attempts, 500 ms backoff)
|
|
477
|
+
* 7. Executes `afterSave` interceptors
|
|
478
|
+
* 8. Triggers embedding generation in the background if configured
|
|
479
|
+
*
|
|
480
|
+
* For STI classes, validates that `_meta_type` is present and correct
|
|
481
|
+
* before writing to the database.
|
|
482
|
+
*
|
|
483
|
+
* @returns This instance after saving (enables chaining)
|
|
484
|
+
* @throws {ValidationError} If a required field is missing or a unique constraint is violated
|
|
485
|
+
* @throws {DatabaseError} If the table does not exist (`DB_SCHEMA_MISSING`) or the query fails
|
|
486
|
+
* @throws {RuntimeError} For any other unexpected failure during save
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const product = new Product({ db: myDb, name: 'Widget', price: 9.99 });
|
|
491
|
+
* await product.initialize();
|
|
492
|
+
* await product.save();
|
|
493
|
+
* console.log(product.id); // UUID assigned during save
|
|
494
|
+
*
|
|
495
|
+
* // Update
|
|
496
|
+
* product.price = 14.99;
|
|
497
|
+
* await product.save();
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
save(): Promise<this>;
|
|
501
|
+
/**
|
|
502
|
+
* Detects tenant-boundary errors that must propagate from `save()` unwrapped.
|
|
503
|
+
*
|
|
504
|
+
* Matches both core's {@link TenantIsolationError} and the duck-typed
|
|
505
|
+
* tenancy-package errors (`TenantIsolationError` / `TenantContextError`) that
|
|
506
|
+
* the `beforeSave` interceptor throws. Those tenancy classes extend plain
|
|
507
|
+
* `Error` — core cannot import the tenancy package (the dependency runs the
|
|
508
|
+
* other way) — so they are matched by their stable `code` constants, with a
|
|
509
|
+
* class-name fallback for resilience.
|
|
510
|
+
*/
|
|
511
|
+
private isTenantContractError;
|
|
512
|
+
/**
|
|
513
|
+
* Validates object state before saving
|
|
514
|
+
* Override in subclasses to add custom validation logic
|
|
515
|
+
*/
|
|
516
|
+
protected validateBeforeSave(): Promise<void>;
|
|
517
|
+
/**
|
|
518
|
+
* Validates cross-package references that opted in via `validate: true`.
|
|
519
|
+
*
|
|
520
|
+
* Iterates registered fields of type `crossPackageRef`. For each one whose
|
|
521
|
+
* field options include `validate: true` AND has a non-empty value, looks up
|
|
522
|
+
* the referenced object via the target package's manifest and throws
|
|
523
|
+
* `ValidationError` if the target row does not exist.
|
|
524
|
+
*
|
|
525
|
+
* Empty/null/undefined values are treated as "no reference set" and skipped.
|
|
526
|
+
* Fields without `validate: true` are always skipped (the registered metadata
|
|
527
|
+
* still powers eager loading and `loadRelated()`).
|
|
528
|
+
*/
|
|
529
|
+
protected validateCrossPackageRefs(): Promise<void>;
|
|
530
|
+
/**
|
|
531
|
+
* Gets the value of a field on this object
|
|
532
|
+
*/
|
|
533
|
+
protected getFieldValue(fieldName: string): any;
|
|
534
|
+
/**
|
|
535
|
+
* Gets the value of a property.
|
|
536
|
+
*
|
|
537
|
+
* @param key - Property name to get value from
|
|
538
|
+
* @returns The property value
|
|
539
|
+
*/
|
|
540
|
+
protected getPropertyValue(key: string): any;
|
|
541
|
+
/**
|
|
542
|
+
* Classifies a raw database driver error message as a unique-constraint or
|
|
543
|
+
* not-null-constraint violation, across SQLite, PostgreSQL and DuckDB.
|
|
544
|
+
*
|
|
545
|
+
* `@happyvertical/sql` does not normalize driver errors, so each dialect's
|
|
546
|
+
* native wording is matched case-insensitively. Returns `null` when the
|
|
547
|
+
* message is not a recognized unique/not-null violation (the caller then
|
|
548
|
+
* falls back to a generic `DatabaseError`). Kept as a pure static so the
|
|
549
|
+
* cross-dialect matching can be unit-tested directly without a live PG/DuckDB
|
|
550
|
+
* connection (#1378).
|
|
551
|
+
*
|
|
552
|
+
* @param message - The raw driver error message.
|
|
553
|
+
* @returns `'unique'`, `'not_null'`, or `null`.
|
|
554
|
+
*/
|
|
555
|
+
static classifyConstraintError(message: string): 'unique' | 'not_null' | null;
|
|
556
|
+
/**
|
|
557
|
+
* Extracts field name from database constraint error messages.
|
|
558
|
+
*
|
|
559
|
+
* Handles SQLite, PostgreSQL and DuckDB phrasings. Returns
|
|
560
|
+
* `'unknown_field'` when no column name can be recovered.
|
|
561
|
+
*/
|
|
562
|
+
protected extractConstraintField(errorMessage: string): string;
|
|
563
|
+
/**
|
|
564
|
+
* Hydrates this object from the database using its `id` property.
|
|
565
|
+
*
|
|
566
|
+
* Queries the database for a row matching `{ id: this._id }` and calls
|
|
567
|
+
* `loadDataFromDb()` if found. Uses a 3-attempt retry with 250 ms initial
|
|
568
|
+
* delay to handle transient failures.
|
|
569
|
+
*
|
|
570
|
+
* Called automatically by `initialize()` when `options.id` is provided.
|
|
571
|
+
* Typically you do not need to call this directly.
|
|
572
|
+
*
|
|
573
|
+
* @returns Promise that resolves when loading is complete (no-op if not found)
|
|
574
|
+
* @throws {ValidationError} If `this._id` is not set
|
|
575
|
+
* @throws {DatabaseError} If the query fails after all retries
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* const product = new Product({ db: myDb });
|
|
580
|
+
* await product.initialize();
|
|
581
|
+
* product._id = 'some-uuid';
|
|
582
|
+
* await product.loadFromId(); // hydrates from DB
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
loadFromId(): Promise<void>;
|
|
586
|
+
/**
|
|
587
|
+
* Hydrates this object from the database using its `slug` (and `context`).
|
|
588
|
+
*
|
|
589
|
+
* Queries for a row matching `{ slug, context }`. The `context` defaults to
|
|
590
|
+
* an empty string when not provided. Calls `loadDataFromDb()` if a matching
|
|
591
|
+
* row is found.
|
|
592
|
+
*
|
|
593
|
+
* Called automatically by `initialize()` when `options.slug` is provided and
|
|
594
|
+
* no `options.id` is set. Typically you do not need to call this directly.
|
|
595
|
+
*
|
|
596
|
+
* @returns Promise that resolves when loading is complete (no-op if not found)
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* const product = new Product({ db: myDb, slug: 'my-widget', context: 'shop' });
|
|
601
|
+
* await product.initialize(); // calls loadFromSlug() automatically
|
|
602
|
+
* console.log(product.name);
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
loadFromSlug(): Promise<void>;
|
|
606
|
+
/**
|
|
607
|
+
* Serializes this instance into the "content body" injected into the AI
|
|
608
|
+
* prompts used by {@link is}, {@link do}, and {@link describe} so those
|
|
609
|
+
* methods reason over the object's own field data, not just the caller's
|
|
610
|
+
* instruction string.
|
|
611
|
+
*
|
|
612
|
+
* Uses {@link toPublicJSON} (never {@link toJSON}) so that
|
|
613
|
+
* `@field({ sensitive: true })` values — API secrets, credentials, tax IDs —
|
|
614
|
+
* are never sent to the model. The serialized payload is truncated to
|
|
615
|
+
* `maxLength` characters as a coarse token-budget guard for large instances;
|
|
616
|
+
* truncation appends a clear marker so the model knows the data was cut.
|
|
617
|
+
*
|
|
618
|
+
* @param maxLength - Maximum characters of object data to include
|
|
619
|
+
* (defaults to {@link AI_PROMPT_DATA_MAX_LENGTH}). A non-positive value
|
|
620
|
+
* disables truncation.
|
|
621
|
+
* @returns A JSON string of the object's public (sensitive-stripped) fields
|
|
622
|
+
*/
|
|
623
|
+
private serializeForAiPrompt;
|
|
624
|
+
/**
|
|
625
|
+
* Builds the optional "content body" section prepended to the AI prompts in
|
|
626
|
+
* {@link is}, {@link do}, and {@link describe}.
|
|
627
|
+
*
|
|
628
|
+
* Returns an empty string when the caller opts out with `includeData: false`
|
|
629
|
+
* — used by callers that already curate the object's relevant fields into
|
|
630
|
+
* their own instruction/criteria string (so the data is not duplicated, and
|
|
631
|
+
* the prompt stays exactly as the caller authored it). Otherwise it wraps
|
|
632
|
+
* {@link serializeForAiPrompt} in `--- Beginning/End of content ---`
|
|
633
|
+
* delimiters so the methods reason over the instance's own data by default.
|
|
634
|
+
*
|
|
635
|
+
* @param includeData - `false` to omit the section; any other value (incl.
|
|
636
|
+
* `undefined`) injects it
|
|
637
|
+
* @param maxLength - Forwarded to {@link serializeForAiPrompt} as the
|
|
638
|
+
* truncation budget
|
|
639
|
+
* @returns The content-body section (with a trailing newline) or `''`
|
|
640
|
+
*/
|
|
641
|
+
private buildAiContentSection;
|
|
642
|
+
/**
|
|
643
|
+
* Evaluates whether this object satisfies the given natural-language criteria using AI.
|
|
644
|
+
*
|
|
645
|
+
* Injects the object's own public field data (via {@link toPublicJSON}, so
|
|
646
|
+
* `@field({ sensitive: true })` values are excluded) into the prompt as the
|
|
647
|
+
* "content body", then asks the AI whether that data meets the criteria and
|
|
648
|
+
* to reply with a `{ result: boolean }` JSON response. Uses any AI-callable
|
|
649
|
+
* tools registered on this class (via `@smrt({ ai })`) as part of the
|
|
650
|
+
* function-calling context.
|
|
651
|
+
*
|
|
652
|
+
* @param criteria - Natural-language description of the condition to evaluate
|
|
653
|
+
* @param options - AI message options passed to `ai.message()` (e.g. model
|
|
654
|
+
* override). Two non-standard control keys are consumed here and not
|
|
655
|
+
* forwarded to `ai.message()`:
|
|
656
|
+
* - `includeData: false` — omit the injected object "content body" (for
|
|
657
|
+
* callers that already curate the relevant fields into `criteria`).
|
|
658
|
+
* - `maxDataLength` (number of characters) — override the injected
|
|
659
|
+
* object-data truncation limit.
|
|
660
|
+
* @returns `true` if the object meets the criteria, `false` otherwise
|
|
661
|
+
* @throws Error if the AI returns a non-boolean or malformed JSON response
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* const article = await articles.get('article-uuid');
|
|
666
|
+
* const isSuitable = await article.is('appropriate for a general audience');
|
|
667
|
+
* if (isSuitable) await article.publish();
|
|
668
|
+
* ```
|
|
669
|
+
*
|
|
670
|
+
* @see {@link do} for open-ended instructions instead of boolean checks
|
|
671
|
+
*/
|
|
672
|
+
is(criteria: string, options?: any): Promise<any>;
|
|
673
|
+
/**
|
|
674
|
+
* Performs a freeform operation on this object using AI instructions.
|
|
675
|
+
*
|
|
676
|
+
* Injects the object's own public field data (via {@link toPublicJSON}, so
|
|
677
|
+
* `@field({ sensitive: true })` values are excluded) into the prompt as the
|
|
678
|
+
* "content body" the instructions operate on, then returns the raw text
|
|
679
|
+
* response. Unlike `is()`, this method does not constrain the response
|
|
680
|
+
* format — use it for transformations, summaries, extractions, or any
|
|
681
|
+
* open-ended AI task.
|
|
682
|
+
*
|
|
683
|
+
* Uses any AI-callable tools registered on this class (via `@smrt({ ai })`)
|
|
684
|
+
* as part of the function-calling context.
|
|
685
|
+
*
|
|
686
|
+
* @param instructions - Natural-language instructions for the AI to follow
|
|
687
|
+
* @param options - AI message options passed to `ai.message()` (e.g. model
|
|
688
|
+
* override). Two non-standard control keys are consumed here and not
|
|
689
|
+
* forwarded to `ai.message()`:
|
|
690
|
+
* - `includeData: false` — omit the injected object "content body" (for
|
|
691
|
+
* callers that already curate the relevant fields into `instructions`).
|
|
692
|
+
* - `maxDataLength` (number of characters) — override the injected
|
|
693
|
+
* object-data truncation limit.
|
|
694
|
+
* @returns The raw AI response string
|
|
695
|
+
*
|
|
696
|
+
* @example
|
|
697
|
+
* ```typescript
|
|
698
|
+
* const article = await articles.get('article-uuid');
|
|
699
|
+
* const summary = await article.do('summarize this article in 3 bullet points');
|
|
700
|
+
* const translated = await article.do('translate the title and body to Spanish');
|
|
701
|
+
* ```
|
|
702
|
+
*
|
|
703
|
+
* @see {@link is} for boolean criteria checks
|
|
704
|
+
*/
|
|
705
|
+
do(instructions: string, options?: any): Promise<string>;
|
|
706
|
+
/**
|
|
707
|
+
* Generates a description of this object using AI (Issue #52)
|
|
708
|
+
*
|
|
709
|
+
* Creates a concise, human-readable description based on the object's content
|
|
710
|
+
* and properties. The object's own public field data (via
|
|
711
|
+
* {@link toPublicJSON}, so `@field({ sensitive: true })` values are excluded)
|
|
712
|
+
* is injected into the prompt as the "content body" the description is built
|
|
713
|
+
* from. Useful for summaries, previews, and documentation.
|
|
714
|
+
*
|
|
715
|
+
* @param options - AI message options (can include style, length, focus,
|
|
716
|
+
* etc.). Two non-standard control keys are consumed here and not forwarded
|
|
717
|
+
* to `ai.message()`:
|
|
718
|
+
* - `includeData: false` — omit the injected object "content body".
|
|
719
|
+
* - `maxDataLength` (number of characters) — override the injected
|
|
720
|
+
* object-data truncation limit.
|
|
721
|
+
* @returns Promise resolving to the AI-generated description
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```typescript
|
|
725
|
+
* const product = await products.get('product-123');
|
|
726
|
+
* const description = await product.describe();
|
|
727
|
+
* // "A high-quality widget for home improvement..."
|
|
728
|
+
*
|
|
729
|
+
* // With custom options
|
|
730
|
+
* const shortDesc = await product.describe({ maxTokens: 50 });
|
|
731
|
+
* // "Premium widget, steel construction"
|
|
732
|
+
* ```
|
|
733
|
+
*/
|
|
734
|
+
describe(options?: any): Promise<string>;
|
|
735
|
+
/**
|
|
736
|
+
* Runs a lifecycle hook if it's defined in the object's configuration
|
|
737
|
+
*
|
|
738
|
+
* @param hookName - Name of the hook to run (e.g., 'beforeDelete', 'afterDelete')
|
|
739
|
+
* @returns Promise that resolves when the hook completes
|
|
740
|
+
*/
|
|
741
|
+
protected runHook(hookName: string): Promise<void>;
|
|
742
|
+
/**
|
|
743
|
+
* Deletes this object from the database.
|
|
744
|
+
*
|
|
745
|
+
* Runs the full lifecycle in order:
|
|
746
|
+
* 1. `beforeDelete` interceptors (e.g. tenant validation)
|
|
747
|
+
* 2. `beforeDelete` lifecycle hook (defined in `@smrt({ hooks })`)
|
|
748
|
+
* 3. Database row deletion
|
|
749
|
+
* 4. `afterDelete` lifecycle hook
|
|
750
|
+
* 5. `afterDelete` interceptors
|
|
751
|
+
*
|
|
752
|
+
* Prefer `collection.delete(id)` from application code — it loads the
|
|
753
|
+
* object first (returning `false` when not found) before calling this method.
|
|
754
|
+
*
|
|
755
|
+
* @returns Promise that resolves when deletion is complete
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```typescript
|
|
759
|
+
* const product = await products.get('product-uuid');
|
|
760
|
+
* if (product) await product.delete();
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
delete(): Promise<void>;
|
|
764
|
+
/**
|
|
765
|
+
* Invalidate cached collection reads after a successful mutation
|
|
766
|
+
* (issue #1498).
|
|
767
|
+
*
|
|
768
|
+
* Always drops this table's in-process entries — a no-op when nothing
|
|
769
|
+
* opted into caching. When the table is cached cross-process (see
|
|
770
|
+
* {@link shouldBroadcastCacheInvalidation}), the invalidation is also
|
|
771
|
+
* broadcast to peer replicas over the database adapter's notification
|
|
772
|
+
* capability, fire-and-forget. Cache maintenance must never fail the
|
|
773
|
+
* write that triggered it.
|
|
774
|
+
*/
|
|
775
|
+
private invalidateCollectionReadCache;
|
|
776
|
+
/**
|
|
777
|
+
* Decide whether a mutation should broadcast a cross-process cache
|
|
778
|
+
* invalidation. Invalidation is table-scoped, so the decision must be too:
|
|
779
|
+
*
|
|
780
|
+
* 1. A per-call `crossProcess` cached read in this process registered
|
|
781
|
+
* interest in the table — broadcast even without model-level config.
|
|
782
|
+
* 2. This class's resolved `@smrt({ cache })` config sets `crossProcess`.
|
|
783
|
+
* 3. Any other STI hierarchy member sharing the table resolves to a
|
|
784
|
+
* `crossProcess` config — a child that opted out with `cache: false`
|
|
785
|
+
* still mutates the shared table its base/siblings are caching.
|
|
786
|
+
*/
|
|
787
|
+
private shouldBroadcastCacheInvalidation;
|
|
788
|
+
/**
|
|
789
|
+
* Check if a relationship has been loaded
|
|
790
|
+
*
|
|
791
|
+
* @param fieldName - Name of the relationship field
|
|
792
|
+
* @returns True if the relationship is loaded, false otherwise
|
|
793
|
+
* @example
|
|
794
|
+
* ```typescript
|
|
795
|
+
* if (order.isRelatedLoaded('customer')) {
|
|
796
|
+
* console.log('Customer already loaded');
|
|
797
|
+
* }
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
isRelatedLoaded(fieldName: string): boolean;
|
|
801
|
+
/**
|
|
802
|
+
* Lazy-loads a `foreignKey` or `crossPackageRef` relationship and caches the
|
|
803
|
+
* result.
|
|
804
|
+
*
|
|
805
|
+
* Looks up the relationship metadata in the ObjectRegistry, reads the
|
|
806
|
+
* foreign key value on this object, and fetches the related object from
|
|
807
|
+
* the database. Subsequent calls return the cached value without hitting
|
|
808
|
+
* the database again.
|
|
809
|
+
*
|
|
810
|
+
* For STI relationships, the correct subclass is determined by reading
|
|
811
|
+
* `_meta_type` from the database row before instantiation.
|
|
812
|
+
*
|
|
813
|
+
* Enforces tenant isolation: if this object and the loaded target both carry
|
|
814
|
+
* a non-null `tenantId` that differ, a {@link TenantIsolationError} is thrown
|
|
815
|
+
* (unless `opts.allowCrossTenant` is set). The check is a no-op for
|
|
816
|
+
* global/null-tenant models and same-tenant loads, so it only catches genuine
|
|
817
|
+
* cross-tenant leaks (Issue #1321).
|
|
818
|
+
*
|
|
819
|
+
* @param fieldName - Name of the `@foreignKey()` or `@crossPackageRef()`
|
|
820
|
+
* decorated property
|
|
821
|
+
* @param opts - Optional loader options; see {@link LoadRelatedOptions}
|
|
822
|
+
* @returns The related object, or `null` if the foreign key is empty
|
|
823
|
+
* @throws {RuntimeError} If `fieldName` is not a `foreignKey` or
|
|
824
|
+
* `crossPackageRef` relationship, or the target class is not found in the
|
|
825
|
+
* ObjectRegistry
|
|
826
|
+
* @throws {TenantIsolationError} If the target belongs to a different,
|
|
827
|
+
* non-null tenant and `opts.allowCrossTenant` is not set
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```typescript
|
|
831
|
+
* // class Order { @foreignKey(Customer) customerId: string = ''; }
|
|
832
|
+
* const customer = await order.loadRelated('customerId');
|
|
833
|
+
* console.log(customer?.name);
|
|
834
|
+
* ```
|
|
835
|
+
*
|
|
836
|
+
* @see {@link getRelated} for a convenience wrapper that auto-detects relationship type
|
|
837
|
+
*/
|
|
838
|
+
loadRelated(fieldName: string, opts?: LoadRelatedOptions): Promise<any>;
|
|
839
|
+
/**
|
|
840
|
+
* Guards a loaded relationship target against cross-tenant access.
|
|
841
|
+
*
|
|
842
|
+
* Throws {@link TenantIsolationError} when this object and `loaded` both carry
|
|
843
|
+
* a non-null `tenantId` that differ — the genuine cross-tenant leak. It is a
|
|
844
|
+
* no-op when `allowCrossTenant === true`, when `loaded` is `null`, when either
|
|
845
|
+
* side has a `null`/`undefined` tenant (global / non-tenant-scoped models),
|
|
846
|
+
* and when both sides share the same tenant (Issue #1321).
|
|
847
|
+
*
|
|
848
|
+
* `loaded` may be a single related object or an array (oneToMany / manyToMany);
|
|
849
|
+
* arrays are validated per item. This runs on both fresh loads and cache hits,
|
|
850
|
+
* so a cache populated by an eager `include` load — or by a prior
|
|
851
|
+
* `allowCrossTenant` load — cannot leak cross-tenant data through a later
|
|
852
|
+
* guarded call.
|
|
853
|
+
*
|
|
854
|
+
* @param loaded - The loaded related object, or array of objects.
|
|
855
|
+
* @param fieldName - The relationship field name (for error context).
|
|
856
|
+
* @param allowCrossTenant - When exactly `true`, bypasses the guard entirely.
|
|
857
|
+
*/
|
|
858
|
+
private assertRelatedTenant;
|
|
859
|
+
/**
|
|
860
|
+
* Load related objects for oneToMany or manyToMany fields (lazy loading)
|
|
861
|
+
*
|
|
862
|
+
* Loads all related objects from the database. For oneToMany, queries by
|
|
863
|
+
* the inverse foreign key. For manyToMany, queries through the join table.
|
|
864
|
+
*
|
|
865
|
+
* Enforces tenant isolation per item: if this object and a loaded target both
|
|
866
|
+
* carry a non-null `tenantId` that differ, a {@link TenantIsolationError} is
|
|
867
|
+
* thrown (unless `opts.allowCrossTenant` is set). The check is a no-op for
|
|
868
|
+
* global/null-tenant models and same-tenant loads, so it only catches genuine
|
|
869
|
+
* cross-tenant leaks (Issue #1321).
|
|
870
|
+
*
|
|
871
|
+
* @param fieldName - Name of the oneToMany or manyToMany field
|
|
872
|
+
* @param opts - Optional loader options; see {@link LoadRelatedOptions}
|
|
873
|
+
* @returns Promise resolving to array of related objects
|
|
874
|
+
* @throws {RuntimeError} If the field is not a relationship or not implemented
|
|
875
|
+
* @throws {TenantIsolationError} If any loaded item belongs to a different,
|
|
876
|
+
* non-null tenant and `opts.allowCrossTenant` is not set
|
|
877
|
+
* @example
|
|
878
|
+
* ```typescript
|
|
879
|
+
* // Given: class Customer with orders = oneToMany(Order)
|
|
880
|
+
* const orders = await customer.loadRelatedMany('orders');
|
|
881
|
+
* console.log(`${orders.length} orders found`);
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
loadRelatedMany(fieldName: string, opts?: LoadRelatedOptions): Promise<any[]>;
|
|
885
|
+
/**
|
|
886
|
+
* Resolves the junction-table coordinates for a manyToMany relationship.
|
|
887
|
+
*
|
|
888
|
+
* Discovers `through`, source-side column, and target-side column from the
|
|
889
|
+
* registered field metadata. Falls back to convention (`<class>_id`) when
|
|
890
|
+
* `sourceKey` / `targetKey` are not explicitly set.
|
|
891
|
+
*/
|
|
892
|
+
protected resolveManyToManyJoin(fieldName: string, relationship: {
|
|
893
|
+
sourceClass: string;
|
|
894
|
+
targetClass: string;
|
|
895
|
+
options?: any;
|
|
896
|
+
}): Promise<{
|
|
897
|
+
through: string;
|
|
898
|
+
sourceColumn: string;
|
|
899
|
+
targetColumn: string;
|
|
900
|
+
targetClassName: string;
|
|
901
|
+
}>;
|
|
902
|
+
/**
|
|
903
|
+
* Get a related object, loading it if not already loaded
|
|
904
|
+
*
|
|
905
|
+
* Convenience method that checks if the relationship is loaded and
|
|
906
|
+
* loads it if necessary. Automatically detects foreignKey vs oneToMany/manyToMany.
|
|
907
|
+
*
|
|
908
|
+
* Tenant isolation is enforced by the underlying loaders; see
|
|
909
|
+
* {@link loadRelated} and {@link loadRelatedMany}.
|
|
910
|
+
*
|
|
911
|
+
* @param fieldName - Name of the relationship field
|
|
912
|
+
* @param opts - Optional loader options; see {@link LoadRelatedOptions}
|
|
913
|
+
* @returns Promise resolving to the related object(s)
|
|
914
|
+
* @throws {TenantIsolationError} If a loaded target belongs to a different,
|
|
915
|
+
* non-null tenant and `opts.allowCrossTenant` is not set
|
|
916
|
+
* @example
|
|
917
|
+
* ```typescript
|
|
918
|
+
* // Loads customer if not already loaded
|
|
919
|
+
* const customer = await order.getRelated('customerId');
|
|
920
|
+
*
|
|
921
|
+
* // Loads orders if not already loaded
|
|
922
|
+
* const orders = await customer.getRelated('orders');
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
getRelated(fieldName: string, opts?: LoadRelatedOptions): Promise<any>;
|
|
926
|
+
/**
|
|
927
|
+
* Get available AI-callable tools for this object
|
|
928
|
+
*
|
|
929
|
+
* Returns the pre-generated tool definitions from the manifest.
|
|
930
|
+
* Tools are generated at build time based on the @smrt decorator's AI config.
|
|
931
|
+
*
|
|
932
|
+
* @returns Array of AITool definitions for LLM function calling
|
|
933
|
+
* @example
|
|
934
|
+
* ```typescript
|
|
935
|
+
* const tools = document.getAvailableTools();
|
|
936
|
+
* console.log(`${tools.length} AI-callable methods available`);
|
|
937
|
+
* ```
|
|
938
|
+
*/
|
|
939
|
+
getAvailableTools(): AITool[];
|
|
940
|
+
/**
|
|
941
|
+
* Execute a tool call from AI on this object instance
|
|
942
|
+
*
|
|
943
|
+
* Validates the tool call against allowed methods and executes it with
|
|
944
|
+
* proper error handling and timing.
|
|
945
|
+
*
|
|
946
|
+
* @param toolCall - Tool call from AI response
|
|
947
|
+
* @returns Promise resolving to the tool call result
|
|
948
|
+
* @example
|
|
949
|
+
* ```typescript
|
|
950
|
+
* const toolCall = {
|
|
951
|
+
* id: 'call_123',
|
|
952
|
+
* type: 'function',
|
|
953
|
+
* function: {
|
|
954
|
+
* name: 'analyze',
|
|
955
|
+
* arguments: '{"type": "detailed"}'
|
|
956
|
+
* }
|
|
957
|
+
* };
|
|
958
|
+
*
|
|
959
|
+
* const result = await document.executeToolCall(toolCall);
|
|
960
|
+
* console.log(result.success ? result.result : result.error);
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
963
|
+
executeToolCall(toolCall: ToolCall): Promise<ToolCallResult>;
|
|
964
|
+
/**
|
|
965
|
+
* Stores a named value in the `_smrt_contexts` system table, scoped to this object.
|
|
966
|
+
*
|
|
967
|
+
* Context entries are keyed by `(owner_class, owner_id, scope, key, version)` and
|
|
968
|
+
* support an optional `confidence` score (0–1, default 1.0) for learned patterns.
|
|
969
|
+
* Calling `remember()` with the same scope+key upserts the existing entry.
|
|
970
|
+
*
|
|
971
|
+
* Requires `initialize()` to have been called (needs `this.systemDb`).
|
|
972
|
+
*
|
|
973
|
+
* @param options.id - Optional explicit ID for the context entry (auto-generated if omitted)
|
|
974
|
+
* @param options.scope - Hierarchical path scoping the context (e.g. `'parser/example.com'`)
|
|
975
|
+
* @param options.key - Lookup key within the scope (e.g. a normalized URL)
|
|
976
|
+
* @param options.value - Any JSON-serializable value to store
|
|
977
|
+
* @param options.metadata - Optional additional JSON metadata
|
|
978
|
+
* @param options.confidence - Confidence score (0–1, default 1.0)
|
|
979
|
+
* @param options.version - Schema version for the stored value (default 1)
|
|
980
|
+
* @param options.expiresAt - Optional expiry date after which `recall()` will ignore this entry
|
|
981
|
+
* @returns Promise that resolves when the context is stored
|
|
982
|
+
* @throws Error if `initialize()` has not been called
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```typescript
|
|
986
|
+
* await agent.remember({
|
|
987
|
+
* scope: 'parser/example.com',
|
|
988
|
+
* key: normalizedUrl,
|
|
989
|
+
* value: { patterns: ['regex1', 'regex2'] },
|
|
990
|
+
* confidence: 0.9,
|
|
991
|
+
* });
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @see {@link recall} to retrieve a single entry
|
|
995
|
+
* @see {@link recallAll} to retrieve all entries in a scope
|
|
996
|
+
* @see {@link forget} to delete a specific entry
|
|
997
|
+
*/
|
|
998
|
+
remember(options: {
|
|
999
|
+
id?: string;
|
|
1000
|
+
scope: string;
|
|
1001
|
+
key: string;
|
|
1002
|
+
value: any;
|
|
1003
|
+
metadata?: any;
|
|
1004
|
+
confidence?: number;
|
|
1005
|
+
version?: number;
|
|
1006
|
+
expiresAt?: Date;
|
|
1007
|
+
}): Promise<void>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Retrieves a single remembered context value for this object.
|
|
1010
|
+
*
|
|
1011
|
+
* Looks up the most recent (highest confidence, then highest version) entry
|
|
1012
|
+
* matching `(owner_class, owner_id, scope, key)`. Returns the JSON-parsed value
|
|
1013
|
+
* or `null` if no matching entry exists.
|
|
1014
|
+
*
|
|
1015
|
+
* When `includeAncestors: true`, walks up the scope hierarchy by progressively
|
|
1016
|
+
* removing the last path segment (e.g. `'a/b/c'` → `'a/b'` → `'a'` → `'global'`)
|
|
1017
|
+
* until a match is found.
|
|
1018
|
+
*
|
|
1019
|
+
* @param options.scope - Scope path to search (e.g. `'parser/example.com/article'`)
|
|
1020
|
+
* @param options.key - Lookup key within the scope
|
|
1021
|
+
* @param options.includeAncestors - If `true`, fall back to parent scopes (default `false`)
|
|
1022
|
+
* @param options.minConfidence - Only return entries at or above this confidence (0–1)
|
|
1023
|
+
* @returns The stored value (parsed from JSON), or `null` if not found
|
|
1024
|
+
* @throws Error if `initialize()` has not been called
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```typescript
|
|
1028
|
+
* const strategy = await agent.recall({
|
|
1029
|
+
* scope: 'parser/example.com/article',
|
|
1030
|
+
* key: normalizedUrl,
|
|
1031
|
+
* includeAncestors: true,
|
|
1032
|
+
* minConfidence: 0.6,
|
|
1033
|
+
* });
|
|
1034
|
+
* ```
|
|
1035
|
+
*
|
|
1036
|
+
* @see {@link remember} to store a context entry
|
|
1037
|
+
* @see {@link recallAll} to retrieve all entries in a scope
|
|
1038
|
+
*/
|
|
1039
|
+
recall(options: {
|
|
1040
|
+
scope: string;
|
|
1041
|
+
key: string;
|
|
1042
|
+
includeAncestors?: boolean;
|
|
1043
|
+
minConfidence?: number;
|
|
1044
|
+
}): Promise<any | null>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Retrieves all remembered context entries for this object in a scope.
|
|
1047
|
+
*
|
|
1048
|
+
* Returns a `Map<key, value>` for every entry owned by this object that matches
|
|
1049
|
+
* the scope and optional filters. When `includeDescendants: true`, a LIKE query
|
|
1050
|
+
* (`scope%`) matches the scope itself and all child scopes.
|
|
1051
|
+
*
|
|
1052
|
+
* @param options.scope - Optional scope path filter; omit to retrieve all scopes
|
|
1053
|
+
* @param options.includeDescendants - If `true`, match `scope` and all child scopes (default `false`)
|
|
1054
|
+
* @param options.minConfidence - Only include entries at or above this confidence (0–1)
|
|
1055
|
+
* @returns `Map<string, any>` of key → JSON-parsed value pairs
|
|
1056
|
+
* @throws Error if `initialize()` has not been called
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```typescript
|
|
1060
|
+
* const strategies = await agent.recallAll({
|
|
1061
|
+
* scope: 'parser/example.com',
|
|
1062
|
+
* minConfidence: 0.5,
|
|
1063
|
+
* });
|
|
1064
|
+
* for (const [url, pattern] of strategies) {
|
|
1065
|
+
* console.log(`Cached pattern for ${url}:`, pattern);
|
|
1066
|
+
* }
|
|
1067
|
+
* ```
|
|
1068
|
+
*
|
|
1069
|
+
* @see {@link recall} to retrieve a single entry by key
|
|
1070
|
+
* @see {@link forgetScope} to delete all entries in a scope
|
|
1071
|
+
*/
|
|
1072
|
+
recallAll(options?: {
|
|
1073
|
+
scope?: string;
|
|
1074
|
+
includeDescendants?: boolean;
|
|
1075
|
+
minConfidence?: number;
|
|
1076
|
+
}): Promise<Map<string, any>>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Deletes a specific remembered context entry for this object.
|
|
1079
|
+
*
|
|
1080
|
+
* Removes the entry matching `(owner_class, owner_id, scope, key)`. A no-op
|
|
1081
|
+
* if the entry does not exist.
|
|
1082
|
+
*
|
|
1083
|
+
* @param options.scope - Scope path of the entry to delete
|
|
1084
|
+
* @param options.key - Key of the entry to delete
|
|
1085
|
+
* @returns Promise that resolves when the entry is deleted
|
|
1086
|
+
* @throws Error if `initialize()` has not been called
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* await agent.forget({ scope: 'parser/example.com', key: normalizedUrl });
|
|
1091
|
+
* ```
|
|
1092
|
+
*
|
|
1093
|
+
* @see {@link forgetScope} to delete all entries in a scope at once
|
|
1094
|
+
* @see {@link remember} to store a context entry
|
|
1095
|
+
*/
|
|
1096
|
+
forget(options: {
|
|
1097
|
+
scope: string;
|
|
1098
|
+
key: string;
|
|
1099
|
+
}): Promise<void>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Deletes all remembered context entries in a scope for this object.
|
|
1102
|
+
*
|
|
1103
|
+
* When `includeDescendants: true`, uses a LIKE query (`scope%`) that matches
|
|
1104
|
+
* the scope itself and all child scopes (e.g. `'parser/example.com'` also
|
|
1105
|
+
* deletes `'parser/example.com/article'`).
|
|
1106
|
+
*
|
|
1107
|
+
* @param options.scope - Scope path to clear
|
|
1108
|
+
* @param options.includeDescendants - If `true`, also delete all child scopes (default `false`)
|
|
1109
|
+
* @returns Number of context entries deleted
|
|
1110
|
+
* @throws Error if `initialize()` has not been called
|
|
1111
|
+
*
|
|
1112
|
+
* @example
|
|
1113
|
+
* ```typescript
|
|
1114
|
+
* const count = await agent.forgetScope({
|
|
1115
|
+
* scope: 'parser/example.com',
|
|
1116
|
+
* includeDescendants: true,
|
|
1117
|
+
* });
|
|
1118
|
+
* console.log(`Cleared ${count} cached strategies`);
|
|
1119
|
+
* ```
|
|
1120
|
+
*
|
|
1121
|
+
* @see {@link forget} to delete a single entry by key
|
|
1122
|
+
* @see {@link recallAll} to bulk-retrieve before clearing
|
|
1123
|
+
*/
|
|
1124
|
+
forgetScope(options: {
|
|
1125
|
+
scope: string;
|
|
1126
|
+
includeDescendants?: boolean;
|
|
1127
|
+
}): Promise<number>;
|
|
1128
|
+
/**
|
|
1129
|
+
* Generate embeddings for configured fields
|
|
1130
|
+
*
|
|
1131
|
+
* Creates embedding vectors for fields configured in the @smrt decorator
|
|
1132
|
+
* and stores them in the _smrt_embeddings system table. Uses content hashing
|
|
1133
|
+
* to detect changes and avoid regenerating unchanged content.
|
|
1134
|
+
*
|
|
1135
|
+
* @param options - Generation options
|
|
1136
|
+
* @returns Promise that resolves when embeddings are generated
|
|
1137
|
+
* @throws Error if no embedding configuration or database not initialized
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* // Generate embeddings for all configured fields
|
|
1142
|
+
* await article.generateEmbeddings();
|
|
1143
|
+
*
|
|
1144
|
+
* // Generate only for specific fields
|
|
1145
|
+
* await article.generateEmbeddings({ fields: ['title'] });
|
|
1146
|
+
*
|
|
1147
|
+
* // Force regeneration (ignore content hash)
|
|
1148
|
+
* await article.generateEmbeddings({ force: true });
|
|
1149
|
+
* ```
|
|
1150
|
+
*/
|
|
1151
|
+
generateEmbeddings(options?: GenerateEmbeddingsOptions): Promise<void>;
|
|
1152
|
+
/**
|
|
1153
|
+
* Get stored embedding for a field
|
|
1154
|
+
*
|
|
1155
|
+
* Retrieves the embedding vector for a specific field from storage.
|
|
1156
|
+
* Returns null if no embedding exists for the field.
|
|
1157
|
+
*
|
|
1158
|
+
* @param fieldName - Name of the field to get embedding for
|
|
1159
|
+
* @param model - Optional model name (defaults to configured model)
|
|
1160
|
+
* @returns Promise resolving to embedding vector or null
|
|
1161
|
+
*
|
|
1162
|
+
* @example
|
|
1163
|
+
* ```typescript
|
|
1164
|
+
* const embedding = await article.getEmbedding('title');
|
|
1165
|
+
* if (embedding) {
|
|
1166
|
+
* console.log(`Embedding has ${embedding.length} dimensions`);
|
|
1167
|
+
* }
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
getEmbedding(fieldName: string, model?: string): Promise<number[] | null>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Check if any embeddings are stale (content has changed)
|
|
1173
|
+
*
|
|
1174
|
+
* Compares content hashes of configured fields with stored embeddings
|
|
1175
|
+
* to determine if regeneration is needed.
|
|
1176
|
+
*
|
|
1177
|
+
* @returns Promise resolving to true if any embeddings are stale
|
|
1178
|
+
*
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```typescript
|
|
1181
|
+
* if (await article.hasStaleEmbeddings()) {
|
|
1182
|
+
* await article.generateEmbeddings();
|
|
1183
|
+
* }
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
hasStaleEmbeddings(): Promise<boolean>;
|
|
1187
|
+
/**
|
|
1188
|
+
* Clear all embeddings for this object
|
|
1189
|
+
*
|
|
1190
|
+
* Removes all stored embeddings from the _smrt_embeddings table.
|
|
1191
|
+
* Useful when deleting objects or resetting embedding state.
|
|
1192
|
+
*
|
|
1193
|
+
* @returns Promise that resolves when embeddings are cleared
|
|
1194
|
+
*
|
|
1195
|
+
* @example
|
|
1196
|
+
* ```typescript
|
|
1197
|
+
* await article.clearEmbeddings();
|
|
1198
|
+
* ```
|
|
1199
|
+
*/
|
|
1200
|
+
clearEmbeddings(): Promise<void>;
|
|
1201
|
+
}
|
|
1202
|
+
//# sourceMappingURL=object.d.ts.map
|