@blocklet/search-kit-js 0.2.6 → 0.2.8

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
@@ -2,6 +2,17 @@
2
2
 
3
3
  const meilisearch = require('meilisearch');
4
4
  const component = require('@blocklet/sdk/lib/component');
5
+ const getWallet = require('@blocklet/sdk/lib/wallet');
6
+ const env = require('@blocklet/sdk/lib/env');
7
+ const ufo = require('ufo');
8
+ const sdk = require('@blocklet/sdk');
9
+ const crypto = require('crypto');
10
+
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
+
13
+ const getWallet__default = /*#__PURE__*/_interopDefaultCompat(getWallet);
14
+ const env__default = /*#__PURE__*/_interopDefaultCompat(env);
15
+ const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto);
5
16
 
6
17
  const SEARCH_KIT_DID = "z8iZorY6mvb5tZrxXTqhBmwu89xjEEazrgT3t";
7
18
  class SearchKitClient extends meilisearch.MeiliSearch {
@@ -13,7 +24,31 @@ class SearchKitClient extends meilisearch.MeiliSearch {
13
24
  }
14
25
  }
15
26
 
27
+ const hash = (str, salt) => crypto__default.createHash("sha256").update(str + salt).digest("hex");
28
+
29
+ const wallet = getWallet__default();
30
+ const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
31
+ const mountPoint = sdk.getComponentMountPoint("ai-kit");
32
+ if (!wallet.secretKey || !mountPoint) {
33
+ throw new Error("wallet.secretKey or ai-kit blocklet is not found");
34
+ }
35
+ return {
36
+ default: {
37
+ source: "rest",
38
+ url: ufo.joinURL(env__default.appUrl, mountPoint, "/api/meilisearch/embeddings"),
39
+ dimensions: 1536,
40
+ apiKey: hash(wallet.secretKey, ":/ai-kit/api/meilisearch/embeddings"),
41
+ request: { data: { text: "{{text}}" } },
42
+ response: { data: { embedding: "{{embedding}}" } },
43
+ distribution: { mean: 0.7, sigma: 0.3 },
44
+ documentTemplate,
45
+ ...rest
46
+ }
47
+ };
48
+ };
49
+
16
50
  exports.SearchKitClient = SearchKitClient;
51
+ exports.resolveRestEmbedders = resolveRestEmbedders;
17
52
  Object.keys(meilisearch).forEach(function (k) {
18
53
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = meilisearch[k];
19
54
  });
package/dist/index.d.cts CHANGED
@@ -1,8 +1,13 @@
1
- import { MeiliSearch, Config } from 'meilisearch';
1
+ import { MeiliSearch, Config, Embedders, RestEmbedder } from 'meilisearch';
2
2
  export * from 'meilisearch';
3
3
 
4
4
  declare class SearchKitClient extends MeiliSearch {
5
- constructor(config: Omit<Config, 'host' | 'apiKey'>);
5
+ constructor(config?: Omit<Config, 'host' | 'apiKey'>);
6
6
  }
7
7
 
8
- export { SearchKitClient };
8
+ type PartialRestEmbedder = Partial<RestEmbedder> & {
9
+ documentTemplate: string;
10
+ };
11
+ declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
+
13
+ export { SearchKitClient, resolveRestEmbedders };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,13 @@
1
- import { MeiliSearch, Config } from 'meilisearch';
1
+ import { MeiliSearch, Config, Embedders, RestEmbedder } from 'meilisearch';
2
2
  export * from 'meilisearch';
3
3
 
4
4
  declare class SearchKitClient extends MeiliSearch {
5
- constructor(config: Omit<Config, 'host' | 'apiKey'>);
5
+ constructor(config?: Omit<Config, 'host' | 'apiKey'>);
6
6
  }
7
7
 
8
- export { SearchKitClient };
8
+ type PartialRestEmbedder = Partial<RestEmbedder> & {
9
+ documentTemplate: string;
10
+ };
11
+ declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
+
13
+ export { SearchKitClient, resolveRestEmbedders };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,13 @@
1
- import { MeiliSearch, Config } from 'meilisearch';
1
+ import { MeiliSearch, Config, Embedders, RestEmbedder } from 'meilisearch';
2
2
  export * from 'meilisearch';
3
3
 
4
4
  declare class SearchKitClient extends MeiliSearch {
5
- constructor(config: Omit<Config, 'host' | 'apiKey'>);
5
+ constructor(config?: Omit<Config, 'host' | 'apiKey'>);
6
6
  }
7
7
 
8
- export { SearchKitClient };
8
+ type PartialRestEmbedder = Partial<RestEmbedder> & {
9
+ documentTemplate: string;
10
+ };
11
+ declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
+
13
+ export { SearchKitClient, resolveRestEmbedders };
package/dist/index.mjs CHANGED
@@ -1,6 +1,11 @@
1
1
  import { MeiliSearch } from 'meilisearch';
2
2
  export * from 'meilisearch';
3
3
  import { getComponentWebEndpoint } from '@blocklet/sdk/lib/component';
4
+ import getWallet from '@blocklet/sdk/lib/wallet';
5
+ import env from '@blocklet/sdk/lib/env';
6
+ import { joinURL } from 'ufo';
7
+ import { getComponentMountPoint } from '@blocklet/sdk';
8
+ import crypto from 'crypto';
4
9
 
5
10
  const SEARCH_KIT_DID = "z8iZorY6mvb5tZrxXTqhBmwu89xjEEazrgT3t";
6
11
  class SearchKitClient extends MeiliSearch {
@@ -12,4 +17,27 @@ class SearchKitClient extends MeiliSearch {
12
17
  }
13
18
  }
14
19
 
15
- export { SearchKitClient };
20
+ const hash = (str, salt) => crypto.createHash("sha256").update(str + salt).digest("hex");
21
+
22
+ const wallet = getWallet();
23
+ const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
24
+ const mountPoint = getComponentMountPoint("ai-kit");
25
+ if (!wallet.secretKey || !mountPoint) {
26
+ throw new Error("wallet.secretKey or ai-kit blocklet is not found");
27
+ }
28
+ return {
29
+ default: {
30
+ source: "rest",
31
+ url: joinURL(env.appUrl, mountPoint, "/api/meilisearch/embeddings"),
32
+ dimensions: 1536,
33
+ apiKey: hash(wallet.secretKey, ":/ai-kit/api/meilisearch/embeddings"),
34
+ request: { data: { text: "{{text}}" } },
35
+ response: { data: { embedding: "{{embedding}}" } },
36
+ distribution: { mean: 0.7, sigma: 0.3 },
37
+ documentTemplate,
38
+ ...rest
39
+ }
40
+ };
41
+ };
42
+
43
+ export { SearchKitClient, resolveRestEmbedders };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/search-kit-js",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -19,8 +19,9 @@
19
19
  "README.md"
20
20
  ],
21
21
  "dependencies": {
22
- "@blocklet/sdk": "^1.16.28",
23
- "meilisearch": "^0.41.0"
22
+ "@blocklet/sdk": "^1.16.31",
23
+ "meilisearch": "^0.42.0",
24
+ "ufo": "^1.5.4"
24
25
  },
25
26
  "scripts": {
26
27
  "build": "unbuild",