@blocklet/search-kit-js 0.5.23 → 0.5.25

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,15 +2,14 @@
2
2
 
3
3
  const meilisearch = require('meilisearch');
4
4
  const component = require('@blocklet/sdk/lib/component');
5
- const verifySign = require('@blocklet/sdk/lib/util/verify-sign');
6
- const axios = require('axios');
5
+ const componentApi = require('@blocklet/sdk/lib/util/component-api');
7
6
  const ufo = require('ufo');
8
7
  const env = require('@blocklet/sdk/lib/env');
9
8
  const crypto = require('crypto');
10
9
 
11
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
11
 
13
- const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
12
+ const componentApi__default = /*#__PURE__*/_interopDefaultCompat(componentApi);
14
13
  const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto);
15
14
 
16
15
  const SEARCH_KIT_DID = "z8iZorY6mvb5tZrxXTqhBmwu89xjEEazrgT3t";
@@ -24,10 +23,10 @@ class SearchKitClient extends meilisearch.MeiliSearch {
24
23
  httpClient: async (url, opts) => {
25
24
  const body = typeof opts?.body === "string" ? JSON.parse(opts.body) : opts?.body ?? {};
26
25
  const headers = typeof opts?.headers === "string" ? JSON.parse(opts.headers) : opts?.headers ?? {};
27
- const response = await axios__default.request({
26
+ const response = await componentApi__default.request({
28
27
  url,
29
28
  data: body,
30
- headers: { "x-component-sig": await verifySign.sign(body), ...headers },
29
+ headers,
31
30
  method: opts?.method?.toLocaleUpperCase() ?? "GET"
32
31
  });
33
32
  return response.data;
@@ -40,17 +39,21 @@ class SearchKitClient extends meilisearch.MeiliSearch {
40
39
  const hash = (str, salt) => crypto__default.createHash("sha256").update(str + salt).digest("hex");
41
40
 
42
41
  const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
43
- const mountPoint = component.getComponentMountPoint("ai-kit");
44
- if (!mountPoint) {
45
- throw new Error("wallet.secretKey or ai-kit blocklet is not found");
42
+ const apiURL = process.env.BLOCKLET_AIGNE_API_URL || "";
43
+ if (!apiURL) {
44
+ throw new Error("AIGNE Hub not connected. Configure it in blocklet dashboard to enable embeddings.");
46
45
  }
46
+ const mountPoint = component.getComponentMountPoint("z8iZorY6mvb5tZrxXTqhBmwu89xjEEazrgT3t");
47
47
  return {
48
48
  default: {
49
49
  source: "rest",
50
50
  // Communicate via the public network to avoid URL changes caused by port changes.
51
51
  url: ufo.joinURL(env.env.appUrl, mountPoint, "/api/meilisearch/embeddings"),
52
52
  dimensions: 1536,
53
- apiKey: hash(process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK, ":/ai-kit/api/meilisearch/embeddings"),
53
+ apiKey: hash(
54
+ process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK,
55
+ ":/search-kit/api/meilisearch/embeddings"
56
+ ),
54
57
  request: { data: { text: "{{text}}" } },
55
58
  response: { data: { embedding: "{{embedding}}" } },
56
59
  distribution: { mean: 0.7, sigma: 0.3 },
@@ -61,6 +64,7 @@ const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
61
64
  };
62
65
 
63
66
  exports.SearchKitClient = SearchKitClient;
67
+ exports.hash = hash;
64
68
  exports.resolveRestEmbedders = resolveRestEmbedders;
65
69
  Object.keys(meilisearch).forEach(function (k) {
66
70
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = meilisearch[k];
package/dist/index.d.cts CHANGED
@@ -10,4 +10,6 @@ type PartialRestEmbedder = Partial<RestEmbedder> & {
10
10
  };
11
11
  declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
12
 
13
- export { SearchKitClient, resolveRestEmbedders };
13
+ declare const hash: (str: string, salt: string) => string;
14
+
15
+ export { SearchKitClient, hash, resolveRestEmbedders };
package/dist/index.d.mts CHANGED
@@ -10,4 +10,6 @@ type PartialRestEmbedder = Partial<RestEmbedder> & {
10
10
  };
11
11
  declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
12
 
13
- export { SearchKitClient, resolveRestEmbedders };
13
+ declare const hash: (str: string, salt: string) => string;
14
+
15
+ export { SearchKitClient, hash, resolveRestEmbedders };
package/dist/index.d.ts CHANGED
@@ -10,4 +10,6 @@ type PartialRestEmbedder = Partial<RestEmbedder> & {
10
10
  };
11
11
  declare const resolveRestEmbedders: ({ documentTemplate, ...rest }: PartialRestEmbedder) => Embedders;
12
12
 
13
- export { SearchKitClient, resolveRestEmbedders };
13
+ declare const hash: (str: string, salt: string) => string;
14
+
15
+ export { SearchKitClient, hash, resolveRestEmbedders };
package/dist/index.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import { MeiliSearch } from 'meilisearch';
2
2
  export * from 'meilisearch';
3
3
  import { getComponentWebEndpoint, getComponentMountPoint } from '@blocklet/sdk/lib/component';
4
- import { sign } from '@blocklet/sdk/lib/util/verify-sign';
5
- import axios from 'axios';
4
+ import componentApi from '@blocklet/sdk/lib/util/component-api';
6
5
  import { joinURL } from 'ufo';
7
6
  import { env } from '@blocklet/sdk/lib/env';
8
7
  import crypto from 'crypto';
@@ -18,10 +17,10 @@ class SearchKitClient extends MeiliSearch {
18
17
  httpClient: async (url, opts) => {
19
18
  const body = typeof opts?.body === "string" ? JSON.parse(opts.body) : opts?.body ?? {};
20
19
  const headers = typeof opts?.headers === "string" ? JSON.parse(opts.headers) : opts?.headers ?? {};
21
- const response = await axios.request({
20
+ const response = await componentApi.request({
22
21
  url,
23
22
  data: body,
24
- headers: { "x-component-sig": await sign(body), ...headers },
23
+ headers,
25
24
  method: opts?.method?.toLocaleUpperCase() ?? "GET"
26
25
  });
27
26
  return response.data;
@@ -34,17 +33,21 @@ class SearchKitClient extends MeiliSearch {
34
33
  const hash = (str, salt) => crypto.createHash("sha256").update(str + salt).digest("hex");
35
34
 
36
35
  const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
37
- const mountPoint = getComponentMountPoint("ai-kit");
38
- if (!mountPoint) {
39
- throw new Error("wallet.secretKey or ai-kit blocklet is not found");
36
+ const apiURL = process.env.BLOCKLET_AIGNE_API_URL || "";
37
+ if (!apiURL) {
38
+ throw new Error("AIGNE Hub not connected. Configure it in blocklet dashboard to enable embeddings.");
40
39
  }
40
+ const mountPoint = getComponentMountPoint("z8iZorY6mvb5tZrxXTqhBmwu89xjEEazrgT3t");
41
41
  return {
42
42
  default: {
43
43
  source: "rest",
44
44
  // Communicate via the public network to avoid URL changes caused by port changes.
45
45
  url: joinURL(env.appUrl, mountPoint, "/api/meilisearch/embeddings"),
46
46
  dimensions: 1536,
47
- apiKey: hash(process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK, ":/ai-kit/api/meilisearch/embeddings"),
47
+ apiKey: hash(
48
+ process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK,
49
+ ":/search-kit/api/meilisearch/embeddings"
50
+ ),
48
51
  request: { data: { text: "{{text}}" } },
49
52
  response: { data: { embedding: "{{embedding}}" } },
50
53
  distribution: { mean: 0.7, sigma: 0.3 },
@@ -54,4 +57,4 @@ const resolveRestEmbedders = ({ documentTemplate, ...rest }) => {
54
57
  };
55
58
  };
56
59
 
57
- export { SearchKitClient, resolveRestEmbedders };
60
+ export { SearchKitClient, hash, resolveRestEmbedders };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/search-kit-js",
3
- "version": "0.5.23",
3
+ "version": "0.5.25",
4
4
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",