@objectstack/runtime 6.5.1 → 6.7.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/dist/index.d.cts CHANGED
@@ -71,6 +71,20 @@ declare class Runtime {
71
71
  getKernel(): ObjectKernel;
72
72
  }
73
73
 
74
+ /**
75
+ * Resolve the ObjectStack home directory used to store cwd-independent
76
+ * runtime data (default sqlite database, downloaded marketplace apps,
77
+ * installed plugin cache).
78
+ *
79
+ * Resolution order:
80
+ * 1. `OS_HOME` env var (absolute path; `~` expanded)
81
+ * 2. `~/.objectstack` (cross-platform user-home default)
82
+ *
83
+ * The directory is created lazily by callers that actually write to it
84
+ * (e.g. the sqlite driver's `mkdirSync(...)`); this helper does not
85
+ * touch the filesystem.
86
+ */
87
+ declare function resolveObjectStackHome(): string;
74
88
  declare const StandaloneStackConfigSchema: z.ZodObject<{
75
89
  databaseUrl: z.ZodOptional<z.ZodString>;
76
90
  databaseAuthToken: z.ZodOptional<z.ZodString>;
@@ -820,6 +834,30 @@ interface KernelManagerConfig {
820
834
  warn?: (...a: any[]) => void;
821
835
  error?: (...a: any[]) => void;
822
836
  };
837
+ /**
838
+ * Optional upstream-change detector. When set, every cache hit older
839
+ * than `staleCheckIntervalMs` triggers this probe before returning the
840
+ * cached kernel. Returning `true` evicts the kernel and forces a
841
+ * rebuild, so changes to the control-plane state that don't reach
842
+ * this process via push (marketplace installs, artifact republish,
843
+ * etc.) become visible without waiting for the LRU TTL to expire.
844
+ *
845
+ * The probe should be cheap (single small GET). Errors thrown here
846
+ * are caught and treated as "still fresh" so a brief upstream
847
+ * outage doesn't churn every cached kernel — the worst case is
848
+ * stale-by-`ttlMs`, which is what we had before adding the probe.
849
+ *
850
+ * `builtAtMs` is the kernel's `createdAt` time so the probe can
851
+ * compare against an upstream "last changed at" timestamp.
852
+ */
853
+ freshnessProbe?: (environmentId: string, builtAtMs: number) => Promise<boolean>;
854
+ /**
855
+ * Minimum gap between successive freshness probes for the same env.
856
+ * Defaults to 10 seconds — enough to avoid hammering the control
857
+ * plane on tight render loops while still keeping the user's
858
+ * post-install refresh perceived as immediate.
859
+ */
860
+ staleCheckIntervalMs?: number;
823
861
  }
824
862
  /**
825
863
  * LRU + TTL cache of per-project {@link ObjectKernel} instances.
@@ -837,6 +875,8 @@ declare class KernelManager {
837
875
  private readonly logger;
838
876
  private readonly cache;
839
877
  private readonly pending;
878
+ private readonly freshnessProbe?;
879
+ private readonly staleCheckIntervalMs;
840
880
  constructor(config: KernelManagerConfig);
841
881
  /** Returns the currently cached environmentIds (ordered by insertion). */
842
882
  keys(): string[];
@@ -1716,6 +1756,24 @@ declare class ArtifactApiClient {
1716
1756
  commitId: string;
1717
1757
  publishedAt?: string | null;
1718
1758
  } | null>;
1759
+ /**
1760
+ * Cheap freshness probe — returns the env's `last_published_at`
1761
+ * (and best-effort current commit) without rebuilding the artifact.
1762
+ * Used by `KernelManager` on cache hits to detect when a per-env
1763
+ * kernel has been invalidated by an upstream change (marketplace
1764
+ * install/uninstall, artifact publish) so it can be rebuilt
1765
+ * without waiting for the 15-minute LRU TTL to expire.
1766
+ *
1767
+ * Returns `null` on definitive 404 / unknown env. Errors propagate
1768
+ * (caller decides whether to treat unreachable cloud as fresh or
1769
+ * stale — typically fresh, so a brief outage doesn't churn every
1770
+ * cached kernel).
1771
+ */
1772
+ getFreshness(environmentId: string): Promise<{
1773
+ environmentId: string;
1774
+ lastPublishedAt: string | null;
1775
+ commitId: string | null;
1776
+ } | null>;
1719
1777
  /** Drop cached entries for a project (and any matching hostname). */
1720
1778
  invalidate(environmentId: string): void;
1721
1779
  /** Drop everything. Used on shutdown / hot-reload. */
@@ -1839,10 +1897,9 @@ declare function createObjectOSStack(config: ObjectOSStackConfig): Promise<Objec
1839
1897
  *
1840
1898
  * Forwards `GET /api/v1/marketplace/*` from a tenant ObjectOS runtime to
1841
1899
  * the configured ObjectStack Cloud control-plane URL. The cloud endpoint
1842
- * (`packages/service-cloud/src/routes/marketplace.ts`) is unauthenticated
1843
- * and only exposes packages whose owner has opted in to the public catalog
1844
- * (`sys_package.marketplace_listed = true`) so the proxy passes through
1845
- * without any credentials.
1900
+ * is unauthenticated and only exposes packages whose owner has opted in
1901
+ * to the public catalog (`sys_package.marketplace_listed = true`) so the
1902
+ * proxy passes through without any credentials.
1846
1903
  *
1847
1904
  * Why proxy instead of direct browser → cloud:
1848
1905
  * - The Console SPA stays on the tenant origin, so no CORS configuration
@@ -2049,9 +2106,9 @@ declare function resolveCloudUrl(explicit?: string | null): string;
2049
2106
  * - a local file artifact (see {@link FileArtifactApiClient} +
2050
2107
  * {@link ArtifactEnvironmentRegistry})
2051
2108
  *
2052
- * The contract was extracted from `@objectstack/service-cloud` in Phase R
2053
- * so the runtime can express "fetch artifact + boot per-project kernel"
2054
- * without taking a dependency on the cloud control plane.
2109
+ * The contract lives in `@objectstack/runtime` so the runtime can
2110
+ * express "fetch artifact + boot per-project kernel" without taking a
2111
+ * dependency on the cloud control plane.
2055
2112
  */
2056
2113
 
2057
2114
  type IDataDriver$1 = Contracts.IDataDriver;
@@ -2521,4 +2578,4 @@ declare function actionBodyRunnerFactory(runner: ScriptRunner, opts: FactoryOpti
2521
2578
  timeoutMs?: number;
2522
2579
  }) => ((actionCtx: any) => Promise<unknown>) | undefined;
2523
2580
 
2524
- export { AppPlugin, ArtifactApiClient, type ArtifactApiClientConfig, ArtifactEnvironmentRegistry, type ArtifactEnvironmentRegistryConfig, ArtifactKernelFactory, type ArtifactKernelFactoryConfig, AuthProxyPlugin, type BackfillPlatformSsoClientsOptions, DEFAULT_CLOUD_URL, DEFAULT_RATE_LIMITS, type DefaultHostConfigOptions, type DefaultHostConfigResult, type DispatcherPluginConfig, DriverPlugin, type EnvironmentArtifactResponse, type EnvironmentDriverRegistry, type EnvironmentKernelFactory, type EnvironmentRuntimeConfig, FileArtifactApiClient, type FileArtifactApiClientConfig, HttpDispatcher, type HttpDispatcherResult, type HttpProtocolContext, HttpServer, KernelManager, type KernelManagerConfig, type LoadArtifactBundleOptions, MarketplaceInstallLocalPlugin, type MarketplaceInstallLocalPluginConfig, MarketplaceProxyPlugin, type MarketplaceProxyPluginConfig, MiddlewareManager, type ObjectOSStackConfig, type ObjectOSStackResult, ObservabilityServicePlugin, type ObservabilityServicePluginOptions, PLATFORM_SSO_PROVIDER_ID, QuickJSScriptRunner, type QuickJSScriptRunnerOptions, type RateLimitBucketConfig, type RateLimitDecision, type RateLimitDefaults, type RateLimitStore, RateLimiter, type ResolvedHostname, Runtime, type RuntimeConfig, RuntimeConfigPlugin, type RuntimeConfigPluginConfig, SYSTEM_ENVIRONMENT_ID, SandboxError, type ScriptContext, type ScriptOrigin, type ScriptResult, type ScriptRunOptions, type ScriptRunner, type SecurityHeadersOptions, SeedLoaderService, type SeedPlatformSsoClientOptions, type StandaloneStackConfig, type StandaloneStackResult, type SystemEnvironmentPluginConfig, type TraceContext, UnimplementedScriptRunner, actionBodyRunnerFactory, backfillPlatformSsoClients, buildPlatformSsoRedirectUri, buildSecurityHeaders, collectBundleActions, collectBundleFunctions, collectBundleHooks, createDefaultHostConfig, createDispatcherPlugin, createObjectOSStack, createStandaloneStack, createSystemEnvironmentPlugin, derivePlatformSsoClientId, derivePlatformSsoClientSecret, extractRequestId, formatTraceparent, generateRequestId, hookBodyRunnerFactory, isHttpUrl, loadArtifactBundle, mergeRuntimeModule, parseTraceparent, readArtifactSource, resolveCloudUrl, resolveDefaultArtifactPath, resolveErrorReporter, resolveMetrics, resolveRequestId, seedPlatformSsoClient };
2581
+ export { AppPlugin, ArtifactApiClient, type ArtifactApiClientConfig, ArtifactEnvironmentRegistry, type ArtifactEnvironmentRegistryConfig, ArtifactKernelFactory, type ArtifactKernelFactoryConfig, AuthProxyPlugin, type BackfillPlatformSsoClientsOptions, DEFAULT_CLOUD_URL, DEFAULT_RATE_LIMITS, type DefaultHostConfigOptions, type DefaultHostConfigResult, type DispatcherPluginConfig, DriverPlugin, type EnvironmentArtifactResponse, type EnvironmentDriverRegistry, type EnvironmentKernelFactory, type EnvironmentRuntimeConfig, FileArtifactApiClient, type FileArtifactApiClientConfig, HttpDispatcher, type HttpDispatcherResult, type HttpProtocolContext, HttpServer, KernelManager, type KernelManagerConfig, type LoadArtifactBundleOptions, MarketplaceInstallLocalPlugin, type MarketplaceInstallLocalPluginConfig, MarketplaceProxyPlugin, type MarketplaceProxyPluginConfig, MiddlewareManager, type ObjectOSStackConfig, type ObjectOSStackResult, ObservabilityServicePlugin, type ObservabilityServicePluginOptions, PLATFORM_SSO_PROVIDER_ID, QuickJSScriptRunner, type QuickJSScriptRunnerOptions, type RateLimitBucketConfig, type RateLimitDecision, type RateLimitDefaults, type RateLimitStore, RateLimiter, type ResolvedHostname, Runtime, type RuntimeConfig, RuntimeConfigPlugin, type RuntimeConfigPluginConfig, SYSTEM_ENVIRONMENT_ID, SandboxError, type ScriptContext, type ScriptOrigin, type ScriptResult, type ScriptRunOptions, type ScriptRunner, type SecurityHeadersOptions, SeedLoaderService, type SeedPlatformSsoClientOptions, type StandaloneStackConfig, type StandaloneStackResult, type SystemEnvironmentPluginConfig, type TraceContext, UnimplementedScriptRunner, actionBodyRunnerFactory, backfillPlatformSsoClients, buildPlatformSsoRedirectUri, buildSecurityHeaders, collectBundleActions, collectBundleFunctions, collectBundleHooks, createDefaultHostConfig, createDispatcherPlugin, createObjectOSStack, createStandaloneStack, createSystemEnvironmentPlugin, derivePlatformSsoClientId, derivePlatformSsoClientSecret, extractRequestId, formatTraceparent, generateRequestId, hookBodyRunnerFactory, isHttpUrl, loadArtifactBundle, mergeRuntimeModule, parseTraceparent, readArtifactSource, resolveCloudUrl, resolveDefaultArtifactPath, resolveErrorReporter, resolveMetrics, resolveObjectStackHome, resolveRequestId, seedPlatformSsoClient };
package/dist/index.d.ts CHANGED
@@ -71,6 +71,20 @@ declare class Runtime {
71
71
  getKernel(): ObjectKernel;
72
72
  }
73
73
 
74
+ /**
75
+ * Resolve the ObjectStack home directory used to store cwd-independent
76
+ * runtime data (default sqlite database, downloaded marketplace apps,
77
+ * installed plugin cache).
78
+ *
79
+ * Resolution order:
80
+ * 1. `OS_HOME` env var (absolute path; `~` expanded)
81
+ * 2. `~/.objectstack` (cross-platform user-home default)
82
+ *
83
+ * The directory is created lazily by callers that actually write to it
84
+ * (e.g. the sqlite driver's `mkdirSync(...)`); this helper does not
85
+ * touch the filesystem.
86
+ */
87
+ declare function resolveObjectStackHome(): string;
74
88
  declare const StandaloneStackConfigSchema: z.ZodObject<{
75
89
  databaseUrl: z.ZodOptional<z.ZodString>;
76
90
  databaseAuthToken: z.ZodOptional<z.ZodString>;
@@ -820,6 +834,30 @@ interface KernelManagerConfig {
820
834
  warn?: (...a: any[]) => void;
821
835
  error?: (...a: any[]) => void;
822
836
  };
837
+ /**
838
+ * Optional upstream-change detector. When set, every cache hit older
839
+ * than `staleCheckIntervalMs` triggers this probe before returning the
840
+ * cached kernel. Returning `true` evicts the kernel and forces a
841
+ * rebuild, so changes to the control-plane state that don't reach
842
+ * this process via push (marketplace installs, artifact republish,
843
+ * etc.) become visible without waiting for the LRU TTL to expire.
844
+ *
845
+ * The probe should be cheap (single small GET). Errors thrown here
846
+ * are caught and treated as "still fresh" so a brief upstream
847
+ * outage doesn't churn every cached kernel — the worst case is
848
+ * stale-by-`ttlMs`, which is what we had before adding the probe.
849
+ *
850
+ * `builtAtMs` is the kernel's `createdAt` time so the probe can
851
+ * compare against an upstream "last changed at" timestamp.
852
+ */
853
+ freshnessProbe?: (environmentId: string, builtAtMs: number) => Promise<boolean>;
854
+ /**
855
+ * Minimum gap between successive freshness probes for the same env.
856
+ * Defaults to 10 seconds — enough to avoid hammering the control
857
+ * plane on tight render loops while still keeping the user's
858
+ * post-install refresh perceived as immediate.
859
+ */
860
+ staleCheckIntervalMs?: number;
823
861
  }
824
862
  /**
825
863
  * LRU + TTL cache of per-project {@link ObjectKernel} instances.
@@ -837,6 +875,8 @@ declare class KernelManager {
837
875
  private readonly logger;
838
876
  private readonly cache;
839
877
  private readonly pending;
878
+ private readonly freshnessProbe?;
879
+ private readonly staleCheckIntervalMs;
840
880
  constructor(config: KernelManagerConfig);
841
881
  /** Returns the currently cached environmentIds (ordered by insertion). */
842
882
  keys(): string[];
@@ -1716,6 +1756,24 @@ declare class ArtifactApiClient {
1716
1756
  commitId: string;
1717
1757
  publishedAt?: string | null;
1718
1758
  } | null>;
1759
+ /**
1760
+ * Cheap freshness probe — returns the env's `last_published_at`
1761
+ * (and best-effort current commit) without rebuilding the artifact.
1762
+ * Used by `KernelManager` on cache hits to detect when a per-env
1763
+ * kernel has been invalidated by an upstream change (marketplace
1764
+ * install/uninstall, artifact publish) so it can be rebuilt
1765
+ * without waiting for the 15-minute LRU TTL to expire.
1766
+ *
1767
+ * Returns `null` on definitive 404 / unknown env. Errors propagate
1768
+ * (caller decides whether to treat unreachable cloud as fresh or
1769
+ * stale — typically fresh, so a brief outage doesn't churn every
1770
+ * cached kernel).
1771
+ */
1772
+ getFreshness(environmentId: string): Promise<{
1773
+ environmentId: string;
1774
+ lastPublishedAt: string | null;
1775
+ commitId: string | null;
1776
+ } | null>;
1719
1777
  /** Drop cached entries for a project (and any matching hostname). */
1720
1778
  invalidate(environmentId: string): void;
1721
1779
  /** Drop everything. Used on shutdown / hot-reload. */
@@ -1839,10 +1897,9 @@ declare function createObjectOSStack(config: ObjectOSStackConfig): Promise<Objec
1839
1897
  *
1840
1898
  * Forwards `GET /api/v1/marketplace/*` from a tenant ObjectOS runtime to
1841
1899
  * the configured ObjectStack Cloud control-plane URL. The cloud endpoint
1842
- * (`packages/service-cloud/src/routes/marketplace.ts`) is unauthenticated
1843
- * and only exposes packages whose owner has opted in to the public catalog
1844
- * (`sys_package.marketplace_listed = true`) so the proxy passes through
1845
- * without any credentials.
1900
+ * is unauthenticated and only exposes packages whose owner has opted in
1901
+ * to the public catalog (`sys_package.marketplace_listed = true`) so the
1902
+ * proxy passes through without any credentials.
1846
1903
  *
1847
1904
  * Why proxy instead of direct browser → cloud:
1848
1905
  * - The Console SPA stays on the tenant origin, so no CORS configuration
@@ -2049,9 +2106,9 @@ declare function resolveCloudUrl(explicit?: string | null): string;
2049
2106
  * - a local file artifact (see {@link FileArtifactApiClient} +
2050
2107
  * {@link ArtifactEnvironmentRegistry})
2051
2108
  *
2052
- * The contract was extracted from `@objectstack/service-cloud` in Phase R
2053
- * so the runtime can express "fetch artifact + boot per-project kernel"
2054
- * without taking a dependency on the cloud control plane.
2109
+ * The contract lives in `@objectstack/runtime` so the runtime can
2110
+ * express "fetch artifact + boot per-project kernel" without taking a
2111
+ * dependency on the cloud control plane.
2055
2112
  */
2056
2113
 
2057
2114
  type IDataDriver$1 = Contracts.IDataDriver;
@@ -2521,4 +2578,4 @@ declare function actionBodyRunnerFactory(runner: ScriptRunner, opts: FactoryOpti
2521
2578
  timeoutMs?: number;
2522
2579
  }) => ((actionCtx: any) => Promise<unknown>) | undefined;
2523
2580
 
2524
- export { AppPlugin, ArtifactApiClient, type ArtifactApiClientConfig, ArtifactEnvironmentRegistry, type ArtifactEnvironmentRegistryConfig, ArtifactKernelFactory, type ArtifactKernelFactoryConfig, AuthProxyPlugin, type BackfillPlatformSsoClientsOptions, DEFAULT_CLOUD_URL, DEFAULT_RATE_LIMITS, type DefaultHostConfigOptions, type DefaultHostConfigResult, type DispatcherPluginConfig, DriverPlugin, type EnvironmentArtifactResponse, type EnvironmentDriverRegistry, type EnvironmentKernelFactory, type EnvironmentRuntimeConfig, FileArtifactApiClient, type FileArtifactApiClientConfig, HttpDispatcher, type HttpDispatcherResult, type HttpProtocolContext, HttpServer, KernelManager, type KernelManagerConfig, type LoadArtifactBundleOptions, MarketplaceInstallLocalPlugin, type MarketplaceInstallLocalPluginConfig, MarketplaceProxyPlugin, type MarketplaceProxyPluginConfig, MiddlewareManager, type ObjectOSStackConfig, type ObjectOSStackResult, ObservabilityServicePlugin, type ObservabilityServicePluginOptions, PLATFORM_SSO_PROVIDER_ID, QuickJSScriptRunner, type QuickJSScriptRunnerOptions, type RateLimitBucketConfig, type RateLimitDecision, type RateLimitDefaults, type RateLimitStore, RateLimiter, type ResolvedHostname, Runtime, type RuntimeConfig, RuntimeConfigPlugin, type RuntimeConfigPluginConfig, SYSTEM_ENVIRONMENT_ID, SandboxError, type ScriptContext, type ScriptOrigin, type ScriptResult, type ScriptRunOptions, type ScriptRunner, type SecurityHeadersOptions, SeedLoaderService, type SeedPlatformSsoClientOptions, type StandaloneStackConfig, type StandaloneStackResult, type SystemEnvironmentPluginConfig, type TraceContext, UnimplementedScriptRunner, actionBodyRunnerFactory, backfillPlatformSsoClients, buildPlatformSsoRedirectUri, buildSecurityHeaders, collectBundleActions, collectBundleFunctions, collectBundleHooks, createDefaultHostConfig, createDispatcherPlugin, createObjectOSStack, createStandaloneStack, createSystemEnvironmentPlugin, derivePlatformSsoClientId, derivePlatformSsoClientSecret, extractRequestId, formatTraceparent, generateRequestId, hookBodyRunnerFactory, isHttpUrl, loadArtifactBundle, mergeRuntimeModule, parseTraceparent, readArtifactSource, resolveCloudUrl, resolveDefaultArtifactPath, resolveErrorReporter, resolveMetrics, resolveRequestId, seedPlatformSsoClient };
2581
+ export { AppPlugin, ArtifactApiClient, type ArtifactApiClientConfig, ArtifactEnvironmentRegistry, type ArtifactEnvironmentRegistryConfig, ArtifactKernelFactory, type ArtifactKernelFactoryConfig, AuthProxyPlugin, type BackfillPlatformSsoClientsOptions, DEFAULT_CLOUD_URL, DEFAULT_RATE_LIMITS, type DefaultHostConfigOptions, type DefaultHostConfigResult, type DispatcherPluginConfig, DriverPlugin, type EnvironmentArtifactResponse, type EnvironmentDriverRegistry, type EnvironmentKernelFactory, type EnvironmentRuntimeConfig, FileArtifactApiClient, type FileArtifactApiClientConfig, HttpDispatcher, type HttpDispatcherResult, type HttpProtocolContext, HttpServer, KernelManager, type KernelManagerConfig, type LoadArtifactBundleOptions, MarketplaceInstallLocalPlugin, type MarketplaceInstallLocalPluginConfig, MarketplaceProxyPlugin, type MarketplaceProxyPluginConfig, MiddlewareManager, type ObjectOSStackConfig, type ObjectOSStackResult, ObservabilityServicePlugin, type ObservabilityServicePluginOptions, PLATFORM_SSO_PROVIDER_ID, QuickJSScriptRunner, type QuickJSScriptRunnerOptions, type RateLimitBucketConfig, type RateLimitDecision, type RateLimitDefaults, type RateLimitStore, RateLimiter, type ResolvedHostname, Runtime, type RuntimeConfig, RuntimeConfigPlugin, type RuntimeConfigPluginConfig, SYSTEM_ENVIRONMENT_ID, SandboxError, type ScriptContext, type ScriptOrigin, type ScriptResult, type ScriptRunOptions, type ScriptRunner, type SecurityHeadersOptions, SeedLoaderService, type SeedPlatformSsoClientOptions, type StandaloneStackConfig, type StandaloneStackResult, type SystemEnvironmentPluginConfig, type TraceContext, UnimplementedScriptRunner, actionBodyRunnerFactory, backfillPlatformSsoClients, buildPlatformSsoRedirectUri, buildSecurityHeaders, collectBundleActions, collectBundleFunctions, collectBundleHooks, createDefaultHostConfig, createDispatcherPlugin, createObjectOSStack, createStandaloneStack, createSystemEnvironmentPlugin, derivePlatformSsoClientId, derivePlatformSsoClientSecret, extractRequestId, formatTraceparent, generateRequestId, hookBodyRunnerFactory, isHttpUrl, loadArtifactBundle, mergeRuntimeModule, parseTraceparent, readArtifactSource, resolveCloudUrl, resolveDefaultArtifactPath, resolveErrorReporter, resolveMetrics, resolveObjectStackHome, resolveRequestId, seedPlatformSsoClient };