@dxos/plugin-search 0.8.4-main.67995b8 → 0.8.4-main.6fa680abb7

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.
Files changed (146) hide show
  1. package/README.md +0 -1
  2. package/dist/lib/browser/SearchDialog-KJL6C2OF.mjs +108 -0
  3. package/dist/lib/browser/SearchDialog-KJL6C2OF.mjs.map +7 -0
  4. package/dist/lib/browser/SearchMain-JCNONOF3.mjs +100 -0
  5. package/dist/lib/browser/SearchMain-JCNONOF3.mjs.map +7 -0
  6. package/dist/lib/browser/app-graph-builder-FHVM5QV7.mjs +78 -0
  7. package/dist/lib/browser/app-graph-builder-FHVM5QV7.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-I3633KKK.mjs +26 -0
  9. package/dist/lib/browser/chunk-I3633KKK.mjs.map +7 -0
  10. package/dist/lib/browser/chunk-NB4JZIOE.mjs +282 -0
  11. package/dist/lib/browser/chunk-NB4JZIOE.mjs.map +7 -0
  12. package/dist/lib/browser/chunk-PZ67KFRU.mjs +22 -0
  13. package/dist/lib/browser/chunk-PZ67KFRU.mjs.map +7 -0
  14. package/dist/lib/browser/index.mjs +52 -59
  15. package/dist/lib/browser/index.mjs.map +4 -4
  16. package/dist/lib/browser/meta.json +1 -1
  17. package/dist/lib/browser/operation-resolver-H4X6BNWR.mjs +26 -0
  18. package/dist/lib/browser/operation-resolver-H4X6BNWR.mjs.map +7 -0
  19. package/dist/lib/browser/react-surface-IPH2UPKO.mjs +60 -0
  20. package/dist/lib/browser/react-surface-IPH2UPKO.mjs.map +7 -0
  21. package/dist/types/src/SearchPlugin.d.ts +2 -1
  22. package/dist/types/src/SearchPlugin.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  24. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  25. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  26. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  27. package/dist/types/src/capabilities/index.d.ts +3 -3
  28. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  29. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  30. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  31. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  32. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  33. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  34. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  35. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  36. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  37. package/dist/types/src/components/index.d.ts +0 -3
  38. package/dist/types/src/components/index.d.ts.map +1 -1
  39. package/dist/types/src/constants.d.ts +2 -0
  40. package/dist/types/src/constants.d.ts.map +1 -0
  41. package/dist/types/src/{components → containers/SearchDialog}/SearchDialog.d.ts +0 -1
  42. package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
  43. package/dist/types/src/containers/SearchDialog/index.d.ts +3 -0
  44. package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
  45. package/dist/types/src/containers/SearchMain/SearchMain.d.ts +6 -0
  46. package/dist/types/src/containers/SearchMain/SearchMain.d.ts.map +1 -0
  47. package/dist/types/src/containers/SearchMain/index.d.ts +3 -0
  48. package/dist/types/src/containers/SearchMain/index.d.ts.map +1 -0
  49. package/dist/types/src/containers/index.d.ts +5 -0
  50. package/dist/types/src/containers/index.d.ts.map +1 -0
  51. package/dist/types/src/hooks/index.d.ts +1 -0
  52. package/dist/types/src/hooks/index.d.ts.map +1 -1
  53. package/dist/types/src/hooks/sync.d.ts +3 -2
  54. package/dist/types/src/hooks/sync.d.ts.map +1 -1
  55. package/dist/types/src/hooks/useGlobalSearch.d.ts +7 -3
  56. package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
  57. package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
  58. package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
  59. package/dist/types/src/hooks/useWebSearch.d.ts +6 -3
  60. package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
  61. package/dist/types/src/meta.d.ts +3 -4
  62. package/dist/types/src/meta.d.ts.map +1 -1
  63. package/dist/types/src/search/exa.d.ts +4 -4
  64. package/dist/types/src/search/exa.d.ts.map +1 -1
  65. package/dist/types/src/translations.d.ts +1 -1
  66. package/dist/types/src/types/action.d.ts +14 -11
  67. package/dist/types/src/types/action.d.ts.map +1 -1
  68. package/dist/types/src/types/search.d.ts +3 -7
  69. package/dist/types/src/types/search.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +56 -47
  72. package/src/SearchPlugin.tsx +28 -46
  73. package/src/capabilities/app-graph-builder/app-graph-builder.ts +70 -0
  74. package/src/capabilities/app-graph-builder/index.ts +7 -0
  75. package/src/capabilities/index.ts +3 -5
  76. package/src/capabilities/operation-resolver/index.ts +7 -0
  77. package/src/capabilities/operation-resolver/operation-resolver.ts +24 -0
  78. package/src/capabilities/react-surface/index.ts +7 -0
  79. package/src/capabilities/react-surface/react-surface.tsx +62 -0
  80. package/src/components/index.ts +0 -4
  81. package/src/constants.ts +7 -0
  82. package/src/containers/SearchDialog/SearchDialog.tsx +120 -0
  83. package/src/containers/SearchDialog/index.ts +6 -0
  84. package/src/containers/SearchMain/SearchMain.tsx +103 -0
  85. package/src/containers/SearchMain/index.ts +7 -0
  86. package/src/containers/index.ts +10 -0
  87. package/src/hooks/index.ts +2 -0
  88. package/src/hooks/sync.test.ts +6 -4
  89. package/src/hooks/sync.ts +27 -31
  90. package/src/hooks/useGlobalSearch.tsx +33 -13
  91. package/src/hooks/useSearchResults.ts +9 -6
  92. package/src/hooks/useWebSearch.ts +21 -11
  93. package/src/meta.ts +10 -7
  94. package/src/search/exa.test.ts +8 -19
  95. package/src/search/exa.ts +135 -154
  96. package/src/translations.ts +1 -1
  97. package/src/types/action.tsx +10 -8
  98. package/src/types/command-score.d.ts +16 -0
  99. package/src/types/search.ts +3 -9
  100. package/dist/lib/browser/app-graph-builder-FLW7KDC5.mjs +0 -77
  101. package/dist/lib/browser/app-graph-builder-FLW7KDC5.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-BXSF7IAU.mjs +0 -190
  103. package/dist/lib/browser/chunk-BXSF7IAU.mjs.map +0 -7
  104. package/dist/lib/browser/chunk-JVMYGOKS.mjs +0 -21
  105. package/dist/lib/browser/chunk-JVMYGOKS.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-KNS62YL2.mjs +0 -20
  107. package/dist/lib/browser/chunk-KNS62YL2.mjs.map +0 -7
  108. package/dist/lib/browser/intent-resolver-JPBGEKFT.mjs +0 -22
  109. package/dist/lib/browser/intent-resolver-JPBGEKFT.mjs.map +0 -7
  110. package/dist/lib/browser/react-surface-ETKK5YS3.mjs +0 -648
  111. package/dist/lib/browser/react-surface-ETKK5YS3.mjs.map +0 -7
  112. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  113. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  114. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  115. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  116. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  117. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  118. package/dist/types/src/components/Search.stories.d.ts +0 -15
  119. package/dist/types/src/components/Search.stories.d.ts.map +0 -1
  120. package/dist/types/src/components/SearchDialog.d.ts.map +0 -1
  121. package/dist/types/src/components/SearchMain.d.ts +0 -7
  122. package/dist/types/src/components/SearchMain.d.ts.map +0 -1
  123. package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
  124. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
  125. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +0 -12
  126. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
  127. package/dist/types/src/components/SearchResults/index.d.ts +0 -2
  128. package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
  129. package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -14
  130. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
  131. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +0 -11
  132. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
  133. package/dist/types/src/components/Searchbar/index.d.ts +0 -2
  134. package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
  135. package/src/capabilities/app-graph-builder.ts +0 -79
  136. package/src/capabilities/intent-resolver.ts +0 -18
  137. package/src/capabilities/react-surface.tsx +0 -59
  138. package/src/components/Search.stories.tsx +0 -66
  139. package/src/components/SearchDialog.tsx +0 -124
  140. package/src/components/SearchMain.tsx +0 -67
  141. package/src/components/SearchResults/SearchResults.stories.tsx +0 -57
  142. package/src/components/SearchResults/SearchResults.tsx +0 -86
  143. package/src/components/SearchResults/index.ts +0 -5
  144. package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
  145. package/src/components/Searchbar/Searchbar.tsx +0 -67
  146. package/src/components/Searchbar/index.ts +0 -5
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SearchMain } from './SearchMain';
6
+
7
+ export default SearchMain;
@@ -0,0 +1,10 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export type { SearchDialogProps } from './SearchDialog';
8
+
9
+ export const SearchDialog: ComponentType<any> = lazy(() => import('./SearchDialog'));
10
+ export const SearchMain: ComponentType<any> = lazy(() => import('./SearchMain'));
@@ -3,5 +3,7 @@
3
3
  //
4
4
 
5
5
  export * from './sync';
6
+
6
7
  export * from './useGlobalSearch';
7
8
  export * from './useSearchResults';
9
+ export * from './useWebSearch';
@@ -5,7 +5,8 @@
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
- import { Obj, Filter, Type } from '@dxos/echo';
8
+ import { Filter, Obj } from '@dxos/echo';
9
+ import { TestSchema } from '@dxos/echo/testing';
9
10
  import { faker } from '@dxos/random';
10
11
 
11
12
  import { filterObjectsSync } from './sync';
@@ -15,7 +16,8 @@ faker.seed(1);
15
16
  // TODO(burdon): Reconcile with agent/minisearch.
16
17
 
17
18
  describe('Search', () => {
18
- test('Prefix text search', async () => {
19
+ // TODO(mykola): Fix FTS index to filter by fields.
20
+ test.skip('Prefix text search', async () => {
19
21
  const client = new Client();
20
22
  await client.initialize();
21
23
  await client.halo.createIdentity();
@@ -25,10 +27,10 @@ describe('Search', () => {
25
27
  Array.from({ length: 20 }).map((_, i) => {
26
28
  const content =
27
29
  i === 10 ? faker.lorem.sentence() + ` ${match}}. ` + faker.lorem.sentence() : faker.lorem.sentences();
28
- return space.db.add(Obj.make(Type.Expando, { title: faker.lorem.sentence(), content }));
30
+ return space.db.add(Obj.make(TestSchema.Expando, { title: faker.lorem.sentence(), content }));
29
31
  });
30
32
 
31
- const { objects } = await space.db.query(Filter.everything()).run();
33
+ const objects = await space.db.query(Filter.everything()).run();
32
34
  const results = filterObjectsSync(objects, new RegExp(match, 'i'));
33
35
  expect(results).to.have.length(1);
34
36
  });
package/src/hooks/sync.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema, SchemaAST } from 'effect';
5
+ import type * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
6
7
 
7
- import { Obj } from '@dxos/echo';
8
- import { DataType } from '@dxos/schema';
8
+ import { type Entity, Obj } from '@dxos/echo';
9
+ import { Text } from '@dxos/schema';
9
10
 
10
11
  import { type SearchResult } from '../types';
11
12
 
@@ -38,39 +39,34 @@ const getIcon = (schema: Schema.Schema.AnyNoContext | undefined): string | undef
38
39
  export type TextFields = Record<string, string>;
39
40
 
40
41
  // TODO(thure): This returns `SearchResult[]` which is not just a narrower set of objects as the name implies.
41
- export const filterObjectsSync = <T extends Record<string, any>>(objects: T[], match?: RegExp): SearchResult[] => {
42
+ export const filterObjectsSync = <T extends Entity.Unknown>(objects: T[], match?: RegExp): SearchResult<T>[] => {
42
43
  if (!match) {
43
44
  return [];
44
45
  }
45
46
 
46
- return objects.reduce<SearchResult[]>((results, object) => {
47
+ return objects.reduce<SearchResult<T>[]>((results, object) => {
47
48
  // TODO(burdon): Hack to ignore Text objects.
48
- if (object instanceof DataType.Text) {
49
+ if (object instanceof Text.Text) {
49
50
  return results;
50
51
  }
51
52
 
52
53
  const fields = mapObjectToTextFields(object);
53
54
  Object.entries(fields).some(([, value]) => {
54
- const result = value.match(match);
55
- if (result) {
56
- // TODO(burdon): Use schema.
57
- const label = getStringProperty(object, ['label', 'name', 'title']);
58
-
59
- results.push({
60
- id: object.id,
61
- type: getIcon(Obj.getSchema(object)),
62
- label,
63
- match,
64
- // TODO(burdon): Truncate.
65
- // TODO(burdon): Issue with sketch documents.
66
- snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
67
- object,
68
- });
69
-
70
- return true;
71
- }
55
+ // TODO(burdon): Use schema.
56
+ const label = Obj.getLabel(object as any);
57
+
58
+ results.push({
59
+ id: object.id,
60
+ type: getIcon(Obj.getSchema(object)),
61
+ label,
62
+ match,
63
+ // TODO(burdon): Truncate.
64
+ // TODO(burdon): Issue with sketch documents.
65
+ snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
66
+ object,
67
+ });
72
68
 
73
- return false;
69
+ return true;
74
70
  });
75
71
 
76
72
  return results;
@@ -94,13 +90,13 @@ export const getStringProperty = (object: any, keys: string[]): string | undefin
94
90
  };
95
91
 
96
92
  // TODO(burdon): Filter system fields.
97
- const getKeys = (object: Record<string, unknown>): string[] => {
93
+ const getKeys = <T extends Entity.Unknown>(object: T): string[] => {
98
94
  try {
99
95
  const obj = JSON.parse(JSON.stringify(object));
100
96
  return Object.keys(obj).filter(
101
97
  (key) => key !== 'id' && key !== 'identityKey' && key[0] !== '_' && key[0] !== '@',
102
98
  ) as string[];
103
- } catch (err) {
99
+ } catch {
104
100
  // TODO(burdon): Error with TLDraw sketch.
105
101
  // Uncaught Error: Type with the name content has already been defined with a different constructor
106
102
  return [];
@@ -108,13 +104,13 @@ const getKeys = (object: Record<string, unknown>): string[] => {
108
104
  };
109
105
 
110
106
  // TODO(burdon): Use ECHO schema.
111
- export const mapObjectToTextFields = <T extends Record<string, unknown>>(object: T): TextFields => {
107
+ export const mapObjectToTextFields = <T extends Entity.Unknown>(object: T): TextFields => {
112
108
  return getKeys(object).reduce<TextFields>((fields, key) => {
113
- const value = object[key] as any;
114
- if (typeof value === 'string' || value instanceof DataType.Text) {
109
+ const value = (object as any)[key];
110
+ if (typeof value === 'string' || value instanceof Text.Text) {
115
111
  try {
116
112
  fields[key] = String(value);
117
- } catch (err) {
113
+ } catch {
118
114
  // TODO(burdon): Exception when parsing sketch document.
119
115
  }
120
116
  }
@@ -2,13 +2,19 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React, { createContext, type PropsWithChildren, useContext, useMemo, useState } from 'react';
5
+ import React, { type PropsWithChildren, createContext, useCallback, useContext, useState } from 'react';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
+ import { type Entity } from '@dxos/echo';
9
+ import { GlobalFilterProvider } from '@dxos/react-ui-searchlist';
8
10
 
9
- import { filterObjectsSync, queryStringToMatch } from './sync';
10
11
  import { type SearchResult } from '../types';
11
12
 
13
+ import { filterObjectsSync, queryStringToMatch } from './sync';
14
+
15
+ // Re-export for backward compatibility.
16
+ export { useGlobalFilteredObjects, GlobalFilterProvider } from '@dxos/react-ui-searchlist';
17
+
12
18
  type SearchContextType = {
13
19
  match?: RegExp;
14
20
  setMatch?: (text?: string) => void;
@@ -16,26 +22,40 @@ type SearchContextType = {
16
22
 
17
23
  const SearchContext = createContext<SearchContextType>({});
18
24
 
25
+ /**
26
+ * Provider for global search context.
27
+ * Also provides the GlobalFilterProvider for useGlobalFilteredObjects to work.
28
+ */
19
29
  export const SearchContextProvider = ({ children }: PropsWithChildren) => {
20
30
  const [match, setMatch] = useState<RegExp>();
21
31
  const handleMatch = (text?: string) => setMatch(queryStringToMatch(text));
22
- return <SearchContext.Provider value={{ match, setMatch: handleMatch }}>{children}</SearchContext.Provider>;
32
+
33
+ // Provide a filter function for useGlobalFilteredObjects.
34
+ const filterFn = useCallback(
35
+ <T extends Entity.Any>(objects: T[]): T[] => {
36
+ if (!match) {
37
+ return objects;
38
+ }
39
+
40
+ return filterObjectsSync(objects, match)
41
+ .filter((result) => result.object)
42
+ .map((result) => result.object!);
43
+ },
44
+ [match],
45
+ );
46
+
47
+ return (
48
+ <SearchContext.Provider value={{ match, setMatch: handleMatch }}>
49
+ <GlobalFilterProvider filter={filterFn}>{children}</GlobalFilterProvider>
50
+ </SearchContext.Provider>
51
+ );
23
52
  };
24
53
 
25
54
  export const useGlobalSearch = () => {
26
55
  return useContext(SearchContext) ?? raise(new Error('Missing SearchContext.'));
27
56
  };
28
57
 
29
- export const useGlobalSearchResults = <T extends Record<string, any>>(objects?: T[]): SearchResult[] => {
58
+ export const useGlobalSearchResults = <T extends Entity.Unknown>(objects?: T[]): SearchResult<T>[] => {
30
59
  const { match } = useGlobalSearch();
31
60
  return objects && match ? filterObjectsSync(objects, match) : [];
32
61
  };
33
-
34
- export const useGlobalFilteredObjects = <T extends Record<string, any>>(objects?: T[]): T[] => {
35
- const { match } = useGlobalSearch();
36
- if (!match || !objects) {
37
- return objects ?? [];
38
- }
39
-
40
- return useMemo(() => filterObjectsSync(objects, match).map((result) => result.object), [objects, match]);
41
- };
@@ -5,12 +5,13 @@
5
5
  import { yieldOrContinue } from 'main-thread-scheduling';
6
6
  import { useEffect, useState } from 'react';
7
7
 
8
- import { DataType } from '@dxos/schema';
8
+ import { type Entity } from '@dxos/echo';
9
+ import { Text } from '@dxos/schema';
9
10
 
10
11
  // TODO(thure): Deprecate search-sync, move still-relevant utilities elsewhere (here, probably).
11
12
  import { mapObjectToTextFields, queryStringToMatch } from './sync';
12
13
 
13
- export const filterObjects = async <T extends Record<string, any>>(
14
+ export const filterObjects = async <T extends Entity.Unknown>(
14
15
  objects: T[],
15
16
  match?: RegExp,
16
17
  ): Promise<Map<T, string[][]>> => {
@@ -18,9 +19,10 @@ export const filterObjects = async <T extends Record<string, any>>(
18
19
  if (!match) {
19
20
  return result;
20
21
  }
22
+
21
23
  await Promise.all(
22
24
  objects
23
- .filter((object) => !(object instanceof DataType.Text))
25
+ .filter((object) => !(object instanceof Text.Text))
24
26
  .map(async (object) => {
25
27
  await yieldOrContinue('interactive');
26
28
  const fields = mapObjectToTextFields<T>(object);
@@ -34,10 +36,11 @@ export const filterObjects = async <T extends Record<string, any>>(
34
36
  });
35
37
  }),
36
38
  );
39
+
37
40
  return result;
38
41
  };
39
42
 
40
- export const useSearchResults = <T extends Record<string, any>>(
43
+ export const useSearchResults = <T extends Entity.Unknown>(
41
44
  queryString?: string,
42
45
  objects?: T[],
43
46
  delay: number = 400,
@@ -47,14 +50,14 @@ export const useSearchResults = <T extends Record<string, any>>(
47
50
 
48
51
  useEffect(() => {
49
52
  setPending(!!(objects && queryString));
50
- const timeoutId = setTimeout(async () => {
53
+ const timeout = setTimeout(async () => {
51
54
  const nextResults =
52
55
  objects && queryString ? await filterObjects(objects, queryStringToMatch(queryString)) : new Map();
53
56
  setResults(nextResults);
54
57
  setPending(false);
55
58
  }, delay);
56
59
 
57
- return () => clearTimeout(timeoutId);
60
+ return () => clearTimeout(timeout);
58
61
  }, [queryString, objects]);
59
62
 
60
63
  return [pending, results];
@@ -2,33 +2,44 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useState } from 'react';
5
+ import { useCallback, useState } from 'react';
6
6
 
7
7
  import { EXA_API_KEY } from '@dxos/ai/testing';
8
- import { todo } from '@dxos/debug';
9
8
  import { Obj } from '@dxos/echo';
10
- import { type DXN } from '@dxos/keys';
11
9
  import { log } from '@dxos/log';
12
10
  import { getIconAnnotation } from '@dxos/schema';
13
- import { Testing } from '@dxos/schema/testing';
11
+ import { TestSchema } from '@dxos/schema/testing';
14
12
 
15
13
  import { search } from '../search';
16
14
  import { type SearchResult } from '../types';
15
+
17
16
  import { getStringProperty } from './sync';
18
17
 
19
- export const useWebSearch = ({ query, context }: { query?: string; context?: string }) => {
18
+ export type UseWebSearchProps = {
19
+ query?: string;
20
+ context?: string;
21
+ };
22
+
23
+ export type UseWebSearch = {
24
+ update: () => Promise<void>;
25
+ results: SearchResult[];
26
+ isLoading: boolean;
27
+ };
28
+
29
+ /** @deprecated */
30
+ // TODO(burdon): Remove testing deps.
31
+ export const useWebSearch = ({ query, context }: UseWebSearchProps): UseWebSearch => {
20
32
  const [results, setResults] = useState<SearchResult[]>([]);
21
33
  const [isLoading, setIsLoading] = useState(false);
22
34
 
23
- const runSearch = async () => {
35
+ const update = useCallback(async () => {
24
36
  try {
25
37
  setIsLoading(true);
26
38
  log.info('Running web search', { query, context });
27
39
  const results = await search({
28
40
  query,
29
41
  context,
30
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
31
- AiService: todo(),
42
+ schema: [TestSchema.Person, TestSchema.Project, TestSchema.Organization], // TODO(burdon): ???
32
43
  exaApiKey: EXA_API_KEY,
33
44
  });
34
45
 
@@ -36,7 +47,6 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
36
47
  const schema = Obj.getSchema(result);
37
48
  return {
38
49
  id: result.id,
39
- objectType: Obj.getTypename(result) as DXN.String | undefined,
40
50
  label: getStringProperty(result, ['name', 'title', 'label']),
41
51
  snippet: getStringProperty(result, ['description', 'content', 'website', 'email']),
42
52
  object: result,
@@ -48,7 +58,7 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
48
58
  } finally {
49
59
  setIsLoading(false);
50
60
  }
51
- };
61
+ }, [query, context]);
52
62
 
53
- return { runSearch, results, isLoading };
63
+ return { update, results, isLoading };
54
64
  };
package/src/meta.ts CHANGED
@@ -2,16 +2,19 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
- export const SEARCH_PLUGIN = 'dxos.org/plugin/search';
8
- export const SEARCH_RESULT = `${SEARCH_PLUGIN}/result`;
9
-
10
- export const meta: PluginMeta = {
11
- id: SEARCH_PLUGIN,
8
+ export const meta: Plugin.Meta = {
9
+ id: 'org.dxos.plugin.search',
12
10
  name: 'Search',
13
- description: 'Search ECHO spaces for content.',
11
+ description: trim`
12
+ Full-text search engine for finding content across all spaces and object types.
13
+ Quickly locate documents, tables, and other objects with instant results and relevance ranking.
14
+ `,
14
15
  icon: 'ph--magnifying-glass--regular',
15
16
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-search',
16
17
  tags: ['labs'],
17
18
  };
19
+
20
+ export const SEARCH_RESULT = `${meta.id}.result`;
@@ -5,9 +5,8 @@
5
5
  import { describe, test } from 'vitest';
6
6
 
7
7
  import { EXA_API_KEY } from '@dxos/ai/testing';
8
- import { todo } from '@dxos/debug';
9
8
  import { log } from '@dxos/log';
10
- import { Testing } from '@dxos/schema/testing';
9
+ import { TestSchema } from '@dxos/schema/testing';
11
10
 
12
11
  import { search } from './exa';
13
12
 
@@ -16,8 +15,7 @@ describe.skip('Search', () => {
16
15
  test.skip('contacts', { timeout: 60_000 }, async () => {
17
16
  const objects = await search({
18
17
  query: 'top executives at google',
19
- schema: [Testing.Contact],
20
- AiService: null as any, // TODO: Implement AiService
18
+ schema: [TestSchema.Person],
21
19
  exaApiKey: EXA_API_KEY,
22
20
  });
23
21
 
@@ -27,8 +25,7 @@ describe.skip('Search', () => {
27
25
  test.skip('contacts projects and orgs', { timeout: 60_000 }, async () => {
28
26
  const objects = await search({
29
27
  query: 'top executives at google',
30
- schema: [Testing.Contact, Testing.Project, Testing.Organization],
31
- AiService: todo(),
28
+ schema: [TestSchema.Person, TestSchema.Project, TestSchema.Organization],
32
29
  exaApiKey: EXA_API_KEY,
33
30
  });
34
31
 
@@ -38,8 +35,7 @@ describe.skip('Search', () => {
38
35
  test('a19z org, projects they invest in and team', { timeout: 60_000 }, async () => {
39
36
  const objects = await search({
40
37
  query: 'a19z org, projects they invest in and team',
41
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
42
- AiService: todo(),
38
+ schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
43
39
  exaApiKey: EXA_API_KEY,
44
40
  });
45
41
 
@@ -49,8 +45,7 @@ describe.skip('Search', () => {
49
45
  test('companies building CRDTs', { timeout: 60_000 }, async () => {
50
46
  const objects = await search({
51
47
  query: 'companies building CRDTs',
52
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
53
- AiService: todo(),
48
+ schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
54
49
  exaApiKey: EXA_API_KEY,
55
50
  });
56
51
 
@@ -62,8 +57,7 @@ describe.skip('Search', () => {
62
57
  test('composer context-based search', { timeout: 60_000 }, async () => {
63
58
  const objects = await search({
64
59
  context: COMPOSER_DXOS_DOC,
65
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
66
- AiService: todo(),
60
+ schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
67
61
  exaApiKey: EXA_API_KEY,
68
62
  });
69
63
 
@@ -73,8 +67,7 @@ describe.skip('Search', () => {
73
67
  test.only('edge architecture', { timeout: 60_000 }, async () => {
74
68
  const objects = await search({
75
69
  context: EDGE_ARCHITECTURE_DOC,
76
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
77
- AiService: todo(),
70
+ schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
78
71
  exaApiKey: EXA_API_KEY,
79
72
  });
80
73
 
@@ -83,9 +76,7 @@ describe.skip('Search', () => {
83
76
  });
84
77
  });
85
78
 
86
- // TODO(dmaretskyi): Import as txt.
87
79
  const COMPOSER_DXOS_DOC = `
88
-
89
80
  ![img](https://dxos.network/dxos-logotype-blue.png)
90
81
  # Welcome to Composer by DXOS
91
82
 
@@ -93,7 +84,7 @@ const COMPOSER_DXOS_DOC = `
93
84
 
94
85
  Composer is an extensible application that includes familiar components such as documents, diagrams, and tables. It leverages DXOS — a full stack framework for building collaborative local-first applications.
95
86
 
96
- With our upcoming SDK, you'll be able to build custom plugins, leverage external APIs and integrate with LLMs. All inside of a private collaborative workspace.
87
+ With our SDK, you'll be able to build custom plugins, leverage external APIs and integrate with LLMs. All inside of a private collaborative workspace.
97
88
 
98
89
  ## Disclaimer
99
90
 
@@ -219,6 +210,4 @@ const EDGE_ARCHITECTURE_DOC = `
219
210
  - given the fq id of the deployment object, anyone in the space should be able to invoke the function even if they don't have access to the object itself
220
211
 
221
212
  ### Service Side
222
-
223
-
224
213
  `;