@dotcms/client 1.2.0-next.5 → 1.2.0-next.6
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 +12 -12
- package/index.cjs.js +11 -7
- package/index.esm.js +11 -7
- package/package.json +1 -1
- package/src/lib/client/ai/ai-api.d.ts +3 -3
package/README.md
CHANGED
|
@@ -241,17 +241,17 @@ Before using AI-powered search, ensure your dotCMS instance is properly configur
|
|
|
241
241
|
#### Basic AI Search
|
|
242
242
|
```typescript
|
|
243
243
|
// Search for content semantically related to your query
|
|
244
|
-
const
|
|
244
|
+
const response = await client.ai.search(
|
|
245
245
|
'articles about machine learning',
|
|
246
246
|
'content_index'
|
|
247
247
|
);
|
|
248
|
-
console.log(results
|
|
248
|
+
console.log(response.results);
|
|
249
249
|
```
|
|
250
250
|
|
|
251
251
|
#### Customizing Search Parameters
|
|
252
252
|
```typescript
|
|
253
253
|
// Fine-tune search with query parameters
|
|
254
|
-
const
|
|
254
|
+
const response = await client.ai.search(
|
|
255
255
|
'artificial intelligence tutorials',
|
|
256
256
|
'content_index',
|
|
257
257
|
{
|
|
@@ -270,7 +270,7 @@ const results = await client.ai.search(
|
|
|
270
270
|
import { DISTANCE_FUNCTIONS } from '@dotcms/types';
|
|
271
271
|
|
|
272
272
|
// Customize AI search behavior with threshold and distance function
|
|
273
|
-
const
|
|
273
|
+
const response = await client.ai.search(
|
|
274
274
|
'deep learning concepts',
|
|
275
275
|
'content_index',
|
|
276
276
|
{
|
|
@@ -286,7 +286,7 @@ const results = await client.ai.search(
|
|
|
286
286
|
#### Complete Example with All Options
|
|
287
287
|
```typescript
|
|
288
288
|
// Combine query and AI parameters for precise control
|
|
289
|
-
const
|
|
289
|
+
const response = await client.ai.search(
|
|
290
290
|
'best practices for content management',
|
|
291
291
|
'articles_index',
|
|
292
292
|
{
|
|
@@ -306,7 +306,7 @@ const results = await client.ai.search(
|
|
|
306
306
|
);
|
|
307
307
|
|
|
308
308
|
// Access results with match scores
|
|
309
|
-
results.
|
|
309
|
+
resp[onse].results.forEach(result => {
|
|
310
310
|
console.log(result.title);
|
|
311
311
|
console.log('Matches:', result.matches); // Distance and extracted text
|
|
312
312
|
});
|
|
@@ -416,7 +416,7 @@ interface Article extends DotCMSBasicContentlet {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
// Type-safe AI search
|
|
419
|
-
const
|
|
419
|
+
const response: DotCMSAISearchResponse<Article> = await client.ai.search<Article>(
|
|
420
420
|
'machine learning tutorials',
|
|
421
421
|
'content_index',
|
|
422
422
|
{
|
|
@@ -432,7 +432,7 @@ const results: DotCMSAISearchResponse<Article> = await client.ai.search<Article>
|
|
|
432
432
|
);
|
|
433
433
|
|
|
434
434
|
// Access typed results with match information
|
|
435
|
-
results.
|
|
435
|
+
response.results.forEach(article => {
|
|
436
436
|
console.log(article.title); // ✅ Type-safe: string
|
|
437
437
|
console.log(article.category); // ✅ Type-safe: string
|
|
438
438
|
|
|
@@ -818,7 +818,7 @@ search<T extends DotCMSBasicContentlet>(
|
|
|
818
818
|
|
|
819
819
|
```typescript
|
|
820
820
|
interface DotCMSAISearchResponse<T> {
|
|
821
|
-
|
|
821
|
+
results: Array<T & {
|
|
822
822
|
matches?: Array<{
|
|
823
823
|
distance: number; // Similarity score
|
|
824
824
|
extractedText: string; // Matched text excerpt
|
|
@@ -867,9 +867,9 @@ client.ai.search(
|
|
|
867
867
|
query: { limit: 10 },
|
|
868
868
|
config: { threshold: 0.8 }
|
|
869
869
|
}
|
|
870
|
-
).then((
|
|
871
|
-
console.log('Found:', results.
|
|
872
|
-
return
|
|
870
|
+
).then((response) => {
|
|
871
|
+
console.log('Found:', response.results.length);
|
|
872
|
+
return response;
|
|
873
873
|
}).catch((error) => {
|
|
874
874
|
console.error('Search failed:', error.message);
|
|
875
875
|
});
|
package/index.cjs.js
CHANGED
|
@@ -336,12 +336,16 @@ class AISearch extends BaseApiClient {
|
|
|
336
336
|
*/
|
|
337
337
|
then(onfulfilled, onrejected) {
|
|
338
338
|
return this.fetch().then((data) => {
|
|
339
|
+
const response = {
|
|
340
|
+
...data,
|
|
341
|
+
results: data.dotCMSResults
|
|
342
|
+
};
|
|
339
343
|
if (typeof onfulfilled === 'function') {
|
|
340
|
-
const result = onfulfilled(
|
|
341
|
-
// Ensure we always return a value, fallback to
|
|
342
|
-
return result ??
|
|
344
|
+
const result = onfulfilled(response);
|
|
345
|
+
// Ensure we always return a value, fallback to data if callback returns undefined
|
|
346
|
+
return result ?? response;
|
|
343
347
|
}
|
|
344
|
-
return
|
|
348
|
+
return response;
|
|
345
349
|
}, (error) => {
|
|
346
350
|
// Wrap error in DotCMSContentError
|
|
347
351
|
let contentError;
|
|
@@ -469,7 +473,7 @@ class AIClient extends BaseApiClient {
|
|
|
469
473
|
* @example
|
|
470
474
|
* @example
|
|
471
475
|
* ```typescript
|
|
472
|
-
* const
|
|
476
|
+
* const response = await client.ai.search('machine learning articles', 'content_index', {
|
|
473
477
|
* query: {
|
|
474
478
|
* limit: 20,
|
|
475
479
|
* contentType: 'BlogPost',
|
|
@@ -492,8 +496,8 @@ class AIClient extends BaseApiClient {
|
|
|
492
496
|
* threshold: 0.7,
|
|
493
497
|
* distanceFunction: DISTANCE_FUNCTIONS.cosine
|
|
494
498
|
* }
|
|
495
|
-
* }).then((
|
|
496
|
-
* console.log(results);
|
|
499
|
+
* }).then((response) => {
|
|
500
|
+
* console.log(response.results);
|
|
497
501
|
* }).catch((error) => {
|
|
498
502
|
* console.error(error);
|
|
499
503
|
* });
|
package/index.esm.js
CHANGED
|
@@ -334,12 +334,16 @@ class AISearch extends BaseApiClient {
|
|
|
334
334
|
*/
|
|
335
335
|
then(onfulfilled, onrejected) {
|
|
336
336
|
return this.fetch().then((data) => {
|
|
337
|
+
const response = {
|
|
338
|
+
...data,
|
|
339
|
+
results: data.dotCMSResults
|
|
340
|
+
};
|
|
337
341
|
if (typeof onfulfilled === 'function') {
|
|
338
|
-
const result = onfulfilled(
|
|
339
|
-
// Ensure we always return a value, fallback to
|
|
340
|
-
return result ??
|
|
342
|
+
const result = onfulfilled(response);
|
|
343
|
+
// Ensure we always return a value, fallback to data if callback returns undefined
|
|
344
|
+
return result ?? response;
|
|
341
345
|
}
|
|
342
|
-
return
|
|
346
|
+
return response;
|
|
343
347
|
}, (error) => {
|
|
344
348
|
// Wrap error in DotCMSContentError
|
|
345
349
|
let contentError;
|
|
@@ -467,7 +471,7 @@ class AIClient extends BaseApiClient {
|
|
|
467
471
|
* @example
|
|
468
472
|
* @example
|
|
469
473
|
* ```typescript
|
|
470
|
-
* const
|
|
474
|
+
* const response = await client.ai.search('machine learning articles', 'content_index', {
|
|
471
475
|
* query: {
|
|
472
476
|
* limit: 20,
|
|
473
477
|
* contentType: 'BlogPost',
|
|
@@ -490,8 +494,8 @@ class AIClient extends BaseApiClient {
|
|
|
490
494
|
* threshold: 0.7,
|
|
491
495
|
* distanceFunction: DISTANCE_FUNCTIONS.cosine
|
|
492
496
|
* }
|
|
493
|
-
* }).then((
|
|
494
|
-
* console.log(results);
|
|
497
|
+
* }).then((response) => {
|
|
498
|
+
* console.log(response.results);
|
|
495
499
|
* }).catch((error) => {
|
|
496
500
|
* console.error(error);
|
|
497
501
|
* });
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ export declare class AIClient extends BaseApiClient {
|
|
|
44
44
|
* @example
|
|
45
45
|
* @example
|
|
46
46
|
* ```typescript
|
|
47
|
-
* const
|
|
47
|
+
* const response = await client.ai.search('machine learning articles', 'content_index', {
|
|
48
48
|
* query: {
|
|
49
49
|
* limit: 20,
|
|
50
50
|
* contentType: 'BlogPost',
|
|
@@ -67,8 +67,8 @@ export declare class AIClient extends BaseApiClient {
|
|
|
67
67
|
* threshold: 0.7,
|
|
68
68
|
* distanceFunction: DISTANCE_FUNCTIONS.cosine
|
|
69
69
|
* }
|
|
70
|
-
* }).then((
|
|
71
|
-
* console.log(results);
|
|
70
|
+
* }).then((response) => {
|
|
71
|
+
* console.log(response.results);
|
|
72
72
|
* }).catch((error) => {
|
|
73
73
|
* console.error(error);
|
|
74
74
|
* });
|