@sitevision/api 2025.1.1 → 2025.1.2
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/common/router/index.d.ts +1 -0
- package/index.d.ts +1 -0
- package/package.json +2 -2
- package/server/MimeTypeUtil/index.d.ts +40 -0
- package/server/MimeTypeUtil/index.js +3 -1
- package/server/OutputUtil/index.d.ts +16 -1
- package/server/ai/index.d.ts +211 -0
- package/server/ai/index.js +10 -0
package/common/router/index.d.ts
CHANGED
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.
|
|
3
|
+
"version": "2025.1.2",
|
|
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": "
|
|
33
|
+
"gitHead": "fad9ce2f6b699279e49c3bf5fb234b0f37605dc8"
|
|
34
34
|
}
|
|
@@ -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
 (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
 {@link #CONTENT_TYPE_TEXT_XML}
|
|
288
|
+
* @return the output result for specified aContentType.
 If aPageNode is null or "current page", an empty String is returned.
 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
|
|
307
|
+
* @param aContentType a content-type marker, i.e. {@link #CONTENT_TYPE_TEXT_PLAIN}, {@link #CONTENT_TYPE_TEXT_HTML} or
 {@link #CONTENT_TYPE_TEXT_XML}
|
|
293
308
|
* @return the output result for specified aContentType.
 If aPageNode is null or "current page", an empty String is returned.
 If current user doesn't have READ permission on aPageNode, an empty String is returned.
 If aPagePartNode is null, the output result of aPageNode is returned.
 If aPagePartNode doesn't exist as content on aPageNode, an empty String is returned.
|
|
294
309
|
* @since Sitevision 2.6
|
|
295
310
|
*/
|
|
@@ -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;
|