@jini-ai/platform 0.7.3-next.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +13 -0
  3. package/dist/download-lock.d.ts +3 -1
  4. package/dist/download-lock.js +4 -6
  5. package/dist/download-maintenance.js +6 -6
  6. package/dist/download-state.js +17 -14
  7. package/dist/download-store.d.ts +34 -10
  8. package/dist/download-store.js +24 -20
  9. package/dist/download-target.d.ts +6 -2
  10. package/dist/download-target.js +7 -7
  11. package/dist/download-transfer.js +18 -12
  12. package/dist/download.js +4 -4
  13. package/dist/fetch-with-timeout.d.ts +0 -53
  14. package/dist/fetch-with-timeout.js +62 -13
  15. package/dist/fs/directory-running-lock.d.ts +4 -0
  16. package/dist/fs/directory-running-lock.js +8 -1
  17. package/dist/fs/directory-workspace.d.ts +2 -1
  18. package/dist/fs/directory-workspace.js +2 -2
  19. package/dist/fs/durable-json.d.ts +3 -16
  20. package/dist/fs/durable-json.js +4 -2
  21. package/dist/fs/guarded-reader.d.ts +10 -0
  22. package/dist/fs/guarded-reader.js +34 -1
  23. package/dist/fs/index.d.ts +4 -0
  24. package/dist/fs/index.js +4 -0
  25. package/dist/fs/leased-directory-move.d.ts +49 -0
  26. package/dist/fs/leased-directory-move.js +31 -0
  27. package/dist/fs/owned-temp-root.d.ts +74 -0
  28. package/dist/fs/owned-temp-root.js +203 -0
  29. package/dist/fs/recent-directories.d.ts +2 -1
  30. package/dist/fs/resolve-directory-target.d.ts +33 -0
  31. package/dist/fs/resolve-directory-target.js +58 -0
  32. package/dist/fs/staged-file.d.ts +40 -0
  33. package/dist/fs/staged-file.js +75 -0
  34. package/dist/fs/strict-containment.d.ts +14 -0
  35. package/dist/fs/strict-containment.js +14 -0
  36. package/dist/image/png-encode.d.ts +41 -0
  37. package/dist/image/png-encode.js +96 -0
  38. package/dist/index.d.ts +3 -1
  39. package/dist/mail/email-template-agent-tools.d.ts +150 -0
  40. package/dist/mail/email-template-agent-tools.js +86 -0
  41. package/dist/mail/email-template-tool-registrations.d.ts +73 -0
  42. package/dist/mail/email-template-tool-registrations.js +66 -0
  43. package/dist/mail/email-template.js +3 -7
  44. package/dist/mail/feedback-route.d.ts +50 -0
  45. package/dist/mail/feedback-route.js +46 -0
  46. package/dist/mail/feedback-setup.d.ts +44 -0
  47. package/dist/mail/feedback-setup.js +53 -0
  48. package/dist/mail/feedback-sources.d.ts +67 -0
  49. package/dist/mail/feedback-sources.js +42 -0
  50. package/dist/mail/index.d.ts +10 -1
  51. package/dist/mail/index.js +4 -0
  52. package/dist/mail/mail-status.d.ts +32 -0
  53. package/dist/mail/mail-status.js +2 -0
  54. package/dist/mail/positional-purpose-gate.d.ts +14 -0
  55. package/dist/mail/positional-purpose-gate.js +18 -0
  56. package/dist/mail/purpose-gate-probe.d.ts +18 -0
  57. package/dist/mail/purpose-gate-probe.js +22 -0
  58. package/dist/mail/purpose-scoped-mailer.d.ts +4 -0
  59. package/dist/mail/purpose-scoped-mailer.js +4 -3
  60. package/dist/mail/resolve-mailer.d.ts +13 -1
  61. package/dist/mail/resolve-mailer.js +11 -5
  62. package/dist/mail/sql/activity.repo.d.ts +20 -0
  63. package/dist/mail/sql/activity.repo.js +133 -0
  64. package/dist/mail/sql/attempts.repo.d.ts +17 -0
  65. package/dist/mail/sql/attempts.repo.js +32 -0
  66. package/dist/mail/sql/capture.repo.d.ts +69 -0
  67. package/dist/mail/sql/capture.repo.js +119 -0
  68. package/dist/mail/sql/feedback-inbox.repo.d.ts +12 -0
  69. package/dist/mail/sql/feedback-inbox.repo.js +32 -0
  70. package/dist/mail/sql/index.d.ts +12 -0
  71. package/dist/mail/sql/index.js +12 -0
  72. package/dist/mail/sql/ledger.repo.d.ts +29 -0
  73. package/dist/mail/sql/ledger.repo.js +57 -0
  74. package/dist/mail/sql/retention.d.ts +23 -0
  75. package/dist/mail/sql/retention.js +53 -0
  76. package/dist/mail/sql/site-feedback-route.d.ts +18 -0
  77. package/dist/mail/sql/site-feedback-route.js +22 -0
  78. package/dist/mail/sql/suppression-admin.repo.d.ts +11 -0
  79. package/dist/mail/sql/suppression-admin.repo.js +76 -0
  80. package/dist/mail/sql/suppression.repo.d.ts +10 -0
  81. package/dist/mail/sql/suppression.repo.js +33 -0
  82. package/dist/mail/test-send.d.ts +147 -0
  83. package/dist/mail/test-send.js +198 -0
  84. package/dist/mail/use-readiness.d.ts +104 -0
  85. package/dist/mail/use-readiness.js +140 -0
  86. package/dist/object-store/local-fs.js +34 -1
  87. package/dist/object-store/site/artifact-provider.d.ts +65 -0
  88. package/dist/object-store/site/artifact-provider.js +37 -0
  89. package/dist/object-store/site/registry.d.ts +110 -0
  90. package/dist/object-store/site/registry.js +93 -0
  91. package/dist/object-store/site/setting.d.ts +34 -0
  92. package/dist/object-store/site/setting.js +32 -0
  93. package/dist/process-probes.d.ts +11 -4
  94. package/dist/process-probes.js +3 -3
  95. package/dist/process-top-footprint.d.ts +1 -1
  96. package/dist/process-top-footprint.js +1 -3
  97. package/dist/process.d.ts +3 -17
  98. package/dist/process.js +3 -2
  99. package/dist/retention/index.d.ts +6 -0
  100. package/dist/retention/index.js +6 -0
  101. package/dist/retention/measure-tree.d.ts +68 -0
  102. package/dist/retention/measure-tree.js +205 -0
  103. package/dist/retention/preview-store.d.ts +12 -0
  104. package/dist/retention/preview-store.js +28 -0
  105. package/dist/retention/routes.d.ts +23 -0
  106. package/dist/retention/routes.js +24 -0
  107. package/dist/retention/runner.d.ts +103 -0
  108. package/dist/retention/runner.js +164 -0
  109. package/dist/secrets/credential-sets/index.d.ts +1 -0
  110. package/dist/secrets/credential-sets/index.js +1 -0
  111. package/dist/secrets/credential-sets/store-vault-guards.d.ts +26 -0
  112. package/dist/secrets/credential-sets/store-vault-guards.js +30 -0
  113. package/dist/secrets/credential-sets/vault.service.d.ts +1 -1
  114. package/dist/secrets/index.d.ts +1 -1
  115. package/dist/secrets/index.js +1 -1
  116. package/dist/secrets/keyring.env.d.ts +1 -1
  117. package/dist/secrets/keyring.env.js +3 -5
  118. package/dist/secrets/keyring.memory.d.ts +4 -1
  119. package/dist/secrets/keyring.memory.js +4 -1
  120. package/dist/secrets/legacy-codecs.d.ts +381 -0
  121. package/dist/secrets/legacy-codecs.js +468 -0
  122. package/dist/secrets/legacy-owner.d.ts +3 -11
  123. package/dist/secrets/root-key/ensure.d.ts +154 -0
  124. package/dist/secrets/root-key/ensure.js +328 -0
  125. package/dist/secrets/root-key/files.d.ts +104 -0
  126. package/dist/secrets/root-key/files.js +166 -0
  127. package/dist/secrets/root-key/material.d.ts +132 -0
  128. package/dist/secrets/root-key/material.js +116 -0
  129. package/dist/secrets/root-key/ordered-keyring.d.ts +157 -0
  130. package/dist/secrets/root-key/ordered-keyring.js +104 -0
  131. package/dist/secrets/root-key/reconcile.d.ts +50 -0
  132. package/dist/secrets/root-key/reconcile.js +147 -0
  133. package/dist/secrets/root-key/site-keyring-errors.d.ts +78 -0
  134. package/dist/secrets/root-key/site-keyring-errors.js +37 -0
  135. package/dist/secrets/root-key/sources.d.ts +79 -0
  136. package/dist/secrets/root-key/sources.js +119 -0
  137. package/dist/secrets/secret-sealer.aesgcm.d.ts +50 -2
  138. package/dist/secrets/secret-sealer.aesgcm.js +107 -19
  139. package/dist/web/tool-registrations.d.ts +67 -0
  140. package/dist/web/tool-registrations.js +44 -0
  141. package/package.json +138 -6
@@ -0,0 +1,65 @@
1
+ import type { ArtifactStorePort, DeployTargetCredential } from "@jini-ai/core/contracts/site/devops-deploy";
2
+ import type { LoadedObjectStoreRegistry } from "./registry.js";
3
+ /**
4
+ * @file Which object-store provider delivers backup shares: any registered provider that can also
5
+ * hand out a single-object artifact store (for example an S3-compatible store), instead of one
6
+ * hard-coded deploy target id. The site's media choice wins when it qualifies, so media and shares
7
+ * use one provider (and one saved connection); otherwise the first qualifying one in registry order.
8
+ * A provider qualifies only once its saved connection resolves and passes its optional artifact
9
+ * credential check, so an installed but unconnected
10
+ * store never hides a connected one behind it. Revoke names the share's saved provider and resolves
11
+ * only that one, so a store connected later can never take over (or block) another store's delete.
12
+ */
13
+ /** A provider's artifact capability as the share path calls it (the deploy-target module ABI). */
14
+ export interface ArtifactStoreCapable {
15
+ /** Optional provider-owned readiness check for artifact-specific companion credentials. */
16
+ acceptsArtifactCredential?(required: {
17
+ readonly credential: unknown;
18
+ }, optional?: Record<string, never>): boolean;
19
+ createArtifactStore(required: {
20
+ readonly credential: DeployTargetCredential;
21
+ readonly config: Record<string, never>;
22
+ readonly kit: unknown;
23
+ }): ArtifactStorePort & {
24
+ /** Non-secret identity of the backing store, when the provider knows it better than the host does. */
25
+ readonly binding?: string;
26
+ };
27
+ }
28
+ /**
29
+ * @param required.resolveCredential The provider's saved connection, or `undefined` when it has none.
30
+ * @param optional.savedProvider A share's recorded provider (its hyphenated connection id): only that
31
+ * provider is considered.
32
+ * @returns The first capable provider (preferred first, then registry order) whose connection
33
+ * resolves and passes the provider's artifact check, with that credential; `undefined` when none qualifies.
34
+ * @complexity O(n) registered providers, one credential lookup per capable provider until a hit.
35
+ */
36
+ export declare function selectArtifactStoreProvider<C, Host>(required: {
37
+ readonly loaded: LoadedObjectStoreRegistry<Host>;
38
+ readonly preferredId: string;
39
+ readonly resolveCredential: (required: {
40
+ readonly id: string;
41
+ }, optional?: Record<string, never>) => Promise<C | undefined>;
42
+ }, optional?: {
43
+ readonly savedProvider?: string;
44
+ }): Promise<{
45
+ readonly id: string;
46
+ readonly provider: ArtifactStoreCapable;
47
+ readonly credential: C;
48
+ } | undefined>;
49
+ /** Provider ids use underscores; the saved connection (and a share's recorded provider) is the hyphenated target id. */
50
+ export declare function artifactStoreTarget({ id }: {
51
+ id: string;
52
+ }, _optional?: Record<string, never>): string;
53
+ /**
54
+ * What revoke must match before deleting: a new default connection must never turn revocation into
55
+ * deletion in another bucket. Non-secret storage coordinates bind, so credentials may rotate for the
56
+ * same store; a provider that names its own store (e.g. a token-scoped one) supplies that instead.
57
+ * @complexity O(1).
58
+ */
59
+ export declare function artifactStoreBinding(required: {
60
+ readonly store: {
61
+ readonly binding?: string;
62
+ };
63
+ readonly credential: Readonly<Record<string, unknown>>;
64
+ }, _optional?: Record<string, never>): string;
65
+ //# sourceMappingURL=artifact-provider.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @param required.resolveCredential The provider's saved connection, or `undefined` when it has none.
3
+ * @param optional.savedProvider A share's recorded provider (its hyphenated connection id): only that
4
+ * provider is considered.
5
+ * @returns The first capable provider (preferred first, then registry order) whose connection
6
+ * resolves and passes the provider's artifact check, with that credential; `undefined` when none qualifies.
7
+ * @complexity O(n) registered providers, one credential lookup per capable provider until a hit.
8
+ */
9
+ export async function selectArtifactStoreProvider(required, optional = {}) {
10
+ const capable = required.loaded.registry.list().filter((entry) => typeof entry.provider.createArtifactStore === "function"
11
+ && (optional.savedProvider === undefined || artifactStoreTarget({ id: entry.id }) === optional.savedProvider));
12
+ const ordered = [...capable.filter((entry) => entry.id === required.preferredId), ...capable.filter((entry) => entry.id !== required.preferredId)];
13
+ for (const entry of ordered) {
14
+ const credential = await required.resolveCredential({ id: entry.id });
15
+ if (credential === undefined)
16
+ continue;
17
+ const provider = entry.provider;
18
+ if (provider.acceptsArtifactCredential?.({ credential }) !== false)
19
+ return { id: entry.id, provider, credential };
20
+ }
21
+ return undefined;
22
+ }
23
+ /** Provider ids use underscores; the saved connection (and a share's recorded provider) is the hyphenated target id. */
24
+ export function artifactStoreTarget({ id }, _optional = {}) {
25
+ return id.replace(/_/g, "-");
26
+ }
27
+ /**
28
+ * What revoke must match before deleting: a new default connection must never turn revocation into
29
+ * deletion in another bucket. Non-secret storage coordinates bind, so credentials may rotate for the
30
+ * same store; a provider that names its own store (e.g. a token-scoped one) supplies that instead.
31
+ * @complexity O(1).
32
+ */
33
+ export function artifactStoreBinding(required, _optional = {}) {
34
+ const { store, credential } = required;
35
+ return store.binding ?? JSON.stringify([credential.bucket, credential.region, credential.endpoint ?? "", credential.publicUrl]);
36
+ }
37
+ //# sourceMappingURL=artifact-provider.js.map
@@ -0,0 +1,110 @@
1
+ import { type ObjectStoreProvider } from "@jini-ai/core/object-store";
2
+ import type { ProviderDefinition, ProviderRegistry } from "@jini-ai/core/provider-registry";
3
+ import { type ObjectStoreEnvDeclaration, type ObjectStoresParseResult } from "../descriptors.js";
4
+ /**
5
+ * @file The site's object-store providers: the built-in `local` filesystem provider (the registry
6
+ * default) plus every provider a trusted Agent Plugin contributes through
7
+ * {@link OBJECT_STORES_FILENAME} — today the bundled s3-compatible plugin's `s3_compatible`.
8
+ *
9
+ * Plugin providers load through Jini's `defineProviderContribution`, so a provider module passes the
10
+ * same gates as every executable seam (active plugin, bundled digest, contained `.mjs`); a bad one is
11
+ * a refusal line, never a boot crash. Core owns the generic contract (`@jini-ai/core/object-store`);
12
+ * this module is the generic site loader.
13
+ *
14
+ * ## Wiring
15
+ * Generic over the host object `Host` a provider's `create()` receives and over the contribution
16
+ * `Definition` the host's plugin loader accepts. The agent-plugins contribution seam
17
+ * (`defineProviderContribution`, `contributeProviders`) and the host's plugin loaders
18
+ * (`loadContributions`, `bundledContributionSources`, `loadPluginContributionsFromSource`) arrive
19
+ * on each function's required args, bound by the host's composition root. `Host` and `Definition`
20
+ * are inferred from the contribution seam only (`NoInfer` on the loaders), because the host's
21
+ * loaders are themselves generic and would otherwise widen both to `unknown`.
22
+ */
23
+ /** The file a plugin ships at its root to contribute object-store providers: `{ schemaVersion: 1, providers: [{ id, module, label? }] }`,
24
+ * parsed by `@jini-ai/platform/object-store`; ids are checked against the shared grammar before any module is imported. */
25
+ export declare const OBJECT_STORES_FILENAME = "jini-object-stores.json";
26
+ /** A provider whose `create()` receives the host object `Host` (signing, optional request tracing). */
27
+ export type SiteObjectStoreProvider<Host> = ObjectStoreProvider<Host>;
28
+ export interface LoadedObjectStoreRegistry<Host> {
29
+ readonly registry: ProviderRegistry<SiteObjectStoreProvider<Host>>;
30
+ /** Log-safe, one line per provider that was not loaded and why. */
31
+ readonly refusals: readonly string[];
32
+ }
33
+ /** One plugin's loaded provider, as the host's contribution loader returns it. */
34
+ export interface LoadedObjectStoreContribution<Host> {
35
+ readonly contract: string;
36
+ readonly pluginId: string;
37
+ readonly definition: ProviderDefinition<SiteObjectStoreProvider<Host>>;
38
+ }
39
+ export interface LoadedObjectStoreContributions<Host> {
40
+ readonly items: readonly LoadedObjectStoreContribution<Host>[];
41
+ readonly refusals: readonly string[];
42
+ }
43
+ /** A trusted bundled plugin package: whose it is and where its files live. */
44
+ export interface ObjectStoreSourcePlugin {
45
+ readonly pluginId: string;
46
+ readonly packageRoot: string;
47
+ }
48
+ /** The spec handed to the injected `defineProviderContribution` (agent-plugins' shared seam). */
49
+ export interface ObjectStoreContributionSpec<Host> {
50
+ readonly contract: string;
51
+ readonly filename: string;
52
+ readonly parse: (input: {
53
+ readonly raw: string;
54
+ }) => ObjectStoresParseResult;
55
+ readonly validate: (input: {
56
+ readonly exported: unknown;
57
+ }) => SiteObjectStoreProvider<Host> | string;
58
+ }
59
+ /** The agent-plugins contribution seam, bound by the host. */
60
+ export interface ObjectStoreContributionPorts<Host, Definition> {
61
+ readonly defineProviderContribution: (spec: ObjectStoreContributionSpec<Host>) => Definition;
62
+ readonly contributeProviders: (required: {
63
+ readonly registry: ProviderRegistry<SiteObjectStoreProvider<Host>>;
64
+ readonly loaded: LoadedObjectStoreContributions<Host>;
65
+ }) => {
66
+ readonly refusals: readonly string[];
67
+ };
68
+ }
69
+ /** The host's bundled-source enumerator (trusted, immutable product sources only). */
70
+ export type BundledObjectStoreSources = (required: {
71
+ readonly sourceRoot: string;
72
+ readonly filename: string;
73
+ }) => readonly ObjectStoreSourcePlugin[];
74
+ /**
75
+ * This workspace's providers from its installed, activated Agent Plugins. Read fresh per call.
76
+ * @complexity O(p) installed plugins, one import per declared provider.
77
+ */
78
+ export declare function loadObjectStoreRegistry<Host, Definition>(required: ObjectStoreContributionPorts<Host, Definition> & {
79
+ readonly workspaceId: string;
80
+ readonly uploadsDir: string;
81
+ readonly loadContributions: (input: {
82
+ readonly workspaceId: string;
83
+ readonly definition: NoInfer<Definition>;
84
+ }, optional: {
85
+ readonly orderByPluginId: boolean;
86
+ }) => Promise<LoadedObjectStoreContributions<NoInfer<Host>>>;
87
+ }, _optional?: Record<string, never>): Promise<LoadedObjectStoreRegistry<Host>>;
88
+ /**
89
+ * Providers read straight from this product's own bundled plugin SOURCE, with no
90
+ * install/activation gate — for the operator env override, which must not depend on a plugin being
91
+ * switched on. Never point `sourceRoot` at anything an operator or third party can write.
92
+ * @complexity O(t) bundled providers, one import each.
93
+ */
94
+ export declare function loadBundledObjectStoreRegistry<Host, Definition>(required: ObjectStoreContributionPorts<Host, Definition> & {
95
+ readonly uploadsDir: string;
96
+ readonly sourceRoot: string;
97
+ readonly bundledContributionSources: BundledObjectStoreSources;
98
+ readonly loadPluginContributionsFromSource: (input: {
99
+ readonly plugin: ObjectStoreSourcePlugin;
100
+ readonly definition: NoInfer<Definition>;
101
+ }) => Promise<LoadedObjectStoreContributions<NoInfer<Host>>>;
102
+ }, _optional?: Record<string, never>): Promise<LoadedObjectStoreRegistry<Host>>;
103
+ /** Synchronous media env mappings from immutable bundled sources; never imports provider modules.
104
+ * @param required Product-owned source root and the host's bundled-source enumerator. @returns Mappings in declaration order.
105
+ * @throws {Error} Unreadable/invalid data or duplicate selectors; an opt-in never silently becomes local. */
106
+ export declare function readBundledObjectStoreEnvDeclarations(required: {
107
+ readonly sourceRoot: string;
108
+ readonly bundledContributionSources: BundledObjectStoreSources;
109
+ }, _optional?: {}): readonly ObjectStoreEnvDeclaration[];
110
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { createObjectStoreRegistry, OBJECT_STORE_CONTRACT, objectStoreProviderFault } from "@jini-ai/core/object-store";
4
+ import { parseObjectStoresFile as parseObjectStoreDescriptors } from "../descriptors.js";
5
+ import { createLocalFsObjectStoreProvider } from "../local-fs.js";
6
+ /**
7
+ * @file The site's object-store providers: the built-in `local` filesystem provider (the registry
8
+ * default) plus every provider a trusted Agent Plugin contributes through
9
+ * {@link OBJECT_STORES_FILENAME} — today the bundled s3-compatible plugin's `s3_compatible`.
10
+ *
11
+ * Plugin providers load through Jini's `defineProviderContribution`, so a provider module passes the
12
+ * same gates as every executable seam (active plugin, bundled digest, contained `.mjs`); a bad one is
13
+ * a refusal line, never a boot crash. Core owns the generic contract (`@jini-ai/core/object-store`);
14
+ * this module is the generic site loader.
15
+ *
16
+ * ## Wiring
17
+ * Generic over the host object `Host` a provider's `create()` receives and over the contribution
18
+ * `Definition` the host's plugin loader accepts. The agent-plugins contribution seam
19
+ * (`defineProviderContribution`, `contributeProviders`) and the host's plugin loaders
20
+ * (`loadContributions`, `bundledContributionSources`, `loadPluginContributionsFromSource`) arrive
21
+ * on each function's required args, bound by the host's composition root. `Host` and `Definition`
22
+ * are inferred from the contribution seam only (`NoInfer` on the loaders), because the host's
23
+ * loaders are themselves generic and would otherwise widen both to `unknown`.
24
+ */
25
+ /** The file a plugin ships at its root to contribute object-store providers: `{ schemaVersion: 1, providers: [{ id, module, label? }] }`,
26
+ * parsed by `@jini-ai/platform/object-store`; ids are checked against the shared grammar before any module is imported. */
27
+ export const OBJECT_STORES_FILENAME = "jini-object-stores.json";
28
+ /** The shared contribution definition for {@link OBJECT_STORES_FILENAME}. @complexity O(1). */
29
+ function objectStoreContribution(required, _optional = {}) {
30
+ return required.defineProviderContribution({
31
+ contract: OBJECT_STORE_CONTRACT, filename: OBJECT_STORES_FILENAME,
32
+ parse: ({ raw }) => parseObjectStoreDescriptors({ raw }),
33
+ validate: ({ exported }) => objectStoreProviderFault({ provider: exported }) ?? exported,
34
+ });
35
+ }
36
+ /**
37
+ * A registry seeded with `local` (rooted at the site's uploads folder), without plugin providers.
38
+ * @complexity O(1).
39
+ */
40
+ function seededRegistry(required) {
41
+ return createObjectStoreRegistry({}, { seed: [{ id: "local", label: "This server's disk", provider: createLocalFsObjectStoreProvider({ rootDir: required.uploadsDir }) }] });
42
+ }
43
+ /**
44
+ * This workspace's providers from its installed, activated Agent Plugins. Read fresh per call.
45
+ * @complexity O(p) installed plugins, one import per declared provider.
46
+ */
47
+ export async function loadObjectStoreRegistry(required, _optional = {}) {
48
+ const registry = seededRegistry(required);
49
+ const loaded = await required.loadContributions({ workspaceId: required.workspaceId, definition: objectStoreContribution(required) }, { orderByPluginId: true });
50
+ return { registry, refusals: required.contributeProviders({ registry, loaded }).refusals };
51
+ }
52
+ /**
53
+ * Providers read straight from this product's own bundled plugin SOURCE, with no
54
+ * install/activation gate — for the operator env override, which must not depend on a plugin being
55
+ * switched on. Never point `sourceRoot` at anything an operator or third party can write.
56
+ * @complexity O(t) bundled providers, one import each.
57
+ */
58
+ export async function loadBundledObjectStoreRegistry(required, _optional = {}) {
59
+ const registry = seededRegistry(required);
60
+ const definition = objectStoreContribution(required);
61
+ const refusals = [];
62
+ for (const plugin of required.bundledContributionSources({ sourceRoot: required.sourceRoot, filename: OBJECT_STORES_FILENAME })) {
63
+ const loaded = await required.loadPluginContributionsFromSource({ plugin, definition });
64
+ refusals.push(...required.contributeProviders({ registry, loaded }).refusals);
65
+ }
66
+ return { registry, refusals };
67
+ }
68
+ /** Synchronous media env mappings from immutable bundled sources; never imports provider modules.
69
+ * @param required Product-owned source root and the host's bundled-source enumerator. @returns Mappings in declaration order.
70
+ * @throws {Error} Unreadable/invalid data or duplicate selectors; an opt-in never silently becomes local. */
71
+ export function readBundledObjectStoreEnvDeclarations(required, _optional = {}) {
72
+ const entries = [];
73
+ for (const plugin of required.bundledContributionSources({ sourceRoot: required.sourceRoot, filename: OBJECT_STORES_FILENAME })) {
74
+ const parsed = parseObjectStoreDescriptors({ raw: readFileSync(path.join(plugin.packageRoot, OBJECT_STORES_FILENAME), "utf8") });
75
+ if (!parsed.ok)
76
+ throw new Error(`Object store env declarations from '${plugin.pluginId}' were not loaded: ${parsed.reason}`);
77
+ appendDeclaredEnvironments({ descriptors: parsed.descriptors, entries });
78
+ }
79
+ const selectors = new Set();
80
+ for (const entry of entries) {
81
+ if (selectors.has(entry.selector))
82
+ throw new Error(`Object store env selector '${entry.selector}' is declared twice.`);
83
+ selectors.add(entry.selector);
84
+ }
85
+ return entries;
86
+ }
87
+ function appendDeclaredEnvironments({ descriptors, entries }, _options = {}) {
88
+ for (const descriptor of descriptors) {
89
+ if (descriptor.env)
90
+ entries.push({ ...descriptor.env, providerId: descriptor.id });
91
+ }
92
+ }
93
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,34 @@
1
+ import { type EnsureSettingDefinitionsDeps, type SettingsRepoPort } from "@jini-ai/core/settings";
2
+ import type { ensureSettingDefinitions, getEffective } from "@jini-ai/core/settings";
3
+ /**
4
+ * @file Which object-store provider holds the site's media bytes: `core.storage.mediaObjectStore`
5
+ * on the existing settings ledger (workspace scope, no schema change). The empty default means the
6
+ * registry default, `local`. Read once per boot when media is first touched, so a change applies
7
+ * on the next restart. The host's media blob-store env var, when set, overrides it.
8
+ *
9
+ * ## Wiring
10
+ * The host binds the settings ledger's implementations: `ensureSettingDefinitions` (the
11
+ * definition writer) and `getEffective` (the reader) arrive on each function's required args, so
12
+ * this module only type-imports their contracts from `@jini-ai/core/settings`.
13
+ */
14
+ export declare const STORAGE_SETTINGS_NAMESPACE = "core.storage";
15
+ export declare const MEDIA_OBJECT_STORE_KEY = "mediaObjectStore";
16
+ /**
17
+ * Registers the definition without replacing an owner's stored value.
18
+ * @complexity O(1), one definition.
19
+ */
20
+ export declare function ensureMediaObjectStoreSetting(required: {
21
+ deps: EnsureSettingDefinitionsDeps;
22
+ systemPrincipalId: string;
23
+ ensureSettingDefinitions: typeof ensureSettingDefinitions;
24
+ }, _optional?: Record<string, never>): Promise<void>;
25
+ /**
26
+ * The saved provider id, trimmed; `""` when unset, blank, non-string or unregistered.
27
+ * @complexity One effective setting read.
28
+ */
29
+ export declare function readMediaObjectStoreSetting(required: {
30
+ settingsRepo: SettingsRepoPort;
31
+ workspaceId: string;
32
+ getEffective: typeof getEffective;
33
+ }, _optional?: Record<string, never>): Promise<string>;
34
+ //# sourceMappingURL=setting.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { SCOPE_BIT } from "@jini-ai/core/settings";
2
+ /**
3
+ * @file Which object-store provider holds the site's media bytes: `core.storage.mediaObjectStore`
4
+ * on the existing settings ledger (workspace scope, no schema change). The empty default means the
5
+ * registry default, `local`. Read once per boot when media is first touched, so a change applies
6
+ * on the next restart. The host's media blob-store env var, when set, overrides it.
7
+ *
8
+ * ## Wiring
9
+ * The host binds the settings ledger's implementations: `ensureSettingDefinitions` (the
10
+ * definition writer) and `getEffective` (the reader) arrive on each function's required args, so
11
+ * this module only type-imports their contracts from `@jini-ai/core/settings`.
12
+ */
13
+ export const STORAGE_SETTINGS_NAMESPACE = "core.storage";
14
+ export const MEDIA_OBJECT_STORE_KEY = "mediaObjectStore";
15
+ /**
16
+ * Registers the definition without replacing an owner's stored value.
17
+ * @complexity O(1), one definition.
18
+ */
19
+ export function ensureMediaObjectStoreSetting(required, _optional = {}) {
20
+ return required.ensureSettingDefinitions(required.deps, { namespace: STORAGE_SETTINGS_NAMESPACE, systemPrincipalId: required.systemPrincipalId, definitions: [
21
+ { key: MEDIA_OBJECT_STORE_KEY, schema: { type: "string" }, defaultValue: "", scopes: SCOPE_BIT.workspace },
22
+ ] });
23
+ }
24
+ /**
25
+ * The saved provider id, trimmed; `""` when unset, blank, non-string or unregistered.
26
+ * @complexity One effective setting read.
27
+ */
28
+ export async function readMediaObjectStoreSetting(required, _optional = {}) {
29
+ const effective = await required.getEffective({ deps: { repo: required.settingsRepo }, namespace: STORAGE_SETTINGS_NAMESPACE, key: MEDIA_OBJECT_STORE_KEY, scopeContext: { workspaceId: required.workspaceId } });
30
+ return typeof effective?.value === "string" ? effective.value.trim() : "";
31
+ }
32
+ //# sourceMappingURL=setting.js.map
@@ -1,6 +1,7 @@
1
1
  import type { ProcessSnapshot } from "@jini-ai/core/contracts/runtime";
2
2
  import { execFileBuffered } from "./shell.js";
3
- import type { ProcessUsage, ProcessUsagePorts, ProcessUsageOptions } from "./process.js";
3
+ import type { ProcessUsagePorts, ProcessUsageOptions } from "./process.js";
4
+ import type { ProcessUsage } from "@jini-ai/core/contracts/site/platform-process";
4
5
  /** @internal Enumerate process snapshots on POSIX via `ps`. */
5
6
  export declare function listPosixProcessSnapshots(input: ProcessUsagePorts, options: ProcessUsageOptions & {
6
7
  commandLines?: boolean;
@@ -10,11 +11,17 @@ export declare function listWindowsProcessSnapshots(input: ProcessUsagePorts, op
10
11
  commandLines?: boolean;
11
12
  }): Promise<ProcessSnapshot[]>;
12
13
  /** @internal Read only comm, never args/command, so credentials cannot enter the result. */
13
- export declare function parsePsUsage(stdout: string): ProcessUsage[];
14
+ export declare function parsePsUsage({ stdout }: {
15
+ stdout: string;
16
+ }, _optional?: Record<string, never>): ProcessUsage[];
14
17
  /** @internal Convert Windows 100ns CPU counters and retain nameless process rows. */
15
- export declare function parseCimUsage(stdout: string): ProcessUsage[];
18
+ export declare function parseCimUsage({ stdout }: {
19
+ stdout: string;
20
+ }, _optional?: Record<string, never>): ProcessUsage[];
16
21
  /** @internal Fixed executable and argv, invoked directly without a command shell. */
17
- export declare function processUsageCommand(windows: boolean): {
22
+ export declare function processUsageCommand({ windows }: {
23
+ windows: boolean;
24
+ }, _optional?: Record<string, never>): {
18
25
  command: string;
19
26
  args: string[];
20
27
  };
@@ -66,7 +66,7 @@ function validProcessUsage(usage) {
66
66
  && [pid, ppid, rssBytes, cpuSeconds].every((value) => value >= 0);
67
67
  }
68
68
  /** @internal Read only comm, never args/command, so credentials cannot enter the result. */
69
- export function parsePsUsage(stdout) {
69
+ export function parsePsUsage({ stdout }, _optional = {}) {
70
70
  return stdout.split(/\r?\n/).flatMap((line) => {
71
71
  const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S.*)$/);
72
72
  if (!match)
@@ -85,7 +85,7 @@ function cimNumber(value) {
85
85
  return typeof value === "string" && value.trim() ? Number(value) : NaN;
86
86
  }
87
87
  /** @internal Convert Windows 100ns CPU counters and retain nameless process rows. */
88
- export function parseCimUsage(stdout) {
88
+ export function parseCimUsage({ stdout }, _optional = {}) {
89
89
  if (!stdout.trim())
90
90
  return [];
91
91
  const payload = JSON.parse(stdout);
@@ -103,7 +103,7 @@ export function parseCimUsage(stdout) {
103
103
  });
104
104
  }
105
105
  /** @internal Fixed executable and argv, invoked directly without a command shell. */
106
- export function processUsageCommand(windows) {
106
+ export function processUsageCommand({ windows }, _optional = {}) {
107
107
  return windows
108
108
  ? { command: windowsPowerShell(), args: ["-NoProfile", "-NonInteractive", "-Command",
109
109
  "$ErrorActionPreference = 'Stop'; Get-CimInstance Win32_Process | Select-Object ProcessId, ParentProcessId, WorkingSetSize, UserModeTime, KernelModeTime, Name | ConvertTo-Json -Compress"] }
@@ -1,4 +1,4 @@
1
- import type { ProcessPrivateMemory } from "./process.js";
1
+ import type { ProcessPrivateMemory } from "@jini-ai/core/contracts/site/platform-process";
2
2
  /** Only the requested PID table is trusted; duplicate rows invalidate that PID. O(text length + p) space/time. */
3
3
  export declare function topReadings({ text, pids }: {
4
4
  text: string;
@@ -1,12 +1,10 @@
1
1
  /** top uses binary K/M/G and may append a change marker. Invalid/unsafe values stay unknown. O(1). */
2
2
  function topBytes({ text }, _options = {}) {
3
3
  const match = /^(\d+(?:\.\d+)?)([BKMG])[+-]?$/.exec(text);
4
- if (!match || match[2] === undefined)
4
+ if (!match)
5
5
  return null;
6
6
  const scale = { B: 1, K: 1024, M: 1024 ** 2, G: 1024 ** 3 };
7
7
  const multiplier = scale[match[2]];
8
- if (multiplier === undefined)
9
- return null;
10
8
  const bytes = Math.round(Number(match[1]) * multiplier);
11
9
  return Number.isSafeInteger(bytes) ? bytes : null;
12
10
  }
package/dist/process.d.ts CHANGED
@@ -12,7 +12,10 @@
12
12
  */
13
13
  import { type ChildProcess } from "node:child_process";
14
14
  import type { CommandInvocationRequest, ProcessSnapshot, StopProcessesResult } from "@jini-ai/core/contracts/runtime";
15
+ import type { ProcessPrivateMemory, ProcessUsage } from "@jini-ai/core/contracts/site/platform-process";
15
16
  import { execFileBuffered } from "./shell.js";
17
+ /** Deprecated re-export: import these from `@jini-ai/core/contracts/site/platform-process`; removed at the next major. */
18
+ export type { ProcessPrivateMemory, ProcessUsage } from "@jini-ai/core/contracts/site/platform-process";
16
19
  export type ProcessStampShape = object;
17
20
  export type ProcessStampField<TStamp extends ProcessStampShape> = Extract<keyof TStamp, string>;
18
21
  export type ProcessStampContract<TStamp extends ProcessStampShape, TCriteria extends Partial<TStamp> = Partial<TStamp>> = {
@@ -28,15 +31,6 @@ export type SpawnProcessRequest = CommandInvocationRequest & {
28
31
  detached?: boolean;
29
32
  logFd?: number | null;
30
33
  };
31
- /** Display-only usage: RSS is bytes; CPU is cumulative seconds across all cores. */
32
- export type ProcessUsage = {
33
- pid: number;
34
- ppid: number;
35
- rssBytes: number;
36
- cpuSeconds: number;
37
- /** Executable basename only; empty when the OS provides no name. */
38
- name: string;
39
- };
40
34
  export type ProcessUsagePorts = {
41
35
  platform?: NodeJS.Platform;
42
36
  run?: typeof execFileBuffered;
@@ -44,14 +38,6 @@ export type ProcessUsagePorts = {
44
38
  export type ProcessUsageOptions = {
45
39
  timeoutMs?: number;
46
40
  };
47
- /** Private-memory samples are separate from RSS; unsupported hosts retain null readings. */
48
- export type ProcessPrivateMemory = {
49
- metric: "physical-footprint" | "private-working-set" | "unavailable";
50
- readings: Array<{
51
- pid: number;
52
- bytes: number | null;
53
- }>;
54
- };
55
41
  export type StampedProcessMatchCriteria<TStamp extends ProcessStampShape> = Partial<TStamp>;
56
42
  /**
57
43
  * Serialize a process stamp into `--flag=value` CLI arguments per the contract.
package/dist/process.js CHANGED
@@ -245,7 +245,7 @@ export async function listProcessSnapshots(input = {}, options = {}) {
245
245
  */
246
246
  export async function listProcessUsage(input = {}, options = {}) {
247
247
  const windows = (input.platform ?? process.platform) === "win32";
248
- const { command, args } = processUsageCommand(windows);
248
+ const { command, args } = processUsageCommand({ windows });
249
249
  try {
250
250
  const result = await (input.run ?? execFileBuffered)(command, args, {
251
251
  encoding: "utf8", timeout: options.timeoutMs ?? 5000, maxBuffer: 8 * 1024 * 1024,
@@ -253,7 +253,8 @@ export async function listProcessUsage(input = {}, options = {}) {
253
253
  });
254
254
  if (!result.ok)
255
255
  return [];
256
- return windows ? parseCimUsage(result.stdout) : parsePsUsage(result.stdout);
256
+ const { stdout } = result;
257
+ return windows ? parseCimUsage({ stdout }) : parsePsUsage({ stdout });
257
258
  }
258
259
  catch {
259
260
  return [];
@@ -0,0 +1,6 @@
1
+ /** Host-neutral storage retention: a serialized pass runner over injected policies, and a read-only
2
+ * tree measurement. Hosts own every path and every policy; nothing in this entry deletes files. */
3
+ export { RETENTION_DEFAULT_INTERVAL_MS, createRetentionRunner, type RetentionMeasurement, type RetentionPassResult, type RetentionPolicy, type RetentionPolicyKind, type RetentionPolicyOutcome, type RetentionRunner, type RetentionRunnerOptional, type RetentionRunnerRequired, type RetentionScheduler, type RetentionSweepResult, } from './runner.js';
4
+ export { measureStorageTree, nodeStorageTreeFs, type StorageTally, type StorageTarget, type StorageTreeDirectory, type StorageTreeFs, type StorageTreeIdentity, type StorageTreeMeasurement, type StorageTreeStats, } from './measure-tree.js';
5
+ export { createCleanupPreviewStore } from './preview-store.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ /** Host-neutral storage retention: a serialized pass runner over injected policies, and a read-only
2
+ * tree measurement. Hosts own every path and every policy; nothing in this entry deletes files. */
3
+ export { RETENTION_DEFAULT_INTERVAL_MS, createRetentionRunner, } from './runner.js';
4
+ export { measureStorageTree, nodeStorageTreeFs, } from './measure-tree.js';
5
+ export { createCleanupPreviewStore } from './preview-store.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,68 @@
1
+ /** A filesystem object's identity; two names for one folder share it, a replacement does not. */
2
+ export interface StorageTreeIdentity {
3
+ readonly dev: number | bigint;
4
+ readonly ino: number | bigint;
5
+ }
6
+ export interface StorageTreeStats extends StorageTreeIdentity {
7
+ isSymbolicLink(): boolean;
8
+ isDirectory(): boolean;
9
+ isFile(): boolean;
10
+ readonly size: number;
11
+ }
12
+ /** One opened folder. Listing and child metadata are read relative to the opened folder, never by
13
+ * re-resolving its pathname, so a later swap of that pathname cannot redirect the reads. */
14
+ export interface StorageTreeDirectory {
15
+ /** Identity of the folder actually opened (never the target of a link). */
16
+ readonly identity: StorageTreeIdentity;
17
+ list(): Promise<string[]>;
18
+ /** Metadata of one child, without following it if it is a link. */
19
+ lstatChild(name: string): Promise<StorageTreeStats>;
20
+ /** False once the folder's pathname no longer names the opened folder. */
21
+ stillOpenedDirectory(): Promise<boolean>;
22
+ close(): Promise<void>;
23
+ }
24
+ /** The read port the walk needs; inject a fake to test unreadable or racing paths. `lstat` is used for
25
+ * the root only; `openDirectory` must refuse (not follow) a link at `target`. */
26
+ export interface StorageTreeFs {
27
+ lstat(target: string): Promise<StorageTreeStats>;
28
+ openDirectory(target: string): Promise<StorageTreeDirectory>;
29
+ }
30
+ export interface StorageTarget {
31
+ readonly id: string;
32
+ readonly path: string;
33
+ }
34
+ export interface StorageTally {
35
+ /** Exact bytes, or `null` when part of this tally could not be read. */
36
+ readonly bytes: number | null;
37
+ /** Bytes actually read: the lower bound when `bytes` is `null`. */
38
+ readonly knownBytes: number;
39
+ readonly files: number;
40
+ readonly unknownPaths: readonly string[];
41
+ readonly skippedSymlinks: readonly string[];
42
+ }
43
+ export interface StorageTreeMeasurement {
44
+ readonly root: string;
45
+ readonly total: StorageTally;
46
+ readonly targets: Readonly<Record<string, StorageTally>>;
47
+ readonly other: StorageTally;
48
+ }
49
+ /** The Node adapter: opens each folder without following a link and, on Linux, reads it through the
50
+ * process's own descriptor link (`/proc/self/fd/N`), which stays bound to the opened folder. Elsewhere it
51
+ * reads by pathname and `stillOpenedDirectory()` re-checks the pathname's identity afterwards.
52
+ * @example await measureStorageTree({ root, targets }, { fs: nodeStorageTreeFs }); */
53
+ export declare const nodeStorageTreeFs: StorageTreeFs;
54
+ /**
55
+ * Measures `root` once, attributing bytes to `targets`.
56
+ * @throws TypeError for a relative root or target, a repeated id or two targets naming one path.
57
+ * @throws RangeError for a target outside `root`.
58
+ * @complexity O(n · t) time for n entries and t targets, O(depth + t) extra space; one `lstat` per
59
+ * entry and one `readdir` per folder, sequential to keep disk pressure low on a serving host.
60
+ * @example await measureStorageTree({ root: siteDir, targets: [{ id: 'uploads', path: uploadsDir }] });
61
+ */
62
+ export declare function measureStorageTree({ root, targets }: {
63
+ root: string;
64
+ targets: readonly StorageTarget[];
65
+ }, { fs: treeFs }?: {
66
+ fs?: StorageTreeFs;
67
+ }): Promise<StorageTreeMeasurement>;
68
+ //# sourceMappingURL=measure-tree.d.ts.map