@tailor-cms/ce-modal-server 0.0.2 → 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/dist/index.cjs CHANGED
@@ -17,20 +17,73 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
19
  // src/index.ts
20
- var src_exports = {};
21
- __export(src_exports, {
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
22
  afterLoaded: () => afterLoaded,
23
23
  afterRetrieve: () => afterRetrieve,
24
24
  afterSave: () => afterSave,
25
+ ai: () => ai,
25
26
  beforeDisplay: () => beforeDisplay,
26
27
  beforeSave: () => beforeSave,
27
- default: () => src_default,
28
+ default: () => index_default,
28
29
  hookMap: () => hookMap,
29
30
  initState: () => initState,
30
31
  onUserInteraction: () => onUserInteraction,
31
32
  type: () => type
32
33
  });
33
- module.exports = __toCommonJS(src_exports);
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
37
+ var byteToHex = [];
38
+ for (let i = 0; i < 256; ++i) {
39
+ byteToHex.push((i + 256).toString(16).slice(1));
40
+ }
41
+ function unsafeStringify(arr, offset = 0) {
42
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
43
+ }
44
+
45
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
46
+ var import_crypto = require("crypto");
47
+ var rnds8Pool = new Uint8Array(256);
48
+ var poolPtr = rnds8Pool.length;
49
+ function rng() {
50
+ if (poolPtr > rnds8Pool.length - 16) {
51
+ (0, import_crypto.randomFillSync)(rnds8Pool);
52
+ poolPtr = 0;
53
+ }
54
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
55
+ }
56
+
57
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
58
+ var import_crypto2 = require("crypto");
59
+ var native_default = { randomUUID: import_crypto2.randomUUID };
60
+
61
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
62
+ function v4(options, buf, offset) {
63
+ var _a;
64
+ if (native_default.randomUUID && !buf && !options) {
65
+ return native_default.randomUUID();
66
+ }
67
+ options = options || {};
68
+ const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
69
+ if (rnds.length < 16) {
70
+ throw new Error("Random bytes length must be >= 16");
71
+ }
72
+ rnds[6] = rnds[6] & 15 | 64;
73
+ rnds[8] = rnds[8] & 63 | 128;
74
+ if (buf) {
75
+ offset = offset || 0;
76
+ if (offset < 0 || offset + 16 > buf.length) {
77
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
78
+ }
79
+ for (let i = 0; i < 16; ++i) {
80
+ buf[offset + i] = rnds[i];
81
+ }
82
+ return buf;
83
+ }
84
+ return unsafeStringify(rnds);
85
+ }
86
+ var v4_default = v4;
34
87
 
35
88
  // ../manifest/dist/index.js
36
89
  var type = "MODAL";
@@ -38,26 +91,67 @@ var initState = () => ({
38
91
  title: null,
39
92
  embeds: {}
40
93
  });
94
+ var ai = {
95
+ Schema: {
96
+ type: "json_schema",
97
+ name: "ce_modal",
98
+ schema: {
99
+ type: "object",
100
+ properties: {
101
+ title: { type: "string" },
102
+ content: { type: "string" }
103
+ },
104
+ required: ["title", "content"],
105
+ additionalProperties: false
106
+ }
107
+ },
108
+ getPrompt: () => `
109
+ Generate a modal content element as an object with the following
110
+ properties:
111
+ {
112
+ "title": "",
113
+ "content": "",
114
+ }
115
+ where:
116
+ - 'title' is the title of the modal. Do not use more than 3 words.
117
+ - 'content' is the text to be displayed in the modal. Create few
118
+ paragraphs about the topic.
119
+ `,
120
+ processResponse: (val) => {
121
+ const embedId = v4_default();
122
+ const embed = {
123
+ id: embedId,
124
+ data: { content: val.content },
125
+ embedded: true,
126
+ position: 1,
127
+ type: "TIPTAP_HTML"
128
+ };
129
+ return {
130
+ title: val.title,
131
+ embeds: { [embedId]: embed }
132
+ };
133
+ }
134
+ };
41
135
 
42
136
  // src/index.ts
43
137
  var IS_CEK = process.env.CEK_RUNTIME;
44
138
  var USER_STATE = {};
45
- function beforeSave(element, services) {
139
+ function beforeSave(element, _services) {
46
140
  return element;
47
141
  }
48
- function afterSave(element, services) {
142
+ function afterSave(element, _services) {
49
143
  return element;
50
144
  }
51
- function afterLoaded(element, services, runtime) {
145
+ function afterLoaded(element, _services, _runtime) {
52
146
  return element;
53
147
  }
54
- function afterRetrieve(element, services, runtime) {
148
+ function afterRetrieve(element, _services, _runtime) {
55
149
  return element;
56
150
  }
57
- function beforeDisplay(element, context) {
151
+ function beforeDisplay(_element, context) {
58
152
  return { ...context, ...USER_STATE };
59
153
  }
60
- function onUserInteraction(element, context, payload) {
154
+ function onUserInteraction(_element, context, payload) {
61
155
  if (IS_CEK) {
62
156
  USER_STATE.interactionTimestamp = (/* @__PURE__ */ new Date()).getTime();
63
157
  context.contextTimestamp = USER_STATE.interactionTimestamp;
@@ -75,7 +169,7 @@ var hookMap = new Map(
75
169
  beforeDisplay
76
170
  })
77
171
  );
78
- var src_default = {
172
+ var index_default = {
79
173
  type,
80
174
  hookMap,
81
175
  initState,
@@ -84,13 +178,15 @@ var src_default = {
84
178
  afterLoaded,
85
179
  afterRetrieve,
86
180
  onUserInteraction,
87
- beforeDisplay
181
+ beforeDisplay,
182
+ ai
88
183
  };
89
184
  // Annotate the CommonJS export names for ESM import in node:
90
185
  0 && (module.exports = {
91
186
  afterLoaded,
92
187
  afterRetrieve,
93
188
  afterSave,
189
+ ai,
94
190
  beforeDisplay,
95
191
  beforeSave,
96
192
  hookMap,
package/dist/index.d.cts CHANGED
@@ -1,14 +1,15 @@
1
+ import * as _tailor_cms_cek_common from '@tailor-cms/cek-common';
2
+ import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
1
3
  import * as _tailor_cms_ce_modal_manifest from '@tailor-cms/ce-modal-manifest';
2
4
  import { Element } from '@tailor-cms/ce-modal-manifest';
3
- export { initState, type } from '@tailor-cms/ce-modal-manifest';
4
- import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
5
+ export { ai, initState, type } from '@tailor-cms/ce-modal-manifest';
5
6
 
6
- declare function beforeSave(element: Element, services: HookServices): Element;
7
- declare function afterSave(element: Element, services: HookServices): Element;
8
- declare function afterLoaded(element: Element, services: HookServices, runtime: ServerRuntime): Element;
9
- declare function afterRetrieve(element: Element, services: HookServices, runtime: ServerRuntime): Element;
10
- declare function beforeDisplay(element: Element, context: any): any;
11
- declare function onUserInteraction(element: Element, context: any, payload: any): any;
7
+ declare function beforeSave(element: Element, _services: HookServices): Element;
8
+ declare function afterSave(element: Element, _services: HookServices): Element;
9
+ declare function afterLoaded(element: Element, _services: HookServices, _runtime: ServerRuntime): Element;
10
+ declare function afterRetrieve(element: Element, _services: HookServices, _runtime: ServerRuntime): Element;
11
+ declare function beforeDisplay(_element: Element, context: any): any;
12
+ declare function onUserInteraction(_element: Element, context: any, payload: any): any;
12
13
  declare const hookMap: Map<string, typeof beforeSave | typeof afterSave | typeof afterLoaded | typeof afterRetrieve | typeof onUserInteraction | typeof beforeDisplay>;
13
14
  declare const _default: {
14
15
  type: string;
@@ -20,6 +21,24 @@ declare const _default: {
20
21
  afterRetrieve: typeof afterRetrieve;
21
22
  onUserInteraction: typeof onUserInteraction;
22
23
  beforeDisplay: typeof beforeDisplay;
24
+ ai: {
25
+ Schema: _tailor_cms_cek_common.OpenAISchema;
26
+ getPrompt: () => string;
27
+ processResponse: (val: any) => {
28
+ title: any;
29
+ embeds: {
30
+ [x: string]: {
31
+ id: string;
32
+ data: {
33
+ content: any;
34
+ };
35
+ embedded: boolean;
36
+ position: number;
37
+ type: string;
38
+ };
39
+ };
40
+ };
41
+ };
23
42
  };
24
43
 
25
44
  export { afterLoaded, afterRetrieve, afterSave, beforeDisplay, beforeSave, _default as default, hookMap, onUserInteraction };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
+ import * as _tailor_cms_cek_common from '@tailor-cms/cek-common';
2
+ import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
1
3
  import * as _tailor_cms_ce_modal_manifest from '@tailor-cms/ce-modal-manifest';
2
4
  import { Element } from '@tailor-cms/ce-modal-manifest';
3
- export { initState, type } from '@tailor-cms/ce-modal-manifest';
4
- import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
5
+ export { ai, initState, type } from '@tailor-cms/ce-modal-manifest';
5
6
 
6
- declare function beforeSave(element: Element, services: HookServices): Element;
7
- declare function afterSave(element: Element, services: HookServices): Element;
8
- declare function afterLoaded(element: Element, services: HookServices, runtime: ServerRuntime): Element;
9
- declare function afterRetrieve(element: Element, services: HookServices, runtime: ServerRuntime): Element;
10
- declare function beforeDisplay(element: Element, context: any): any;
11
- declare function onUserInteraction(element: Element, context: any, payload: any): any;
7
+ declare function beforeSave(element: Element, _services: HookServices): Element;
8
+ declare function afterSave(element: Element, _services: HookServices): Element;
9
+ declare function afterLoaded(element: Element, _services: HookServices, _runtime: ServerRuntime): Element;
10
+ declare function afterRetrieve(element: Element, _services: HookServices, _runtime: ServerRuntime): Element;
11
+ declare function beforeDisplay(_element: Element, context: any): any;
12
+ declare function onUserInteraction(_element: Element, context: any, payload: any): any;
12
13
  declare const hookMap: Map<string, typeof beforeSave | typeof afterSave | typeof afterLoaded | typeof afterRetrieve | typeof onUserInteraction | typeof beforeDisplay>;
13
14
  declare const _default: {
14
15
  type: string;
@@ -20,6 +21,24 @@ declare const _default: {
20
21
  afterRetrieve: typeof afterRetrieve;
21
22
  onUserInteraction: typeof onUserInteraction;
22
23
  beforeDisplay: typeof beforeDisplay;
24
+ ai: {
25
+ Schema: _tailor_cms_cek_common.OpenAISchema;
26
+ getPrompt: () => string;
27
+ processResponse: (val: any) => {
28
+ title: any;
29
+ embeds: {
30
+ [x: string]: {
31
+ id: string;
32
+ data: {
33
+ content: any;
34
+ };
35
+ embedded: boolean;
36
+ position: number;
37
+ type: string;
38
+ };
39
+ };
40
+ };
41
+ };
23
42
  };
24
43
 
25
44
  export { afterLoaded, afterRetrieve, afterSave, beforeDisplay, beforeSave, _default as default, hookMap, onUserInteraction };
package/dist/index.js CHANGED
@@ -1,29 +1,122 @@
1
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
2
+ var byteToHex = [];
3
+ for (let i = 0; i < 256; ++i) {
4
+ byteToHex.push((i + 256).toString(16).slice(1));
5
+ }
6
+ function unsafeStringify(arr, offset = 0) {
7
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
8
+ }
9
+
10
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
11
+ import { randomFillSync } from "crypto";
12
+ var rnds8Pool = new Uint8Array(256);
13
+ var poolPtr = rnds8Pool.length;
14
+ function rng() {
15
+ if (poolPtr > rnds8Pool.length - 16) {
16
+ randomFillSync(rnds8Pool);
17
+ poolPtr = 0;
18
+ }
19
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
20
+ }
21
+
22
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
23
+ import { randomUUID } from "crypto";
24
+ var native_default = { randomUUID };
25
+
26
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
27
+ function v4(options, buf, offset) {
28
+ var _a;
29
+ if (native_default.randomUUID && !buf && !options) {
30
+ return native_default.randomUUID();
31
+ }
32
+ options = options || {};
33
+ const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
34
+ if (rnds.length < 16) {
35
+ throw new Error("Random bytes length must be >= 16");
36
+ }
37
+ rnds[6] = rnds[6] & 15 | 64;
38
+ rnds[8] = rnds[8] & 63 | 128;
39
+ if (buf) {
40
+ offset = offset || 0;
41
+ if (offset < 0 || offset + 16 > buf.length) {
42
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
43
+ }
44
+ for (let i = 0; i < 16; ++i) {
45
+ buf[offset + i] = rnds[i];
46
+ }
47
+ return buf;
48
+ }
49
+ return unsafeStringify(rnds);
50
+ }
51
+ var v4_default = v4;
52
+
1
53
  // ../manifest/dist/index.js
2
54
  var type = "MODAL";
3
55
  var initState = () => ({
4
56
  title: null,
5
57
  embeds: {}
6
58
  });
59
+ var ai = {
60
+ Schema: {
61
+ type: "json_schema",
62
+ name: "ce_modal",
63
+ schema: {
64
+ type: "object",
65
+ properties: {
66
+ title: { type: "string" },
67
+ content: { type: "string" }
68
+ },
69
+ required: ["title", "content"],
70
+ additionalProperties: false
71
+ }
72
+ },
73
+ getPrompt: () => `
74
+ Generate a modal content element as an object with the following
75
+ properties:
76
+ {
77
+ "title": "",
78
+ "content": "",
79
+ }
80
+ where:
81
+ - 'title' is the title of the modal. Do not use more than 3 words.
82
+ - 'content' is the text to be displayed in the modal. Create few
83
+ paragraphs about the topic.
84
+ `,
85
+ processResponse: (val) => {
86
+ const embedId = v4_default();
87
+ const embed = {
88
+ id: embedId,
89
+ data: { content: val.content },
90
+ embedded: true,
91
+ position: 1,
92
+ type: "TIPTAP_HTML"
93
+ };
94
+ return {
95
+ title: val.title,
96
+ embeds: { [embedId]: embed }
97
+ };
98
+ }
99
+ };
7
100
 
8
101
  // src/index.ts
9
102
  var IS_CEK = process.env.CEK_RUNTIME;
10
103
  var USER_STATE = {};
11
- function beforeSave(element, services) {
104
+ function beforeSave(element, _services) {
12
105
  return element;
13
106
  }
14
- function afterSave(element, services) {
107
+ function afterSave(element, _services) {
15
108
  return element;
16
109
  }
17
- function afterLoaded(element, services, runtime) {
110
+ function afterLoaded(element, _services, _runtime) {
18
111
  return element;
19
112
  }
20
- function afterRetrieve(element, services, runtime) {
113
+ function afterRetrieve(element, _services, _runtime) {
21
114
  return element;
22
115
  }
23
- function beforeDisplay(element, context) {
116
+ function beforeDisplay(_element, context) {
24
117
  return { ...context, ...USER_STATE };
25
118
  }
26
- function onUserInteraction(element, context, payload) {
119
+ function onUserInteraction(_element, context, payload) {
27
120
  if (IS_CEK) {
28
121
  USER_STATE.interactionTimestamp = (/* @__PURE__ */ new Date()).getTime();
29
122
  context.contextTimestamp = USER_STATE.interactionTimestamp;
@@ -41,7 +134,7 @@ var hookMap = new Map(
41
134
  beforeDisplay
42
135
  })
43
136
  );
44
- var src_default = {
137
+ var index_default = {
45
138
  type,
46
139
  hookMap,
47
140
  initState,
@@ -50,15 +143,17 @@ var src_default = {
50
143
  afterLoaded,
51
144
  afterRetrieve,
52
145
  onUserInteraction,
53
- beforeDisplay
146
+ beforeDisplay,
147
+ ai
54
148
  };
55
149
  export {
56
150
  afterLoaded,
57
151
  afterRetrieve,
58
152
  afterSave,
153
+ ai,
59
154
  beforeDisplay,
60
155
  beforeSave,
61
- src_default as default,
156
+ index_default as default,
62
157
  hookMap,
63
158
  initState,
64
159
  onUserInteraction,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Tailor CMS modal server component",
4
4
  "author": "Studion <info@gostudion.com> (https://github.com/tailor-cms)",
5
5
  "type": "module",
6
- "version": "0.0.2",
6
+ "version": "0.1.0",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/index.js",
@@ -16,11 +16,11 @@
16
16
  "dist"
17
17
  ],
18
18
  "devDependencies": {
19
- "@tailor-cms/cek-common": "^0.0.3",
20
- "@tailor-cms/eslint-config": "0.0.2",
21
- "tsup": "^7.2.0",
22
- "typescript": "^5.1.6",
23
- "@tailor-cms/ce-modal-manifest": "0.0.2"
19
+ "@tailor-cms/cek-common": "^1.3.2",
20
+ "@tailor-cms/eslint-config": "1.1.2",
21
+ "tsup": "^8.5.0",
22
+ "typescript": "^5.8.3",
23
+ "@tailor-cms/ce-modal-manifest": "0.1.0"
24
24
  },
25
25
  "tsup": {
26
26
  "entry": [
@@ -44,8 +44,11 @@
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "tsup --watch src --watch ../manifest/dist",
47
- "build": "tsup",
48
- "lint": "eslint --ext .js,.ts .",
49
- "lint:fix": "pnpm lint --fix"
47
+ "build": "pnpm nuke:dist && tsup",
48
+ "lint": "eslint .",
49
+ "lint:fix": "pnpm lint --fix",
50
+ "nuke": "pnpm dlx del-cli dist node_modules",
51
+ "nuke:dist": "pnpm dlx del-cli dist",
52
+ "prepublish": "pnpm build"
50
53
  }
51
54
  }