@dxos/plugin-search 0.8.2-staging.7ac8446 → 0.8.2

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 (52) hide show
  1. package/dist/lib/browser/app-graph-builder-NZN3MIDZ.mjs +77 -0
  2. package/dist/lib/browser/app-graph-builder-NZN3MIDZ.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-J6YWSQTW.mjs → chunk-ARZYMSFF.mjs} +3 -3
  4. package/dist/lib/browser/{chunk-J6YWSQTW.mjs.map → chunk-ARZYMSFF.mjs.map} +1 -1
  5. package/dist/lib/browser/{chunk-NFZSXZMP.mjs → chunk-CKQAVN5U.mjs} +23 -17
  6. package/dist/lib/browser/chunk-CKQAVN5U.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-LXHJVTYG.mjs → chunk-VMEXQBHE.mjs} +7 -7
  8. package/dist/lib/browser/chunk-VMEXQBHE.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +6 -6
  10. package/dist/lib/browser/{intent-resolver-G76A35DX.mjs → intent-resolver-RWC63UGI.mjs} +3 -3
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/{react-surface-QBBLEI2Q.mjs → react-surface-UJOSZGP5.mjs} +293 -258
  13. package/dist/lib/browser/react-surface-UJOSZGP5.mjs.map +7 -0
  14. package/dist/types/src/capabilities/app-graph-builder.d.ts +2 -179
  15. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  16. package/dist/types/src/capabilities/index.d.ts +1 -177
  17. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  18. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  19. package/dist/types/src/components/SearchDialog.d.ts.map +1 -1
  20. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +1 -1
  21. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +1 -1
  22. package/dist/types/src/hooks/sync.d.ts.map +1 -1
  23. package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
  24. package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
  25. package/dist/types/src/hooks/useWebSearch.d.ts +1 -1
  26. package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
  27. package/dist/types/src/search/exa.d.ts +4 -4
  28. package/dist/types/src/search/exa.d.ts.map +1 -1
  29. package/dist/types/src/types/action.d.ts +5 -5
  30. package/dist/types/src/types/action.d.ts.map +1 -1
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +35 -28
  33. package/src/capabilities/app-graph-builder.ts +59 -41
  34. package/src/capabilities/react-surface.tsx +4 -7
  35. package/src/components/SearchDialog.tsx +8 -7
  36. package/src/components/SearchMain.tsx +4 -4
  37. package/src/components/SearchResults/SearchResults.tsx +1 -1
  38. package/src/components/Searchbar/Searchbar.tsx +2 -2
  39. package/src/hooks/sync.test.ts +4 -4
  40. package/src/hooks/sync.ts +8 -7
  41. package/src/hooks/useSearchResults.ts +2 -2
  42. package/src/hooks/useWebSearch.ts +6 -8
  43. package/src/meta.ts +2 -2
  44. package/src/search/exa.test.ts +7 -8
  45. package/src/search/exa.ts +32 -26
  46. package/src/types/action.tsx +4 -4
  47. package/dist/lib/browser/app-graph-builder-RHZORTY2.mjs +0 -76
  48. package/dist/lib/browser/app-graph-builder-RHZORTY2.mjs.map +0 -7
  49. package/dist/lib/browser/chunk-LXHJVTYG.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-NFZSXZMP.mjs.map +0 -7
  51. package/dist/lib/browser/react-surface-QBBLEI2Q.mjs.map +0 -7
  52. /package/dist/lib/browser/{intent-resolver-G76A35DX.mjs.map → intent-resolver-RWC63UGI.mjs.map} +0 -0
@@ -4,151 +4,173 @@ import {
4
4
  useGlobalSearch,
5
5
  useGlobalSearchResults,
6
6
  useSearchResults
7
- } from "./chunk-NFZSXZMP.mjs";
7
+ } from "./chunk-CKQAVN5U.mjs";
8
8
  import {
9
9
  SEARCH_PLUGIN,
10
10
  SEARCH_RESULT
11
- } from "./chunk-J6YWSQTW.mjs";
11
+ } from "./chunk-ARZYMSFF.mjs";
12
12
 
13
13
  // packages/plugins/plugin-search/src/capabilities/react-surface.tsx
14
14
  import React5 from "react";
15
- import { Capabilities, contributes, createSurface, useLayout as useLayout2, useAppGraph as useAppGraph2 } from "@dxos/app-framework";
16
- import { getActiveSpace } from "@dxos/plugin-space";
15
+ import { Capabilities, contributes, createSurface } from "@dxos/app-framework";
16
+ import { useActiveSpace } from "@dxos/plugin-space";
17
17
  import { isSpace } from "@dxos/react-client/echo";
18
18
 
19
19
  // packages/plugins/plugin-search/src/components/Searchbar/Searchbar.tsx
20
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
20
21
  import { MagnifyingGlass } from "@phosphor-icons/react";
21
22
  import React, { useEffect, useRef, useState } from "react";
22
23
  import { Input } from "@dxos/react-ui";
23
24
  import { getSize, mx } from "@dxos/react-ui-theme";
24
25
  var Searchbar = ({ classes, variant, placeholder, value, onChange, onSubmit }) => {
25
- const inputRef = useRef(null);
26
- const [text, setText] = useState(value);
27
- useEffect(() => {
28
- setText(value);
29
- }, [
30
- value
31
- ]);
32
- const handleChange = (text2) => {
33
- setText(text2);
34
- onChange?.(text2);
35
- };
36
- const handleReset = () => {
37
- handleChange(void 0);
38
- inputRef.current?.focus();
39
- };
40
- const handleKeyDown = (event) => {
41
- switch (event.key) {
42
- case "Enter":
43
- onSubmit?.(text);
44
- break;
45
- case "Escape":
46
- handleReset();
47
- break;
48
- }
49
- };
50
- return /* @__PURE__ */ React.createElement("div", {
51
- className: "flex shrink-0w-full items-center pli-1 pbs-1"
52
- }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
53
- ref: inputRef,
54
- placeholder,
55
- variant,
56
- value: text ?? "",
57
- classNames: mx("pl-3 pr-10", classes?.input),
58
- onChange: ({ target }) => handleChange(target.value),
59
- onKeyDown: handleKeyDown
60
- }), /* @__PURE__ */ React.createElement("div", {
61
- role: "button",
62
- className: "-ml-7 p-0 cursor-pointer",
63
- onClick: handleReset
64
- }, /* @__PURE__ */ React.createElement(MagnifyingGlass, {
65
- className: getSize(5)
66
- }))));
26
+ var _effect = _useSignals();
27
+ try {
28
+ const inputRef = useRef(null);
29
+ const [text, setText] = useState(value);
30
+ useEffect(() => {
31
+ setText(value);
32
+ }, [
33
+ value
34
+ ]);
35
+ const handleChange = (text2) => {
36
+ setText(text2);
37
+ onChange?.(text2);
38
+ };
39
+ const handleReset = () => {
40
+ handleChange(void 0);
41
+ inputRef.current?.focus();
42
+ };
43
+ const handleKeyDown = (event) => {
44
+ switch (event.key) {
45
+ case "Enter":
46
+ onSubmit?.(text);
47
+ break;
48
+ case "Escape":
49
+ handleReset();
50
+ break;
51
+ }
52
+ };
53
+ return /* @__PURE__ */ React.createElement("div", {
54
+ className: "flex shrink-0w-full items-center pli-1 pbs-1"
55
+ }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
56
+ ref: inputRef,
57
+ placeholder,
58
+ variant,
59
+ value: text ?? "",
60
+ classNames: mx("pl-3 pr-10", classes?.input),
61
+ onChange: ({ target }) => handleChange(target.value),
62
+ onKeyDown: handleKeyDown
63
+ }), /* @__PURE__ */ React.createElement("div", {
64
+ role: "button",
65
+ className: "-ml-7 p-0 cursor-pointer",
66
+ onClick: handleReset
67
+ }, /* @__PURE__ */ React.createElement(MagnifyingGlass, {
68
+ className: getSize(5)
69
+ }))));
70
+ } finally {
71
+ _effect.f();
72
+ }
67
73
  };
68
74
 
69
75
  // packages/plugins/plugin-search/src/components/SearchMain.tsx
76
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
70
77
  import React3, { useState as useState3 } from "react";
71
78
  import { log as log3 } from "@dxos/log";
72
79
  import { useClient } from "@dxos/react-client";
73
80
  import { Filter, useQuery } from "@dxos/react-client/echo";
74
81
  import { useTranslation } from "@dxos/react-ui";
75
- import { groupSurface, mx as mx3 } from "@dxos/react-ui-theme";
82
+ import { activeSurface, mx as mx3 } from "@dxos/react-ui-theme";
76
83
 
77
84
  // packages/plugins/plugin-search/src/components/SearchResults/SearchResults.tsx
85
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
78
86
  import React2, { forwardRef } from "react";
79
87
  import { Card } from "@dxos/react-ui-card";
80
88
  import { ghostHover, mx as mx2 } from "@dxos/react-ui-theme";
81
89
  var Snippet = ({ text, match }) => {
82
- let content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, text);
83
- if (match) {
84
- const result = text.match(match);
85
- if (result?.index !== void 0) {
86
- const maxOffset = 16;
87
- let before = text.slice(0, result.index);
88
- if (before.length > maxOffset) {
89
- const idx = before.indexOf(" ", result.index - maxOffset);
90
- before = "\u2026 " + before.slice(idx);
90
+ var _effect = _useSignals2();
91
+ try {
92
+ let content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, text);
93
+ if (match) {
94
+ const result = text.match(match);
95
+ if (result?.index !== void 0) {
96
+ const maxOffset = 16;
97
+ let before = text.slice(0, result.index);
98
+ if (before.length > maxOffset) {
99
+ const idx = before.indexOf(" ", result.index - maxOffset);
100
+ before = "\u2026 " + before.slice(idx);
101
+ }
102
+ const after = text.slice(result.index + result[0].length);
103
+ content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, before, /* @__PURE__ */ React2.createElement("span", {
104
+ className: "text-blue-500"
105
+ }, result[0]), after);
91
106
  }
92
- const after = text.slice(result.index + result[0].length);
93
- content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, before, /* @__PURE__ */ React2.createElement("span", {
94
- className: "text-blue-500"
95
- }, result[0]), after);
96
107
  }
108
+ return /* @__PURE__ */ React2.createElement("span", {
109
+ className: "text-xs mb-1 line-clamp-3 text-neutral-300"
110
+ }, content);
111
+ } finally {
112
+ _effect.f();
97
113
  }
98
- return /* @__PURE__ */ React2.createElement("span", {
99
- className: "text-xs mb-1 line-clamp-3 text-neutral-300"
100
- }, content);
101
114
  };
102
115
  var SearchItem = /* @__PURE__ */ forwardRef((item, forwardRef3) => {
103
- const { id, objectType, label, snippet, match, selected, onSelect } = item;
104
- const Icon2 = void 0;
105
- return /* @__PURE__ */ React2.createElement(Card.Root, {
106
- ref: forwardRef3,
107
- classNames: mx2("mx-2 mt-2 cursor-pointer", selected && "!bg-groupSurface", ghostHover),
108
- onClick: () => onSelect?.(id)
109
- }, objectType && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", {
110
- className: "text-xs text-neutral-400 ml-4"
111
- }, objectType)), /* @__PURE__ */ React2.createElement(Card.Header, null, /* @__PURE__ */ React2.createElement(Card.Title, {
112
- title: label ?? "Untitled"
113
- }), Icon2 && /* @__PURE__ */ React2.createElement(Card.Endcap, {
114
- Icon: Icon2
115
- })), snippet && /* @__PURE__ */ React2.createElement(Card.Body, {
116
- gutter: true
117
- }, /* @__PURE__ */ React2.createElement(Snippet, {
118
- text: snippet,
119
- match
120
- })));
116
+ var _effect = _useSignals2();
117
+ try {
118
+ const { id, objectType, label, snippet, match, selected, onSelect } = item;
119
+ const Icon2 = void 0;
120
+ return /* @__PURE__ */ React2.createElement(Card.Root, {
121
+ ref: forwardRef3,
122
+ classNames: mx2("mx-2 mt-2 cursor-pointer", selected && "!bg-activeSurface", ghostHover),
123
+ onClick: () => onSelect?.(id)
124
+ }, objectType && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", {
125
+ className: "text-xs text-neutral-400 ml-4"
126
+ }, objectType)), /* @__PURE__ */ React2.createElement(Card.Header, null, /* @__PURE__ */ React2.createElement(Card.Title, {
127
+ title: label ?? "Untitled"
128
+ }), Icon2 && /* @__PURE__ */ React2.createElement(Card.Endcap, {
129
+ Icon: Icon2
130
+ })), snippet && /* @__PURE__ */ React2.createElement(Card.Body, {
131
+ gutter: true
132
+ }, /* @__PURE__ */ React2.createElement(Snippet, {
133
+ text: snippet,
134
+ match
135
+ })));
136
+ } finally {
137
+ _effect.f();
138
+ }
121
139
  });
122
140
  var SearchResults = ({ items, selected, onSelect }) => {
123
- return /* @__PURE__ */ React2.createElement("div", {
124
- className: "flex flex-col grow overflow-y-auto"
125
- }, /* @__PURE__ */ React2.createElement("div", {
126
- className: "flex flex-col"
127
- }, items.map((item) => /* @__PURE__ */ React2.createElement(SearchItem, {
128
- key: item.id,
129
- type: SEARCH_RESULT,
130
- ...item,
131
- onSelect,
132
- selected: selected === item.id
133
- }))));
141
+ var _effect = _useSignals2();
142
+ try {
143
+ return /* @__PURE__ */ React2.createElement("div", {
144
+ className: "flex flex-col grow overflow-y-auto"
145
+ }, /* @__PURE__ */ React2.createElement("div", {
146
+ className: "flex flex-col"
147
+ }, items.map((item) => /* @__PURE__ */ React2.createElement(SearchItem, {
148
+ key: item.id,
149
+ type: SEARCH_RESULT,
150
+ ...item,
151
+ onSelect,
152
+ selected: selected === item.id
153
+ }))));
154
+ } finally {
155
+ _effect.f();
156
+ }
134
157
  };
135
158
 
136
159
  // packages/plugins/plugin-search/src/hooks/useWebSearch.ts
137
160
  import { useState as useState2 } from "react";
138
- import { AIServiceEdgeClient } from "@dxos/assistant";
139
- import { AI_SERVICE_ENDPOINT } from "@dxos/assistant/testing";
161
+ import { AIServiceEdgeClient } from "@dxos/ai";
162
+ import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from "@dxos/ai/testing";
140
163
  import { getSchema, getTypename } from "@dxos/echo-schema";
141
164
  import { log as log2 } from "@dxos/log";
142
165
  import { getIconAnnotation } from "@dxos/schema";
143
166
  import { Testing } from "@dxos/schema/testing";
144
167
 
145
168
  // packages/plugins/plugin-search/src/search/exa.ts
146
- import { Option, SchemaAST as AST } from "effect";
169
+ import { Option, Schema, SchemaAST } from "effect";
147
170
  import Exa from "exa-js";
148
- import { defineTool, Message } from "@dxos/artifact";
149
- import { MixedStreamParser } from "@dxos/assistant";
171
+ import { Message, MixedStreamParser, createTool } from "@dxos/ai";
150
172
  import { isEncodedReference } from "@dxos/echo-protocol";
151
- import { createStatic, getTypeAnnotation, ObjectId, ReferenceAnnotationId, S } from "@dxos/echo-schema";
173
+ import { create, getTypeAnnotation, ObjectId, ReferenceAnnotationId } from "@dxos/echo-schema";
152
174
  import { mapAst } from "@dxos/effect";
153
175
  import { assertArgument, failedInvariant } from "@dxos/invariant";
154
176
  import { log } from "@dxos/log";
@@ -163,7 +185,7 @@ var search = async (options) => {
163
185
  additionalSearchTerms: contextSearchTerms
164
186
  }, {
165
187
  F: __dxlog_file,
166
- L: 47,
188
+ L: 53,
167
189
  S: void 0,
168
190
  C: (f, a) => f(...a)
169
191
  });
@@ -182,7 +204,7 @@ var search = async (options) => {
182
204
  context
183
205
  }, {
184
206
  F: __dxlog_file,
185
- L: 63,
207
+ L: 69,
186
208
  S: void 0,
187
209
  C: (f, a) => f(...a)
188
210
  });
@@ -201,7 +223,7 @@ var search = async (options) => {
201
223
  model: "@anthropic/claude-3-5-haiku-20241022",
202
224
  systemPrompt,
203
225
  history: [
204
- createStatic(Message, {
226
+ create(Message, {
205
227
  role: "user",
206
228
  content: context.results.map((r) => ({
207
229
  type: "text",
@@ -211,11 +233,11 @@ ${r.text}`
211
233
  }))
212
234
  })
213
235
  ],
214
- schema: S.Struct({
236
+ schema: Schema.Struct({
215
237
  ...Object.fromEntries(mappedSchema.map((schema, index) => [
216
238
  `objects_${index}`,
217
- S.Array(schema).annotations({
218
- description: `The objects to answer the query of type ${getTypeAnnotation(schema)?.typename ?? AST.getIdentifierAnnotation(schema.ast).pipe(Option.getOrNull)}`
239
+ Schema.Array(schema).annotations({
240
+ description: `The objects to answer the query of type ${getTypeAnnotation(schema)?.typename ?? SchemaAST.getIdentifierAnnotation(schema.ast).pipe(Option.getOrNull)}`
219
241
  })
220
242
  ]))
221
243
  })
@@ -225,7 +247,7 @@ ${r.text}`
225
247
  result
226
248
  }, {
227
249
  F: __dxlog_file,
228
- L: 107,
250
+ L: 113,
229
251
  S: void 0,
230
252
  C: (f, a) => f(...a)
231
253
  });
@@ -260,11 +282,11 @@ var DATA_EXTRACTION_INSTRUCTIONS = `
260
282
  - Prefer using ids when available.
261
283
  `;
262
284
  var getStructuredOutput = async (aiService, request) => {
263
- const result = await new MixedStreamParser().parse(await aiService.exec({
285
+ const result = await new MixedStreamParser().parse(await aiService.execStream({
264
286
  ...request,
265
287
  systemPrompt: request.systemPrompt + "\nDo not output anything other then the tool call. Call the submit_result tool with the result.",
266
288
  tools: [
267
- defineTool("submit_result", {
289
+ createTool("submit_result", {
268
290
  name: "submit_result",
269
291
  description: "Submit the result",
270
292
  schema: request.schema,
@@ -284,7 +306,7 @@ var getSearchTerms = async (aiService, context) => {
284
306
  Prefer own names of people, companies, and projects, technologies, and other entities.
285
307
  `,
286
308
  history: [
287
- createStatic(Message, {
309
+ create(Message, {
288
310
  role: "user",
289
311
  content: [
290
312
  {
@@ -296,8 +318,8 @@ ${context}`
296
318
  ]
297
319
  })
298
320
  ],
299
- schema: S.Struct({
300
- terms: S.Array(S.String).annotations({
321
+ schema: Schema.Struct({
322
+ terms: Schema.Array(Schema.String).annotations({
301
323
  description: "The search terms to use to find the objects. 0-10 terms."
302
324
  })
303
325
  })
@@ -326,27 +348,26 @@ var sanitizeObjects = (entries) => {
326
348
  }
327
349
  return recurse(value);
328
350
  });
329
- return createStatic(entry.schema, data);
351
+ return create(entry.schema, data);
330
352
  });
331
353
  };
332
- var SoftRef = S.Struct({
333
- "/": S.String
354
+ var SoftRef = Schema.Struct({
355
+ "/": Schema.String
334
356
  }).annotations({
335
357
  description: "Reference to another object."
336
358
  });
337
359
  var mapSchemaRefs = (schema) => {
338
360
  const go = (ast) => {
339
- if (AST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome)) {
361
+ if (SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome)) {
340
362
  return SoftRef.ast;
341
363
  }
342
364
  return mapAst(ast, go);
343
365
  };
344
- return S.make(mapAst(schema.ast, go));
366
+ return Schema.make(mapAst(schema.ast, go));
345
367
  };
346
368
 
347
369
  // packages/plugins/plugin-search/src/hooks/useWebSearch.ts
348
370
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-search/src/hooks/useWebSearch.ts";
349
- var EXA_API_KEY = "9c7e17ff-0c85-4cd5-827a-8b489f139e03";
350
371
  var useWebSearch = ({ query, context }) => {
351
372
  const aiService = new AIServiceEdgeClient({
352
373
  endpoint: AI_SERVICE_ENDPOINT.REMOTE
@@ -361,7 +382,7 @@ var useWebSearch = ({ query, context }) => {
361
382
  context
362
383
  }, {
363
384
  F: __dxlog_file2,
364
- L: 33,
385
+ L: 30,
365
386
  S: void 0,
366
387
  C: (f, a) => f(...a)
367
388
  });
@@ -370,7 +391,7 @@ var useWebSearch = ({ query, context }) => {
370
391
  context,
371
392
  schema: [
372
393
  Testing.Project,
373
- Testing.Org,
394
+ Testing.Organization,
374
395
  Testing.Contact
375
396
  ],
376
397
  aiService,
@@ -411,54 +432,61 @@ var useWebSearch = ({ query, context }) => {
411
432
  // packages/plugins/plugin-search/src/components/SearchMain.tsx
412
433
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-search/src/components/SearchMain.tsx";
413
434
  var SearchMain = ({ classNames, space }) => {
414
- const { t } = useTranslation(SEARCH_PLUGIN);
415
- const client = useClient();
416
- const { setMatch } = useGlobalSearch();
417
- const [query, setQuery] = useState3();
418
- const allSpaces = false;
419
- const objects = useQuery(allSpaces ? client.spaces : space, Filter.all());
420
- const results = useGlobalSearchResults(objects);
421
- const { runSearch, results: webResults, isLoading } = useWebSearch({
422
- query
423
- });
424
- const [selected, setSelected] = useState3();
425
- const handleSelect = (id) => {
426
- setSelected((selected2) => selected2 === id ? void 0 : id);
427
- };
428
- const allResults = [
429
- ...results,
430
- ...webResults
431
- ];
432
- log3.info("results", {
433
- results,
434
- webResults
435
- }, {
436
- F: __dxlog_file3,
437
- L: 47,
438
- S: void 0,
439
- C: (f, a) => f(...a)
440
- });
441
- return /* @__PURE__ */ React3.createElement("div", {
442
- className: mx3("flex flex-col grow h-full overflow-hidden", classNames)
443
- }, /* @__PURE__ */ React3.createElement(Searchbar, {
444
- placeholder: t("search placeholder"),
445
- onChange: (text) => {
446
- setQuery(text);
447
- setMatch?.(text);
448
- },
449
- onSubmit: runSearch
450
- }), isLoading && /* @__PURE__ */ React3.createElement("div", {
451
- className: mx3("flex flex-col grow overflow-hidden", groupSurface)
452
- }, "Loading..."), allResults.length > 0 && /* @__PURE__ */ React3.createElement("div", {
453
- className: mx3("flex flex-col grow overflow-hidden", groupSurface)
454
- }, /* @__PURE__ */ React3.createElement(SearchResults, {
455
- items: allResults,
456
- selected,
457
- onSelect: handleSelect
458
- })));
435
+ var _effect = _useSignals3();
436
+ try {
437
+ const { t } = useTranslation(SEARCH_PLUGIN);
438
+ const client = useClient();
439
+ const { setMatch } = useGlobalSearch();
440
+ const [query, setQuery] = useState3();
441
+ const allSpaces = false;
442
+ const objects = useQuery(allSpaces ? client.spaces : space, Filter.everything());
443
+ const results = useGlobalSearchResults(objects);
444
+ const { runSearch, results: webResults, isLoading } = useWebSearch({
445
+ query
446
+ });
447
+ const [selected, setSelected] = useState3();
448
+ const handleSelect = (id) => {
449
+ setSelected((selected2) => selected2 === id ? void 0 : id);
450
+ };
451
+ const allResults = [
452
+ ...results,
453
+ ...webResults
454
+ ];
455
+ log3.info("results", {
456
+ results,
457
+ webResults
458
+ }, {
459
+ F: __dxlog_file3,
460
+ L: 47,
461
+ S: void 0,
462
+ C: (f, a) => f(...a)
463
+ });
464
+ return /* @__PURE__ */ React3.createElement("div", {
465
+ className: mx3("flex flex-col grow h-full overflow-hidden", classNames)
466
+ }, /* @__PURE__ */ React3.createElement(Searchbar, {
467
+ placeholder: t("search placeholder"),
468
+ onChange: (text) => {
469
+ setQuery(text);
470
+ setMatch?.(text);
471
+ },
472
+ onSubmit: runSearch
473
+ }), isLoading && /* @__PURE__ */ React3.createElement("div", {
474
+ className: mx3("flex flex-col grow overflow-hidden", activeSurface)
475
+ }, "Loading..."), allResults.length > 0 && /* @__PURE__ */ React3.createElement("div", {
476
+ className: mx3("flex flex-col grow overflow-hidden", activeSurface)
477
+ }, /* @__PURE__ */ React3.createElement(SearchResults, {
478
+ items: allResults,
479
+ selected,
480
+ onSelect: handleSelect
481
+ })));
482
+ } finally {
483
+ _effect.f();
484
+ }
459
485
  };
460
486
 
461
487
  // packages/plugins/plugin-search/src/components/SearchDialog.tsx
488
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
489
+ import { Option as Option2 } from "effect";
462
490
  import React4, { forwardRef as forwardRef2, useCallback, useState as useState4 } from "react";
463
491
  import { LayoutAction, createIntent, useAppGraph, useIntentDispatcher, useLayout } from "@dxos/app-framework";
464
492
  import { useClient as useClient2 } from "@dxos/react-client";
@@ -468,100 +496,110 @@ import { SearchList } from "@dxos/react-ui-searchlist";
468
496
  import { descriptionText, mx as mx4 } from "@dxos/react-ui-theme";
469
497
  var SEARCH_DIALOG = `${SEARCH_PLUGIN}/SearchDialog`;
470
498
  var SearchListResult = /* @__PURE__ */ forwardRef2(({ node, onSelect }, forwardedRef) => {
471
- const { t } = useTranslation2(SEARCH_PLUGIN);
472
- const label = toLocalizedString(node?.properties.label ?? "never", t);
473
- return /* @__PURE__ */ React4.createElement(SearchList.Item, {
474
- value: label,
475
- key: node.id,
476
- classNames: "flex gap-2 items-center pli-2",
477
- onSelect: () => onSelect?.(node.id),
478
- ref: forwardedRef
479
- }, /* @__PURE__ */ React4.createElement(Icon, {
480
- size: 5,
481
- icon: node?.properties.icon
482
- }), /* @__PURE__ */ React4.createElement("span", {
483
- className: "is-0 grow truncate"
484
- }, label));
499
+ var _effect = _useSignals4();
500
+ try {
501
+ const { t } = useTranslation2(SEARCH_PLUGIN);
502
+ const label = toLocalizedString(node?.properties.label ?? "never", t);
503
+ return /* @__PURE__ */ React4.createElement(SearchList.Item, {
504
+ value: label,
505
+ key: node.id,
506
+ classNames: "flex gap-2 items-center pli-2",
507
+ onSelect: () => onSelect?.(node.id),
508
+ ref: forwardedRef
509
+ }, /* @__PURE__ */ React4.createElement(Icon, {
510
+ size: 5,
511
+ icon: node?.properties.icon
512
+ }), /* @__PURE__ */ React4.createElement("span", {
513
+ className: "is-0 grow truncate"
514
+ }, label));
515
+ } finally {
516
+ _effect.f();
517
+ }
485
518
  });
486
519
  var SearchDialog = ({ pivotId }) => {
487
- const { t } = useTranslation2(SEARCH_PLUGIN);
488
- const { graph } = useAppGraph();
489
- const layout = useLayout();
490
- const closed = (Array.isArray(layout.inactive) ? layout.inactive : [
491
- layout.inactive
492
- ]).map((id) => graph?.findNode(id)).filter(Boolean);
493
- const [queryString, setQueryString] = useState4("");
494
- const client = useClient2();
495
- const dangerouslyLoadAllObjects = useQuery2(client.spaces, Filter2.all());
496
- const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
497
- const resultObjects = Array.from(results.keys());
498
- const { dispatchPromise: dispatch } = useIntentDispatcher();
499
- const handleSelect = useCallback(async (nodeId) => {
500
- await dispatch(createIntent(LayoutAction.UpdateDialog, {
501
- part: "dialog",
502
- options: {
503
- state: false
504
- }
505
- }));
506
- const index = layout.active.findIndex((id) => id === nodeId);
507
- if (index !== -1) {
508
- await dispatch(createIntent(LayoutAction.ScrollIntoView, {
509
- part: "current",
510
- subject: nodeId
511
- }));
512
- } else {
513
- await dispatch(createIntent(LayoutAction.Open, {
514
- part: "main",
515
- subject: [
516
- nodeId
517
- ],
520
+ var _effect = _useSignals4();
521
+ try {
522
+ const { t } = useTranslation2(SEARCH_PLUGIN);
523
+ const { graph } = useAppGraph();
524
+ const layout = useLayout();
525
+ const closed = (Array.isArray(layout.inactive) ? layout.inactive : [
526
+ layout.inactive
527
+ ]).map((id) => graph?.getNode(id)).filter(Boolean);
528
+ const [queryString, setQueryString] = useState4("");
529
+ const client = useClient2();
530
+ const dangerouslyLoadAllObjects = useQuery2(client.spaces, Filter2.everything());
531
+ const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
532
+ const resultObjects = Array.from(results.keys());
533
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
534
+ const handleSelect = useCallback(async (nodeId) => {
535
+ await dispatch(createIntent(LayoutAction.UpdateDialog, {
536
+ part: "dialog",
518
537
  options: {
519
- pivotId,
520
- positioning: "end"
538
+ state: false
521
539
  }
522
540
  }));
523
- }
524
- }, [
525
- pivotId,
526
- dispatch,
527
- layout
528
- ]);
529
- return /* @__PURE__ */ React4.createElement(Dialog.Content, {
530
- classNames: [
531
- "md:max-is-[24rem] overflow-hidden mbs-12"
532
- ]
533
- }, /* @__PURE__ */ React4.createElement(Dialog.Title, null, t("search dialog title")), /* @__PURE__ */ React4.createElement(SearchList.Root, {
534
- label: t("search placeholder"),
535
- classNames: "flex flex-col grow overflow-hidden my-2"
536
- }, /* @__PURE__ */ React4.createElement(SearchList.Input, {
537
- value: queryString,
538
- onValueChange: (nextValue) => {
539
- setQueryString(nextValue);
540
- },
541
- placeholder: t("search placeholder"),
542
- classNames: "px-1 my-2"
543
- }), /* @__PURE__ */ React4.createElement(SearchList.Content, {
544
- classNames: "max-bs-[24rem] overflow-auto"
545
- }, queryString.length > 0 ? resultObjects.length > 0 ? resultObjects.map((object) => graph?.findNode(fullyQualifiedId(object))).filter(Boolean).map((node) => /* @__PURE__ */ React4.createElement(SearchListResult, {
546
- key: node.id,
547
- node,
548
- onSelect: handleSelect
549
- })) : /* @__PURE__ */ React4.createElement("p", {
550
- className: "pli-1"
551
- }, t(pending ? "pending results message" : "empty results message")) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, closed.length > 0 && /* @__PURE__ */ React4.createElement("h2", {
552
- className: mx4("mlb-1", descriptionText)
553
- }, t("recently closed heading")), closed.map((node) => /* @__PURE__ */ React4.createElement(SearchListResult, {
554
- key: node.id,
555
- node,
556
- onSelect: handleSelect
557
- }))))), /* @__PURE__ */ React4.createElement(Dialog.Close, {
558
- asChild: true
559
- }, /* @__PURE__ */ React4.createElement(Button, {
560
- variant: "primary",
561
- classNames: "mbs-2"
562
- }, t("close label", {
563
- ns: "os"
564
- }))));
541
+ const index = layout.active.findIndex((id) => id === nodeId);
542
+ if (index !== -1) {
543
+ await dispatch(createIntent(LayoutAction.ScrollIntoView, {
544
+ part: "current",
545
+ subject: nodeId
546
+ }));
547
+ } else {
548
+ await dispatch(createIntent(LayoutAction.Open, {
549
+ part: "main",
550
+ subject: [
551
+ nodeId
552
+ ],
553
+ options: {
554
+ pivotId,
555
+ positioning: "end"
556
+ }
557
+ }));
558
+ }
559
+ }, [
560
+ pivotId,
561
+ dispatch,
562
+ layout
563
+ ]);
564
+ return /* @__PURE__ */ React4.createElement(Dialog.Content, {
565
+ classNames: [
566
+ "md:max-is-[24rem] overflow-hidden mbs-12"
567
+ ]
568
+ }, /* @__PURE__ */ React4.createElement(Dialog.Title, null, t("search dialog title")), /* @__PURE__ */ React4.createElement(SearchList.Root, {
569
+ label: t("search placeholder"),
570
+ classNames: "flex flex-col grow overflow-hidden my-2"
571
+ }, /* @__PURE__ */ React4.createElement(SearchList.Input, {
572
+ value: queryString,
573
+ onValueChange: (nextValue) => {
574
+ setQueryString(nextValue);
575
+ },
576
+ placeholder: t("search placeholder"),
577
+ classNames: "px-1 my-2"
578
+ }), /* @__PURE__ */ React4.createElement(SearchList.Content, {
579
+ classNames: "max-bs-[24rem] overflow-auto"
580
+ }, queryString.length > 0 ? resultObjects.length > 0 ? resultObjects.map((object) => graph.getNode(fullyQualifiedId(object))).filter(Option2.isSome).map((node) => /* @__PURE__ */ React4.createElement(SearchListResult, {
581
+ key: node.value.id,
582
+ node: node.value,
583
+ onSelect: handleSelect
584
+ })) : /* @__PURE__ */ React4.createElement("p", {
585
+ className: "pli-1"
586
+ }, t(pending ? "pending results message" : "empty results message")) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, closed.length > 0 && /* @__PURE__ */ React4.createElement("h2", {
587
+ className: mx4("mlb-1", descriptionText)
588
+ }, t("recently closed heading")), closed.filter(Option2.isSome).map((node) => /* @__PURE__ */ React4.createElement(SearchListResult, {
589
+ key: node.value.id,
590
+ node: node.value,
591
+ onSelect: handleSelect
592
+ }))))), /* @__PURE__ */ React4.createElement(Dialog.Close, {
593
+ asChild: true
594
+ }, /* @__PURE__ */ React4.createElement(Button, {
595
+ variant: "primary",
596
+ classNames: "mbs-2"
597
+ }, t("close label", {
598
+ ns: "os"
599
+ }))));
600
+ } finally {
601
+ _effect.f();
602
+ }
565
603
  };
566
604
 
567
605
  // packages/plugins/plugin-search/src/capabilities/react-surface.tsx
@@ -573,13 +611,10 @@ var react_surface_default = () => contributes(Capabilities.ReactSurface, [
573
611
  component: ({ data }) => /* @__PURE__ */ React5.createElement(SearchContextProvider, null, /* @__PURE__ */ React5.createElement(SearchDialog, data.props))
574
612
  }),
575
613
  createSurface({
576
- // id: `${SEARCH_DIALOG}/search-input`,
577
- id: "search-input",
614
+ id: `${SEARCH_DIALOG}/search-input`,
578
615
  role: "search-input",
579
616
  component: () => {
580
- const layout = useLayout2();
581
- const { graph } = useAppGraph2();
582
- const space = graph ? getActiveSpace(graph, layout.active[0]) : void 0;
617
+ const space = useActiveSpace();
583
618
  if (!space) {
584
619
  return null;
585
620
  }
@@ -606,4 +641,4 @@ var react_surface_default = () => contributes(Capabilities.ReactSurface, [
606
641
  export {
607
642
  react_surface_default as default
608
643
  };
609
- //# sourceMappingURL=react-surface-QBBLEI2Q.mjs.map
644
+ //# sourceMappingURL=react-surface-UJOSZGP5.mjs.map