@tailor-cms/ce-accordion-server 0.0.16 → 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
@@ -22,6 +22,7 @@ __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
28
  default: () => index_default,
@@ -32,7 +33,7 @@ __export(index_exports, {
32
33
  });
33
34
  module.exports = __toCommonJS(index_exports);
34
35
 
35
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/stringify.js
36
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
36
37
  var byteToHex = [];
37
38
  for (let i = 0; i < 256; ++i) {
38
39
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -41,7 +42,7 @@ function unsafeStringify(arr, offset = 0) {
41
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();
42
43
  }
43
44
 
44
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/rng.js
45
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
45
46
  var import_crypto = require("crypto");
46
47
  var rnds8Pool = new Uint8Array(256);
47
48
  var poolPtr = rnds8Pool.length;
@@ -53,11 +54,11 @@ function rng() {
53
54
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
54
55
  }
55
56
 
56
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/native.js
57
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
57
58
  var import_crypto2 = require("crypto");
58
59
  var native_default = { randomUUID: import_crypto2.randomUUID };
59
60
 
60
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/v4.js
61
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
61
62
  function v4(options, buf, offset) {
62
63
  var _a;
63
64
  if (native_default.randomUUID && !buf && !options) {
@@ -85,39 +86,113 @@ function v4(options, buf, offset) {
85
86
  var v4_default = v4;
86
87
 
87
88
  // ../manifest/dist/index.js
88
- var id = v4_default();
89
+ var id1 = v4_default();
90
+ var id2 = v4_default();
89
91
  var type = "ACCORDION";
90
92
  var initState = () => ({
91
93
  embeds: {},
92
94
  items: {
93
- [id]: {
94
- id,
95
+ [id1]: {
96
+ id: id1,
97
+ header: "Accordion Item Title",
98
+ body: {},
99
+ position: 1
100
+ },
101
+ [id2]: {
102
+ id: id2,
95
103
  header: "Accordion Item Title",
96
104
  body: {},
97
105
  position: 1
98
106
  }
99
107
  }
100
108
  });
109
+ var ai = {
110
+ Schema: {
111
+ type: "json_schema",
112
+ name: "ce_accordion",
113
+ schema: {
114
+ type: "object",
115
+ properties: {
116
+ items: {
117
+ type: "array",
118
+ minItems: 2,
119
+ items: {
120
+ type: "object",
121
+ properties: {
122
+ header: { type: "string" },
123
+ content: { type: "string" }
124
+ },
125
+ required: ["header", "content"],
126
+ additionalProperties: false
127
+ }
128
+ }
129
+ },
130
+ required: ["items"],
131
+ additionalProperties: false
132
+ }
133
+ },
134
+ getPrompt: () => `
135
+ Generate a accordion content element as an object with the following
136
+ properties:
137
+ {
138
+ "items": [
139
+ {
140
+ "header": "",
141
+ "content": ""
142
+ }
143
+ ]
144
+ }
145
+ where:
146
+ - 'items' is an array of accordion item objects where:
147
+ - 'header' is the title of the accordion item.
148
+ - 'content' is the text to be displayed in the accordion item.
149
+ The content should be relevant to the topic of the accordion and
150
+ have a few paragraphs about the topic.
151
+ `,
152
+ processResponse: (val) => {
153
+ return val.items.reduce(
154
+ (acc, { header, content }, index) => {
155
+ const embedId = v4_default();
156
+ const itemId = v4_default();
157
+ acc.embeds[embedId] = {
158
+ id: embedId,
159
+ data: { content },
160
+ embedded: true,
161
+ position: 1,
162
+ type: "TIPTAP_HTML"
163
+ };
164
+ acc.items[itemId] = {
165
+ id: itemId,
166
+ body: { [embedId]: true },
167
+ header,
168
+ position: index + 1
169
+ };
170
+ return acc;
171
+ },
172
+ { items: {}, embeds: {} }
173
+ );
174
+ }
175
+ };
101
176
 
102
177
  // src/index.ts
103
178
  var IS_CEK = process.env.CEK_RUNTIME;
104
179
  var USER_STATE = {};
105
- function beforeSave(element, services) {
180
+ function beforeSave(element, _services) {
106
181
  return element;
107
182
  }
108
- function afterSave(element, services) {
183
+ function afterSave(element, _services) {
109
184
  return element;
110
185
  }
111
- function afterLoaded(element, services, runtime) {
186
+ function afterLoaded(element, _services, _runtime) {
112
187
  return element;
113
188
  }
114
- function afterRetrieve(element, services, runtime) {
189
+ function afterRetrieve(element, _services, _runtime) {
115
190
  return element;
116
191
  }
117
- function beforeDisplay(element, context) {
192
+ function beforeDisplay(_element, context) {
118
193
  return { ...context, ...USER_STATE };
119
194
  }
120
- function onUserInteraction(element, context, payload) {
195
+ function onUserInteraction(_element, context, payload) {
121
196
  if (IS_CEK) {
122
197
  USER_STATE.interactionTimestamp = (/* @__PURE__ */ new Date()).getTime();
123
198
  context.contextTimestamp = USER_STATE.interactionTimestamp;
@@ -144,13 +219,15 @@ var index_default = {
144
219
  afterLoaded,
145
220
  afterRetrieve,
146
221
  onUserInteraction,
147
- beforeDisplay
222
+ beforeDisplay,
223
+ ai
148
224
  };
149
225
  // Annotate the CommonJS export names for ESM import in node:
150
226
  0 && (module.exports = {
151
227
  afterLoaded,
152
228
  afterRetrieve,
153
229
  afterSave,
230
+ ai,
154
231
  beforeDisplay,
155
232
  beforeSave,
156
233
  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_accordion_manifest from '@tailor-cms/ce-accordion-manifest';
2
4
  import { Element } from '@tailor-cms/ce-accordion-manifest';
3
- export { initState, type } from '@tailor-cms/ce-accordion-manifest';
4
- import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
5
+ export { ai, initState, type } from '@tailor-cms/ce-accordion-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,11 @@ 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) => any;
28
+ };
23
29
  };
24
30
 
25
31
  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_accordion_manifest from '@tailor-cms/ce-accordion-manifest';
2
4
  import { Element } from '@tailor-cms/ce-accordion-manifest';
3
- export { initState, type } from '@tailor-cms/ce-accordion-manifest';
4
- import { HookServices, ServerRuntime } from '@tailor-cms/cek-common';
5
+ export { ai, initState, type } from '@tailor-cms/ce-accordion-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,11 @@ 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) => any;
28
+ };
23
29
  };
24
30
 
25
31
  export { afterLoaded, afterRetrieve, afterSave, beforeDisplay, beforeSave, _default as default, hookMap, onUserInteraction };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/stringify.js
1
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
2
2
  var byteToHex = [];
3
3
  for (let i = 0; i < 256; ++i) {
4
4
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -7,7 +7,7 @@ function unsafeStringify(arr, offset = 0) {
7
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
8
  }
9
9
 
10
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/rng.js
10
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
11
11
  import { randomFillSync } from "crypto";
12
12
  var rnds8Pool = new Uint8Array(256);
13
13
  var poolPtr = rnds8Pool.length;
@@ -19,11 +19,11 @@ function rng() {
19
19
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
20
20
  }
21
21
 
22
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/native.js
22
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
23
23
  import { randomUUID } from "crypto";
24
24
  var native_default = { randomUUID };
25
25
 
26
- // ../../node_modules/.pnpm/uuid@11.0.5/node_modules/uuid/dist/esm/v4.js
26
+ // ../../node_modules/.pnpm/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
27
27
  function v4(options, buf, offset) {
28
28
  var _a;
29
29
  if (native_default.randomUUID && !buf && !options) {
@@ -51,39 +51,113 @@ function v4(options, buf, offset) {
51
51
  var v4_default = v4;
52
52
 
53
53
  // ../manifest/dist/index.js
54
- var id = v4_default();
54
+ var id1 = v4_default();
55
+ var id2 = v4_default();
55
56
  var type = "ACCORDION";
56
57
  var initState = () => ({
57
58
  embeds: {},
58
59
  items: {
59
- [id]: {
60
- id,
60
+ [id1]: {
61
+ id: id1,
62
+ header: "Accordion Item Title",
63
+ body: {},
64
+ position: 1
65
+ },
66
+ [id2]: {
67
+ id: id2,
61
68
  header: "Accordion Item Title",
62
69
  body: {},
63
70
  position: 1
64
71
  }
65
72
  }
66
73
  });
74
+ var ai = {
75
+ Schema: {
76
+ type: "json_schema",
77
+ name: "ce_accordion",
78
+ schema: {
79
+ type: "object",
80
+ properties: {
81
+ items: {
82
+ type: "array",
83
+ minItems: 2,
84
+ items: {
85
+ type: "object",
86
+ properties: {
87
+ header: { type: "string" },
88
+ content: { type: "string" }
89
+ },
90
+ required: ["header", "content"],
91
+ additionalProperties: false
92
+ }
93
+ }
94
+ },
95
+ required: ["items"],
96
+ additionalProperties: false
97
+ }
98
+ },
99
+ getPrompt: () => `
100
+ Generate a accordion content element as an object with the following
101
+ properties:
102
+ {
103
+ "items": [
104
+ {
105
+ "header": "",
106
+ "content": ""
107
+ }
108
+ ]
109
+ }
110
+ where:
111
+ - 'items' is an array of accordion item objects where:
112
+ - 'header' is the title of the accordion item.
113
+ - 'content' is the text to be displayed in the accordion item.
114
+ The content should be relevant to the topic of the accordion and
115
+ have a few paragraphs about the topic.
116
+ `,
117
+ processResponse: (val) => {
118
+ return val.items.reduce(
119
+ (acc, { header, content }, index) => {
120
+ const embedId = v4_default();
121
+ const itemId = v4_default();
122
+ acc.embeds[embedId] = {
123
+ id: embedId,
124
+ data: { content },
125
+ embedded: true,
126
+ position: 1,
127
+ type: "TIPTAP_HTML"
128
+ };
129
+ acc.items[itemId] = {
130
+ id: itemId,
131
+ body: { [embedId]: true },
132
+ header,
133
+ position: index + 1
134
+ };
135
+ return acc;
136
+ },
137
+ { items: {}, embeds: {} }
138
+ );
139
+ }
140
+ };
67
141
 
68
142
  // src/index.ts
69
143
  var IS_CEK = process.env.CEK_RUNTIME;
70
144
  var USER_STATE = {};
71
- function beforeSave(element, services) {
145
+ function beforeSave(element, _services) {
72
146
  return element;
73
147
  }
74
- function afterSave(element, services) {
148
+ function afterSave(element, _services) {
75
149
  return element;
76
150
  }
77
- function afterLoaded(element, services, runtime) {
151
+ function afterLoaded(element, _services, _runtime) {
78
152
  return element;
79
153
  }
80
- function afterRetrieve(element, services, runtime) {
154
+ function afterRetrieve(element, _services, _runtime) {
81
155
  return element;
82
156
  }
83
- function beforeDisplay(element, context) {
157
+ function beforeDisplay(_element, context) {
84
158
  return { ...context, ...USER_STATE };
85
159
  }
86
- function onUserInteraction(element, context, payload) {
160
+ function onUserInteraction(_element, context, payload) {
87
161
  if (IS_CEK) {
88
162
  USER_STATE.interactionTimestamp = (/* @__PURE__ */ new Date()).getTime();
89
163
  context.contextTimestamp = USER_STATE.interactionTimestamp;
@@ -110,12 +184,14 @@ var index_default = {
110
184
  afterLoaded,
111
185
  afterRetrieve,
112
186
  onUserInteraction,
113
- beforeDisplay
187
+ beforeDisplay,
188
+ ai
114
189
  };
115
190
  export {
116
191
  afterLoaded,
117
192
  afterRetrieve,
118
193
  afterSave,
194
+ ai,
119
195
  beforeDisplay,
120
196
  beforeSave,
121
197
  index_default as default,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Tailor CMS accordion element",
4
4
  "author": "Studion <info@gostudion.com> (https://github.com/tailor-cms)",
5
5
  "type": "module",
6
- "version": "0.0.16",
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.4",
20
- "@tailor-cms/eslint-config": "0.0.2",
21
- "tsup": "^8.3.6",
22
- "typescript": "^5.7.3",
23
- "@tailor-cms/ce-accordion-manifest": "0.0.16"
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-accordion-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
  }