@jini-ai/integrations 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 (189) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1 -0
  3. package/dist/api-connections/bundled-client-namespace.d.ts +24 -0
  4. package/dist/api-connections/bundled-client-namespace.js +22 -0
  5. package/dist/api-connections/connect.d.ts +2 -10
  6. package/dist/api-connections/connect.js +1 -1
  7. package/dist/api-connections/contribution.d.ts +71 -0
  8. package/dist/api-connections/contribution.js +69 -0
  9. package/dist/api-connections/form-delivery-connection.d.ts +68 -0
  10. package/dist/api-connections/form-delivery-connection.js +73 -0
  11. package/dist/api-connections/hosted-mcp/contracts.d.ts +4 -171
  12. package/dist/api-connections/hosted-mcp/index.d.ts +2 -0
  13. package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +3 -1
  14. package/dist/api-connections/hosted-mcp/oauth-row-writes.js +6 -3
  15. package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +2 -1
  16. package/dist/api-connections/hosted-mcp/sign-in-configuration.js +1 -1
  17. package/dist/api-connections/hosted-mcp/sign-in-discovery.js +1 -1
  18. package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +9 -3
  19. package/dist/api-connections/hosted-mcp/sign-in-flow.js +6 -6
  20. package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +16 -4
  21. package/dist/api-connections/hosted-mcp/sign-in-provider.js +3 -3
  22. package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +13 -2
  23. package/dist/api-connections/hosted-mcp/sign-in-status.js +17 -4
  24. package/dist/api-connections/hosted-mcp/sign-in.d.ts +1 -1
  25. package/dist/api-connections/hosted-mcp/sign-in.js +28 -30
  26. package/dist/api-connections/shared-api.d.ts +87 -0
  27. package/dist/api-connections/shared-api.js +135 -0
  28. package/dist/api-connections/shared-oauth-disconnect.d.ts +73 -0
  29. package/dist/api-connections/shared-oauth-disconnect.js +41 -0
  30. package/dist/api-connections/shared-owner.d.ts +107 -0
  31. package/dist/api-connections/shared-owner.js +79 -0
  32. package/dist/api-connections/vault-stores.d.ts +110 -0
  33. package/dist/api-connections/vault-stores.js +202 -0
  34. package/dist/credentialed-http/auth-schemes.d.ts +2 -9
  35. package/dist/credentialed-http/tools/index.d.ts +30 -0
  36. package/dist/credentialed-http/tools/index.js +19 -0
  37. package/dist/credentialed-http/tools/tool-registrations.js +0 -1
  38. package/dist/custom-credentials/agent-tools.d.ts +79 -0
  39. package/dist/custom-credentials/agent-tools.js +98 -0
  40. package/dist/custom-credentials/card-token.d.ts +15 -0
  41. package/dist/custom-credentials/card-token.js +35 -0
  42. package/dist/custom-credentials/credential-ports.d.ts +70 -0
  43. package/dist/custom-credentials/credential-ports.js +41 -0
  44. package/dist/custom-credentials/credential-recovery.d.ts +20 -0
  45. package/dist/custom-credentials/credential-recovery.js +22 -0
  46. package/dist/custom-credentials/credentialed-request.d.ts +83 -0
  47. package/dist/custom-credentials/credentialed-request.js +93 -0
  48. package/dist/custom-credentials/custom-credential-create-ui.d.ts +106 -0
  49. package/dist/custom-credentials/custom-credential-create-ui.js +136 -0
  50. package/dist/custom-credentials/custom-credential-set-token-ui.d.ts +84 -0
  51. package/dist/custom-credentials/custom-credential-set-token-ui.js +104 -0
  52. package/dist/custom-credentials/delete-request-confirmation-ui.d.ts +33 -0
  53. package/dist/custom-credentials/delete-request-confirmation-ui.js +35 -0
  54. package/dist/custom-credentials/provider-settings-card.d.ts +109 -0
  55. package/dist/custom-credentials/provider-settings-card.js +166 -0
  56. package/dist/custom-credentials/write-files-validation.d.ts +102 -0
  57. package/dist/custom-credentials/write-files-validation.js +202 -0
  58. package/dist/media-providers/catalog-projection.d.ts +29 -0
  59. package/dist/media-providers/catalog-projection.js +45 -0
  60. package/dist/media-providers/catalog.d.ts +6 -3
  61. package/dist/media-providers/catalog.js +4 -3
  62. package/dist/media-providers/configurable-catalog.d.ts +9 -0
  63. package/dist/media-providers/configurable-catalog.js +70 -0
  64. package/dist/media-providers/dispatch/builtin-vendors.js +0 -2
  65. package/dist/media-providers/dispatch/credentials.d.ts +4 -1
  66. package/dist/media-providers/dispatch/credentials.js +3 -2
  67. package/dist/media-providers/dispatch/engine.d.ts +1 -1
  68. package/dist/media-providers/dispatch/engine.js +17 -5
  69. package/dist/media-providers/dispatch/index.d.ts +3 -2
  70. package/dist/media-providers/dispatch/index.js +2 -2
  71. package/dist/media-providers/dispatch/media-provider-registry.d.ts +23 -4
  72. package/dist/media-providers/dispatch/media-provider-registry.js +26 -11
  73. package/dist/media-providers/dispatch/media-wire.d.ts +14 -0
  74. package/dist/media-providers/dispatch/media-wire.js +22 -0
  75. package/dist/media-providers/dispatch/node.d.ts +5 -0
  76. package/dist/media-providers/dispatch/node.js +5 -1
  77. package/dist/media-providers/dispatch/openai-compatible.d.ts +3 -1
  78. package/dist/media-providers/dispatch/openai-compatible.js +1 -1
  79. package/dist/media-providers/dispatch/operation-runtime.js +5 -4
  80. package/dist/media-providers/dispatch/outbound.d.ts +28 -3
  81. package/dist/media-providers/dispatch/outbound.js +10 -3
  82. package/dist/media-providers/dispatch/providers/custom-image.js +1 -1
  83. package/dist/media-providers/dispatch/providers/imagerouter.js +1 -1
  84. package/dist/media-providers/dispatch/providers/nanobanana.js +1 -1
  85. package/dist/media-providers/dispatch/providers/openrouter.js +1 -1
  86. package/dist/media-providers/dispatch/ssrf-guard.js +2 -2
  87. package/dist/media-providers/dispatch/types.d.ts +13 -4
  88. package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
  89. package/dist/media-providers/index.d.ts +2 -0
  90. package/dist/media-providers/providers.d.ts +9 -5
  91. package/dist/media-providers/providers.js +9 -12
  92. package/dist/media-providers/sqlite-task-store.d.ts +4 -4
  93. package/dist/media-providers/task-store.d.ts +1 -1
  94. package/dist/media-providers/task-store.js +1 -1
  95. package/dist/media-providers/types.d.ts +0 -36
  96. package/dist/media-providers/ui-defaults.js +0 -4
  97. package/dist/react/admin-credentials/AdminByokKeyPanel.d.ts +130 -0
  98. package/dist/react/admin-credentials/AdminByokKeyPanel.js +115 -0
  99. package/dist/react/admin-credentials/byok-footer-status.d.ts +37 -0
  100. package/dist/react/admin-credentials/byok-footer-status.js +25 -0
  101. package/dist/react/credentials/OtherCredentialsSection.d.ts +36 -0
  102. package/dist/react/credentials/OtherCredentialsSection.hooks.d.ts +55 -0
  103. package/dist/react/credentials/OtherCredentialsSection.hooks.js +26 -0
  104. package/dist/react/credentials/OtherCredentialsSection.js +120 -0
  105. package/dist/react/credentials/access-token-forms.d.ts +219 -0
  106. package/dist/react/credentials/access-token-forms.js +114 -0
  107. package/dist/react/credentials/credential-copy.d.ts +17 -0
  108. package/dist/react/credentials/credential-copy.js +7 -0
  109. package/dist/react/credentials/other-credential-stores.d.ts +115 -0
  110. package/dist/react/credentials/other-credential-stores.js +76 -0
  111. package/dist/react/site-key/SiteKeyRecoveryCard.d.ts +16 -0
  112. package/dist/react/site-key/SiteKeyRecoveryCard.js +36 -0
  113. package/dist/react/site-key/SiteKeyTab.d.ts +100 -0
  114. package/dist/react/site-key/SiteKeyTab.js +127 -0
  115. package/dist/react/site-key/hooks/use-site-key-recovery.hooks.d.ts +77 -0
  116. package/dist/react/site-key/hooks/use-site-key-recovery.hooks.js +126 -0
  117. package/dist/react/site-key/hooks/use-site-key.hooks.d.ts +120 -0
  118. package/dist/react/site-key/hooks/use-site-key.hooks.js +95 -0
  119. package/dist/react/webhooks/IntegrationDeliveries.d.ts +41 -0
  120. package/dist/react/webhooks/IntegrationDeliveries.js +24 -0
  121. package/dist/react/webhooks/Integrations.d.ts +73 -0
  122. package/dist/react/webhooks/Integrations.js +97 -0
  123. package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.d.ts +59 -0
  124. package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.js +11 -0
  125. package/dist/react/webhooks/hooks/use-integrations.hooks.d.ts +119 -0
  126. package/dist/react/webhooks/hooks/use-integrations.hooks.js +129 -0
  127. package/dist/react/webhooks/rules.d.ts +118 -0
  128. package/dist/react/webhooks/rules.js +103 -0
  129. package/dist/saved-requests/execute.js +2 -3
  130. package/dist/saved-requests/types.d.ts +4 -1
  131. package/dist/secrets/index.d.ts +3 -0
  132. package/dist/secrets/index.js +3 -0
  133. package/dist/secrets/ports.d.ts +25 -0
  134. package/dist/secrets/ports.js +2 -0
  135. package/dist/secrets/types.d.ts +10 -0
  136. package/dist/secrets/types.js +2 -0
  137. package/dist/vendor-credentials/abort-guarded-repo.d.ts +14 -0
  138. package/dist/vendor-credentials/abort-guarded-repo.js +41 -0
  139. package/dist/vendor-credentials/project-scope.d.ts +43 -0
  140. package/dist/vendor-credentials/project-scope.js +32 -0
  141. package/dist/vendor-credentials/vault-adapter.d.ts +157 -0
  142. package/dist/vendor-credentials/vault-adapter.js +220 -0
  143. package/dist/web-screenshot/capture-files.d.ts +44 -0
  144. package/dist/web-screenshot/capture-files.js +62 -0
  145. package/dist/web-screenshot/capture-retention.d.ts +157 -0
  146. package/dist/web-screenshot/capture-retention.js +134 -0
  147. package/dist/web-screenshot/capture-root-file-lock.d.ts +20 -0
  148. package/dist/web-screenshot/capture-root-file-lock.js +15 -0
  149. package/dist/web-screenshot/desktop-page-capture.d.ts +37 -0
  150. package/dist/web-screenshot/desktop-page-capture.js +62 -0
  151. package/dist/web-screenshot/own-site-opener.d.ts +40 -0
  152. package/dist/web-screenshot/own-site-opener.js +27 -0
  153. package/dist/web-screenshot/screenshot-image.d.ts +11 -0
  154. package/dist/web-screenshot/screenshot-image.js +12 -0
  155. package/dist/web-screenshot/web-screenshot.d.ts +188 -0
  156. package/dist/web-screenshot/web-screenshot.js +329 -0
  157. package/dist/webhooks/delivery.d.ts +16 -0
  158. package/dist/webhooks/delivery.js +41 -1
  159. package/dist/webhooks/ports.d.ts +1 -29
  160. package/dist/webhooks/signing.keyring.d.ts +1 -1
  161. package/dist/webhooks/site/delivery.d.ts +60 -0
  162. package/dist/webhooks/site/delivery.js +45 -0
  163. package/dist/webhooks/site/http.memory.d.ts +51 -0
  164. package/dist/webhooks/site/http.memory.js +28 -0
  165. package/dist/webhooks/site/repo.memory.d.ts +136 -0
  166. package/dist/webhooks/site/repo.memory.js +215 -0
  167. package/dist/webhooks/site/seal-aad-invariant.d.ts +26 -0
  168. package/dist/webhooks/site/seal-aad-invariant.js +61 -0
  169. package/dist/webhooks/site/seal-aad-invariant.node.d.ts +42 -0
  170. package/dist/webhooks/site/seal-aad-invariant.node.js +52 -0
  171. package/dist/webhooks/site/signing.d.ts +28 -0
  172. package/dist/webhooks/site/signing.js +27 -0
  173. package/dist/webhooks/site/signing.keyring.d.ts +29 -0
  174. package/dist/webhooks/site/signing.keyring.js +30 -0
  175. package/dist/webhooks/site/subscriptions.d.ts +118 -0
  176. package/dist/webhooks/site/subscriptions.js +98 -0
  177. package/dist/webhooks/sql/index.d.ts +4 -0
  178. package/dist/webhooks/sql/index.js +2 -0
  179. package/dist/webhooks/sql/repo.rows.d.ts +47 -0
  180. package/dist/webhooks/sql/repo.rows.js +2 -0
  181. package/dist/webhooks/sql/webhook-repo.d.ts +152 -0
  182. package/dist/webhooks/sql/webhook-repo.js +308 -0
  183. package/dist/webhooks/subscriptions.d.ts +3 -1
  184. package/dist/webhooks/subscriptions.js +4 -1
  185. package/dist/webhooks/tools/tool-handlers.js +2 -1
  186. package/dist/webhooks/types.d.ts +6 -10
  187. package/package.json +517 -12
  188. package/dist/media-providers/dispatch/providers/grok.d.ts +0 -55
  189. package/dist/media-providers/dispatch/providers/grok.js +0 -116
@@ -0,0 +1,62 @@
1
+ import { link, mkdir, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ /**
4
+ * @file Where `web_screenshot_page` keeps its captures: `<siteDir>/.captures/<UTC date>/<name>.jpg`
5
+ * (names from `captureRelativePaths`). Saved so a report can cite the exact picture later, e.g. the
6
+ * source-vs-theme rounds of the host theme skill's "match a reference site" loop (2026-10-08); before this the
7
+ * images existed only inside the chat turn.
8
+ *
9
+ * A dot-folder of its own rather than `ops/` (the site's runtime state: logs, journal, daemon file):
10
+ * these are agent artifacts a person opens. Neither site backup (each scope walks only its own
11
+ * subtree) nor publish/export reads it. No automatic retention: captures are a few hundred KB each and
12
+ * are the owner's to delete, through the preview + confirm cleanup in `capture-retention.ts`.
13
+ */
14
+ export const CAPTURES_DIR_NAME = ".captures";
15
+ /** The captures folder of a site folder. */
16
+ export function captureRootFor({ siteDir }) {
17
+ return path.join(siteDir, CAPTURES_DIR_NAME);
18
+ }
19
+ /** The suffix a capture carries while it is being written; cleanup never touches such a file. */
20
+ export const CAPTURE_PARTIAL_SUFFIX = ".partial";
21
+ /**
22
+ * Writes each file under `rootDir`, creating folders as needed, and resolves to the absolute paths.
23
+ * Each capture is staged as `<name>.partial` (opened `wx`) and only then linked to its final name, all
24
+ * under `lock.withLock({ key: rootDir })`, so a reader never mistakes half a picture for a finished one.
25
+ * Never overwrites: publication uses `link`, which fails with `EEXIST` if the final name exists, so a
26
+ * name collision is a rejection, not a silently replaced capture. The staged file is removed either way.
27
+ * @throws Error when a `relPath` would land outside `rootDir` (checked for all files before any write).
28
+ * @complexity O(total bytes).
29
+ */
30
+ export function createCaptureFileWriter({ rootDir, lock }, _optional = {}) {
31
+ const root = path.resolve(rootDir);
32
+ return async ({ files }) => {
33
+ const targets = files.map(({ relPath, bytes }) => {
34
+ const target = path.resolve(root, relPath);
35
+ if (path.isAbsolute(relPath) || !target.startsWith(`${root}${path.sep}`))
36
+ throw new Error(`capture path '${relPath}' escapes the captures folder`);
37
+ return { target, bytes };
38
+ });
39
+ return lock.withLock({ key: root, run: async () => {
40
+ const written = [];
41
+ for (const { target, bytes } of targets) {
42
+ await publishCapture({ target, bytes });
43
+ written.push(target);
44
+ }
45
+ return written;
46
+ } }, {});
47
+ };
48
+ }
49
+ /** Stages one capture as `.partial`, then hard-links it to the final name (no overwrite) and drops the stage. */
50
+ async function publishCapture({ target, bytes }) {
51
+ const staged = `${target}${CAPTURE_PARTIAL_SUFFIX}`;
52
+ await mkdir(path.dirname(target), { recursive: true });
53
+ await writeFile(staged, bytes, { flag: "wx" });
54
+ try {
55
+ // `link`, not `rename`: rename silently replaces an existing file; link refuses with EEXIST.
56
+ await link(staged, target);
57
+ }
58
+ finally {
59
+ await rm(staged, { force: true });
60
+ }
61
+ }
62
+ //# sourceMappingURL=capture-files.js.map
@@ -0,0 +1,157 @@
1
+ import type { CleanupPreviewStore } from "@jini-ai/core/contracts/storage";
2
+ import { type CaptureRootLock } from "./capture-files.js";
3
+ /**
4
+ * @file Manual "delete screenshots older than…" for one captures folder (`capture-files.ts`).
5
+ *
6
+ * Why preview + confirm and not a cache sweep: a capture is an owner artifact, not a cache. A report
7
+ * may cite it by path, and nothing can regenerate the exact picture of a page as it looked then, so
8
+ * no age makes a capture safe to drop on its own. Deletion happens only when the owner asked, saw the
9
+ * list, and confirmed it, and then only for the files that are still exactly what was shown.
10
+ *
11
+ * Only writer-owned files are ever offered: regular files (by `lstat`, never through a symlink) named
12
+ * `<YYYY-MM-DD>/<name>.jpg` the way `captureRelativePaths` names them, never a `.partial` still being
13
+ * written. Paths come only from the lister, never from the caller. The host supplies the authorized
14
+ * principal, the root, the ports and the root-keyed lock the writer also holds.
15
+ */
16
+ /** One entry under the captures root as `lstat` saw it; `identity` changes when the file is replaced or rewritten. */
17
+ export interface CaptureEntry {
18
+ relPath: string;
19
+ kind: "file" | "directory" | "symlink" | "other";
20
+ identity: string;
21
+ mtimeMs: number;
22
+ size: number;
23
+ }
24
+ export type ListOwnedCaptures = (required: {
25
+ root: string;
26
+ }, optional?: Record<string, never>) => Promise<readonly CaptureEntry[]>;
27
+ /** Removes `relPath` only if it is still a regular file with `identity`; resolves whether it removed it. */
28
+ export type RemoveOwnedCapture = (required: {
29
+ root: string;
30
+ relPath: string;
31
+ identity: string;
32
+ }, optional?: Record<string, never>) => Promise<boolean>;
33
+ export interface CaptureRetentionPreview {
34
+ previewToken: string;
35
+ deadline: number;
36
+ count: number;
37
+ bytes: number;
38
+ items: string[];
39
+ }
40
+ export interface CaptureRetentionResult {
41
+ deleted: string[];
42
+ kept: {
43
+ relPath: string;
44
+ reason: "missing" | "changed" | "not-eligible";
45
+ }[];
46
+ }
47
+ /**
48
+ * Preview/apply engine for manual capture cleanup.
49
+ * `preview` lists at most `limit` eligible captures (oldest first) under the lock and stores their
50
+ * identities behind a single-use token bound to principal and scope. `apply` requires `confirm: true`
51
+ * and that token, then, under the same lock, re-lists and deletes only token entries that are still
52
+ * present with the same identity, still contained, still finished, and still older than the cutoff.
53
+ * @throws Error "Choose a time that has already passed." for a future or invalid cutoff;
54
+ * "Confirm the screenshot preview first." without confirm; "This preview is out of date. Preview again."
55
+ * for an unknown, used, expired or foreign token.
56
+ * @complexity O(n log n) in captures listed; one remove call per confirmed capture.
57
+ */
58
+ export declare function createCaptureRetention({ root, listOwned, removeOwned, previewStore, clock, lock }: {
59
+ root: string;
60
+ listOwned: ListOwnedCaptures;
61
+ removeOwned: RemoveOwnedCapture;
62
+ previewStore: CleanupPreviewStore;
63
+ clock: () => number;
64
+ lock: CaptureRootLock;
65
+ }, { limit }?: {
66
+ limit?: number;
67
+ }): {
68
+ preview({ principal, scope, before }: {
69
+ principal: string;
70
+ scope: string;
71
+ before: number;
72
+ }, _optional?: Record<string, never>): Promise<CaptureRetentionPreview>;
73
+ apply({ principal, scope, previewToken, confirm }: {
74
+ principal: string;
75
+ scope: string;
76
+ previewToken: string;
77
+ confirm: boolean;
78
+ }, _optional?: Record<string, never>): Promise<CaptureRetentionResult>;
79
+ };
80
+ /** The slice of `node:fs/promises` the default ports use. */
81
+ export interface CaptureFs {
82
+ readdir(path: string): Promise<string[]>;
83
+ lstat(path: string, options: {
84
+ bigint: true;
85
+ }): Promise<{
86
+ dev: bigint;
87
+ ino: bigint;
88
+ size: bigint;
89
+ mtimeMs: bigint;
90
+ mtimeNs: bigint;
91
+ isFile(): boolean;
92
+ isDirectory(): boolean;
93
+ isSymbolicLink(): boolean;
94
+ }>;
95
+ unlink(path: string): Promise<void>;
96
+ }
97
+ /**
98
+ * Default `listOwned` / `removeOwned` over an injected fs. Lists the root and its real (non-symlinked)
99
+ * date folders one level deep with `lstat`; symlinks are reported as such and never followed.
100
+ * `removeOwned` re-`lstat`s and unlinks only a regular file whose identity still matches.
101
+ * @complexity O(entries) fs calls for a listing; two for a removal.
102
+ */
103
+ export declare function createCaptureFilePorts({ fs }: {
104
+ fs: CaptureFs;
105
+ }, _optional?: Record<string, never>): {
106
+ listOwned: ListOwnedCaptures;
107
+ removeOwned: RemoveOwnedCapture;
108
+ };
109
+ /** Who may clean up: the authorized owner's principal. `authorizeOwner` throws for anyone else. */
110
+ export interface CaptureCleanupOwner {
111
+ principal: string;
112
+ }
113
+ /** Required collaborators of {@link bindCaptureRetention}. */
114
+ export interface BindCaptureRetentionRequired<Context> {
115
+ /** The booted site's folder; only its current captures root is ever listed. */
116
+ siteDir: string;
117
+ /** The writer's own root derivation (`@jini-ai/integrations/web-screenshot/capture-files`). */
118
+ captureRootFor: (required: {
119
+ siteDir: string;
120
+ }) => string;
121
+ /** The same root-keyed lock instance the capture writer holds. */
122
+ writerFence: CaptureRootLock;
123
+ fs: CaptureFs;
124
+ clock: () => number;
125
+ previewStore: CleanupPreviewStore;
126
+ /** Resolves the owner from the authenticated request context, or throws (owner-only). */
127
+ authorizeOwner: (required: {
128
+ context: Context;
129
+ }) => CaptureCleanupOwner | Promise<CaptureCleanupOwner>;
130
+ }
131
+ /** The owner-facing preview/apply pair the screenshot storage routes call. */
132
+ export interface CaptureRetentionBinding<Context> {
133
+ preview(required: {
134
+ context: Context;
135
+ before: number;
136
+ }, optional?: Record<string, never>): Promise<CaptureRetentionPreview>;
137
+ apply(required: {
138
+ context: Context;
139
+ previewToken: string;
140
+ confirm: boolean;
141
+ }, optional?: Record<string, never>): Promise<CaptureRetentionResult>;
142
+ }
143
+ /**
144
+ * Binds Jini's manual capture cleanup to this site's captures folder: the writer's root only, the
145
+ * writer's fence, the default lstat-based ports (date/name shape, no symlinks, no `..`), and an
146
+ * owner check before every preview and every apply. Nothing here registers a schedule or a sweep:
147
+ * cited captures stay until the owner explicitly removes them, because a report or a chat may cite a
148
+ * capture by path and nothing can re-take a picture of the page as it looked then, so no age alone
149
+ * makes one safe to drop; only an owner who saw the list and confirmed it may delete.
150
+ * @throws Whatever `authorizeOwner` throws for a non-owner, before any listing; the engine's plain
151
+ * errors for a future cutoff, a missing confirm, or an out-of-date preview.
152
+ * @complexity As `createCaptureRetention`: O(n log n) in captures listed.
153
+ */
154
+ export declare function bindCaptureRetention<Context>({ siteDir, captureRootFor, writerFence, fs, clock, previewStore, authorizeOwner }: BindCaptureRetentionRequired<Context>, { limit }?: {
155
+ limit?: number;
156
+ }): CaptureRetentionBinding<Context>;
157
+ //# sourceMappingURL=capture-retention.d.ts.map
@@ -0,0 +1,134 @@
1
+ import path from "node:path";
2
+ import { CAPTURE_PARTIAL_SUFFIX } from "./capture-files.js";
3
+ const PREVIEW_KIND = "capture-retention";
4
+ const SHOWN_ITEMS = 50;
5
+ const OWNED_NAME = /^\d{4}-\d{2}-\d{2}\/[^/\\]+\.jpg$/;
6
+ /** Whether an entry is a finished, writer-named regular file inside the root and older than `before`. */
7
+ function isEligible({ entry, before }) {
8
+ if (entry.kind !== "file" || entry.relPath.endsWith(CAPTURE_PARTIAL_SUFFIX))
9
+ return false;
10
+ if (!OWNED_NAME.test(entry.relPath) || entry.relPath.split("/").includes(".."))
11
+ return false;
12
+ return entry.mtimeMs < before;
13
+ }
14
+ /**
15
+ * Preview/apply engine for manual capture cleanup.
16
+ * `preview` lists at most `limit` eligible captures (oldest first) under the lock and stores their
17
+ * identities behind a single-use token bound to principal and scope. `apply` requires `confirm: true`
18
+ * and that token, then, under the same lock, re-lists and deletes only token entries that are still
19
+ * present with the same identity, still contained, still finished, and still older than the cutoff.
20
+ * @throws Error "Choose a time that has already passed." for a future or invalid cutoff;
21
+ * "Confirm the screenshot preview first." without confirm; "This preview is out of date. Preview again."
22
+ * for an unknown, used, expired or foreign token.
23
+ * @complexity O(n log n) in captures listed; one remove call per confirmed capture.
24
+ */
25
+ export function createCaptureRetention({ root, listOwned, removeOwned, previewStore, clock, lock }, { limit = 500 } = {}) {
26
+ const key = path.resolve(root);
27
+ const eligible = async (before) => (await listOwned({ root: key }, {}))
28
+ .filter((entry) => isEligible({ entry, before }));
29
+ return {
30
+ async preview({ principal, scope, before }, _optional = {}) {
31
+ if (!Number.isFinite(before) || before > clock())
32
+ throw new Error("Choose a time that has already passed.");
33
+ const chosen = await lock.withLock({ key, run: async () => (await eligible(before))
34
+ .sort((a, b) => a.mtimeMs - b.mtimeMs || a.relPath.localeCompare(b.relPath)).slice(0, limit) }, {});
35
+ const items = chosen.map(({ relPath, identity }) => ({ relPath, identity }));
36
+ const { token, deadline } = previewStore.put({ principal, kind: PREVIEW_KIND, scope, payload: { before, items } }, {});
37
+ return { previewToken: token, deadline, count: chosen.length, bytes: chosen.reduce((sum, entry) => sum + entry.size, 0), items: chosen.slice(0, SHOWN_ITEMS).map((entry) => entry.relPath) };
38
+ },
39
+ async apply({ principal, scope, previewToken, confirm }, _optional = {}) {
40
+ if (confirm !== true)
41
+ throw new Error("Confirm the screenshot preview first.");
42
+ const taken = previewStore.take({ token: previewToken, principal, kind: PREVIEW_KIND, scope }, {});
43
+ if (!taken)
44
+ throw new Error("This preview is out of date. Preview again.");
45
+ const { before, items } = taken.payload;
46
+ return lock.withLock({ key, run: async () => {
47
+ const current = new Map((await eligible(before)).map((entry) => [entry.relPath, entry]));
48
+ const result = { deleted: [], kept: [] };
49
+ for (const { relPath, identity } of items) {
50
+ const now = current.get(relPath);
51
+ if (!now)
52
+ result.kept.push({ relPath, reason: "not-eligible" });
53
+ else if (now.identity !== identity)
54
+ result.kept.push({ relPath, reason: "changed" });
55
+ else if (await removeOwned({ root: key, relPath, identity }, {}))
56
+ result.deleted.push(relPath);
57
+ else
58
+ result.kept.push({ relPath, reason: "missing" });
59
+ }
60
+ return result;
61
+ } }, {});
62
+ },
63
+ };
64
+ }
65
+ function entryOf({ relPath, stat }) {
66
+ const kind = stat.isSymbolicLink() ? "symlink" : stat.isFile() ? "file" : stat.isDirectory() ? "directory" : "other";
67
+ return { relPath, kind, identity: `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}`, mtimeMs: Number(stat.mtimeMs), size: Number(stat.size) };
68
+ }
69
+ /**
70
+ * Default `listOwned` / `removeOwned` over an injected fs. Lists the root and its real (non-symlinked)
71
+ * date folders one level deep with `lstat`; symlinks are reported as such and never followed.
72
+ * `removeOwned` re-`lstat`s and unlinks only a regular file whose identity still matches.
73
+ * @complexity O(entries) fs calls for a listing; two for a removal.
74
+ */
75
+ export function createCaptureFilePorts({ fs }, _optional = {}) {
76
+ const lstatOrNull = (file) => fs.lstat(file, { bigint: true }).catch(() => null);
77
+ const listDir = async (dir, prefix) => {
78
+ const names = await fs.readdir(dir).catch(() => []);
79
+ const entries = [];
80
+ for (const name of names) {
81
+ const stat = await lstatOrNull(path.join(dir, name));
82
+ if (stat)
83
+ entries.push(entryOf({ relPath: prefix + name, stat }));
84
+ }
85
+ return entries;
86
+ };
87
+ return {
88
+ async listOwned({ root }) {
89
+ const rootStat = await lstatOrNull(root);
90
+ if (!rootStat?.isDirectory() || rootStat.isSymbolicLink())
91
+ return [];
92
+ const top = await listDir(root, "");
93
+ const nested = await Promise.all(top.filter((entry) => entry.kind === "directory").map((entry) => listDir(path.join(root, entry.relPath), `${entry.relPath}/`)));
94
+ return [...top, ...nested.flat()];
95
+ },
96
+ async removeOwned({ root, relPath, identity }) {
97
+ const file = path.join(root, relPath);
98
+ const stat = await lstatOrNull(file);
99
+ const now = stat && entryOf({ relPath, stat });
100
+ if (!now || now.kind !== "file" || now.identity !== identity)
101
+ return false;
102
+ await fs.unlink(file);
103
+ return true;
104
+ },
105
+ };
106
+ }
107
+ /**
108
+ * Binds Jini's manual capture cleanup to this site's captures folder: the writer's root only, the
109
+ * writer's fence, the default lstat-based ports (date/name shape, no symlinks, no `..`), and an
110
+ * owner check before every preview and every apply. Nothing here registers a schedule or a sweep:
111
+ * cited captures stay until the owner explicitly removes them, because a report or a chat may cite a
112
+ * capture by path and nothing can re-take a picture of the page as it looked then, so no age alone
113
+ * makes one safe to drop; only an owner who saw the list and confirmed it may delete.
114
+ * @throws Whatever `authorizeOwner` throws for a non-owner, before any listing; the engine's plain
115
+ * errors for a future cutoff, a missing confirm, or an out-of-date preview.
116
+ * @complexity As `createCaptureRetention`: O(n log n) in captures listed.
117
+ */
118
+ export function bindCaptureRetention({ siteDir, captureRootFor, writerFence, fs, clock, previewStore, authorizeOwner }, { limit } = {}) {
119
+ const root = path.resolve(captureRootFor({ siteDir }));
120
+ // The scope binds a token to this one root, so a preview of another site's captures never applies here.
121
+ const scope = `captures:${root}`;
122
+ const retention = createCaptureRetention({ root, ...createCaptureFilePorts({ fs }, {}), previewStore, clock, lock: writerFence }, limit === undefined ? {} : { limit });
123
+ return {
124
+ async preview({ context, before }) {
125
+ const { principal } = await authorizeOwner({ context });
126
+ return retention.preview({ principal, scope, before }, {});
127
+ },
128
+ async apply({ context, previewToken, confirm }) {
129
+ const { principal } = await authorizeOwner({ context });
130
+ return retention.apply({ principal, scope, previewToken, confirm }, {});
131
+ },
132
+ };
133
+ }
134
+ //# sourceMappingURL=capture-retention.js.map
@@ -0,0 +1,20 @@
1
+ import type { CaptureRootLock } from "./capture-files.js";
2
+ /** The lock file's name inside the captures root; it is not a `<date>/<name>.jpg`, so cleanup never offers it. */
3
+ export declare const CAPTURE_LOCK_NAME = ".writer.lock";
4
+ /** The slice of `@jini-ai/platform/fs`'s `withFileLock` this lock uses. */
5
+ export type CaptureFileLockRunner = <T>(required: {
6
+ lockPath: string;
7
+ run: () => Promise<T>;
8
+ }, options: {
9
+ createParent: boolean;
10
+ }) => Promise<T>;
11
+ /**
12
+ * A cross-process lock keyed by the resolved captures root: the agent's capture writer and the
13
+ * owner's cleanup may run in different processes (desktop and server share one site folder), so an
14
+ * in-memory mutex would not keep a cleanup from deleting a capture mid-publication.
15
+ * @complexity O(1) per acquisition beyond the file lock's own polling.
16
+ */
17
+ export declare function createCaptureRootFileLock({ withFileLock }: {
18
+ withFileLock: CaptureFileLockRunner;
19
+ }, _optional?: Record<string, never>): CaptureRootLock;
20
+ //# sourceMappingURL=capture-root-file-lock.d.ts.map
@@ -0,0 +1,15 @@
1
+ import path from "node:path";
2
+ /** The lock file's name inside the captures root; it is not a `<date>/<name>.jpg`, so cleanup never offers it. */
3
+ export const CAPTURE_LOCK_NAME = ".writer.lock";
4
+ /**
5
+ * A cross-process lock keyed by the resolved captures root: the agent's capture writer and the
6
+ * owner's cleanup may run in different processes (desktop and server share one site folder), so an
7
+ * in-memory mutex would not keep a cleanup from deleting a capture mid-publication.
8
+ * @complexity O(1) per acquisition beyond the file lock's own polling.
9
+ */
10
+ export function createCaptureRootFileLock({ withFileLock }, _optional = {}) {
11
+ return {
12
+ withLock: ({ key, run }) => withFileLock({ lockPath: path.join(path.resolve(key), CAPTURE_LOCK_NAME), run }, { createParent: true }),
13
+ };
14
+ }
15
+ //# sourceMappingURL=capture-root-file-lock.js.map
@@ -0,0 +1,37 @@
1
+ /** Map Jini's native render capability onto the existing screenshot port. The site/theme opener,
2
+ * serialization, JPEG tiles and saved files remain owned by the screenshot feature.
3
+ */
4
+ import type { PageCapture, PageCapturePort, PageCaptureRequest } from '@jini-ai/core/contracts/site/web-screenshot';
5
+ /** The slice of the desktop host's URL capture port this adapter drives (`UrlCapturePort` satisfies it). */
6
+ export interface NativeUrlCapture {
7
+ captureUrl(required: Pick<PageCaptureRequest, 'url' | 'viewport' | 'fullPage' | 'maxPageHeightPx' | 'settleMs'>, options?: {
8
+ signal?: AbortSignal;
9
+ }): Promise<Omit<PageCapture, 'png'> & {
10
+ png: Uint8Array;
11
+ }>;
12
+ }
13
+ /** The slice of the desktop host's render error this adapter reads. */
14
+ export interface NativeRenderError {
15
+ code: string;
16
+ message: string;
17
+ }
18
+ /** Recognises the desktop host's render error (the host binds it to `instanceof RenderServiceError`). */
19
+ export type IsNativeRenderError = (error: unknown) => error is NativeRenderError;
20
+ /** A native window is owned per request; closing this port has no shared browser to terminate.
21
+ * @throws PageCaptureError for every expected native/transport failure.
22
+ * @complexity O(pixels), bounded by Jini's capture contract.
23
+ */
24
+ export declare function createDesktopPageCapture({ capture, isRenderServiceError }: {
25
+ capture: NativeUrlCapture;
26
+ isRenderServiceError: IsNativeRenderError;
27
+ }, _options?: {}): PageCapturePort;
28
+ /** Both compiled serve and source-mode desktop use this same composition decision. No channel
29
+ * means the existing Playwright adapter (and its unavailable-browser error) is unchanged.
30
+ * @complexity O(1).
31
+ */
32
+ export declare function createPageCaptureForHost({ playwright, nativeCapture, isRenderServiceError }: {
33
+ playwright: PageCapturePort;
34
+ nativeCapture: NativeUrlCapture | null;
35
+ isRenderServiceError: IsNativeRenderError;
36
+ }, _optional?: {}): PageCapturePort;
37
+ //# sourceMappingURL=desktop-page-capture.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { PageCaptureError } from './web-screenshot.js';
2
+ /** A native window is owned per request; closing this port has no shared browser to terminate.
3
+ * @throws PageCaptureError for every expected native/transport failure.
4
+ * @complexity O(pixels), bounded by Jini's capture contract.
5
+ */
6
+ export function createDesktopPageCapture({ capture, isRenderServiceError }, _options = {}) {
7
+ return {
8
+ async capture(request, { signal } = {}) {
9
+ // Desktop's native channel is deliberately own-site only, including the ephemeral theme
10
+ // render origin supplied by openOwnSite. A public-reference URL retains the clear refusal.
11
+ if (!request.allowedOrigins.includes(new URL(request.url).origin)) {
12
+ throw new PageCaptureError({ kind: 'refused', message: 'desktop capture requires sitePath on this site' });
13
+ }
14
+ if (request.dismissCookieBanners || typeof request.waitFor === 'string') {
15
+ throw new PageCaptureError({ kind: 'failed', message: 'native capture does not support consent clicks or selector waits' });
16
+ }
17
+ try {
18
+ const result = await capture.captureUrl({ url: request.url, viewport: request.viewport,
19
+ fullPage: request.fullPage, maxPageHeightPx: request.maxPageHeightPx,
20
+ settleMs: typeof request.waitFor === 'number' ? request.waitFor * 1000 : request.settleMs,
21
+ }, signal ? { signal } : {});
22
+ return { ...result, png: Buffer.from(result.png) };
23
+ }
24
+ catch (error) {
25
+ throw nativeCaptureError({ error, isRenderServiceError });
26
+ }
27
+ },
28
+ async close() { },
29
+ };
30
+ }
31
+ function nativeCaptureError({ error, isRenderServiceError }, _options = {}) {
32
+ if (!isRenderServiceError(error)) {
33
+ return new PageCaptureError({ kind: 'failed', message: 'native capture failed' });
34
+ }
35
+ if (error.code === 'timeout' || error.code === 'aborted') {
36
+ return new PageCaptureError({ kind: 'timeout', message: error.message });
37
+ }
38
+ const kind = error.code === 'navigation-blocked' ? 'refused' : 'failed';
39
+ return new PageCaptureError({ kind, message: error.message });
40
+ }
41
+ // The host injects its Playwright adapter, its resolved native channel (or `null`) and its render-error check.
42
+ /** Both compiled serve and source-mode desktop use this same composition decision. No channel
43
+ * means the existing Playwright adapter (and its unavailable-browser error) is unchanged.
44
+ * @complexity O(1).
45
+ */
46
+ export function createPageCaptureForHost({ playwright, nativeCapture, isRenderServiceError }, _optional = {}) {
47
+ if (!nativeCapture)
48
+ return playwright;
49
+ const desktop = createDesktopPageCapture({ capture: nativeCapture, isRenderServiceError });
50
+ return {
51
+ capture(request, optional) {
52
+ // Public references retain the guarded public browser. Explicit consent/selector interaction
53
+ // also keeps its existing implementation; the native capability never broadens its policy.
54
+ if (request.allowedOrigins.length === 0 || request.dismissCookieBanners || typeof request.waitFor === 'string') {
55
+ return playwright.capture(request, optional);
56
+ }
57
+ return desktop.capture(request, optional);
58
+ },
59
+ async close() { await Promise.all([desktop.close(), playwright.close()]); },
60
+ };
61
+ }
62
+ //# sourceMappingURL=desktop-page-capture.js.map
@@ -0,0 +1,40 @@
1
+ import { type OpenOwnSite, type OwnSiteServer } from "./web-screenshot.js";
2
+ /**
3
+ * @file The own-site opener behind `web_screenshot_page`'s `sitePath` + `themeId`: checks the theme
4
+ * against this site's discovered themes, then boots the per-call loopback server with that theme as a
5
+ * render override (`openLoopbackSiteServer` -> `RouteDeps.createSiteApp({ themeId })`).
6
+ *
7
+ * Why the check lives here and not in the render: the site render (`resolveActiveTheme`) quietly
8
+ * falls back to the default theme for an unknown or invalid id, which is right for visitors but would
9
+ * hand the agent a picture of the WRONG theme to compare against its reference (2026-10-08, the
10
+ * "match a reference site" loop in the host theme skill, Part C).
11
+ *
12
+ * Every capture's app also leaves out the cookie consent layer (`consentAudit`): with the banner on
13
+ * by default, each picture showed it over the page and the agent could not judge the layout
14
+ * (2026-10-27). The option belongs to this throwaway app only; visitors still get the banner.
15
+ */
16
+ /** The slice of a discovered theme this needs (`DiscoveredTheme` satisfies it structurally). */
17
+ export interface RenderableTheme {
18
+ manifest: {
19
+ id: string;
20
+ };
21
+ status: string;
22
+ }
23
+ /** Boots this site's app on a loopback origin; `optional.themeId` is the render override and
24
+ * `optional.consentAudit` leaves out the cookie consent layer. */
25
+ export type OpenLoopbackSite = (required: {}, optional: {
26
+ themeId?: string;
27
+ consentAudit?: true;
28
+ }) => Promise<OwnSiteServer>;
29
+ /**
30
+ * @param required.themes - The boot-discovered roster. Read per call: discovery and `theme_duplicate`
31
+ * mutate it in place, so a copy made after boot is visible without a restart.
32
+ * @param required.openLoopback - Boots the server (`openLoopbackSiteServer` over the site's deps).
33
+ * @returns An {@link OpenOwnSite}. It throws ToolInputError for an unknown or invalid `themeId`, before booting anything.
34
+ * @complexity O(themes) per call.
35
+ */
36
+ export declare function createOwnSiteOpener({ themes, openLoopback }: {
37
+ themes: readonly RenderableTheme[];
38
+ openLoopback: OpenLoopbackSite;
39
+ }): OpenOwnSite;
40
+ //# sourceMappingURL=own-site-opener.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { ToolInputError } from "@jini-ai/core";
2
+ import { WEB_SCREENSHOT_TOOL_ID } from "./web-screenshot.js";
3
+ function refusal({ message }, _optional = {}) {
4
+ return new ToolInputError({ message: `${WEB_SCREENSHOT_TOOL_ID}: ${message}` });
5
+ }
6
+ /**
7
+ * @param required.themes - The boot-discovered roster. Read per call: discovery and `theme_duplicate`
8
+ * mutate it in place, so a copy made after boot is visible without a restart.
9
+ * @param required.openLoopback - Boots the server (`openLoopbackSiteServer` over the site's deps).
10
+ * @returns An {@link OpenOwnSite}. It throws ToolInputError for an unknown or invalid `themeId`, before booting anything.
11
+ * @complexity O(themes) per call.
12
+ */
13
+ export function createOwnSiteOpener({ themes, openLoopback }) {
14
+ return async (_required = {}, { themeId } = {}) => {
15
+ if (themeId === undefined)
16
+ return openLoopback({}, { consentAudit: true });
17
+ const theme = themes.find((candidate) => candidate.manifest.id === themeId);
18
+ if (!theme) {
19
+ const installed = themes.filter((candidate) => candidate.status === "valid").map((candidate) => candidate.manifest.id);
20
+ throw refusal({ message: `themeId '${themeId}' is not an installed theme. Installed themes: ${installed.join(", ") || "none"}.` });
21
+ }
22
+ if (theme.status !== "valid")
23
+ throw refusal({ message: `themeId '${themeId}' is installed but invalid (it fails theme validation), so the site would render a different theme instead. Fix the theme first.` });
24
+ return openLoopback({}, { themeId, consentAudit: true });
25
+ };
26
+ }
27
+ //# sourceMappingURL=own-site-opener.js.map
@@ -0,0 +1,11 @@
1
+ import type { ImageCodecPort } from "@jini-ai/core/contracts/site/cms-media";
2
+ import type { EncodeTiles } from "./web-screenshot.js";
3
+ /**
4
+ * Downscales a PNG screenshot to `maxWidth` (never enlarged) and cuts it into JPEG tiles of at most
5
+ * `tileHeight` px, top to bottom. One decode, one resize, one encode per tile, owned by the codec.
6
+ * @complexity O(pixels).
7
+ */
8
+ export declare function createScreenshotTileEncoder({ imageCodec }: {
9
+ imageCodec: ImageCodecPort;
10
+ }, _options?: {}): EncodeTiles;
11
+ //# sourceMappingURL=screenshot-image.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Downscales a PNG screenshot to `maxWidth` (never enlarged) and cuts it into JPEG tiles of at most
3
+ * `tileHeight` px, top to bottom. One decode, one resize, one encode per tile, owned by the codec.
4
+ * @complexity O(pixels).
5
+ */
6
+ export function createScreenshotTileEncoder({ imageCodec }, _options = {}) {
7
+ return async ({ png, maxWidth, tileHeight }, { quality = 70 } = {}) => {
8
+ const tiles = await imageCodec.encodeTiles({ source: png, maxWidth, tileHeight }, { quality });
9
+ return tiles.map(tile => ({ ...tile, bytes: Buffer.from(tile.bytes) }));
10
+ };
11
+ }
12
+ //# sourceMappingURL=screenshot-image.js.map