@dotcms/ai 26.10.20-1 → 26.10.21-1

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 (72) hide show
  1. package/README.md +203 -29
  2. package/adapter.cjs.default.js +1 -0
  3. package/adapter.cjs.js +14 -0
  4. package/adapter.cjs.mjs +2 -0
  5. package/adapter.cjs2.js +0 -0
  6. package/adapter.d.ts +1 -0
  7. package/adapter.esm.js +2 -0
  8. package/adapter.esm2.js +0 -0
  9. package/errors.cjs.js +192 -0
  10. package/errors.esm.js +180 -0
  11. package/format-result.cjs.js +833 -0
  12. package/format-result.esm.js +825 -0
  13. package/package.json +25 -20
  14. package/runtime.cjs.js +0 -0
  15. package/runtime.esm.js +0 -0
  16. package/sandbox.cjs.default.js +1 -0
  17. package/sandbox.cjs.js +69 -0
  18. package/sandbox.cjs.mjs +2 -0
  19. package/sandbox.d.ts +1 -0
  20. package/sandbox.esm.js +50 -0
  21. package/spec.cjs.default.js +1 -0
  22. package/spec.cjs.js +3 -23912
  23. package/spec.cjs.mjs +2 -0
  24. package/spec.cjs2.js +23916 -0
  25. package/spec.d.ts +1 -0
  26. package/spec.esm.js +1 -23914
  27. package/spec.esm2.js +23914 -0
  28. package/src/adapter/context.d.ts +11 -0
  29. package/src/adapter/request-core.d.ts +30 -0
  30. package/src/adapter.d.ts +1 -0
  31. package/src/runtime.d.ts +5 -4
  32. package/src/sandbox/errors.d.ts +23 -1
  33. package/src/sandbox/index.d.ts +1 -1
  34. package/src/sandbox.d.ts +1 -0
  35. package/src/spec.d.ts +1 -0
  36. package/src/tools/definitions/download-assets.d.ts +27 -0
  37. package/src/tools/definitions/execute.d.ts +15 -0
  38. package/src/tools/definitions/page-create.d.ts +23 -0
  39. package/src/tools/definitions/page-place-content.d.ts +32 -0
  40. package/src/tools/definitions/page-verify.d.ts +20 -0
  41. package/src/tools/definitions/search.d.ts +13 -0
  42. package/src/tools/definitions/upload-assets.d.ts +23 -0
  43. package/src/tools/index.d.ts +40 -0
  44. package/src/tools/operations/download-assets.d.ts +55 -0
  45. package/src/tools/operations/page-create.d.ts +81 -0
  46. package/src/tools/operations/page-place-content.d.ts +102 -0
  47. package/src/tools/operations/page-verify.d.ts +164 -0
  48. package/src/tools/operations/shared/asset-common.d.ts +28 -0
  49. package/src/tools/operations/shared/glob.d.ts +22 -0
  50. package/src/tools/operations/shared/local-root.d.ts +11 -0
  51. package/src/tools/operations/shared/page-common.d.ts +45 -0
  52. package/src/tools/operations/shared/page-path.d.ts +49 -0
  53. package/src/tools/operations/shared/resolve.d.ts +43 -0
  54. package/src/tools/operations/upload-assets.d.ts +64 -0
  55. package/src/tools/toolkit/connection.d.ts +56 -0
  56. package/src/tools/toolkit/create-tool.d.ts +66 -0
  57. package/src/tools/toolkit/endpoints.d.ts +52 -0
  58. package/src/tools/toolkit/lenient-boolean.d.ts +14 -0
  59. package/src/tools/toolkit/results.d.ts +32 -0
  60. package/src/tools/toolkit/tool-runtime.d.ts +108 -0
  61. package/src/tools/toolkit/types.d.ts +120 -0
  62. package/src/tools.d.ts +1 -0
  63. package/tools.cjs.default.js +1 -0
  64. package/tools.cjs.js +3850 -0
  65. package/tools.cjs.mjs +2 -0
  66. package/tools.d.ts +1 -0
  67. package/tools.esm.js +3817 -0
  68. package/index.cjs.default.js +0 -1
  69. package/index.cjs.js +0 -7
  70. package/index.cjs.mjs +0 -2
  71. package/index.d.ts +0 -1
  72. package/index.esm.js +0 -1
@@ -36,6 +36,17 @@ export interface DotCMSContext {
36
36
  languages: LanguageSummary[];
37
37
  currentUser: CurrentUserSummary | null;
38
38
  }
39
+ /**
40
+ * The endpoints loading instance context reads — all `GET`. Exported as the one source of
41
+ * truth for anything that must permit the context load: a tool's own allow-list names these
42
+ * rather than repeating the paths, so a loader that changes its endpoint changes them too.
43
+ */
44
+ export declare const CONTEXT_PATHS: {
45
+ readonly contentTypes: "/api/v1/contenttype";
46
+ readonly sites: "/api/v1/site";
47
+ readonly languages: "/api/v2/languages";
48
+ readonly currentUser: "/api/v1/users/current";
49
+ };
39
50
  /**
40
51
  * Load a minimal snapshot of dotCMS instance context for sandbox injection.
41
52
  * Each loader is independent — a failure in one does not poison the others.
@@ -13,6 +13,13 @@ interface FileFieldDescriptor {
13
13
  type: string;
14
14
  data?: string;
15
15
  url?: string;
16
+ blob?: Blob;
17
+ }
18
+ /** What a response-body sink is told about the body it receives. */
19
+ export interface ResponseBodyInfo {
20
+ contentType: string;
21
+ /** From `Content-Length`, when the server sent one. */
22
+ contentLength?: number;
16
23
  }
17
24
  type FormDataFieldValue = string | FileFieldDescriptor;
18
25
  export interface RequestOptions {
@@ -23,16 +30,39 @@ export interface RequestOptions {
23
30
  formData?: Record<string, FormDataFieldValue>;
24
31
  headers?: Record<string, string>;
25
32
  responseType?: 'auto' | 'base64';
33
+ onBody?: (body: ReadableStream<Uint8Array>, info: ResponseBodyInfo) => Promise<unknown>;
26
34
  }
27
35
  /**
28
36
  * A policy hook consulted before a request reaches the wire. Return `false` (or throw) to
29
37
  * reject. The single place a caller-owned allow-list plugs in — both verbs honor it because
30
38
  * both flow through `requestCore`.
39
+ *
40
+ * `path` is the RESOLVED path — dot-segments, encoded dots and backslashes already collapsed
41
+ * the way the URL that is sent will collapse them — so a policy never has to defend against
42
+ * `/allowed/../elsewhere` itself.
31
43
  */
32
44
  export type RequestPolicy = (req: {
33
45
  method: string;
34
46
  path: string;
35
47
  }) => boolean | void;
48
+ /**
49
+ * Normalize an `allow` setting into the policy the request core consults: a list of paths
50
+ * (a request is allowed when its resolved path IS one of them or lies UNDER one), or a
51
+ * predicate used as-is. The one place that meaning is defined, so every caller that accepts
52
+ * `allow` reads it the same way.
53
+ *
54
+ * Matching is by whole segment, never by raw `startsWith`: `/api/v1/content` allows
55
+ * `/api/v1/content` and `/api/v1/content/abc`, but not `/api/v1/contenttype`. As a string
56
+ * prefix it allowed every endpoint whose name happened to begin the same way. A trailing
57
+ * slash on an entry changes nothing: `/api/v1/page/` and `/api/v1/page` mean the same, and
58
+ * `'/'` is the explicit way to allow every path.
59
+ *
60
+ * An entry that is not a path (`''`, blank, relative, protocol-relative) throws a
61
+ * `ValidationError` here, when the runtime or tool is created. This is a security boundary,
62
+ * so a malformed entry must fail closed and loudly: `''` used to match every path, so a typo or
63
+ * an unset variable silently opened the whole API.
64
+ */
65
+ export declare function toRequestPolicy(allow: string[] | RequestPolicy | undefined): RequestPolicy | undefined;
36
66
  /** Host-side context the request core needs. Auth lives here, never in the caller's code. */
37
67
  export interface RequestCoreContext {
38
68
  baseUrl: string;
@@ -0,0 +1 @@
1
+ export * from './adapter/index';
package/src/runtime.d.ts CHANGED
@@ -2,8 +2,9 @@ import { type RequestCallEvent, type RequestOptions, type RequestPolicy } from '
2
2
  import type { DotCMSContext } from './adapter/context';
3
3
  import type { SandboxResult } from './sandbox/types';
4
4
  /**
5
- * Policy controlling which requests are permitted. Either a list of allowed path prefixes
6
- * (a request is allowed if its path starts with any entry) or a predicate consulted per call.
5
+ * Policy controlling which requests are permitted. Either a list of allowed paths (a request
6
+ * is allowed if its path is an entry or lies under one, matched by whole segment, so
7
+ * `/api/v1/content` does not allow `/api/v1/contenttype`) or a predicate consulted per call.
7
8
  * Both verbs honor it, because both flow through the one shared request core.
8
9
  */
9
10
  export type RuntimeAllow = string[] | RequestPolicy;
@@ -62,11 +63,11 @@ export interface DotCMSRuntime {
62
63
  export declare function createRuntime(config: DotCMSRuntimeConfig): DotCMSRuntime;
63
64
  export { defineAdapter, describeAdapterForLLM } from './sandbox/define-adapter';
64
65
  export type { AdapterContext, AdapterDef, AdapterMethodDef, DefinedAdapter } from './sandbox/define-adapter';
65
- export { DotCMSError, ValidationError, PolicyError, HttpError, TimeoutError, AbortError, SandboxError, RuntimeError, isDotCMSError, serializeError } from './sandbox/errors';
66
+ export { DotCMSError, ValidationError, PolicyError, HttpError, NetworkError, TimeoutError, AbortError, SandboxError, RuntimeError, isDotCMSError, serializeError } from './sandbox/errors';
66
67
  export type { DotCMSErrorCode, SerializedDotCMSError } from './sandbox/errors';
67
68
  export type { SandboxResult, SandboxResultError } from './sandbox/types';
68
69
  export { formatSandboxResult } from './sandbox/format-result';
69
70
  export type { FormatSandboxResultOptions } from './sandbox/format-result';
70
71
  export { isBinaryResponseEnvelope } from './adapter/request-core';
71
- export type { BinaryResponseEnvelope, RequestOptions, RequestCallEvent } from './adapter/request-core';
72
+ export type { BinaryResponseEnvelope, RequestOptions, RequestCallEvent, ResponseBodyInfo } from './adapter/request-core';
72
73
  export type { DotCMSContext, ContentTypeSummary, SiteSummary, LanguageSummary, CurrentUserSummary } from './adapter/context';
@@ -10,7 +10,7 @@
10
10
  * the worker→host serialization boundary (a thrown error becomes `{ name, message, stack }`
11
11
  * by default; these types preserve `code` and the structured detail too).
12
12
  */
13
- export type DotCMSErrorCode = 'VALIDATION' | 'POLICY' | 'HTTP' | 'TIMEOUT' | 'ABORT' | 'SANDBOX' | 'RUNTIME';
13
+ export type DotCMSErrorCode = 'VALIDATION' | 'POLICY' | 'HTTP' | 'NETWORK' | 'TIMEOUT' | 'ABORT' | 'SANDBOX' | 'RUNTIME';
14
14
  /** Serializable shape every DotCMSError flattens to (and that crosses the worker boundary). */
15
15
  export interface SerializedDotCMSError {
16
16
  name: string;
@@ -35,6 +35,7 @@ export declare abstract class DotCMSError extends Error {
35
35
  }
36
36
  /** Adapter input failed validation, or request options were malformed. */
37
37
  export declare class ValidationError extends DotCMSError {
38
+ readonly name = "ValidationError";
38
39
  readonly code: "VALIDATION";
39
40
  /** Field-level issues, when the source was a Zod (or similar) schema. */
40
41
  readonly issues?: unknown[];
@@ -43,6 +44,7 @@ export declare class ValidationError extends DotCMSError {
43
44
  }
44
45
  /** The allow-list / policy rejected the call before it reached the network. */
45
46
  export declare class PolicyError extends DotCMSError {
47
+ readonly name = "PolicyError";
46
48
  readonly code: "POLICY";
47
49
  readonly method: string;
48
50
  readonly path: string;
@@ -51,6 +53,7 @@ export declare class PolicyError extends DotCMSError {
51
53
  }
52
54
  /** dotCMS responded with a non-2xx status. Carries the status and the (text) body. */
53
55
  export declare class HttpError extends DotCMSError {
56
+ readonly name = "HttpError";
54
57
  readonly code: "HTTP";
55
58
  readonly status: number;
56
59
  readonly statusText: string;
@@ -58,8 +61,24 @@ export declare class HttpError extends DotCMSError {
58
61
  constructor(status: number, statusText: string, body: string);
59
62
  detail(): Record<string, unknown>;
60
63
  }
64
+ /**
65
+ * The request never got a response — the connection was refused or reset, the host did not
66
+ * resolve, the socket timed out. Distinct from `HttpError` (the instance answered, with an
67
+ * error) because the two call for opposite reactions: this one is usually worth retrying.
68
+ */
69
+ export declare class NetworkError extends DotCMSError {
70
+ readonly name = "NetworkError";
71
+ readonly code: "NETWORK";
72
+ readonly method: string;
73
+ readonly path: string;
74
+ /** The platform's own reason, e.g. `ECONNREFUSED`, when it gave one. */
75
+ readonly reason?: string;
76
+ constructor(method: string, path: string, cause: unknown);
77
+ detail(): Record<string, unknown>;
78
+ }
61
79
  /** A timeout elapsed (sandbox wall-clock, per-adapter-call, or context load). */
62
80
  export declare class TimeoutError extends DotCMSError {
81
+ readonly name = "TimeoutError";
63
82
  readonly code: "TIMEOUT";
64
83
  readonly timeoutMs?: number;
65
84
  constructor(message: string, timeoutMs?: number);
@@ -67,10 +86,12 @@ export declare class TimeoutError extends DotCMSError {
67
86
  }
68
87
  /** The call was aborted in-flight (typically because the sandbox timed out). */
69
88
  export declare class AbortError extends DotCMSError {
89
+ readonly name = "AbortError";
70
90
  readonly code: "ABORT";
71
91
  }
72
92
  /** Model-authored code threw while executing inside the sandbox. */
73
93
  export declare class SandboxError extends DotCMSError {
94
+ readonly name = "SandboxError";
74
95
  readonly code: "SANDBOX";
75
96
  /** The original error's name (e.g. "TypeError") as seen inside the sandbox. */
76
97
  readonly originalName?: string;
@@ -79,6 +100,7 @@ export declare class SandboxError extends DotCMSError {
79
100
  }
80
101
  /** Catch-all for runtime-internal failures that don't fit a more specific type. */
81
102
  export declare class RuntimeError extends DotCMSError {
103
+ readonly name = "RuntimeError";
82
104
  readonly code: "RUNTIME";
83
105
  }
84
106
  /** Type guard for any error in the hierarchy. */
@@ -13,7 +13,7 @@ export { formatSandboxResult } from './format-result';
13
13
  export type { FormatSandboxResultOptions } from './format-result';
14
14
  export { defineAdapter, isDefinedAdapter, describeAdapterForLLM } from './define-adapter';
15
15
  export type { AdapterContext, AdapterDef, AdapterMethodDef, DefinedAdapter, RequestLike } from './define-adapter';
16
- export { DotCMSError, ValidationError, PolicyError, HttpError, TimeoutError, AbortError, SandboxError, RuntimeError, isDotCMSError, serializeError } from './errors';
16
+ export { DotCMSError, ValidationError, PolicyError, HttpError, NetworkError, TimeoutError, AbortError, SandboxError, RuntimeError, isDotCMSError, serializeError } from './errors';
17
17
  export type { DotCMSErrorCode, SerializedDotCMSError } from './errors';
18
18
  export type { Adapter, AdapterMethod, AdapterMethodParameter, SandboxConfig, SandboxResourceLimits, SandboxResult, SandboxResultError, ExecutionContext } from './types';
19
19
  export interface CreateSandboxConfig {
@@ -0,0 +1 @@
1
+ export * from './sandbox/index';
package/src/spec.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './spec/index';
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { type DownloadAssetsManifest } from '../operations/download-assets';
3
+ import type { DotCMSConnection } from '../toolkit/connection';
4
+ import type { AssetToolOptions, DotCMSTool } from '../toolkit/types';
5
+ declare const definition: import("../toolkit/create-tool").ToolDefinition<z.ZodObject<{
6
+ path: z.ZodString;
7
+ kind: z.ZodDefault<z.ZodEnum<{
8
+ auto: "auto";
9
+ folder: "folder";
10
+ asset: "asset";
11
+ }>>;
12
+ dest: z.ZodString;
13
+ recursive: z.ZodDefault<z.ZodBoolean>;
14
+ overwrite: z.ZodDefault<z.ZodEnum<{
15
+ error: "error";
16
+ skip: "skip";
17
+ overwrite: "overwrite";
18
+ }>>;
19
+ include: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>, DownloadAssetsManifest, AssetToolOptions>;
21
+ /**
22
+ * The `download_assets` tool: streams dotCMS file assets to a local directory — the bytes
23
+ * never pass through the model. Needs Node or Bun. Resolves to a {@link DownloadAssetsManifest}.
24
+ * `options.root` bounds which local directories the model may write into.
25
+ */
26
+ export declare function downloadAssetsTool(connection: DotCMSConnection, options: AssetToolOptions): DotCMSTool<typeof definition.inputSchema, DownloadAssetsManifest>;
27
+ export {};
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ import type { DotCMSConnection } from '../toolkit/connection';
3
+ import type { CodeToolResult } from '../toolkit/results';
4
+ import type { DotCMSTool, ExecuteToolOptions } from '../toolkit/types';
5
+ /** Sandbox wall-clock timeout for `execute` when the factory is given none. */
6
+ export declare const DEFAULT_EXECUTE_TIMEOUT_MS = 45000;
7
+ declare const input: z.ZodObject<{
8
+ code: z.ZodString;
9
+ }, z.core.$strip>;
10
+ /**
11
+ * The `execute` tool: the model writes JavaScript, and it runs in the sandbox against the
12
+ * dotCMS API. Resolves to `{ result }`, the capped text of the code's result (or its error).
13
+ */
14
+ export declare function executeTool(connection: DotCMSConnection, options?: ExecuteToolOptions): DotCMSTool<typeof input, CodeToolResult>;
15
+ export {};
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import { type CreatePageManifest } from '../operations/page-create';
3
+ import type { DotCMSConnection } from '../toolkit/connection';
4
+ import type { DotCMSTool, RequestToolOptions } from '../toolkit/types';
5
+ declare const definition: import("../toolkit/create-tool").ToolDefinition<z.ZodObject<{
6
+ site: z.ZodString;
7
+ urlPath: z.ZodString;
8
+ title: z.ZodString;
9
+ template: z.ZodString;
10
+ contentType: z.ZodOptional<z.ZodString>;
11
+ extraFields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
12
+ friendlyName: z.ZodOptional<z.ZodString>;
13
+ pageTitle: z.ZodOptional<z.ZodString>;
14
+ languageId: z.ZodDefault<z.ZodNumber>;
15
+ cacheTtl: z.ZodDefault<z.ZodString>;
16
+ sortOrder: z.ZodDefault<z.ZodNumber>;
17
+ }, z.core.$strip>, CreatePageManifest, RequestToolOptions>;
18
+ /**
19
+ * The `page_create` tool: creates and publishes a page, creating its parent folder first so
20
+ * the URL lands where it was asked for. Resolves to a {@link CreatePageManifest}.
21
+ */
22
+ export declare function pageCreateTool(connection: DotCMSConnection, options?: RequestToolOptions): DotCMSTool<typeof definition.inputSchema, CreatePageManifest>;
23
+ export {};
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import { type PagePlaceContentManifest } from '../operations/page-place-content';
3
+ import type { DotCMSConnection } from '../toolkit/connection';
4
+ import type { DotCMSTool, RequestToolOptions } from '../toolkit/types';
5
+ declare const definition: import("../toolkit/create-tool").ToolDefinition<z.ZodObject<{
6
+ path: z.ZodString;
7
+ site: z.ZodOptional<z.ZodString>;
8
+ slots: z.ZodArray<z.ZodObject<{
9
+ slot: z.ZodUnion<readonly [z.ZodNumber, z.ZodObject<{
10
+ container: z.ZodString;
11
+ instance: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strict>]>;
13
+ contentlets: z.ZodArray<z.ZodString>;
14
+ op: z.ZodOptional<z.ZodEnum<{
15
+ remove: "remove";
16
+ set: "set";
17
+ append: "append";
18
+ }>>;
19
+ }, z.core.$strict>>;
20
+ variantName: z.ZodOptional<z.ZodString>;
21
+ languageId: z.ZodOptional<z.ZodNumber>;
22
+ mode: z.ZodOptional<z.ZodEnum<{
23
+ replace: "replace";
24
+ merge: "merge";
25
+ }>>;
26
+ }, z.core.$strip>, PagePlaceContentManifest, RequestToolOptions>;
27
+ /**
28
+ * The `page_place_content` tool: places contentlets into a page's slots while preserving
29
+ * every slot it was not asked to touch. Resolves to a {@link PagePlaceContentManifest}.
30
+ */
31
+ export declare function pagePlaceContentTool(connection: DotCMSConnection, options?: RequestToolOptions): DotCMSTool<typeof definition.inputSchema, PagePlaceContentManifest>;
32
+ export {};
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ import { type VerifyPageManifest } from '../operations/page-verify';
3
+ import type { DotCMSConnection } from '../toolkit/connection';
4
+ import type { DotCMSTool, RequestToolOptions } from '../toolkit/types';
5
+ declare const definition: import("../toolkit/create-tool").ToolDefinition<z.ZodObject<{
6
+ path: z.ZodString;
7
+ site: z.ZodOptional<z.ZodString>;
8
+ languageId: z.ZodOptional<z.ZodNumber>;
9
+ mode: z.ZodOptional<z.ZodEnum<{
10
+ LIVE: "LIVE";
11
+ WORKING: "WORKING";
12
+ }>>;
13
+ includeHtml: z.ZodOptional<z.ZodBoolean>;
14
+ }, z.core.$strip>, VerifyPageManifest, RequestToolOptions>;
15
+ /**
16
+ * The `page_verify` tool: renders a page and diagnoses each slot — empty, swallowed VTL
17
+ * error, stale cache, not assembled. Read-only. Resolves to a {@link VerifyPageManifest}.
18
+ */
19
+ export declare function pageVerifyTool(connection: DotCMSConnection, options?: RequestToolOptions): DotCMSTool<typeof definition.inputSchema, VerifyPageManifest>;
20
+ export {};
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ import type { DotCMSConnection } from '../toolkit/connection';
3
+ import type { CodeToolResult } from '../toolkit/results';
4
+ import type { DotCMSTool } from '../toolkit/types';
5
+ declare const input: z.ZodObject<{
6
+ code: z.ZodString;
7
+ }, z.core.$strip>;
8
+ /**
9
+ * The `search` tool: the model writes JavaScript that explores the bundled OpenAPI spec.
10
+ * Read-only. Resolves to `{ result }`, the capped text of the code's result (or its error).
11
+ */
12
+ export declare function searchTool(connection: DotCMSConnection): DotCMSTool<typeof input, CodeToolResult>;
13
+ export {};
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import { type UploadAssetsManifest } from '../operations/upload-assets';
3
+ import type { DotCMSConnection } from '../toolkit/connection';
4
+ import type { DotCMSTool, UploadToolOptions } from '../toolkit/types';
5
+ declare const definition: import("../toolkit/create-tool").ToolDefinition<z.ZodObject<{
6
+ src: z.ZodString;
7
+ dest: z.ZodString;
8
+ include: z.ZodOptional<z.ZodString>;
9
+ publish: z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodBoolean>>>;
10
+ verify: z.ZodDefault<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodBoolean>>>;
11
+ }, z.core.$strip>, UploadAssetsManifest, UploadToolOptions>;
12
+ /**
13
+ * The `upload_assets` tool: uploads a local directory into dotCMS as file assets — the bytes
14
+ * never pass through the model. Needs Node or Bun. Resolves to an {@link UploadAssetsManifest}.
15
+ * `options.root` bounds which local directories the model may read from.
16
+ *
17
+ * The model chooses `src`, so the tool is bounded by default: `options.maxFileBytes` (100 MB),
18
+ * `options.maxFiles` (1,000) and `options.maxScannedEntries` (20,000 entries walked). Each file
19
+ * is held in memory once while it is sent (`fetch` buffers request bodies), so the file limit
20
+ * is also the upload's memory bound. Pass `Infinity` to lift any of them.
21
+ */
22
+ export declare function uploadAssetsTool(connection: DotCMSConnection, options: UploadToolOptions): DotCMSTool<typeof definition.inputSchema, UploadAssetsManifest>;
23
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
2
+ * `@dotcms/ai/tools` — ready-made dotCMS tools for a host's own MCP server or agent.
3
+ *
4
+ * Two public layers, the same split as the runtime's two verbs:
5
+ * - `definitions/` — the tool factories (`searchTool()`, `pageCreateTool()`, …), the
6
+ * model-facing layer. Each returns a plain object shaped for the Vercel AI SDK and the MCP
7
+ * TypeScript SDK alike, whose `execute` validates the model's input and never throws.
8
+ * - `operations/` — `createPage`, `placeContent`, `verifyPage`, `uploadAssets`,
9
+ * `downloadAssets`, the direct layer. Typed options in, typed manifest out, typed errors
10
+ * thrown. Use these when YOU write the call; the tools are formatting on top.
11
+ *
12
+ * Both are built on `toolkit/`, which is internal. See ./README.md for what goes where.
13
+ *
14
+ * This is the top layer of the package: it builds on `@dotcms/ai/runtime`, and nothing below
15
+ * it may import it (lint-enforced).
16
+ */
17
+ export { dotcmsConnection } from './toolkit/connection';
18
+ export type { DotCMSConnection, DotCMSConnectionConfig, Resolvable } from './toolkit/connection';
19
+ export { executeTool } from './definitions/execute';
20
+ export { searchTool } from './definitions/search';
21
+ export { pageCreateTool } from './definitions/page-create';
22
+ export { pagePlaceContentTool } from './definitions/page-place-content';
23
+ export { pageVerifyTool } from './definitions/page-verify';
24
+ export { uploadAssetsTool } from './definitions/upload-assets';
25
+ export { downloadAssetsTool } from './definitions/download-assets';
26
+ export type { AnyDotCMSTool, AssetToolOptions, DotCMSTool, DotCMSToolAnnotations, ExecuteToolOptions, RequestToolOptions, UploadToolOptions } from './toolkit/types';
27
+ export { isToolFailure } from './toolkit/tool-runtime';
28
+ export type { ToolFailure, ToolFailureCode } from './toolkit/tool-runtime';
29
+ export type { CodeToolResult, JSONValue, ToolModelOutput } from './toolkit/results';
30
+ export { createPage } from './operations/page-create';
31
+ export type { CreatePageManifest, CreatePageOptions } from './operations/page-create';
32
+ export { placeContent } from './operations/page-place-content';
33
+ export type { PagePlaceContentManifest, PagePlaceContentOptions, PlaceMode, PlaceOp, SlotAddress, SlotAssignment, SlotResult } from './operations/page-place-content';
34
+ export { verifyPage } from './operations/page-verify';
35
+ export type { SlotVerdict, UrlMapResult, VerifyHtmlResult, VerifyMode, VerifyPageManifest, VerifyPageOptions, VerifySlotResult } from './operations/page-verify';
36
+ export { uploadAssets } from './operations/upload-assets';
37
+ export type { UploadAssetsManifest, UploadAssetsOptions } from './operations/upload-assets';
38
+ export { downloadAssets } from './operations/download-assets';
39
+ export type { DownloadAssetsManifest, DownloadAssetsOptions, DownloadKind, OverwriteMode } from './operations/download-assets';
40
+ export type { AssetManifestFailure, AssetManifestFile, AssetManifestSkipped } from './operations/shared/asset-common';
@@ -0,0 +1,55 @@
1
+ import { type AssetManifestFailure, type AssetManifestFile, type AssetManifestSkipped } from './shared/asset-common';
2
+ import { type DotCMSRuntime } from '../../runtime';
3
+ import { type Endpoint } from '../toolkit/endpoints';
4
+ /**
5
+ * Every endpoint `downloadAssets` calls — all reads. The `download_assets` tool enforces
6
+ * exactly this list, and `download-assets.spec.ts` checks every request against it.
7
+ */
8
+ export declare const DOWNLOAD_ASSETS_ENDPOINTS: readonly Endpoint[];
9
+ /** What `downloadAssets` does when a destination file already exists. */
10
+ export type OverwriteMode = 'skip' | 'overwrite' | 'error';
11
+ /**
12
+ * What `path` names. `'asset'` and `'folder'` say so outright. `'auto'` guesses from the last
13
+ * segment (an extension means an asset) and, when that reading finds nothing, tries the other:
14
+ * so a folder named `v1.2` and an asset named `robots` both work without the caller knowing.
15
+ */
16
+ export type DownloadKind = 'auto' | 'asset' | 'folder';
17
+ export interface DownloadAssetsOptions {
18
+ dotcms: DotCMSRuntime;
19
+ /**
20
+ * dotCMS folder or asset path, optionally host-qualified (`//host/path`). A folder is
21
+ * searched on that one site; a path with no host means the default site.
22
+ */
23
+ path: string;
24
+ /** Whether `path` is one asset or a folder. Default `'auto'`; see {@link DownloadKind}. */
25
+ kind?: DownloadKind;
26
+ /** Absolute local directory the files are written into. */
27
+ dest: string;
28
+ /** Include files in nested folders. */
29
+ recursive: boolean;
30
+ overwrite: OverwriteMode;
31
+ /** Comma-separated glob filter, e.g. `*.vtl,*.scss`. */
32
+ include?: string;
33
+ /**
34
+ * Directory `dest`, and every file written, must stay inside — after symlinks resolve.
35
+ * Omit only when YOU chose `dest`; the `download_assets` tool always sets it.
36
+ */
37
+ root?: string;
38
+ }
39
+ /** What `downloadAssets` returns — never the file bytes, only where they landed. */
40
+ export interface DownloadAssetsManifest {
41
+ path: string;
42
+ dest: string;
43
+ count: number;
44
+ bytes: number;
45
+ files: AssetManifestFile[];
46
+ failures: AssetManifestFailure[];
47
+ skipped: AssetManifestSkipped[];
48
+ warnings: string[];
49
+ }
50
+ /**
51
+ * Download a dotCMS asset, or every asset under a folder, to a local directory. Relative
52
+ * paths are preserved, and one failed file is recorded in the manifest rather than aborting
53
+ * the batch.
54
+ */
55
+ export declare function downloadAssets(options: DownloadAssetsOptions): Promise<DownloadAssetsManifest>;
@@ -0,0 +1,81 @@
1
+ import { type DotCMSRuntime } from '../../runtime';
2
+ import { type Endpoint } from '../toolkit/endpoints';
3
+ /**
4
+ * Every endpoint `createPage` calls — the `page_create` tool enforces exactly this list, and
5
+ * `page-create.spec.ts` checks every request against it. Add a request, add it here.
6
+ */
7
+ export declare const PAGE_CREATE_ENDPOINTS: readonly Endpoint[];
8
+ /** The default page content type when the caller does not name one. */
9
+ export declare const DEFAULT_PAGE_CONTENT_TYPE = "htmlpageasset";
10
+ export interface CreatePageOptions {
11
+ dotcms: DotCMSRuntime;
12
+ /** Site identifier (UUID) or hostname the page lives on. */
13
+ site: string;
14
+ /** Page-relative URL path, e.g. "/books/index" or "/books". The leaf becomes the page url. */
15
+ urlPath: string;
16
+ /** Page title. */
17
+ title: string;
18
+ /** Template identifier the page renders with. */
19
+ template: string;
20
+ /**
21
+ * Content type for the page — variable or id. Defaults to `htmlpageasset`. Any content type
22
+ * works as long as its base type is HTMLPAGE (a custom page type may add its own fields).
23
+ */
24
+ contentType?: string;
25
+ /**
26
+ * Values for content-type fields beyond the common page fields — keyed by field variable.
27
+ * Required for any user-added required field on a custom page type that has no default value.
28
+ */
29
+ extraFields?: Record<string, unknown>;
30
+ /** Optional friendly name; defaults to `title`. */
31
+ friendlyName?: string;
32
+ /** Optional page title (browser <title>); defaults to `title`. */
33
+ pageTitle?: string;
34
+ /** Language id. Default 1. */
35
+ languageId?: number;
36
+ /** Cache TTL seconds (as dotCMS expects: a string). Default "0". */
37
+ cacheTtl?: string;
38
+ /** Sort order. Default 0. */
39
+ sortOrder?: number;
40
+ }
41
+ export interface CreatePageManifest {
42
+ /** Identifier of the created page contentlet. */
43
+ identifier?: string;
44
+ /** Inode of the created version. */
45
+ inode?: string;
46
+ /** The resolved content type variable the page was created as. */
47
+ contentType: string;
48
+ /** The folder path the page was placed under (e.g. "/books"). */
49
+ folder: string;
50
+ /** The leaf url stored on the page (e.g. "index"). */
51
+ url: string;
52
+ /** Full live URL on the site (e.g. "/books/index"). */
53
+ fullPath: string;
54
+ /** Site the page lives on. */
55
+ site: string;
56
+ /** Whether the page is live after the publish fire. */
57
+ live: boolean;
58
+ /**
59
+ * Set when the page was created but NOT verified live. The page exists; it just may render
60
+ * blank with no content placed (the two-step trap). Not a hard failure.
61
+ */
62
+ warnings: string[];
63
+ }
64
+ /**
65
+ * Create and publish a dotCMS page in one safe call.
66
+ *
67
+ * A "page" is a contentlet whose content type's base type is HTMLPAGE, fired through the generic
68
+ * workflow endpoint — there is no dedicated create-page endpoint. The content type defaults to
69
+ * `htmlpageasset` but can be any page type; custom page types may add their own (possibly required)
70
+ * fields, so we resolve the type and validate against its actual field set before firing.
71
+ *
72
+ * This wrapper absorbs the URL-collapse trap: dotCMS silently collapses a page `url` whose parent
73
+ * folder does not exist down to `/index`, which then 400s against the home page. We split `urlPath`
74
+ * into folder + leaf, create the folder first, then fire the page with `url: "<leaf>"` and
75
+ * `hostFolder: <created folder>` so the URL lands where the caller meant.
76
+ *
77
+ * This is the THIN tier: it does NOT place content. The page comes up live but blank — content
78
+ * placement and the re-publish that follows are a separate, explicit step for the caller. The
79
+ * manifest flags this so a successful create is never mistaken for a fully-populated page.
80
+ */
81
+ export declare function createPage(options: CreatePageOptions): Promise<CreatePageManifest>;
@@ -0,0 +1,102 @@
1
+ import { type DotCMSRuntime } from '../../runtime';
2
+ import { type Endpoint } from '../toolkit/endpoints';
3
+ /**
4
+ * Every endpoint `placeContent` calls — the `page_place_content` tool enforces exactly this
5
+ * list, and `page-place-content.spec.ts` checks every request against it. Add a request, add it
6
+ * here.
7
+ */
8
+ export declare const PAGE_PLACE_CONTENT_ENDPOINTS: readonly Endpoint[];
9
+ /** The default variant when the caller does not name one. */
10
+ export declare const DEFAULT_VARIANT = "DEFAULT";
11
+ /** The default language id when the caller does not name one. */
12
+ export declare const DEFAULT_LANGUAGE_ID = 1;
13
+ /** How a slot's contentlet list is combined with the ids the caller supplies. */
14
+ export type PlaceOp = 'append' | 'set' | 'remove';
15
+ /** Whether the tool merges into the page's current content or replaces it wholesale. */
16
+ export type PlaceMode = 'merge' | 'replace';
17
+ /**
18
+ * How the caller points at a slot. Either the 1-based index into the page's real slots (in layout
19
+ * order), or a container reference. `instance` (the slot uuid) is optional ONLY when the named
20
+ * container occupies exactly one slot on the page; otherwise it is required to disambiguate.
21
+ */
22
+ export type SlotAddress = number | {
23
+ container: string;
24
+ instance?: string;
25
+ };
26
+ /** One slot assignment in the multi-slot (`slots[]`) form. */
27
+ export interface SlotAssignment {
28
+ slot: SlotAddress;
29
+ contentlets: string[];
30
+ op?: PlaceOp;
31
+ }
32
+ export interface PagePlaceContentOptions {
33
+ dotcms: DotCMSRuntime;
34
+ /** Page URL path (e.g. "/about-us"), host-qualified path, or a page identifier (UUID). */
35
+ path: string;
36
+ /**
37
+ * Site hostname or identifier. Required unless `path` is host-qualified as
38
+ * `//hostname/path`; the qualified form supplies this value implicitly.
39
+ */
40
+ site?: string;
41
+ /**
42
+ * One or more slot assignments applied in a single atomic write. Placing content in one slot is
43
+ * just an array of one: `[{ slot, contentlets }]`.
44
+ */
45
+ slots: SlotAssignment[];
46
+ /** Variant name. Default "DEFAULT". */
47
+ variantName?: string;
48
+ /** Language id. Default 1. */
49
+ languageId?: number;
50
+ /**
51
+ * "merge" (default) reads the page's current content and applies the ops on top, preserving every
52
+ * untouched slot. "replace" treats the supplied slots as the complete desired map — every other
53
+ * slot on the page is cleared. Both still validate slot existence and return a before/after diff.
54
+ */
55
+ mode?: PlaceMode;
56
+ }
57
+ /** The before/after picture of one slot the write touched or preserved. */
58
+ export interface SlotResult {
59
+ /** Container key as the layout addresses it (path for file containers, id for db containers). */
60
+ identifier: string;
61
+ /** Slot instance uuid. */
62
+ uuid: string;
63
+ /** Contentlet ids in the slot before the write. */
64
+ before: string[];
65
+ /** Contentlet ids in the slot after the write. */
66
+ after: string[];
67
+ /** True when before/after differ. */
68
+ changed: boolean;
69
+ }
70
+ export interface PagePlaceContentManifest {
71
+ /** Identifier of the page whose content was written. */
72
+ pageId: string;
73
+ /** Hostname of the site whose page was updated. */
74
+ site: string;
75
+ /** The page's url path. */
76
+ url: string;
77
+ /** Variant the write targeted. */
78
+ variantName: string;
79
+ /** Language id the write targeted. */
80
+ languageId: number;
81
+ /** The effective mode ("merge" or "replace"). */
82
+ mode: PlaceMode;
83
+ /** Per-slot before/after for every slot on the page (touched and untouched). */
84
+ slots: SlotResult[];
85
+ /** Actionable notices: content loss, net-loss conflict, etc. Empty on a clean happy path. */
86
+ warnings: string[];
87
+ }
88
+ /**
89
+ * Place content into a page's container slots without wiping the rest of the page.
90
+ *
91
+ * `POST /api/v1/page/{pageId}/content` is a FULL replacement of the page's container-to-contentlet
92
+ * map: any slot omitted from the body is emptied. A caller that means "add one contentlet to one
93
+ * slot" but sends only that slot silently clears every other slot. This wrapper absorbs that trap:
94
+ * it reads the page's current content first, applies the requested op(s) to the addressed slot(s)
95
+ * only, then POSTs the COMPLETE map back so untouched slots survive.
96
+ *
97
+ * It also removes the discovery friction: the caller addresses a slot by index or container name
98
+ * and we resolve it to the exact `identifier`+`uuid` the endpoint needs — sourced from the page's
99
+ * real layout, so a typo fails clearly instead of silently doing nothing. The returned manifest
100
+ * gives a before/after diff per slot and flags any slot that lost content.
101
+ */
102
+ export declare function placeContent(options: PagePlaceContentOptions): Promise<PagePlaceContentManifest>;