@dxos/plugin-search 0.8.4-main.c4373fc → 0.8.4-main.d05673bc65
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 +0 -1
- package/dist/lib/browser/SearchDialog-KJL6C2OF.mjs +108 -0
- package/dist/lib/browser/SearchDialog-KJL6C2OF.mjs.map +7 -0
- package/dist/lib/browser/SearchMain-JCNONOF3.mjs +100 -0
- package/dist/lib/browser/SearchMain-JCNONOF3.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-FHVM5QV7.mjs +78 -0
- package/dist/lib/browser/app-graph-builder-FHVM5QV7.mjs.map +7 -0
- package/dist/lib/browser/chunk-I3633KKK.mjs +26 -0
- package/dist/lib/browser/chunk-I3633KKK.mjs.map +7 -0
- package/dist/lib/browser/chunk-NB4JZIOE.mjs +282 -0
- package/dist/lib/browser/chunk-NB4JZIOE.mjs.map +7 -0
- package/dist/lib/browser/chunk-PZ67KFRU.mjs +22 -0
- package/dist/lib/browser/chunk-PZ67KFRU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +52 -57
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-H4X6BNWR.mjs +26 -0
- package/dist/lib/browser/operation-resolver-H4X6BNWR.mjs.map +7 -0
- package/dist/lib/browser/react-surface-IPH2UPKO.mjs +60 -0
- package/dist/lib/browser/react-surface-IPH2UPKO.mjs.map +7 -0
- package/dist/types/src/SearchPlugin.d.ts +2 -1
- package/dist/types/src/SearchPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +3 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +0 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/constants.d.ts +2 -0
- package/dist/types/src/constants.d.ts.map +1 -0
- package/dist/types/src/{components → containers/SearchDialog}/SearchDialog.d.ts +0 -1
- package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts +3 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
- package/dist/types/src/containers/SearchMain/SearchMain.d.ts +6 -0
- package/dist/types/src/containers/SearchMain/SearchMain.d.ts.map +1 -0
- package/dist/types/src/containers/SearchMain/index.d.ts +3 -0
- package/dist/types/src/containers/SearchMain/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +5 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/sync.d.ts +3 -2
- package/dist/types/src/hooks/sync.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobalSearch.d.ts +7 -3
- package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
- package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
- package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts +6 -3
- package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/search/exa.d.ts +3 -1
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -1
- package/dist/types/src/types/action.d.ts +13 -10
- package/dist/types/src/types/action.d.ts.map +1 -1
- package/dist/types/src/types/search.d.ts +3 -7
- package/dist/types/src/types/search.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +56 -46
- package/src/SearchPlugin.tsx +25 -42
- package/src/capabilities/app-graph-builder/app-graph-builder.ts +70 -0
- package/src/capabilities/app-graph-builder/index.ts +7 -0
- package/src/capabilities/index.ts +3 -5
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +24 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +62 -0
- package/src/components/index.ts +0 -4
- package/src/constants.ts +7 -0
- package/src/containers/SearchDialog/SearchDialog.tsx +120 -0
- package/src/containers/SearchDialog/index.ts +6 -0
- package/src/containers/SearchMain/SearchMain.tsx +103 -0
- package/src/containers/SearchMain/index.ts +7 -0
- package/src/containers/index.ts +10 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/sync.test.ts +6 -4
- package/src/hooks/sync.ts +25 -30
- package/src/hooks/useGlobalSearch.tsx +31 -12
- package/src/hooks/useSearchResults.ts +7 -4
- package/src/hooks/useWebSearch.ts +20 -9
- package/src/meta.ts +9 -5
- package/src/search/exa.test.ts +9 -11
- package/src/search/exa.ts +6 -5
- package/src/translations.ts +1 -1
- package/src/types/action.tsx +8 -6
- package/src/types/command-score.d.ts +16 -0
- package/src/types/search.ts +3 -9
- package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs +0 -78
- package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs.map +0 -7
- package/dist/lib/browser/chunk-5N6LDSFF.mjs +0 -18
- package/dist/lib/browser/chunk-5N6LDSFF.mjs.map +0 -7
- package/dist/lib/browser/chunk-WN3TVQLV.mjs +0 -190
- package/dist/lib/browser/chunk-WN3TVQLV.mjs.map +0 -7
- package/dist/lib/browser/chunk-YJGHPWUO.mjs +0 -21
- package/dist/lib/browser/chunk-YJGHPWUO.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs +0 -22
- package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs.map +0 -7
- package/dist/lib/browser/react-surface-YOGLADC4.mjs +0 -470
- package/dist/lib/browser/react-surface-YOGLADC4.mjs.map +0 -7
- package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/Search.stories.d.ts +0 -19
- package/dist/types/src/components/Search.stories.d.ts.map +0 -1
- package/dist/types/src/components/SearchDialog.d.ts.map +0 -1
- package/dist/types/src/components/SearchMain.d.ts +0 -7
- package/dist/types/src/components/SearchMain.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
- package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +0 -16
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/index.d.ts +0 -2
- package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -14
- package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +0 -13
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/index.d.ts +0 -2
- package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
- package/src/capabilities/app-graph-builder.ts +0 -80
- package/src/capabilities/intent-resolver.ts +0 -18
- package/src/capabilities/react-surface.tsx +0 -59
- package/src/components/Search.stories.tsx +0 -67
- package/src/components/SearchDialog.tsx +0 -124
- package/src/components/SearchMain.tsx +0 -68
- package/src/components/SearchResults/SearchResults.stories.tsx +0 -58
- package/src/components/SearchResults/SearchResults.tsx +0 -86
- package/src/components/SearchResults/index.ts +0 -5
- package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
- package/src/components/Searchbar/Searchbar.tsx +0 -67
- package/src/components/Searchbar/index.ts +0 -5
|
@@ -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'));
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/sync.test.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
|
-
import { Filter, Obj
|
|
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
|
-
|
|
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(
|
|
30
|
+
return space.db.add(Obj.make(TestSchema.Expando, { title: faker.lorem.sentence(), content }));
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
const
|
|
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
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import type * as Schema from 'effect/Schema';
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import {
|
|
8
|
+
import { type Entity, Obj } from '@dxos/echo';
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
10
10
|
|
|
11
11
|
import { type SearchResult } from '../types';
|
|
12
12
|
|
|
@@ -39,39 +39,34 @@ const getIcon = (schema: Schema.Schema.AnyNoContext | undefined): string | undef
|
|
|
39
39
|
export type TextFields = Record<string, string>;
|
|
40
40
|
|
|
41
41
|
// TODO(thure): This returns `SearchResult[]` which is not just a narrower set of objects as the name implies.
|
|
42
|
-
export const filterObjectsSync = <T extends
|
|
42
|
+
export const filterObjectsSync = <T extends Entity.Unknown>(objects: T[], match?: RegExp): SearchResult<T>[] => {
|
|
43
43
|
if (!match) {
|
|
44
44
|
return [];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
return objects.reduce<SearchResult[]>((results, object) => {
|
|
47
|
+
return objects.reduce<SearchResult<T>[]>((results, object) => {
|
|
48
48
|
// TODO(burdon): Hack to ignore Text objects.
|
|
49
|
-
if (object instanceof
|
|
49
|
+
if (object instanceof Text.Text) {
|
|
50
50
|
return results;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const fields = mapObjectToTextFields(object);
|
|
54
54
|
Object.entries(fields).some(([, value]) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
object,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
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
|
+
});
|
|
73
68
|
|
|
74
|
-
return
|
|
69
|
+
return true;
|
|
75
70
|
});
|
|
76
71
|
|
|
77
72
|
return results;
|
|
@@ -95,13 +90,13 @@ export const getStringProperty = (object: any, keys: string[]): string | undefin
|
|
|
95
90
|
};
|
|
96
91
|
|
|
97
92
|
// TODO(burdon): Filter system fields.
|
|
98
|
-
const getKeys = (object:
|
|
93
|
+
const getKeys = <T extends Entity.Unknown>(object: T): string[] => {
|
|
99
94
|
try {
|
|
100
95
|
const obj = JSON.parse(JSON.stringify(object));
|
|
101
96
|
return Object.keys(obj).filter(
|
|
102
97
|
(key) => key !== 'id' && key !== 'identityKey' && key[0] !== '_' && key[0] !== '@',
|
|
103
98
|
) as string[];
|
|
104
|
-
} catch
|
|
99
|
+
} catch {
|
|
105
100
|
// TODO(burdon): Error with TLDraw sketch.
|
|
106
101
|
// Uncaught Error: Type with the name content has already been defined with a different constructor
|
|
107
102
|
return [];
|
|
@@ -109,13 +104,13 @@ const getKeys = (object: Record<string, unknown>): string[] => {
|
|
|
109
104
|
};
|
|
110
105
|
|
|
111
106
|
// TODO(burdon): Use ECHO schema.
|
|
112
|
-
export const mapObjectToTextFields = <T extends
|
|
107
|
+
export const mapObjectToTextFields = <T extends Entity.Unknown>(object: T): TextFields => {
|
|
113
108
|
return getKeys(object).reduce<TextFields>((fields, key) => {
|
|
114
|
-
const value = object
|
|
115
|
-
if (typeof value === 'string' || value instanceof
|
|
109
|
+
const value = (object as any)[key];
|
|
110
|
+
if (typeof value === 'string' || value instanceof Text.Text) {
|
|
116
111
|
try {
|
|
117
112
|
fields[key] = String(value);
|
|
118
|
-
} catch
|
|
113
|
+
} catch {
|
|
119
114
|
// TODO(burdon): Exception when parsing sketch document.
|
|
120
115
|
}
|
|
121
116
|
}
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { type PropsWithChildren, createContext,
|
|
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
11
|
import { type SearchResult } from '../types';
|
|
10
12
|
|
|
11
13
|
import { filterObjectsSync, queryStringToMatch } from './sync';
|
|
12
14
|
|
|
15
|
+
// Re-export for backward compatibility.
|
|
16
|
+
export { useGlobalFilteredObjects, GlobalFilterProvider } from '@dxos/react-ui-searchlist';
|
|
17
|
+
|
|
13
18
|
type SearchContextType = {
|
|
14
19
|
match?: RegExp;
|
|
15
20
|
setMatch?: (text?: string) => void;
|
|
@@ -17,26 +22,40 @@ type SearchContextType = {
|
|
|
17
22
|
|
|
18
23
|
const SearchContext = createContext<SearchContextType>({});
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Provider for global search context.
|
|
27
|
+
* Also provides the GlobalFilterProvider for useGlobalFilteredObjects to work.
|
|
28
|
+
*/
|
|
20
29
|
export const SearchContextProvider = ({ children }: PropsWithChildren) => {
|
|
21
30
|
const [match, setMatch] = useState<RegExp>();
|
|
22
31
|
const handleMatch = (text?: string) => setMatch(queryStringToMatch(text));
|
|
23
|
-
|
|
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
|
+
);
|
|
24
52
|
};
|
|
25
53
|
|
|
26
54
|
export const useGlobalSearch = () => {
|
|
27
55
|
return useContext(SearchContext) ?? raise(new Error('Missing SearchContext.'));
|
|
28
56
|
};
|
|
29
57
|
|
|
30
|
-
export const useGlobalSearchResults = <T extends
|
|
58
|
+
export const useGlobalSearchResults = <T extends Entity.Unknown>(objects?: T[]): SearchResult<T>[] => {
|
|
31
59
|
const { match } = useGlobalSearch();
|
|
32
60
|
return objects && match ? filterObjectsSync(objects, match) : [];
|
|
33
61
|
};
|
|
34
|
-
|
|
35
|
-
export const useGlobalFilteredObjects = <T extends Record<string, any>>(objects?: T[]): T[] => {
|
|
36
|
-
const { match } = useGlobalSearch();
|
|
37
|
-
if (!match || !objects) {
|
|
38
|
-
return objects ?? [];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return useMemo(() => filterObjectsSync(objects, match).map((result) => result.object), [objects, match]);
|
|
42
|
-
};
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
import { yieldOrContinue } from 'main-thread-scheduling';
|
|
6
6
|
import { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
43
|
+
export const useSearchResults = <T extends Entity.Unknown>(
|
|
41
44
|
queryString?: string,
|
|
42
45
|
objects?: T[],
|
|
43
46
|
delay: number = 400,
|
|
@@ -2,32 +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
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { type DXN } from '@dxos/keys';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
10
|
import { getIconAnnotation } from '@dxos/schema';
|
|
12
|
-
import {
|
|
11
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
13
12
|
|
|
14
13
|
import { search } from '../search';
|
|
15
14
|
import { type SearchResult } from '../types';
|
|
16
15
|
|
|
17
16
|
import { getStringProperty } from './sync';
|
|
18
17
|
|
|
19
|
-
export
|
|
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
|
|
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: [
|
|
42
|
+
schema: [TestSchema.Person, TestSchema.Project, TestSchema.Organization], // TODO(burdon): ???
|
|
31
43
|
exaApiKey: EXA_API_KEY,
|
|
32
44
|
});
|
|
33
45
|
|
|
@@ -35,7 +47,6 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
|
|
|
35
47
|
const schema = Obj.getSchema(result);
|
|
36
48
|
return {
|
|
37
49
|
id: result.id,
|
|
38
|
-
objectType: Obj.getTypename(result) as DXN.String | undefined,
|
|
39
50
|
label: getStringProperty(result, ['name', 'title', 'label']),
|
|
40
51
|
snippet: getStringProperty(result, ['description', 'content', 'website', 'email']),
|
|
41
52
|
object: result,
|
|
@@ -47,7 +58,7 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
|
|
|
47
58
|
} finally {
|
|
48
59
|
setIsLoading(false);
|
|
49
60
|
}
|
|
50
|
-
};
|
|
61
|
+
}, [query, context]);
|
|
51
62
|
|
|
52
|
-
return {
|
|
63
|
+
return { update, results, isLoading };
|
|
53
64
|
};
|
package/src/meta.ts
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const meta:
|
|
8
|
-
id: 'dxos.
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
9
|
+
id: 'org.dxos.plugin.search',
|
|
9
10
|
name: 'Search',
|
|
10
|
-
description:
|
|
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
|
+
`,
|
|
11
15
|
icon: 'ph--magnifying-glass--regular',
|
|
12
16
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-search',
|
|
13
17
|
tags: ['labs'],
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
export const SEARCH_RESULT = `${meta.id}
|
|
20
|
+
export const SEARCH_RESULT = `${meta.id}.result`;
|
package/src/search/exa.test.ts
CHANGED
|
@@ -6,8 +6,7 @@ import { describe, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { EXA_API_KEY } from '@dxos/ai/testing';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import {
|
|
10
|
-
import { trim } from '@dxos/util';
|
|
9
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
11
10
|
|
|
12
11
|
import { search } from './exa';
|
|
13
12
|
|
|
@@ -16,7 +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: [
|
|
18
|
+
schema: [TestSchema.Person],
|
|
20
19
|
exaApiKey: EXA_API_KEY,
|
|
21
20
|
});
|
|
22
21
|
|
|
@@ -26,7 +25,7 @@ describe.skip('Search', () => {
|
|
|
26
25
|
test.skip('contacts projects and orgs', { timeout: 60_000 }, async () => {
|
|
27
26
|
const objects = await search({
|
|
28
27
|
query: 'top executives at google',
|
|
29
|
-
schema: [
|
|
28
|
+
schema: [TestSchema.Person, TestSchema.Project, TestSchema.Organization],
|
|
30
29
|
exaApiKey: EXA_API_KEY,
|
|
31
30
|
});
|
|
32
31
|
|
|
@@ -36,7 +35,7 @@ describe.skip('Search', () => {
|
|
|
36
35
|
test('a19z org, projects they invest in and team', { timeout: 60_000 }, async () => {
|
|
37
36
|
const objects = await search({
|
|
38
37
|
query: 'a19z org, projects they invest in and team',
|
|
39
|
-
schema: [
|
|
38
|
+
schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
|
|
40
39
|
exaApiKey: EXA_API_KEY,
|
|
41
40
|
});
|
|
42
41
|
|
|
@@ -46,7 +45,7 @@ describe.skip('Search', () => {
|
|
|
46
45
|
test('companies building CRDTs', { timeout: 60_000 }, async () => {
|
|
47
46
|
const objects = await search({
|
|
48
47
|
query: 'companies building CRDTs',
|
|
49
|
-
schema: [
|
|
48
|
+
schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
|
|
50
49
|
exaApiKey: EXA_API_KEY,
|
|
51
50
|
});
|
|
52
51
|
|
|
@@ -58,7 +57,7 @@ describe.skip('Search', () => {
|
|
|
58
57
|
test('composer context-based search', { timeout: 60_000 }, async () => {
|
|
59
58
|
const objects = await search({
|
|
60
59
|
context: COMPOSER_DXOS_DOC,
|
|
61
|
-
schema: [
|
|
60
|
+
schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
|
|
62
61
|
exaApiKey: EXA_API_KEY,
|
|
63
62
|
});
|
|
64
63
|
|
|
@@ -68,7 +67,7 @@ describe.skip('Search', () => {
|
|
|
68
67
|
test.only('edge architecture', { timeout: 60_000 }, async () => {
|
|
69
68
|
const objects = await search({
|
|
70
69
|
context: EDGE_ARCHITECTURE_DOC,
|
|
71
|
-
schema: [
|
|
70
|
+
schema: [TestSchema.Project, TestSchema.Organization, TestSchema.Person],
|
|
72
71
|
exaApiKey: EXA_API_KEY,
|
|
73
72
|
});
|
|
74
73
|
|
|
@@ -77,8 +76,7 @@ describe.skip('Search', () => {
|
|
|
77
76
|
});
|
|
78
77
|
});
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
const COMPOSER_DXOS_DOC = trim`
|
|
79
|
+
const COMPOSER_DXOS_DOC = `
|
|
82
80
|

|
|
83
81
|
# Welcome to Composer by DXOS
|
|
84
82
|
|
|
@@ -86,7 +84,7 @@ const COMPOSER_DXOS_DOC = trim`
|
|
|
86
84
|
|
|
87
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.
|
|
88
86
|
|
|
89
|
-
With our
|
|
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.
|
|
90
88
|
|
|
91
89
|
## Disclaimer
|
|
92
90
|
|
package/src/search/exa.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as Option from 'effect/Option';
|
|
|
8
8
|
import * as Schema from 'effect/Schema';
|
|
9
9
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
10
10
|
|
|
11
|
-
import { Key, Obj } from '@dxos/echo';
|
|
11
|
+
import { type Entity, Key, Obj, type Type } from '@dxos/echo';
|
|
12
12
|
import { ReferenceAnnotationId } from '@dxos/echo/internal';
|
|
13
13
|
import { isEncodedReference } from '@dxos/echo-protocol';
|
|
14
14
|
import { mapAst } from '@dxos/effect';
|
|
@@ -31,9 +31,10 @@ export type SearchResult<T = unknown> = {
|
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/** @deprecated Use MixedStreamParser */
|
|
34
35
|
export const search = async <Schema extends Schema.Schema.AnyNoContext>(
|
|
35
36
|
options: SearchOptions<Schema>,
|
|
36
|
-
): Promise<SearchResult<
|
|
37
|
+
): Promise<SearchResult<Entity.Unknown>> => {
|
|
37
38
|
throw new Error('Not implemented');
|
|
38
39
|
// assertArgument(options.query || options.context, "query or context", "query or context is required");
|
|
39
40
|
// let contextSearchTerms: readonly string[] = [];
|
|
@@ -63,7 +64,7 @@ export const search = async <Schema extends Schema.Schema.AnyNoContext>(
|
|
|
63
64
|
// model: '@anthropic/claude-3-5-haiku-20241022',
|
|
64
65
|
// systemPrompt,
|
|
65
66
|
// history: [
|
|
66
|
-
// Obj.make(
|
|
67
|
+
// Obj.make(Message.Message, {
|
|
67
68
|
// created: new Date().toISOString(),
|
|
68
69
|
// sender: { role: 'user' },
|
|
69
70
|
// blocks: context.results.map(
|
|
@@ -159,7 +160,7 @@ const DATA_EXTRACTION_INSTRUCTIONS = trim`
|
|
|
159
160
|
// Prefer own names of people, companies, and projects, technologies, and other entities.
|
|
160
161
|
// `,
|
|
161
162
|
// history: [
|
|
162
|
-
// Obj.make(
|
|
163
|
+
// Obj.make(Message.Message, {
|
|
163
164
|
// created: new Date().toISOString(),
|
|
164
165
|
// sender: { role: 'user' },
|
|
165
166
|
// blocks: [
|
|
@@ -180,7 +181,7 @@ const DATA_EXTRACTION_INSTRUCTIONS = trim`
|
|
|
180
181
|
// return terms;
|
|
181
182
|
// };
|
|
182
183
|
|
|
183
|
-
const sanitizeObjects = (entries: { data: any; schema:
|
|
184
|
+
const sanitizeObjects = (entries: { data: any; schema: Type.AnyObj }[]) => {
|
|
184
185
|
const idMap = new Map<string, string>();
|
|
185
186
|
|
|
186
187
|
return entries
|
package/src/translations.ts
CHANGED
|
@@ -16,7 +16,7 @@ export const translations = [
|
|
|
16
16
|
'search dialog title': 'Open',
|
|
17
17
|
'recently closed heading': 'Recently closed',
|
|
18
18
|
'pending results message': 'Searching…',
|
|
19
|
-
'empty results message': 'No matching
|
|
19
|
+
'empty results message': 'No matching objects',
|
|
20
20
|
'search label': 'Search',
|
|
21
21
|
},
|
|
22
22
|
},
|
package/src/types/action.tsx
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
+
import { Operation } from '@dxos/operation';
|
|
8
|
+
|
|
7
9
|
import { meta } from '../meta';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
const SEARCH_ACTION = `${meta.id}/action`;
|
|
11
|
+
const SEARCH_OPERATION = `${meta.id}.operation`;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export namespace SearchOperation {
|
|
14
|
+
export const OpenSearch = Operation.make({
|
|
15
|
+
meta: { key: `${SEARCH_OPERATION}.open-search`, name: 'Open Search' },
|
|
16
|
+
schema: { input: Schema.Void, output: Schema.Void },
|
|
17
|
+
});
|
|
16
18
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
declare module 'command-score' {
|
|
6
|
+
/**
|
|
7
|
+
* Scores how well a string matches a query using a fuzzy matching algorithm.
|
|
8
|
+
* Used by cmdk for its built-in filtering.
|
|
9
|
+
*
|
|
10
|
+
* @param string - The string to score against.
|
|
11
|
+
* @param query - The search query.
|
|
12
|
+
* @returns A score between 0 and 1, where higher values indicate better matches.
|
|
13
|
+
*/
|
|
14
|
+
function commandScore(string: string, query: string): number;
|
|
15
|
+
export default commandScore;
|
|
16
|
+
}
|
package/src/types/search.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Entity } from '@dxos/echo';
|
|
6
6
|
|
|
7
|
-
export type SearchResult = {
|
|
7
|
+
export type SearchResult<T extends Entity.Unknown = Entity.Unknown> = {
|
|
8
8
|
id: string;
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -19,11 +19,5 @@ export type SearchResult = {
|
|
|
19
19
|
* Icon id.
|
|
20
20
|
*/
|
|
21
21
|
icon?: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* DXN of the object type.
|
|
25
|
-
*/
|
|
26
|
-
objectType?: DXN.String;
|
|
27
|
-
|
|
28
|
-
object?: any;
|
|
22
|
+
object?: T;
|
|
29
23
|
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SearchAction
|
|
3
|
-
} from "./chunk-YJGHPWUO.mjs";
|
|
4
|
-
import {
|
|
5
|
-
meta
|
|
6
|
-
} from "./chunk-5N6LDSFF.mjs";
|
|
7
|
-
|
|
8
|
-
// src/capabilities/app-graph-builder.ts
|
|
9
|
-
import { Rx } from "@effect-rx/rx-react";
|
|
10
|
-
import * as Function from "effect/Function";
|
|
11
|
-
import * as Option from "effect/Option";
|
|
12
|
-
import { Capabilities, contributes, createIntent } from "@dxos/app-framework";
|
|
13
|
-
import { ClientCapabilities } from "@dxos/plugin-client";
|
|
14
|
-
import { ATTENDABLE_PATH_SEPARATOR, DECK_COMPANION_TYPE } from "@dxos/plugin-deck/types";
|
|
15
|
-
import { ROOT_ID, createExtension, rxFromSignal } from "@dxos/plugin-graph";
|
|
16
|
-
import { parseId } from "@dxos/react-client/echo";
|
|
17
|
-
var app_graph_builder_default = ((context) => contributes(Capabilities.AppGraphBuilder, [
|
|
18
|
-
createExtension({
|
|
19
|
-
id: `${meta.id}/space-search`,
|
|
20
|
-
connector: (node) => Rx.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id === ROOT_ID ? Option.some(node2) : Option.none()), Option.map((node2) => {
|
|
21
|
-
const workspace = get(rxFromSignal(() => context.getCapability(Capabilities.Layout).workspace));
|
|
22
|
-
const client = context.getCapability(ClientCapabilities.Client);
|
|
23
|
-
const { spaceId } = parseId(workspace);
|
|
24
|
-
const space = spaceId ? client.spaces.get(spaceId) : null;
|
|
25
|
-
return [
|
|
26
|
-
{
|
|
27
|
-
id: [
|
|
28
|
-
node2.id,
|
|
29
|
-
"search"
|
|
30
|
-
].join(ATTENDABLE_PATH_SEPARATOR),
|
|
31
|
-
type: DECK_COMPANION_TYPE,
|
|
32
|
-
data: space,
|
|
33
|
-
properties: {
|
|
34
|
-
label: [
|
|
35
|
-
"search label",
|
|
36
|
-
{
|
|
37
|
-
ns: meta.id
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
icon: "ph--magnifying-glass--regular",
|
|
41
|
-
disposition: "hidden"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
}), Option.getOrElse(() => [])))
|
|
46
|
-
}),
|
|
47
|
-
createExtension({
|
|
48
|
-
id: meta.id,
|
|
49
|
-
actions: (node) => Rx.make((get) => Function.pipe(get(node), Option.flatMap((node2) => node2.id === ROOT_ID ? Option.some(node2) : Option.none()), Option.map(() => {
|
|
50
|
-
return [
|
|
51
|
-
{
|
|
52
|
-
id: SearchAction.OpenSearch._tag,
|
|
53
|
-
data: async () => {
|
|
54
|
-
const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
55
|
-
await dispatch(createIntent(SearchAction.OpenSearch));
|
|
56
|
-
},
|
|
57
|
-
properties: {
|
|
58
|
-
label: [
|
|
59
|
-
"search action label",
|
|
60
|
-
{
|
|
61
|
-
ns: meta.id
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
icon: "ph--magnifying-glass--regular",
|
|
65
|
-
keyBinding: {
|
|
66
|
-
macos: "shift+meta+f",
|
|
67
|
-
windows: "shift+alt+f"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
];
|
|
72
|
-
}), Option.getOrElse(() => [])))
|
|
73
|
-
})
|
|
74
|
-
]));
|
|
75
|
-
export {
|
|
76
|
-
app_graph_builder_default as default
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=app-graph-builder-YME7SN7O.mjs.map
|