@dotcms/ai 0.1.0
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.
- package/README.md +137 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +7 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +1 -0
- package/package.json +72 -0
- package/runtime.cjs.default.js +1 -0
- package/runtime.cjs.js +0 -0
- package/runtime.cjs.mjs +2 -0
- package/runtime.d.ts +1 -0
- package/runtime.esm.js +0 -0
- package/spec.cjs.js +16090 -0
- package/spec.esm.js +16088 -0
- package/src/adapter/context-cache.d.ts +35 -0
- package/src/adapter/context.d.ts +42 -0
- package/src/adapter/http-client.d.ts +37 -0
- package/src/adapter/index.d.ts +12 -0
- package/src/adapter/request-core.d.ts +77 -0
- package/src/runtime.d.ts +70 -0
- package/src/sandbox/bun-worker.d.ts +10 -0
- package/src/sandbox/define-adapter.d.ts +88 -0
- package/src/sandbox/errors.d.ts +91 -0
- package/src/sandbox/executor.d.ts +27 -0
- package/src/sandbox/factory.d.ts +13 -0
- package/src/sandbox/index.d.ts +44 -0
- package/src/sandbox/interface.d.ts +8 -0
- package/src/sandbox/node-worker.d.ts +10 -0
- package/src/sandbox/types.d.ts +111 -0
- package/src/sandbox/worker-harness.d.ts +15 -0
- package/src/spec/index.d.ts +7 -0
- package/src/spec/spec.d.ts +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for an adapter method parameter
|
|
3
|
+
*/
|
|
4
|
+
export interface AdapterMethodParameter {
|
|
5
|
+
name: string;
|
|
6
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
7
|
+
description?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
default?: unknown;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A method exposed by an adapter
|
|
13
|
+
*/
|
|
14
|
+
export interface AdapterMethod {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters: AdapterMethodParameter[];
|
|
18
|
+
execute: (...args: unknown[]) => unknown | Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A registered adapter instance
|
|
22
|
+
*/
|
|
23
|
+
export interface Adapter {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
version: string;
|
|
27
|
+
methods: Map<string, AdapterMethod>;
|
|
28
|
+
config?: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Per-execution resource caps for the worker. Maps onto Node's `worker_threads`
|
|
32
|
+
* `resourceLimits`; ignored fields are simply not applied on runtimes that lack them.
|
|
33
|
+
*/
|
|
34
|
+
export interface SandboxResourceLimits {
|
|
35
|
+
/** Max old-generation heap (MB). The main memory cap. */
|
|
36
|
+
maxOldGenerationSizeMb?: number;
|
|
37
|
+
/** Max young-generation heap (MB). */
|
|
38
|
+
maxYoungGenerationSizeMb?: number;
|
|
39
|
+
/** Worker stack size (MB). */
|
|
40
|
+
stackSizeMb?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration for the sandbox execution environment.
|
|
44
|
+
*
|
|
45
|
+
* The boundary this enforces is **capability confinement for trusted code generators, NOT a
|
|
46
|
+
* defense against adversarial code** (see the package threat model). It blocks accidental
|
|
47
|
+
* egress and runaway cost; it is not a hardened isolate.
|
|
48
|
+
*/
|
|
49
|
+
export interface SandboxConfig {
|
|
50
|
+
/** Wall-clock timeout (ms) for one execution. On expiry the worker is terminated. */
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/** Extra globals injected into the worker (e.g. `spec`). */
|
|
53
|
+
globals?: Record<string, unknown>;
|
|
54
|
+
/** Per-execution memory/stack caps. */
|
|
55
|
+
resourceLimits?: SandboxResourceLimits;
|
|
56
|
+
/**
|
|
57
|
+
* Fired when the execution is torn down (timeout, error, or completion) so the host can
|
|
58
|
+
* abort in-flight adapter work (the threaded `AbortController.abort()`). The runtime wires
|
|
59
|
+
* this to the same signal it gave the adapter, so a sandbox timeout stops an in-flight fetch.
|
|
60
|
+
*/
|
|
61
|
+
onTeardown?: () => void;
|
|
62
|
+
}
|
|
63
|
+
/** The serializable error shape carried back from an execution. Mirrors SerializedDotCMSError. */
|
|
64
|
+
export interface SandboxResultError {
|
|
65
|
+
name: string;
|
|
66
|
+
message: string;
|
|
67
|
+
/** Machine-readable error code from the typed hierarchy, when available. */
|
|
68
|
+
code?: string;
|
|
69
|
+
/** Only present when the runtime opts into leaking stacks to executed code. */
|
|
70
|
+
stack?: string;
|
|
71
|
+
/** Type-specific structured detail. */
|
|
72
|
+
detail?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/** Fully-resolved sandbox config (timeout/globals always present). Shared by both backends. */
|
|
75
|
+
export type ResolvedSandboxConfig = SandboxConfig & {
|
|
76
|
+
timeout: number;
|
|
77
|
+
globals: Record<string, unknown>;
|
|
78
|
+
};
|
|
79
|
+
export interface WorkerMessage {
|
|
80
|
+
type: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
export interface AdapterCallMessage {
|
|
84
|
+
adapter: string;
|
|
85
|
+
method: string;
|
|
86
|
+
args: unknown[];
|
|
87
|
+
id: number;
|
|
88
|
+
}
|
|
89
|
+
export interface ResultMessage {
|
|
90
|
+
success: boolean;
|
|
91
|
+
value?: unknown;
|
|
92
|
+
error?: SandboxResultError;
|
|
93
|
+
logs?: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Result from sandbox code execution
|
|
97
|
+
*/
|
|
98
|
+
export interface SandboxResult<T = unknown> {
|
|
99
|
+
success: boolean;
|
|
100
|
+
value?: T;
|
|
101
|
+
error?: SandboxResultError;
|
|
102
|
+
logs: string[];
|
|
103
|
+
executionTime: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Context passed to sandbox execution
|
|
107
|
+
*/
|
|
108
|
+
export interface ExecutionContext {
|
|
109
|
+
adapters: Record<string, Record<string, (...args: unknown[]) => unknown | Promise<unknown>>>;
|
|
110
|
+
variables?: Record<string, unknown>;
|
|
111
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Node `worker_threads` bootstrap: transport via `parentPort`, plus `require` removal. */
|
|
2
|
+
declare const NODE_WORKER_CODE: string;
|
|
3
|
+
/** Bun / Web Worker bootstrap: transport via `self`. */
|
|
4
|
+
declare const BUN_WORKER_CODE: string;
|
|
5
|
+
/**
|
|
6
|
+
* Default per-execution resource caps, shared by both backends so a runaway/ballooning
|
|
7
|
+
* script can't exhaust the host. (Node applies these via `worker_threads.resourceLimits`;
|
|
8
|
+
* Bun applies what its Worker supports.)
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_RESOURCE_LIMITS: {
|
|
11
|
+
readonly maxOldGenerationSizeMb: 256;
|
|
12
|
+
readonly maxYoungGenerationSizeMb: 32;
|
|
13
|
+
readonly stackSizeMb: 4;
|
|
14
|
+
};
|
|
15
|
+
export { NODE_WORKER_CODE, BUN_WORKER_CODE };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@dotcms/ai/spec` — the filtered dotCMS OpenAPI spec, behind its own subpath so importing
|
|
3
|
+
* the adapter doesn't drag in the ~hundreds-of-KB JSON. Opt-in for the search use case. The
|
|
4
|
+
* spec is build-generated (not committed) from a specific dotCMS instance; see the support
|
|
5
|
+
* matrix in the README for the spec ↔ server-version coupling.
|
|
6
|
+
*/
|
|
7
|
+
export { getSpec } from './spec';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSpec(): Record<string, unknown>;
|