@sitevision/api 2025.1.1 → 2025.2.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.
@@ -57,6 +57,7 @@ export interface Response {
57
57
  redirect(path: string, query?: string, status?: number): void;
58
58
  cookie(cookie: Cookie): void;
59
59
  clearCookie(name: string, path?: string): void;
60
+ flush(): void;
60
61
 
61
62
  /**
62
63
  * This method will render a component with data
package/index.d.ts CHANGED
@@ -132,6 +132,7 @@ import './server/WebContentUtil';
132
132
  import './server/WebResourceFactory';
133
133
  import './server/XSLTUtil';
134
134
  import './server/XmlParserUtil';
135
+ import './server/ai';
135
136
  import './server/appData';
136
137
  import './server/appInfo';
137
138
  import './server/appResource';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitevision/api",
3
- "version": "2025.1.1",
3
+ "version": "2025.2.1",
4
4
  "author": "Sitevision AB",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,5 +30,5 @@
30
30
  "access": "public",
31
31
  "directory": "dist"
32
32
  },
33
- "gitHead": "fef445686db4d5d6ccf41b93179735c9604c05f8"
33
+ "gitHead": "279e1e34f8224c63489e1ad18b19fce9659e0cf1"
34
34
  }
@@ -244,7 +244,7 @@ export interface ArticleUtil extends ArticleUtilConstants {
244
244
  * </ul>
245
245
  *
246
246
  * <p>The article content is specified using the
247
- * content map containing keys corresponding to layout names (e.g. "mittenspalt") on the articel and values containing the
247
+ * content map containing keys corresponding to layout names (e.g. "Huvudinnehåll") on the article and values containing the
248
248
  * HTML used to generate a portlet structure in the layout. The provided content is converted to
249
249
  * Sitevision text, table and image modules. It is also possible to specify that a horizontal or a vertical
250
250
  * layout should be created. For more information about the HTML to portlet mapping can be found in the
@@ -235,6 +235,46 @@ export interface MimeTypeUtil extends MimeTypeUtilConstants {
235
235
  * @since Sitevision 2024.04.1
236
236
  */
237
237
  isAudioType(aFileExtensionExpression: String | string): boolean;
238
+
239
+ /**
240
+ * Checks if a specified file extension is a JSON type (according to its mapped MIME type).
241
+ * @param aFileExtensionExpression a file extension (e.g "json") or an expression that ends with a period and a file extension&#xA; (e.g "myfile.json" or "https://www.xyz.com/files/myfile.json"). Case insensitive.
242
+ * @return true if aFileExtensionExpression is mapped to a MIME type that depicts the JSON format, false otherwise
243
+ * @see #isJsonMime(String)
244
+ * @since Sitevision 2025.01.2
245
+ */
246
+ isJsonType(aFileExtensionExpression: String | string): boolean;
247
+
248
+ /**
249
+ * Checks if a specified MIME type depicts the JSON format.
250
+ *
251
+ * <p>
252
+ * The primary JSON format MIME is <code>"application/json"</code> and should always be handled as UTF-8 text. Other MIME:s that uses the JSON
253
+ * format typically has a <code>"+json"</code> suffix (see <a href="https://www.rfc-editor.org/rfc/rfc6839#section-3.1">RFC 6839</a>)
254
+ * or a <code>"+json-seq"</code> suffix (see <a href="https://www.rfc-editor.org/rfc/rfc8091#section-3">RFC 8091</a>). But there
255
+ * are also some legacy/unofficial MIME:s that also depicts the JSON format (e.g. "text/json", "application/jsonrequest").
256
+ * Example of typical MIME types that depicts the JSON format:
257
+ * </p>
258
+ * <ul>
259
+ * <li>application/json</li>
260
+ * <li>application/vnd.api+json</li>
261
+ * <li>application/vnd.restful+json</li>
262
+ * <li>application/ld+json</li>
263
+ * <li>application/ld-frame+json</li>
264
+ * <li>application/jsonml+json</li>
265
+ * <li>application/geo+json</li>
266
+ * <li>application/calendar+json</li>
267
+ * </ul>
268
+ *
269
+ * <p>
270
+ * A <code>Content-Type</code> header value for a JSON response is typically <code>"application/json; charset=utf-8"</code>.
271
+ * This method handles such values, only the leading MIME part will be checked (any semicolon suffix part will be completely ignored).
272
+ * </p>
273
+ * @param aMimeType a MIME value or Content-Type header value
274
+ * @return true if aMimeType matches a MIME that depicts the JSON format, false otherwise
275
+ * @since Sitevision 2025.01.2
276
+ */
277
+ isJsonMime(aMimeType: String | string): boolean;
238
278
  }
239
279
 
240
280
  declare namespace MimeTypeUtil {}
@@ -17,5 +17,7 @@ var _default = exports["default"] = {
17
17
  isMSPowerpointType: function isMSPowerpointType() {},
18
18
  isMSOfficeType: function isMSOfficeType() {},
19
19
  isFontType: function isFontType() {},
20
- isAudioType: function isAudioType() {}
20
+ isAudioType: function isAudioType() {},
21
+ isJsonType: function isJsonType() {},
22
+ isJsonMime: function isJsonMime() {}
21
23
  };
@@ -276,6 +276,21 @@ export interface OutputUtil extends OutputUtilConstants {
276
276
  */
277
277
  getNodeAsText(aNode: Node): string;
278
278
 
279
+ /**
280
+ * Gets the output as a specific content-type from a page node.
281
+ *
282
+ * <p>
283
+ * <strong>Note! Due to security reasons (potential never-ending loops) it is prohibited to get the output of
284
+ * the currently executing page (i.e. {@link senselogic.sitevision.api.context.PortletContextUtil#getCurrentPage()})!</strong>
285
+ * </p>
286
+ * @param aPageNode a page node (sv:page, sv:article, sv:sitePage) where current user has READ permission, must not be null or "current page".
287
+ * @param aContentType a content-type marker, i.e. {@link #CONTENT_TYPE_TEXT_PLAIN}, {@link #CONTENT_TYPE_TEXT_HTML} or&#xA; {@link #CONTENT_TYPE_TEXT_XML}
288
+ * @return the output result for specified aContentType.&#xA; If aPageNode is null or "current page", an empty String is returned.&#xA; If current user doesn't have READ permission on aPageNode, an empty String is returned.
289
+ * @see #getNodeOutput(Node, Node, int)
290
+ * @since Sitevision 2025.01.2
291
+ */
292
+ getNodeOutput(aPageNode: Node, aContentType: number): string;
293
+
279
294
  /**
280
295
  * Gets the output as a specific content-type from a page node or a page content node.
281
296
  *
@@ -289,7 +304,7 @@ export interface OutputUtil extends OutputUtilConstants {
289
304
  * </p>
290
305
  * @param aPageNode a page node (sv:page, sv:article, sv:sitePage) where current user has READ permission, must not be null or "current page".
291
306
  * @param aPagePartNode a page part node that exist as content on aPageNode (or null if you want the complete output from aPageNode).
292
- * @param aContentType a content-type marker, i.e.&#xA; <a href="#CONTENT_TYPE_TEXT_PLAIN">CONTENT_TYPE_TEXT_PLAIN</a>,&#xA; <a href="#CONTENT_TYPE_TEXT_HTML">CONTENT_TYPE_TEXT_HTML</a> or&#xA; <a href="#CONTENT_TYPE_TEXT_XML">CONTENT_TYPE_TEXT_XML</a>.
307
+ * @param aContentType a content-type marker, i.e. {@link #CONTENT_TYPE_TEXT_PLAIN}, {@link #CONTENT_TYPE_TEXT_HTML} or&#xA; {@link #CONTENT_TYPE_TEXT_XML}
293
308
  * @return the output result for specified aContentType.&#xA; If aPageNode is null or "current page", an empty String is returned.&#xA; If current user doesn't have READ permission on aPageNode, an empty String is returned.&#xA; If aPagePartNode is null, the output result of aPageNode is returned.&#xA; If aPagePartNode doesn't exist as content on aPageNode, an empty String is returned.
294
309
  * @since Sitevision 2.6
295
310
  */
@@ -306,7 +321,7 @@ export interface OutputUtil extends OutputUtilConstants {
306
321
  * <em>
307
322
  * <strong>Note!</strong> This method is intended for debugging purposes during development ONLY!
308
323
  * Important: Only the types and properties that are officially specified on the
309
- * <a href="http://help.sitevision.se/nodetypes">Sitevision developer web</a>
324
+ * <a href="https://developer.sitevision.se/nodetypes">Sitevision developer web</a>
310
325
  * can be relied upon and used in production. All other types and properties should
311
326
  * be considered volatile. Output produced by this method is not indexed by the Sitevision indexer.
312
327
  * </em>
@@ -328,7 +343,7 @@ export interface OutputUtil extends OutputUtilConstants {
328
343
  * <em>
329
344
  * <strong>Note!</strong> This method is intended for debugging purposes during development ONLY!
330
345
  * Important: Only the types and properties that are officially specified on the
331
- * <a href="http://help.sitevision.se/nodetypes">Sitevision developer web</a>
346
+ * <a href="https://developer.sitevision.se/nodetypes">Sitevision developer web</a>
332
347
  * can be relied upon and used in production. All other types and properties should
333
348
  * be considered volatile. Output produced by this method is not indexed by the Sitevision indexer.
334
349
  * </em>
@@ -237,7 +237,7 @@ export interface PageUtil extends PageUtilConstants {
237
237
  * </ul>
238
238
  *
239
239
  * <p>The page content is specified using the
240
- * content map containing keys corresponding to layout names (e.g. "mittenspalt") on the page and values containing the
240
+ * content map containing keys corresponding to layout names (e.g. "Huvudinnehåll") on the page and values containing the
241
241
  * HTML used to generate a portlet structure in the layout. The provided content is converted to
242
242
  * Sitevision text, table and image modules. It is also possible to specify that a horizontal or a vertical
243
243
  * layout should be created. For more information about the HTML to portlet mapping can be found in the
@@ -225,7 +225,7 @@ export interface WebContentUtil {
225
225
  *
226
226
  * <p>
227
227
  * If an invalid node type is specified a <code>IllegalArgumentException</code> is thrown. The page content is specified using the
228
- * content map containing keys corresponding to layout names (e.g. "mittenspalt") on the page and values containing the
228
+ * content map containing keys corresponding to layout names (e.g. "Huvudinnehåll") on the page and values containing the
229
229
  * HTML used to generate a portlet structure in the layout. The provided content is converted to
230
230
  * Sitevision text, table and image modules. It is also possible to specify that a horizontal or a vertical
231
231
  * layout should be created.
@@ -349,7 +349,7 @@ export interface WebContentUtil {
349
349
  *
350
350
  * <p>
351
351
  * If an invalid node type is specified a <code>IllegalArgumentException</code> is thrown. The page content is specified using the
352
- * content map containing keys corresponding to layout names (e.g. "mittenspalt") on the page and values containing the
352
+ * content map containing keys corresponding to layout names (e.g. "Huvudinnehåll") on the page and values containing the
353
353
  * HTML used to generate a portlet structure in the layout. The provided content is converted to
354
354
  * Sitevision text, table and image modules. It is also possible to specify that a horizontal or a vertical
355
355
  * layout should be created.
@@ -494,7 +494,7 @@ export interface WebContentUtil {
494
494
  * <em>This method is typically called to clear all content before adding new content via {@link #updateContent(Node, Map)}</em>
495
495
  * </p>
496
496
  * @param aPageNode the node that will be altered, typically a node with primary node type sv:page or sv:article.&#xA; May not be null and may not be the site page
497
- * @param aRootLayoutName the name of the root layout of aPageNode to remove content from (e.g. "Mittenspalt")
497
+ * @param aRootLayoutName the name of the root layout of aPageNode to remove content from (e.g. "Huvudinnehåll")
498
498
  * @throws NullPointerException if aPageNode or aRootLayoutName is null
499
499
  * @throws IllegalArgumentException if aPageNode is of invalid type or if there are no root layout named aRootLayoutName
500
500
  * @throws ConstraintViolationException if current user is not allowed to alter aPageNode
@@ -0,0 +1,211 @@
1
+ import type { Node } from '../../types/javax/jcr/Node';
2
+
3
+ /**
4
+ * Represents a message in an AI conversation.
5
+ */
6
+ export interface Message {
7
+ /**
8
+ * The role of the entity generating the message.
9
+ * - `system`: Provides context or instructions.
10
+ * - `user`: Represents the end user.
11
+ * - `assistant`: Represents the AI model.
12
+ */
13
+ role: 'system' | 'user' | 'assistant';
14
+
15
+ /**
16
+ * The actual content of the message.
17
+ */
18
+ content: string;
19
+ }
20
+
21
+ /**
22
+ * Options for generating text using an AI model.
23
+ */
24
+ export interface GenerateTextOptions {
25
+ /**
26
+ * Messages that form the conversation context.
27
+ */
28
+ messages: Message[];
29
+
30
+ /**
31
+ * Maximum duration (in milliseconds) before timing out.
32
+ * The default value and valid range are environment-dependent and can be
33
+ * configured via a system property. If not explicitly set, the system
34
+ * determines an appropriate timeout value.
35
+ */
36
+ timeout?: number;
37
+
38
+ /**
39
+ * The maximum number of tokens (words/word fragments) the model can generate.
40
+ */
41
+ maxTokens?: number;
42
+
43
+ /**
44
+ * Controls response randomness:
45
+ * - Lower values (e.g., 0) make responses deterministic.
46
+ * - Higher values (e.g., 1) increase variability.
47
+ */
48
+ temperature?: number;
49
+
50
+ /**
51
+ * Reduces repeated token usage in generated text.
52
+ * Higher values promote more diverse output.
53
+ */
54
+ frequencyPenalty?: number;
55
+ }
56
+
57
+ /**
58
+ * Result object for text generation.
59
+ */
60
+ export interface GenerateTextResult {
61
+ /**
62
+ * The generated text output from the AI model.
63
+ */
64
+ text: string;
65
+
66
+ /**
67
+ * Contains an error message if something went wrong, otherwise an empty string.
68
+ */
69
+ error: string;
70
+
71
+ /**
72
+ * The reason why the generation process stopped.
73
+ * Possible values:
74
+ * - `stop`: Completed successfully.
75
+ * - `length`: Stopped due to reaching max tokens.
76
+ * - `error`: Failed unexpectedly.
77
+ * - `other`: Other reasons (model/system behavior).
78
+ */
79
+ finishReason: string;
80
+
81
+ /**
82
+ * (Optional) Token usage statistics for this request.
83
+ */
84
+ usage?: {
85
+ promptTokens: number;
86
+ completionTokens: number;
87
+ totalTokens: number;
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Options for streaming text from an AI model.
93
+ */
94
+ export interface StreamTextOptions {
95
+ /**
96
+ * Messages that form the conversation context.
97
+ */
98
+ messages: Message[];
99
+
100
+ /**
101
+ * Maximum duration (in milliseconds) before timing out.
102
+ * The default value and valid range are environment-dependent and can be
103
+ * configured via a system property. If not explicitly set, the system
104
+ * determines an appropriate timeout value.
105
+ */
106
+ timeout?: number;
107
+
108
+ /**
109
+ * The maximum number of tokens (words/word fragments) the model can generate.
110
+ */
111
+ maxTokens?: number;
112
+
113
+ /**
114
+ * Controls response randomness:
115
+ * - Lower values (e.g., 0) make responses deterministic.
116
+ * - Higher values (e.g., 1) increase variability.
117
+ */
118
+ temperature?: number;
119
+
120
+ /**
121
+ * Reduces repeated token usage in generated text.
122
+ * Higher values promote more diverse output.
123
+ */
124
+ frequencyPenalty?: number;
125
+
126
+ /**
127
+ * Callback function that is triggered for each received token.
128
+ * The function receives the token as a string.
129
+ *
130
+ * @param token The streamed token received from the AI model.
131
+ */
132
+ onChunk: (token: string) => void;
133
+
134
+ /**
135
+ * Callback function triggered when the streaming operation completes.
136
+ *
137
+ * @param result The final result of the stream operation.
138
+ */
139
+ onFinish: (result: StreamFinishResult) => void;
140
+ }
141
+
142
+ /**
143
+ * Final result object for a streaming text operation.
144
+ */
145
+ export interface StreamFinishResult {
146
+ /**
147
+ * Always an empty string (for structural consistency with `GenerateTextResult`).
148
+ */
149
+ text: string;
150
+
151
+ /**
152
+ * Contains an error message if something went wrong, otherwise an empty string.
153
+ */
154
+ error: string;
155
+
156
+ /**
157
+ * The reason why the streaming process stopped.
158
+ * Possible values:
159
+ * - `stop`: Completed successfully.
160
+ * - `length`: Stopped due to reaching max tokens.
161
+ * - `error`: Failed unexpectedly.
162
+ * - `other`: Other reasons (model/system behavior).
163
+ */
164
+ finishReason: string;
165
+
166
+ /**
167
+ * (Optional) Token usage statistics for this request.
168
+ */
169
+ usage?: {
170
+ promptTokens: number;
171
+ completionTokens: number;
172
+ totalTokens: number;
173
+ };
174
+ }
175
+
176
+ /**
177
+ * AI SDK for interacting with Large Language Models (LLMs).
178
+ */
179
+ export interface AI {
180
+ /**
181
+ * Generates text based on provided messages.
182
+ *
183
+ * @param llmConfiguration The AI model configuration node.
184
+ * @param options Options for text generation.
185
+ * @returns The generated text result.
186
+ */
187
+ generateText(
188
+ llmConfiguration: Node,
189
+ options: GenerateTextOptions
190
+ ): GenerateTextResult;
191
+
192
+ /**
193
+ * Streams generated text from an AI model.
194
+ *
195
+ * This function does not return a value. Instead, it processes streamed responses
196
+ * using the provided `onChunk` and `onFinish` callback functions.
197
+ *
198
+ * @param llmConfiguration The AI model configuration node.
199
+ * @param options Options for streaming text.
200
+ */
201
+ streamText(llmConfiguration: Node, options: StreamTextOptions): void;
202
+ }
203
+
204
+ declare namespace AI {}
205
+
206
+ /**
207
+ * The AI SDK instance.
208
+ */
209
+ declare var ai: AI;
210
+
211
+ export default ai;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = exports["default"] = {
8
+ generateText: function generateText() {},
9
+ streamText: function streamText() {}
10
+ };