@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
@@ -0,0 +1,108 @@
1
+ import { type DotCMSErrorCode, type DotCMSRuntime, type DotCMSRuntimeConfig } from '../../runtime';
2
+ /**
3
+ * The runtime settings a tool host supplies once. Everything else a tool needs (its sandbox
4
+ * timeout, whether it gets the `spec` global) is decided per tool, not by the host.
5
+ */
6
+ export type ToolRuntimeConfig = Pick<DotCMSRuntimeConfig, 'url' | 'token' | 'allow' | 'onCall' | 'onContextError' | 'includeStacks'>;
7
+ /** What an individual tool asks of the runtime it is handed for one call. */
8
+ export interface ToolRuntimeOptions {
9
+ /** Sandbox wall-clock timeout (ms) for `run()`. */
10
+ timeout?: number;
11
+ /** Inject the OpenAPI `spec` global into `run()`. */
12
+ includeSpec?: boolean;
13
+ /** Deadline (ms) for each direct `request()`. Default {@link DEFAULT_REQUEST_TIMEOUT_MS}. */
14
+ requestTimeout?: number;
15
+ }
16
+ /**
17
+ * Cap on any single error string handed back to the model.
18
+ *
19
+ * A dotCMS 5xx returns its full HTML stack-trace page, tens to hundreds of KB, and
20
+ * `HttpError.message` embeds the body verbatim. A transfer manifest keeps one message PER
21
+ * FAILED FILE, so 200 files against a broken instance would otherwise carry 200 copies of
22
+ * that page in a single tool result.
23
+ */
24
+ export declare const MAX_ERROR_CHARS = 2000;
25
+ /**
26
+ * The tool host is misconfigured — a deployment problem, not a bad tool call.
27
+ *
28
+ * Carries its own `code` so it lands in {@link ToolFailure} as `CONFIGURATION` rather than
29
+ * `UNKNOWN`, which is what lets the model tell "I called this wrong" from "this server
30
+ * cannot serve anyone right now".
31
+ */
32
+ export declare class ConfigurationError extends Error {
33
+ readonly code: "CONFIGURATION";
34
+ /**
35
+ * `cause` carries the underlying error for the HOST (e.g. what a token resolver threw). It
36
+ * is never part of the message, which is what reaches the model.
37
+ */
38
+ constructor(message: string, options?: {
39
+ cause?: unknown;
40
+ });
41
+ }
42
+ /**
43
+ * Build the runtime one tool call runs against. One place owns the per-request deadline —
44
+ * so every tool constructs its runtime the same way instead of re-deriving it (and silently
45
+ * drifting on which options they set).
46
+ *
47
+ * Called once per tool invocation, deliberately: the runtime owns its context cache, so a
48
+ * fresh runtime is what lets the next call see sites, content types or languages the
49
+ * previous call created. That is also why no session id is threaded through — a runtime
50
+ * that lives for one call has nothing to key a cache on.
51
+ */
52
+ export declare function createToolRuntime(config: ToolRuntimeConfig, opts?: ToolRuntimeOptions): DotCMSRuntime;
53
+ /**
54
+ * Normalize any thrown value to a message string, capped at {@link MAX_ERROR_CHARS}.
55
+ *
56
+ * The cap is the point: see MAX_ERROR_CHARS for why an uncapped `HttpError.message` is a
57
+ * real problem rather than a cosmetic one.
58
+ */
59
+ export declare function errorMessage(error: unknown): string;
60
+ /**
61
+ * Give a caught error a clearer message, and return that SAME error for the caller to throw.
62
+ *
63
+ * For an operation that explains a failure in its own terms ("the save was rejected as a
64
+ * net-loss conflict…") before rethrowing. Wrapping it in a new `Error` instead loses the
65
+ * error's class, and with it the `code`, the HTTP `status` and whether a retry can help: a 503
66
+ * worth retrying reaches the model as `UNKNOWN`, not retryable. Only a non-`Error` throw, which
67
+ * has no class to keep, becomes a plain `Error`.
68
+ */
69
+ export declare function withMessage(error: unknown, message: string): Error;
70
+ /**
71
+ * Every code a {@link ToolFailure} can carry: the runtime's error codes, `CONFIGURATION` for a
72
+ * connection the host has not set up, and `UNKNOWN` for anything that is not a typed error.
73
+ * A union rather than `string`, so a host switching on it gets completion and a misspelt code
74
+ * is a compile error rather than a branch that silently never runs.
75
+ */
76
+ export type ToolFailureCode = DotCMSErrorCode | ConfigurationError['code'] | 'UNKNOWN';
77
+ /** The structured failure a tool returns instead of a bare message. */
78
+ export interface ToolFailure {
79
+ ok: false;
80
+ operation: string;
81
+ error: string;
82
+ /** Stable machine-readable code (`HTTP`, `TIMEOUT`, `POLICY`, …), or `UNKNOWN`. */
83
+ code: ToolFailureCode;
84
+ /**
85
+ * Whether retrying could help. A FIELD rather than only a type, because MCP hands the
86
+ * model a STRING — `instanceof` is unavailable on the far side, so anything the model
87
+ * needs to branch on has to survive JSON.
88
+ */
89
+ retryable: boolean;
90
+ /** HTTP status when the failure was an HTTP error. */
91
+ status?: number;
92
+ [key: string]: unknown;
93
+ }
94
+ /**
95
+ * Build the failure a tool returns instead of throwing.
96
+ *
97
+ * Owns the `[dotCMS - <operation>]` prefix convention in one place rather than as a
98
+ * template string at each throw site, and preserves the typed detail (`code`, `status`,
99
+ * `retryable`) that flattening to `.message` used to discard.
100
+ *
101
+ * Deliberately NOT a parallel error hierarchy: `formatSandboxResult` remains the layer for
102
+ * sandbox results (`execute`/`search` already use it). This is only for failures a tool
103
+ * call raises outside a sandbox result — a direct request, invalid arguments, a host
104
+ * misconfiguration.
105
+ */
106
+ export declare function toToolFailure(operation: string, error: unknown, extra?: Record<string, unknown>): ToolFailure;
107
+ /** Whether a tool result is a {@link ToolFailure} rather than the tool's normal result. */
108
+ export declare function isToolFailure(value: unknown): value is ToolFailure;
@@ -0,0 +1,120 @@
1
+ import type { ToolModelOutput } from './results';
2
+ import type { ToolFailure } from './tool-runtime';
3
+ import type { RuntimeAllow } from '../../runtime';
4
+ import type { z } from 'zod';
5
+ /**
6
+ * Behavior hints a host forwards to its framework — they map one-to-one onto MCP's
7
+ * `ToolAnnotations`. Hints, not guarantees: `execute` is marked destructive because the code a
8
+ * model writes for it CAN delete content, not because every call does.
9
+ */
10
+ export interface DotCMSToolAnnotations {
11
+ readOnlyHint: boolean;
12
+ destructiveHint: boolean;
13
+ idempotentHint: boolean;
14
+ openWorldHint: boolean;
15
+ }
16
+ /** Options for `executeTool`. */
17
+ export interface ExecuteToolOptions {
18
+ /**
19
+ * Allow-list or policy bounding what the model's code can reach — the same one
20
+ * `createRuntime` takes. The one tool that has it: here the MODEL chooses the endpoints,
21
+ * so this is the consumer governing the model, not configuring the tool.
22
+ */
23
+ allow?: RuntimeAllow;
24
+ /** Sandbox wall-clock timeout (ms) for the model's code. Default 45000. */
25
+ timeout?: number;
26
+ /** Pass host stack traces through to the code's error results. Default false. */
27
+ includeStacks?: boolean;
28
+ }
29
+ /** Options for the tools that call the API directly: the page and asset tools. */
30
+ export interface RequestToolOptions {
31
+ /** Deadline (ms) for each request. Default 30000. */
32
+ requestTimeout?: number;
33
+ }
34
+ /** Options for `uploadAssetsTool` and `downloadAssetsTool`, which touch the local disk. */
35
+ export interface AssetToolOptions extends RequestToolOptions {
36
+ /**
37
+ * The local directory the model's `src` / `dest` must stay inside — symlinks resolved.
38
+ * Required, because the paths come from the model: without a boundary a hosted server's
39
+ * `upload_assets` reads any directory the process can, and `download_assets` writes into
40
+ * any directory it can. `'/'` is the explicit "whole disk" choice, for a local agent acting
41
+ * as its own user.
42
+ */
43
+ root: string;
44
+ }
45
+ /** Options for `uploadAssetsTool`: the asset options, plus the limits on what one call sends. */
46
+ export interface UploadToolOptions extends AssetToolOptions {
47
+ /**
48
+ * Largest file one call sends, in bytes. Default 100 MB. A larger file is a failure in the
49
+ * manifest, before it is read; the rest still upload. Each file is held in memory once
50
+ * while it is sent, so this also bounds the upload's memory. `Infinity` lifts it.
51
+ */
52
+ maxFileBytes?: number;
53
+ /**
54
+ * Most files one call sends, after `include`. Default 1,000. More is a VALIDATION
55
+ * failure before anything is sent. `Infinity` lifts it.
56
+ */
57
+ maxFiles?: number;
58
+ /**
59
+ * Most entries — files and directories — one call's walk of `src` visits, matched by
60
+ * `include` or not. Default 20,000. More is a VALIDATION failure before anything is sent,
61
+ * so a vast `src` with a narrow `include` is not walked to the end. `Infinity` lifts it.
62
+ */
63
+ maxScannedEntries?: number;
64
+ }
65
+ /**
66
+ * One dotCMS tool, shaped the way the Vercel AI SDK and the MCP TypeScript SDK both expect:
67
+ * pass it straight into AI SDK's `tools`, or into MCP's `registerTool` config. Every result is
68
+ * an object, as Google ADK requires.
69
+ *
70
+ * `execute` never throws. It validates `input` (it comes from the model, so this is the trust
71
+ * boundary), runs the tool, and resolves to the tool's result — or to a {@link ToolFailure}
72
+ * carrying a stable `code` and a `retryable` flag, because a model cannot `instanceof` its
73
+ * way through a failure.
74
+ *
75
+ * `input` is typed from the tool's own schema, so code that calls a tool directly gets
76
+ * completion and a compile error for a wrong field. That is a convenience for the caller, not
77
+ * the check: `execute` still validates at run time, because what reaches it from a model was
78
+ * never type-checked. A host that holds several tools in one list and calls whichever the
79
+ * model picked types that list as {@link AnyDotCMSTool}.
80
+ */
81
+ export interface DotCMSTool<TInput extends z.ZodObject = z.ZodObject, TResult = unknown> extends DotCMSToolBase<TResult> {
82
+ readonly inputSchema: TInput;
83
+ execute(input: z.input<TInput>): Promise<TResult | ToolFailure>;
84
+ }
85
+ /**
86
+ * Any dotCMS tool, whatever its schema — the element type of a registry: `AnyDotCMSTool[]`, or
87
+ * a map from tool name to tool. `execute` takes `unknown`, because a registry dispatches on the
88
+ * name the model chose and hands over the model's arguments as they came; `execute` validates
89
+ * them. Every {@link DotCMSTool} is assignable to it.
90
+ */
91
+ export interface AnyDotCMSTool extends DotCMSToolBase<unknown> {
92
+ readonly inputSchema: z.ZodObject;
93
+ execute(input: unknown): Promise<unknown>;
94
+ }
95
+ /** What every tool has, whatever its input: identity, annotations and rendering. */
96
+ interface DotCMSToolBase<TResult> {
97
+ /**
98
+ * The name the tool's description expects to be called by. The descriptions refer to their
99
+ * siblings by these names ("use the `search` tool first"), so register each tool under it.
100
+ */
101
+ readonly name: string;
102
+ readonly title: string;
103
+ /** The model-facing description — tuned prompt text. */
104
+ readonly description: string;
105
+ readonly annotations: DotCMSToolAnnotations;
106
+ /**
107
+ * What the model sees of a result, for frameworks that ask (the AI SDK picks this up on its
108
+ * own): text for the tools that declare a text form (`search`, `execute`), structured JSON
109
+ * for the rest and for any failure.
110
+ */
111
+ toModelOutput(options: {
112
+ output: TResult | ToolFailure;
113
+ }): ToolModelOutput;
114
+ /**
115
+ * The same rendering, as the text a text-only transport such as an MCP `content` block
116
+ * carries: a text tool's output as-is, everything else pretty-printed JSON.
117
+ */
118
+ toText(output: TResult | ToolFailure): string;
119
+ }
120
+ export {};
package/src/tools.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './tools/index';
@@ -0,0 +1 @@
1
+ exports._default = require('./tools.cjs.js').default;