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

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 (136) hide show
  1. package/README.md +13 -0
  2. package/dist/download-lock.d.ts +3 -1
  3. package/dist/download-lock.js +4 -4
  4. package/dist/download-maintenance.js +6 -6
  5. package/dist/download-state.js +17 -14
  6. package/dist/download-store.d.ts +34 -10
  7. package/dist/download-store.js +24 -20
  8. package/dist/download-target.d.ts +6 -2
  9. package/dist/download-target.js +7 -7
  10. package/dist/download-transfer.js +18 -12
  11. package/dist/download.js +4 -4
  12. package/dist/fetch-with-timeout.d.ts +0 -53
  13. package/dist/fetch-with-timeout.js +56 -6
  14. package/dist/fs/directory-running-lock.d.ts +4 -0
  15. package/dist/fs/directory-running-lock.js +8 -1
  16. package/dist/fs/directory-workspace.d.ts +2 -1
  17. package/dist/fs/directory-workspace.js +2 -2
  18. package/dist/fs/durable-json.d.ts +3 -16
  19. package/dist/fs/durable-json.js +4 -2
  20. package/dist/fs/guarded-reader.d.ts +10 -0
  21. package/dist/fs/guarded-reader.js +34 -1
  22. package/dist/fs/index.d.ts +4 -0
  23. package/dist/fs/index.js +4 -0
  24. package/dist/fs/leased-directory-move.d.ts +49 -0
  25. package/dist/fs/leased-directory-move.js +31 -0
  26. package/dist/fs/owned-temp-root.d.ts +74 -0
  27. package/dist/fs/owned-temp-root.js +203 -0
  28. package/dist/fs/recent-directories.d.ts +2 -1
  29. package/dist/fs/resolve-directory-target.d.ts +33 -0
  30. package/dist/fs/resolve-directory-target.js +58 -0
  31. package/dist/fs/staged-file.d.ts +40 -0
  32. package/dist/fs/staged-file.js +75 -0
  33. package/dist/fs/strict-containment.d.ts +14 -0
  34. package/dist/fs/strict-containment.js +14 -0
  35. package/dist/image/png-encode.d.ts +41 -0
  36. package/dist/image/png-encode.js +96 -0
  37. package/dist/index.d.ts +3 -1
  38. package/dist/mail/email-template-agent-tools.d.ts +150 -0
  39. package/dist/mail/email-template-agent-tools.js +86 -0
  40. package/dist/mail/email-template-tool-registrations.d.ts +73 -0
  41. package/dist/mail/email-template-tool-registrations.js +66 -0
  42. package/dist/mail/feedback-route.d.ts +50 -0
  43. package/dist/mail/feedback-route.js +46 -0
  44. package/dist/mail/feedback-setup.d.ts +44 -0
  45. package/dist/mail/feedback-setup.js +53 -0
  46. package/dist/mail/feedback-sources.d.ts +67 -0
  47. package/dist/mail/feedback-sources.js +42 -0
  48. package/dist/mail/index.d.ts +10 -1
  49. package/dist/mail/index.js +4 -0
  50. package/dist/mail/mail-status.d.ts +32 -0
  51. package/dist/mail/mail-status.js +2 -0
  52. package/dist/mail/positional-purpose-gate.d.ts +14 -0
  53. package/dist/mail/positional-purpose-gate.js +18 -0
  54. package/dist/mail/purpose-gate-probe.d.ts +18 -0
  55. package/dist/mail/purpose-gate-probe.js +22 -0
  56. package/dist/mail/resolve-mailer.d.ts +13 -1
  57. package/dist/mail/resolve-mailer.js +11 -5
  58. package/dist/mail/sql/activity.repo.d.ts +20 -0
  59. package/dist/mail/sql/activity.repo.js +133 -0
  60. package/dist/mail/sql/attempts.repo.d.ts +17 -0
  61. package/dist/mail/sql/attempts.repo.js +32 -0
  62. package/dist/mail/sql/capture.repo.d.ts +69 -0
  63. package/dist/mail/sql/capture.repo.js +119 -0
  64. package/dist/mail/sql/feedback-inbox.repo.d.ts +12 -0
  65. package/dist/mail/sql/feedback-inbox.repo.js +32 -0
  66. package/dist/mail/sql/index.d.ts +12 -0
  67. package/dist/mail/sql/index.js +12 -0
  68. package/dist/mail/sql/ledger.repo.d.ts +29 -0
  69. package/dist/mail/sql/ledger.repo.js +57 -0
  70. package/dist/mail/sql/retention.d.ts +23 -0
  71. package/dist/mail/sql/retention.js +53 -0
  72. package/dist/mail/sql/site-feedback-route.d.ts +18 -0
  73. package/dist/mail/sql/site-feedback-route.js +22 -0
  74. package/dist/mail/sql/suppression-admin.repo.d.ts +11 -0
  75. package/dist/mail/sql/suppression-admin.repo.js +76 -0
  76. package/dist/mail/sql/suppression.repo.d.ts +10 -0
  77. package/dist/mail/sql/suppression.repo.js +33 -0
  78. package/dist/mail/test-send.d.ts +147 -0
  79. package/dist/mail/test-send.js +201 -0
  80. package/dist/mail/use-readiness.d.ts +104 -0
  81. package/dist/mail/use-readiness.js +140 -0
  82. package/dist/object-store/local-fs.js +34 -1
  83. package/dist/object-store/site/artifact-provider.d.ts +65 -0
  84. package/dist/object-store/site/artifact-provider.js +37 -0
  85. package/dist/object-store/site/registry.d.ts +110 -0
  86. package/dist/object-store/site/registry.js +93 -0
  87. package/dist/object-store/site/setting.d.ts +34 -0
  88. package/dist/object-store/site/setting.js +32 -0
  89. package/dist/process-probes.d.ts +11 -4
  90. package/dist/process-probes.js +3 -3
  91. package/dist/process-top-footprint.d.ts +1 -1
  92. package/dist/process.d.ts +3 -17
  93. package/dist/process.js +3 -2
  94. package/dist/retention/index.d.ts +6 -0
  95. package/dist/retention/index.js +6 -0
  96. package/dist/retention/measure-tree.d.ts +68 -0
  97. package/dist/retention/measure-tree.js +205 -0
  98. package/dist/retention/preview-store.d.ts +10 -0
  99. package/dist/retention/preview-store.js +26 -0
  100. package/dist/retention/routes.d.ts +23 -0
  101. package/dist/retention/routes.js +24 -0
  102. package/dist/retention/runner.d.ts +103 -0
  103. package/dist/retention/runner.js +164 -0
  104. package/dist/secrets/credential-sets/index.d.ts +1 -0
  105. package/dist/secrets/credential-sets/index.js +1 -0
  106. package/dist/secrets/credential-sets/store-vault-guards.d.ts +26 -0
  107. package/dist/secrets/credential-sets/store-vault-guards.js +30 -0
  108. package/dist/secrets/credential-sets/vault.service.d.ts +1 -1
  109. package/dist/secrets/index.d.ts +1 -1
  110. package/dist/secrets/index.js +1 -1
  111. package/dist/secrets/keyring.env.d.ts +1 -1
  112. package/dist/secrets/keyring.env.js +3 -5
  113. package/dist/secrets/keyring.memory.d.ts +4 -1
  114. package/dist/secrets/keyring.memory.js +4 -1
  115. package/dist/secrets/legacy-codecs.d.ts +381 -0
  116. package/dist/secrets/legacy-codecs.js +468 -0
  117. package/dist/secrets/legacy-owner.d.ts +3 -11
  118. package/dist/secrets/root-key/ensure.d.ts +154 -0
  119. package/dist/secrets/root-key/ensure.js +328 -0
  120. package/dist/secrets/root-key/files.d.ts +104 -0
  121. package/dist/secrets/root-key/files.js +166 -0
  122. package/dist/secrets/root-key/material.d.ts +132 -0
  123. package/dist/secrets/root-key/material.js +116 -0
  124. package/dist/secrets/root-key/ordered-keyring.d.ts +157 -0
  125. package/dist/secrets/root-key/ordered-keyring.js +104 -0
  126. package/dist/secrets/root-key/reconcile.d.ts +50 -0
  127. package/dist/secrets/root-key/reconcile.js +147 -0
  128. package/dist/secrets/root-key/site-keyring-errors.d.ts +78 -0
  129. package/dist/secrets/root-key/site-keyring-errors.js +37 -0
  130. package/dist/secrets/root-key/sources.d.ts +79 -0
  131. package/dist/secrets/root-key/sources.js +119 -0
  132. package/dist/secrets/secret-sealer.aesgcm.d.ts +50 -2
  133. package/dist/secrets/secret-sealer.aesgcm.js +107 -19
  134. package/dist/web/tool-registrations.d.ts +67 -0
  135. package/dist/web/tool-registrations.js +44 -0
  136. package/package.json +138 -6
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file Path-containment resolution for a caller-supplied directory argument.
3
+ *
4
+ * Purpose:
5
+ * Resolve a caller-supplied `dirArg` to the ONE real target path every subsequent fs operation must derive
6
+ * from — never re-derived from the raw, unresolved argument. Handles three cases:
7
+ * 1. An ordinary path (existing or not, and NOT itself a symlink) — `path.resolve` collapses
8
+ * any embedded `..` segments purely lexically, with no filesystem access needed. Returned
9
+ * as-is, deliberately WITHOUT canonicalizing every ancestor segment (`fs.realpathSync` on
10
+ * the whole path would also resolve unrelated, pre-existing OS-level symlinks the caller
11
+ * never named — e.g. macOS aliases `/var` to `/private/var` — which would silently change
12
+ * an already-unambiguous, non-symlinked target path for no containment benefit).
13
+ * 2. `dirArg` itself IS an existing symlink whose destination already exists — `fs.realpathSync`
14
+ * is authoritative here and handles nested symlinks / relative link targets in one call.
15
+ * 3. `dirArg` itself IS an existing symlink whose destination does NOT exist yet (e.g. a
16
+ * dangling symlink at an `init` target) — `fs.realpathSync` cannot resolve this (it requires
17
+ * the final path to exist), so this falls back to one `readlinkSync` level, which is enough
18
+ * for the "symlink at the target" shape this containment guarantee covers.
19
+ *
20
+ * Architectural role:
21
+ * Node-only filesystem utility with no host-specific input; hosts call it before deriving any path from a
22
+ * directory argument.
23
+ */
24
+ /**
25
+ * Resolve `dirArg` to the real target path every subsequent write must be derived from.
26
+ *
27
+ * @complexity O(1) — at most one `lstatSync` plus one `realpathSync`/`readlinkSync` call, plus a
28
+ * constant number of `path` operations; not a function of any caller-controlled collection.
29
+ */
30
+ export declare function resolveDirectoryTarget({ dirArg }: {
31
+ dirArg: string;
32
+ }, _optional?: {}): string;
33
+ //# sourceMappingURL=resolve-directory-target.d.ts.map
@@ -0,0 +1,58 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * @file Path-containment resolution for a caller-supplied directory argument.
5
+ *
6
+ * Purpose:
7
+ * Resolve a caller-supplied `dirArg` to the ONE real target path every subsequent fs operation must derive
8
+ * from — never re-derived from the raw, unresolved argument. Handles three cases:
9
+ * 1. An ordinary path (existing or not, and NOT itself a symlink) — `path.resolve` collapses
10
+ * any embedded `..` segments purely lexically, with no filesystem access needed. Returned
11
+ * as-is, deliberately WITHOUT canonicalizing every ancestor segment (`fs.realpathSync` on
12
+ * the whole path would also resolve unrelated, pre-existing OS-level symlinks the caller
13
+ * never named — e.g. macOS aliases `/var` to `/private/var` — which would silently change
14
+ * an already-unambiguous, non-symlinked target path for no containment benefit).
15
+ * 2. `dirArg` itself IS an existing symlink whose destination already exists — `fs.realpathSync`
16
+ * is authoritative here and handles nested symlinks / relative link targets in one call.
17
+ * 3. `dirArg` itself IS an existing symlink whose destination does NOT exist yet (e.g. a
18
+ * dangling symlink at an `init` target) — `fs.realpathSync` cannot resolve this (it requires
19
+ * the final path to exist), so this falls back to one `readlinkSync` level, which is enough
20
+ * for the "symlink at the target" shape this containment guarantee covers.
21
+ *
22
+ * Architectural role:
23
+ * Node-only filesystem utility with no host-specific input; hosts call it before deriving any path from a
24
+ * directory argument.
25
+ */
26
+ /**
27
+ * Resolve `dirArg` to the real target path every subsequent write must be derived from.
28
+ *
29
+ * @complexity O(1) — at most one `lstatSync` plus one `realpathSync`/`readlinkSync` call, plus a
30
+ * constant number of `path` operations; not a function of any caller-controlled collection.
31
+ */
32
+ export function resolveDirectoryTarget({ dirArg }, _optional = {}) {
33
+ const lexicallyResolved = path.resolve(dirArg);
34
+ let lst;
35
+ try {
36
+ lst = fs.lstatSync(lexicallyResolved);
37
+ }
38
+ catch {
39
+ // Doesn't exist at all — the common `init` case. Nothing to resolve beyond the lexical form.
40
+ return lexicallyResolved;
41
+ }
42
+ if (!lst.isSymbolicLink()) {
43
+ // An ordinary existing file/dir — return as-is, without canonicalizing unrelated ancestor
44
+ // symlinks (see file header).
45
+ return lexicallyResolved;
46
+ }
47
+ try {
48
+ // The target IS a symlink whose destination exists — resolve it fully and authoritatively.
49
+ return fs.realpathSync(lexicallyResolved);
50
+ }
51
+ catch {
52
+ // A dangling symlink — its destination doesn't exist yet. Follow the link one level instead
53
+ // of requiring the destination to already exist.
54
+ const linkTarget = fs.readlinkSync(lexicallyResolved);
55
+ return path.isAbsolute(linkTarget) ? linkTarget : path.resolve(path.dirname(lexicallyResolved), linkTarget);
56
+ }
57
+ }
58
+ //# sourceMappingURL=resolve-directory-target.js.map
@@ -0,0 +1,40 @@
1
+ import type * as nodeFs from "node:fs/promises";
2
+ import type { StagedMediaFile } from "@jini-ai/core/contracts/site/cms-media";
3
+ export interface StagedFileDependencies {
4
+ filesystem: Pick<typeof nodeFs, "open" | "stat" | "chmod">;
5
+ withTempRoot: <T>(required: {
6
+ work: (owned: {
7
+ root: string;
8
+ }) => Promise<T>;
9
+ }, optional?: Record<string, never>) => Promise<T>;
10
+ sniffContentType: (required: {
11
+ bytes: Uint8Array;
12
+ }) => string | undefined;
13
+ }
14
+ declare function withStagedFile<T>({ deps, chunks, byteLength, contentType, consume }: {
15
+ deps: StagedFileDependencies;
16
+ chunks: AsyncIterable<Uint8Array>;
17
+ byteLength: number;
18
+ contentType: string;
19
+ consume: (staged: StagedMediaFile) => Promise<T>;
20
+ }, { signal }?: {
21
+ signal?: AbortSignal;
22
+ }): Promise<T>;
23
+ declare function sealStagedFile({ deps, root, path, maxBytes }: {
24
+ deps: StagedFileDependencies;
25
+ root: string;
26
+ path: string;
27
+ maxBytes: number;
28
+ }, { signal }?: {
29
+ signal?: AbortSignal;
30
+ }): Promise<StagedMediaFile>;
31
+ export declare function createStagedFileAdapter(deps: StagedFileDependencies, _optional?: Record<string, never>): {
32
+ withStagedFile: <T>(required: Omit<Parameters<typeof withStagedFile<T>>[0], "deps">, optional?: {
33
+ signal?: AbortSignal;
34
+ }) => Promise<T>;
35
+ sealStagedFile: (required: Omit<Parameters<typeof sealStagedFile>[0], "deps">, optional?: {
36
+ signal?: AbortSignal;
37
+ }) => Promise<StagedMediaFile>;
38
+ };
39
+ export {};
40
+ //# sourceMappingURL=staged-file.d.ts.map
@@ -0,0 +1,75 @@
1
+ import { createHash } from "node:crypto";
2
+ import { join } from "node:path";
3
+ async function* openChunks({ filesystem, path }, { signal } = {}) {
4
+ signal?.throwIfAborted();
5
+ const file = await filesystem.open(path, "r");
6
+ try {
7
+ while (true) {
8
+ signal?.throwIfAborted();
9
+ const buffer = Buffer.alloc(64 * 1024);
10
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, null);
11
+ if (bytesRead === 0)
12
+ return;
13
+ yield buffer.subarray(0, bytesRead);
14
+ }
15
+ }
16
+ finally {
17
+ await file.close();
18
+ }
19
+ }
20
+ async function withStagedFile({ deps, chunks, byteLength, contentType, consume }, { signal } = {}) {
21
+ return deps.withTempRoot({ work: async ({ root }) => {
22
+ const path = join(root, "input");
23
+ const file = await deps.filesystem.open(path, "wx", 0o600);
24
+ const hash = createHash("sha256");
25
+ let length = 0;
26
+ try {
27
+ for await (const chunk of chunks) {
28
+ signal?.throwIfAborted();
29
+ length += chunk.byteLength;
30
+ if (length > byteLength)
31
+ throw new Error("staged source length mismatch");
32
+ await file.writeFile(chunk);
33
+ hash.update(chunk);
34
+ }
35
+ if (length !== byteLength)
36
+ throw new Error("staged source length mismatch");
37
+ }
38
+ finally {
39
+ await file.close();
40
+ }
41
+ signal?.throwIfAborted();
42
+ return consume(Object.freeze({ path, root, byteLength, contentType, sha256: hash.digest("hex"),
43
+ openChunks: (_required, optional = {}) => openChunks({ filesystem: deps.filesystem, path }, optional),
44
+ }));
45
+ } }, {});
46
+ }
47
+ async function sealStagedFile({ deps, root, path, maxBytes }, { signal } = {}) {
48
+ await deps.filesystem.chmod(path, 0o600);
49
+ const { size: byteLength } = await deps.filesystem.stat(path);
50
+ if (byteLength > maxBytes)
51
+ throw Object.assign(new Error("staged output exceeds limit"), { reason: "too-large" });
52
+ const hash = createHash("sha256");
53
+ let length = 0;
54
+ let contentType;
55
+ for await (const chunk of openChunks({ filesystem: deps.filesystem, path }, signal ? { signal } : {})) {
56
+ if (length === 0)
57
+ contentType = deps.sniffContentType({ bytes: chunk });
58
+ length += chunk.byteLength;
59
+ if (length > byteLength)
60
+ throw Object.assign(new Error("staged output grew"), { reason: "too-large" });
61
+ hash.update(chunk);
62
+ }
63
+ if (length !== byteLength || contentType !== "video/mp4")
64
+ throw Object.assign(new Error("invalid staged output"), { reason: "invalid" });
65
+ return Object.freeze({ path, root, byteLength, contentType, sha256: hash.digest("hex"),
66
+ openChunks: (_required, optional = {}) => openChunks({ filesystem: deps.filesystem, path }, optional),
67
+ });
68
+ }
69
+ export function createStagedFileAdapter(deps, _optional = {}) {
70
+ return {
71
+ withStagedFile: (required, optional = {}) => withStagedFile({ deps, ...required }, optional),
72
+ sealStagedFile: (required, optional = {}) => sealStagedFile({ deps, ...required }, optional),
73
+ };
74
+ }
75
+ //# sourceMappingURL=staged-file.js.map
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Resolves `<root>/<segment>` and refuses (returns `null`) unless the result stays strictly
3
+ * within `root`. Two different escapes are checked, not one duplicated:
4
+ * `resolved !== path.join(root, segment)` catches `path.resolve` diverging from a naive join —
5
+ * the case where `root` itself was not already absolute, so `resolve` silently anchors against
6
+ * `process.cwd()` instead; `!resolved.startsWith(prefix)` catches `segment` carrying enough
7
+ * `../` to walk back out of an (already-absolute) `root` even though both agree on the
8
+ * normalized result. `prefix` is built from `path.resolve(root)` rather than raw `root` so a
9
+ * trailing separator on `root` (or `root` being exactly `/`) can't double up into a separator
10
+ * nothing would ever start with — that would silently refuse every valid child instead of only
11
+ * real traversal. Calling `path.resolve` on `root` here is safe specifically because the guard
12
+ * above already proved `root` is absolute (a relative `root` would have diverged from
13
+ * `path.join` and returned already), so this can only normalize `root`, not re-anchor it.
14
+ */
1
15
  export declare function resolvePathWithin({ root, segment }: {
2
16
  root: string;
3
17
  segment: string;
@@ -1,5 +1,19 @@
1
1
  /** Preserve strict lexical containment: relative roots, root equality and traversal are refused (except the filesystem-root edge case). Symlinks require a separate physical-path guard. */
2
2
  import path from "node:path";
3
+ /**
4
+ * Resolves `<root>/<segment>` and refuses (returns `null`) unless the result stays strictly
5
+ * within `root`. Two different escapes are checked, not one duplicated:
6
+ * `resolved !== path.join(root, segment)` catches `path.resolve` diverging from a naive join —
7
+ * the case where `root` itself was not already absolute, so `resolve` silently anchors against
8
+ * `process.cwd()` instead; `!resolved.startsWith(prefix)` catches `segment` carrying enough
9
+ * `../` to walk back out of an (already-absolute) `root` even though both agree on the
10
+ * normalized result. `prefix` is built from `path.resolve(root)` rather than raw `root` so a
11
+ * trailing separator on `root` (or `root` being exactly `/`) can't double up into a separator
12
+ * nothing would ever start with — that would silently refuse every valid child instead of only
13
+ * real traversal. Calling `path.resolve` on `root` here is safe specifically because the guard
14
+ * above already proved `root` is absolute (a relative `root` would have diverged from
15
+ * `path.join` and returned already), so this can only normalize `root`, not re-anchor it.
16
+ */
3
17
  export function resolvePathWithin({ root, segment }, _optional = {}) {
4
18
  const resolved = path.resolve(root, segment);
5
19
  if (resolved !== path.join(root, segment))
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @file A dependency-free, minimal PNG encoder — just enough to produce a real, decodable image for
3
+ * a host demo tool to prove the typed-media pipeline end to end ("tool results must carry typed
4
+ * media rather than flattened text").
5
+ *
6
+ * A solid-color square, not a photo or a fetched asset, deliberately: the point of such a demo
7
+ * tool is proving the TRANSPORT (daemon -> wire -> chat-core -> ToolCard `<img>`), not
8
+ * building an image generator. A hand-rolled encoder over a third-party image library or a real
9
+ * external call keeps the dependency count at zero — `node:zlib`, already in the runtime — and
10
+ * deterministic, so its own tests assert exact pixel bytes rather than "didn't throw".
11
+ *
12
+ * The format written is the minimum PNG needs to be valid: signature, `IHDR` (8-bit truecolor,
13
+ * no interlacing), one `IDAT` holding every scanline (each prefixed with filter type 0 — "none",
14
+ * the simplest legal choice for uncompressed-looking row data before deflate), and an empty `IEND`.
15
+ * Every chunk is real deflate + real CRC-32, so a real PNG decoder (a browser `<img>`, `zlib.inflateSync`
16
+ * in this file's own tests) can round-trip it — nothing here is a stub shaped like a PNG.
17
+ */
18
+ /** 0-255 per channel. */
19
+ export interface RgbColor {
20
+ readonly r: number;
21
+ readonly g: number;
22
+ readonly b: number;
23
+ }
24
+ export interface RenderSolidColorPngOptions {
25
+ /** Pixel width. Must be a positive integer. @default 64 */
26
+ readonly width?: number;
27
+ /** Pixel height. Must be a positive integer. @default 64 */
28
+ readonly height?: number;
29
+ /** Fill color. @default { r: 79, g: 70, b: 229 } (indigo). */
30
+ readonly color?: RgbColor;
31
+ }
32
+ /**
33
+ * Renders a solid-color square as a real, valid 8-bit truecolor PNG.
34
+ *
35
+ * @param options - Dimensions and fill color; every field optional with the module's own defaults.
36
+ * @returns The complete PNG file as a `Buffer` — signature through `IEND`.
37
+ * @throws {Error} If `width`/`height` is not a positive integer, or any `color` channel is outside `0..255`.
38
+ * @complexity O(width * height) to build the raw scanlines plus the `deflateSync` call's own cost.
39
+ */
40
+ export declare function renderSolidColorPng(options?: RenderSolidColorPngOptions): Buffer;
41
+ //# sourceMappingURL=png-encode.d.ts.map
@@ -0,0 +1,96 @@
1
+ import { deflateSync } from "node:zlib";
2
+ const DEFAULT_WIDTH = 64;
3
+ const DEFAULT_HEIGHT = 64;
4
+ const DEFAULT_COLOR = { r: 79, g: 70, b: 229 };
5
+ const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
6
+ /**
7
+ * The standard PNG/zlib CRC-32 table (ITU-T V.42 polynomial 0xEDB88320), built once at module load
8
+ * — every chunk's trailing CRC is computed against it.
9
+ *
10
+ * @complexity O(1) — 256 iterations, once per process.
11
+ */
12
+ function buildCrcTable() {
13
+ const table = new Uint32Array(256);
14
+ for (let n = 0; n < 256; n++) {
15
+ let c = n;
16
+ for (let k = 0; k < 8; k++) {
17
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
18
+ }
19
+ table[n] = c >>> 0;
20
+ }
21
+ return table;
22
+ }
23
+ const CRC_TABLE = buildCrcTable();
24
+ /** PNG's chunk CRC: computed over the chunk's `type` + `data` bytes, per the spec — never over `length`. */
25
+ function crc32({ bytes }, _optional = {}) {
26
+ let crc = 0xffffffff;
27
+ for (let i = 0; i < bytes.length; i++) {
28
+ crc = (CRC_TABLE[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8)) >>> 0;
29
+ }
30
+ return (crc ^ 0xffffffff) >>> 0;
31
+ }
32
+ /** One length-prefixed, CRC-suffixed PNG chunk: `length(4) + type(4) + data(n) + crc(4)`. */
33
+ function chunk({ type, data }, _optional = {}) {
34
+ const typeBytes = Buffer.from(type, "ascii");
35
+ const length = Buffer.alloc(4);
36
+ length.writeUInt32BE(data.length, 0);
37
+ const crcInput = Buffer.concat([typeBytes, data]);
38
+ const crc = Buffer.alloc(4);
39
+ crc.writeUInt32BE(crc32({ bytes: crcInput }), 0);
40
+ return Buffer.concat([length, typeBytes, data, crc]);
41
+ }
42
+ /** @throws {Error} `"renderSolidColorPng: {label} must be a positive integer, got {value}"` for a non-integer or non-positive dimension. */
43
+ function assertPositiveInteger({ value, label }, _optional = {}) {
44
+ if (!Number.isInteger(value) || value <= 0) {
45
+ throw new Error(`renderSolidColorPng: ${label} must be a positive integer, got ${value}`);
46
+ }
47
+ }
48
+ /** @throws {Error} `"renderSolidColorPng: color.{channel} must be an integer between 0 and 255, got {value}"` for an out-of-range channel. */
49
+ function assertChannel({ value, channel }, _optional = {}) {
50
+ if (!Number.isInteger(value) || value < 0 || value > 255) {
51
+ throw new Error(`renderSolidColorPng: color.${channel} must be an integer between 0 and 255, got ${value}`);
52
+ }
53
+ }
54
+ /**
55
+ * Renders a solid-color square as a real, valid 8-bit truecolor PNG.
56
+ *
57
+ * @param options - Dimensions and fill color; every field optional with the module's own defaults.
58
+ * @returns The complete PNG file as a `Buffer` — signature through `IEND`.
59
+ * @throws {Error} If `width`/`height` is not a positive integer, or any `color` channel is outside `0..255`.
60
+ * @complexity O(width * height) to build the raw scanlines plus the `deflateSync` call's own cost.
61
+ */
62
+ export function renderSolidColorPng(options = {}) {
63
+ const width = options.width ?? DEFAULT_WIDTH;
64
+ const height = options.height ?? DEFAULT_HEIGHT;
65
+ const color = options.color ?? DEFAULT_COLOR;
66
+ assertPositiveInteger({ value: width, label: "width" });
67
+ assertPositiveInteger({ value: height, label: "height" });
68
+ assertChannel({ value: color.r, channel: "r" });
69
+ assertChannel({ value: color.g, channel: "g" });
70
+ assertChannel({ value: color.b, channel: "b" });
71
+ // One filter byte (0 = "None") plus 3 bytes/pixel per scanline — PNG's raw, pre-deflate layout for
72
+ // 8-bit truecolor (colorType 2, no alpha).
73
+ const bytesPerRow = 1 + width * 3;
74
+ const raw = Buffer.alloc(bytesPerRow * height);
75
+ for (let y = 0; y < height; y++) {
76
+ const rowStart = y * bytesPerRow;
77
+ raw[rowStart] = 0; // filter type: None
78
+ for (let x = 0; x < width; x++) {
79
+ const pixelStart = rowStart + 1 + x * 3;
80
+ raw[pixelStart] = color.r;
81
+ raw[pixelStart + 1] = color.g;
82
+ raw[pixelStart + 2] = color.b;
83
+ }
84
+ }
85
+ const ihdr = Buffer.alloc(13);
86
+ ihdr.writeUInt32BE(width, 0);
87
+ ihdr.writeUInt32BE(height, 4);
88
+ ihdr[8] = 8; // bit depth
89
+ ihdr[9] = 2; // color type: truecolor (RGB, no palette, no alpha)
90
+ ihdr[10] = 0; // compression method: deflate (the only defined value)
91
+ ihdr[11] = 0; // filter method: adaptive (the only defined value; per-row filter is still 0/"None" above)
92
+ ihdr[12] = 0; // interlace method: none
93
+ const idat = deflateSync(raw);
94
+ return Buffer.concat([PNG_SIGNATURE, chunk({ type: "IHDR", data: ihdr }), chunk({ type: "IDAT", data: idat }), chunk({ type: "IEND", data: Buffer.alloc(0) })]);
95
+ }
96
+ //# sourceMappingURL=png-encode.js.map
package/dist/index.d.ts CHANGED
@@ -34,7 +34,9 @@
34
34
  export { createCommandInvocation, createPackageManagerInvocation } from "./command.js";
35
35
  export type { ResolveSystemProxyEnvOptions, SystemProxyCommandRunner } from "./proxy-env.js";
36
36
  export { mergeProxyAwareEnv, parseMacosScutilProxyOutput, parseWindowsInternetSettingsProxyOutput, resolveSystemProxyEnv, } from "./proxy-env.js";
37
- export type { ProcessUsage, ProcessUsagePorts, ProcessUsageOptions, ProcessStampContract, ProcessStampField, ProcessStampShape, SpawnProcessRequest, StampedProcessMatchCriteria, } from "./process.js";
37
+ /** Deprecated re-export: import these from `@jini-ai/core/contracts/site/platform-process`; removed at the next major. */
38
+ export type { ProcessUsage } from "@jini-ai/core/contracts/site/platform-process";
39
+ export type { ProcessUsagePorts, ProcessUsageOptions, ProcessStampContract, ProcessStampField, ProcessStampShape, SpawnProcessRequest, StampedProcessMatchCriteria, } from "./process.js";
38
40
  export { createProcessStampArgs, isProcessAlive, listProcessSnapshots, listProcessUsage, matchesProcessStamp, matchesStampedProcess, readFlagValue, readProcessStamp, readProcessStampFromCommand, spawnBackgroundProcess, spawnLoggedProcess, stopProcesses, waitForProcessExit, } from "./process.js";
39
41
  export type { AtomicCopyFileOptions, AtomicCopyFileResult, RemovePathBestEffortOptions, RemovePathBestEffortResult, } from "./fs.js";
40
42
  export { atomicCopyFile, pathContains, readLogTail, removePathBestEffort } from "./fs.js";
@@ -0,0 +1,150 @@
1
+ /**
2
+ * @file Email-template tools. Same permissions as the Pages HTML tools they mirror: reading is
3
+ * `content.read`, writing raw HTML is `pages.edit_html` (a template is raw HTML on Pages storage).
4
+ */
5
+ /** The host's names the email-template catalog text and authorization carry. */
6
+ export interface EmailTemplatesHostCopy {
7
+ /** The host permission that writes raw HTML (its Pages HTML edit permission), named in the write tools' text and authorization. */
8
+ readonly editHtmlPermission: string;
9
+ }
10
+ /**
11
+ * The email-template tool catalog, bound once by the host with its {@link EmailTemplatesHostCopy};
12
+ * bound with the host's own permission name, the model-facing text is the host's original catalog text.
13
+ */
14
+ export declare function createEmailTemplatesAgentToolCatalog({ copy }: {
15
+ copy: EmailTemplatesHostCopy;
16
+ }, _optional?: Record<string, never>): ({
17
+ name: string;
18
+ description: string;
19
+ sideEffects: "none";
20
+ authorization: {
21
+ permission: string;
22
+ };
23
+ inputSchema: {
24
+ type: string;
25
+ additionalProperties: boolean;
26
+ properties: {
27
+ limit: {
28
+ type: string;
29
+ minimum: number;
30
+ maximum: number;
31
+ clamp: boolean;
32
+ };
33
+ cursor: {
34
+ type: string;
35
+ };
36
+ };
37
+ };
38
+ } | {
39
+ name: string;
40
+ description: string;
41
+ sideEffects: "none";
42
+ authorization: {
43
+ permission: string;
44
+ };
45
+ inputSchema: {
46
+ type: string;
47
+ additionalProperties: boolean;
48
+ required: string[];
49
+ properties: {
50
+ id: {
51
+ type: string;
52
+ };
53
+ };
54
+ };
55
+ } | {
56
+ name: string;
57
+ description: string;
58
+ sideEffects: "none";
59
+ authorization: {
60
+ permission: string;
61
+ };
62
+ inputSchema: {
63
+ type: string;
64
+ additionalProperties: boolean;
65
+ properties: {
66
+ id: {
67
+ type: string;
68
+ };
69
+ html: {
70
+ type: string;
71
+ };
72
+ values: {
73
+ type: string;
74
+ description: string;
75
+ additionalProperties: {
76
+ type: string[];
77
+ };
78
+ };
79
+ mode: {
80
+ type: string;
81
+ enum: string[];
82
+ };
83
+ };
84
+ };
85
+ } | {
86
+ name: string;
87
+ description: string;
88
+ sideEffects: "mutates-durable-state";
89
+ authorization: {
90
+ permission: string;
91
+ };
92
+ inputSchema: {
93
+ type: string;
94
+ additionalProperties: boolean;
95
+ required: string[];
96
+ properties: {
97
+ name: {
98
+ type: string;
99
+ maxLength: number;
100
+ description: string;
101
+ };
102
+ html: {
103
+ type: string;
104
+ description: string;
105
+ };
106
+ subject: {
107
+ type: string;
108
+ description: string;
109
+ };
110
+ fields: {
111
+ type: string;
112
+ items: {
113
+ type: string;
114
+ };
115
+ description: string;
116
+ };
117
+ id?: never;
118
+ expectedVersion?: never;
119
+ };
120
+ };
121
+ } | {
122
+ name: string;
123
+ description: string;
124
+ sideEffects: "mutates-durable-state";
125
+ authorization: {
126
+ permission: string;
127
+ };
128
+ inputSchema: {
129
+ type: string;
130
+ additionalProperties: boolean;
131
+ required: string[];
132
+ properties: {
133
+ id: {
134
+ type: string;
135
+ };
136
+ html: {
137
+ type: string;
138
+ description?: never;
139
+ };
140
+ expectedVersion: {
141
+ type: string;
142
+ minimum: number;
143
+ };
144
+ name?: never;
145
+ subject?: never;
146
+ fields?: never;
147
+ };
148
+ };
149
+ })[];
150
+ //# sourceMappingURL=email-template-agent-tools.d.ts.map
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @file Email-template tools. Same permissions as the Pages HTML tools they mirror: reading is
3
+ * `content.read`, writing raw HTML is `pages.edit_html` (a template is raw HTML on Pages storage).
4
+ */
5
+ const FIELD_CONTRACT = "A template is a full HTML email document. Its <title> is the subject (it may use fields). Fill-in fields are " +
6
+ "written {{name}} anywhere in the HTML or the subject and declared in the head as " +
7
+ '<meta name="email-fields" content="name=Ada, orderId">, each name optionally =sample (the value previews use). ' +
8
+ "Values are HTML-escaped; a field with no value renders empty and is listed in missingFields. " +
9
+ "Use table layout and inline styles: mail clients ignore most CSS and all script. Scripts run only in the admin " +
10
+ "preview; sent emails are static HTML with <script>, on* handlers, javascript: URLs, <iframe>/<object>/<embed> " +
11
+ "and comments removed.";
12
+ const VALUES_SCHEMA = {
13
+ type: "object",
14
+ description: "Field values by name, e.g. {\"name\":\"Ada\"}.",
15
+ additionalProperties: { type: ["string", "number", "boolean"] },
16
+ };
17
+ /** The read-only list tool: no host wording, so it is a static declaration. */
18
+ const EMAIL_TEMPLATE_LIST_TOOL = {
19
+ name: "email_template_list",
20
+ description: "Lists this site's HTML email templates. Returns {templates:[{id,name,subject,fields,version,updatedAt}]}. Requires content.read.",
21
+ sideEffects: "none",
22
+ authorization: { permission: "content.read" },
23
+ inputSchema: { type: "object", additionalProperties: false, properties: { limit: { type: "integer", minimum: 1, maximum: 100, clamp: true }, cursor: { type: "string" } } },
24
+ };
25
+ /** The read-only get tool: carries the field contract, which is static text. */
26
+ const EMAIL_TEMPLATE_GET_TOOL = {
27
+ name: "email_template_get",
28
+ description: `Reads one email template: {id,name,subject,fields,version,updatedAt,html,undeclaredFields}. Pass version back as expectedVersion when editing. ${FIELD_CONTRACT} Requires content.read.`,
29
+ sideEffects: "none",
30
+ authorization: { permission: "content.read" },
31
+ inputSchema: { type: "object", additionalProperties: false, required: ["id"], properties: { id: { type: "string" } } },
32
+ };
33
+ /** The read-only preview tool: renders and sends nothing. */
34
+ const EMAIL_TEMPLATE_PREVIEW_TOOL = {
35
+ name: "email_template_preview",
36
+ description: "Renders an email template with field values, as the live preview shows it. Pass id for a saved template or html for unsaved markup. mode admin (default) fills declared samples for missing values and keeps scripts; mode sent returns exactly what would be emailed (static html plus the plain-text alternative). Returns {subject,html,missingFields,undeclaredFields,mode,scriptsStripped,text?}. Sends nothing. Requires content.read.",
37
+ sideEffects: "none",
38
+ authorization: { permission: "content.read" },
39
+ inputSchema: {
40
+ type: "object",
41
+ additionalProperties: false,
42
+ properties: { id: { type: "string" }, html: { type: "string" }, values: VALUES_SCHEMA, mode: { type: "string", enum: ["admin", "sent"] } },
43
+ },
44
+ };
45
+ /** The create and edit tools: the only ones whose text and authorization name the host's edit-HTML permission. */
46
+ function emailTemplateWriteTools({ copy }) {
47
+ return [
48
+ {
49
+ name: "email_template_create",
50
+ description: `Creates an HTML email template. Give html for the full document, or omit it to start from a simple starter email built from subject and fields. Returns the template as email_template_get does. ${FIELD_CONTRACT} Requires ${copy.editHtmlPermission}.`,
51
+ sideEffects: "mutates-durable-state",
52
+ authorization: { permission: copy.editHtmlPermission },
53
+ inputSchema: {
54
+ type: "object",
55
+ additionalProperties: false,
56
+ required: ["name"],
57
+ properties: {
58
+ name: { type: "string", maxLength: 200, description: "Admin-facing name, e.g. Order confirmation." },
59
+ html: { type: "string", description: "The full HTML document." },
60
+ subject: { type: "string", description: "Starter only (ignored with html): the subject; defaults to name." },
61
+ fields: { type: "array", items: { type: "string" }, description: "Starter only (ignored with html): field names, each optionally name=sample." },
62
+ },
63
+ },
64
+ },
65
+ {
66
+ name: "email_template_edit",
67
+ description: `Replaces an email template's whole HTML document. Read it first with email_template_get and send its version as expectedVersion; a stale version writes nothing (EMAIL_TEMPLATES_VERSION_CONFLICT). Returns the saved template. ${FIELD_CONTRACT} Requires ${copy.editHtmlPermission}.`,
68
+ sideEffects: "mutates-durable-state",
69
+ authorization: { permission: copy.editHtmlPermission },
70
+ inputSchema: {
71
+ type: "object",
72
+ additionalProperties: false,
73
+ required: ["id", "html", "expectedVersion"],
74
+ properties: { id: { type: "string" }, html: { type: "string" }, expectedVersion: { type: "integer", minimum: 1 } },
75
+ },
76
+ },
77
+ ];
78
+ }
79
+ /**
80
+ * The email-template tool catalog, bound once by the host with its {@link EmailTemplatesHostCopy};
81
+ * bound with the host's own permission name, the model-facing text is the host's original catalog text.
82
+ */
83
+ export function createEmailTemplatesAgentToolCatalog({ copy }, _optional = {}) {
84
+ return [EMAIL_TEMPLATE_LIST_TOOL, EMAIL_TEMPLATE_GET_TOOL, ...emailTemplateWriteTools({ copy }), EMAIL_TEMPLATE_PREVIEW_TOOL];
85
+ }
86
+ //# sourceMappingURL=email-template-agent-tools.js.map