@dxos/assistant 0.8.4-main.3f58842 → 0.8.4-main.406dc2a

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 (168) hide show
  1. package/dist/lib/browser/chunk-CWGVG235.mjs +380 -0
  2. package/dist/lib/browser/chunk-CWGVG235.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-UB26N5UF.mjs +89 -0
  4. package/dist/lib/browser/chunk-UB26N5UF.mjs.map +7 -0
  5. package/dist/lib/browser/extraction/index.mjs +272 -0
  6. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +747 -1645
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +13 -0
  11. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +91 -0
  13. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +382 -0
  15. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +7 -0
  16. package/dist/lib/node-esm/extraction/index.mjs +273 -0
  17. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +746 -1645
  19. package/dist/lib/node-esm/index.mjs.map +4 -4
  20. package/dist/lib/node-esm/meta.json +1 -1
  21. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +14 -0
  22. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +7 -0
  23. package/dist/types/src/conversation/context.d.ts +103 -0
  24. package/dist/types/src/conversation/context.d.ts.map +1 -0
  25. package/dist/types/src/conversation/conversation.d.ts +28 -22
  26. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  27. package/dist/types/src/conversation/index.d.ts +1 -0
  28. package/dist/types/src/conversation/index.d.ts.map +1 -1
  29. package/dist/types/src/diff.d.ts +15 -0
  30. package/dist/types/src/diff.d.ts.map +1 -0
  31. package/dist/types/src/diff.test.d.ts +2 -0
  32. package/dist/types/src/diff.test.d.ts.map +1 -0
  33. package/dist/types/src/errors.d.ts +46 -9
  34. package/dist/types/src/errors.d.ts.map +1 -1
  35. package/dist/types/src/execution-graph.d.ts +82 -0
  36. package/dist/types/src/execution-graph.d.ts.map +1 -0
  37. package/dist/types/src/execution-graph.test.d.ts +2 -0
  38. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  39. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +1 -1
  40. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  41. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +95 -56
  42. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  43. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  44. package/dist/types/src/extraction/extraction.d.ts +252 -218
  45. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  46. package/dist/types/src/extraction/quotes.d.ts +1 -1
  47. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  48. package/dist/types/src/functions/services.d.ts +17 -4
  49. package/dist/types/src/functions/services.d.ts.map +1 -1
  50. package/dist/types/src/index.d.ts +3 -3
  51. package/dist/types/src/index.d.ts.map +1 -1
  52. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  53. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  54. package/dist/types/src/session/error-handling.d.ts +4 -0
  55. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  56. package/dist/types/src/session/format.d.ts +184 -0
  57. package/dist/types/src/session/format.d.ts.map +1 -0
  58. package/dist/types/src/session/format.test.d.ts +2 -0
  59. package/dist/types/src/session/format.test.d.ts.map +1 -0
  60. package/dist/types/src/session/index.d.ts +3 -0
  61. package/dist/types/src/session/index.d.ts.map +1 -1
  62. package/dist/types/src/session/observer.d.ts +22 -0
  63. package/dist/types/src/session/observer.d.ts.map +1 -0
  64. package/dist/types/src/session/session.d.ts +27 -236
  65. package/dist/types/src/session/session.d.ts.map +1 -1
  66. package/dist/types/src/session/toolkit.d.ts +15 -0
  67. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  68. package/dist/types/src/session/version-pin.d.ts +3 -3
  69. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  70. package/dist/types/src/templates/index.d.ts +1 -1
  71. package/dist/types/src/templates/system.d.ts +18 -0
  72. package/dist/types/src/templates/system.d.ts.map +1 -0
  73. package/dist/types/src/{types.d.ts → types/artifact.d.ts} +6 -3
  74. package/dist/types/src/types/artifact.d.ts.map +1 -0
  75. package/dist/types/src/types/index.d.ts +2 -0
  76. package/dist/types/src/types/index.d.ts.map +1 -0
  77. package/dist/types/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +44 -32
  79. package/src/conversation/context.ts +186 -0
  80. package/src/conversation/conversation.ts +89 -53
  81. package/src/conversation/index.ts +1 -0
  82. package/src/diff.test.ts +43 -0
  83. package/src/diff.ts +79 -0
  84. package/src/errors.ts +6 -1
  85. package/src/execution-graph.test.ts +738 -0
  86. package/src/execution-graph.ts +500 -0
  87. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +13 -24
  88. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +13 -11
  89. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +9 -9
  90. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +15 -8
  91. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -1
  92. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +2 -0
  93. package/src/extraction/extraction.ts +2 -2
  94. package/src/extraction/quotes.test.ts +3 -3
  95. package/src/extraction/quotes.ts +4 -4
  96. package/src/functions/services.ts +114 -95
  97. package/src/index.ts +3 -3
  98. package/src/session/artifact-diff.ts +41 -0
  99. package/src/session/error-handling.ts +41 -0
  100. package/src/session/format.test.ts +60 -0
  101. package/src/session/format.ts +142 -0
  102. package/src/session/index.ts +3 -0
  103. package/src/session/observer.ts +59 -0
  104. package/src/session/session.conversations.json +1 -0
  105. package/src/session/session.test.ts +37 -198
  106. package/src/session/session.ts +125 -249
  107. package/src/session/toolkit.ts +48 -0
  108. package/src/session/version-pin.ts +5 -5
  109. package/src/summarization/summarization.test.ts +19 -39
  110. package/src/templates/format.tpl +60 -0
  111. package/src/templates/index.ts +1 -1
  112. package/src/templates/system.tpl +48 -0
  113. package/src/templates/system.ts +41 -0
  114. package/src/{types.ts → types/artifact.ts} +12 -7
  115. package/src/types/index.ts +5 -0
  116. package/src/typings.d.ts +5 -0
  117. package/dist/types/bin/chat.d.ts +0 -2
  118. package/dist/types/bin/chat.d.ts.map +0 -1
  119. package/dist/types/src/context/binder.d.ts +0 -34
  120. package/dist/types/src/context/binder.d.ts.map +0 -1
  121. package/dist/types/src/context/binding.d.ts +0 -56
  122. package/dist/types/src/context/binding.d.ts.map +0 -1
  123. package/dist/types/src/context/index.d.ts +0 -3
  124. package/dist/types/src/context/index.d.ts.map +0 -1
  125. package/dist/types/src/research/exa.d.ts +0 -12
  126. package/dist/types/src/research/exa.d.ts.map +0 -1
  127. package/dist/types/src/research/graph.d.ts +0 -51
  128. package/dist/types/src/research/graph.d.ts.map +0 -1
  129. package/dist/types/src/research/graph.test.d.ts +0 -2
  130. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  131. package/dist/types/src/research/index.d.ts +0 -4
  132. package/dist/types/src/research/index.d.ts.map +0 -1
  133. package/dist/types/src/research/research.d.ts +0 -10
  134. package/dist/types/src/research/research.d.ts.map +0 -1
  135. package/dist/types/src/research/research.test.d.ts +0 -2
  136. package/dist/types/src/research/research.test.d.ts.map +0 -1
  137. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  138. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  139. package/dist/types/src/templates/prompt.d.ts +0 -30
  140. package/dist/types/src/templates/prompt.d.ts.map +0 -1
  141. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  142. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  143. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  144. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  145. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  146. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  147. package/dist/types/src/testing/index.d.ts +0 -3
  148. package/dist/types/src/testing/index.d.ts.map +0 -1
  149. package/dist/types/src/types.d.ts.map +0 -1
  150. package/src/context/binder.ts +0 -103
  151. package/src/context/binding.ts +0 -32
  152. package/src/context/index.ts +0 -6
  153. package/src/research/exa.ts +0 -97
  154. package/src/research/graph.test.ts +0 -64
  155. package/src/research/graph.ts +0 -369
  156. package/src/research/index.ts +0 -7
  157. package/src/research/instructions-research.tpl +0 -98
  158. package/src/research/research.test.ts +0 -190
  159. package/src/research/research.ts +0 -87
  160. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  161. package/src/session/version-pin.test.ts +0 -7
  162. package/src/templates/assistant.tpl +0 -111
  163. package/src/templates/prompt.ts +0 -45
  164. package/src/testing/exa-search-1748337321991.ts +0 -131
  165. package/src/testing/exa-search-1748337331526.ts +0 -144
  166. package/src/testing/exa-search-1748337344119.ts +0 -133
  167. package/src/testing/index.ts +0 -11
  168. package/src/typedefs.d.ts +0 -8
@@ -1,38 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- image?: undefined;
15
- favicon?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- image: string;
25
- favicon: string;
26
- })[];
27
- costDollars: {
28
- total: number;
29
- search: {
30
- neural: number;
31
- };
32
- contents: {
33
- text: number;
34
- };
35
- };
36
- };
37
- export default _default;
38
- //# sourceMappingURL=exa-search-1748337321991.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337321991.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337321991.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA8HE"}
@@ -1,37 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- resolvedSearchType: string;
5
- results: ({
6
- id: string;
7
- title: string;
8
- url: string;
9
- publishedDate: string;
10
- author: string;
11
- score: number;
12
- text: string;
13
- image: string;
14
- favicon: string;
15
- } | {
16
- id: string;
17
- title: string;
18
- url: string;
19
- publishedDate: string;
20
- author: string;
21
- text: string;
22
- image: string;
23
- favicon: string;
24
- score?: undefined;
25
- })[];
26
- costDollars: {
27
- total: number;
28
- search: {
29
- neural: number;
30
- };
31
- contents: {
32
- text: number;
33
- };
34
- };
35
- };
36
- export default _default;
37
- //# sourceMappingURL=exa-search-1748337331526.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337331526.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337331526.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA2IE"}
@@ -1,58 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- favicon: string;
15
- image?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- favicon?: undefined;
25
- image?: undefined;
26
- } | {
27
- id: string;
28
- title: string;
29
- url: string;
30
- publishedDate: string;
31
- author: string;
32
- score: number;
33
- text: string;
34
- image: string;
35
- favicon: string;
36
- } | {
37
- id: string;
38
- title: string;
39
- url: string;
40
- author: string;
41
- text: string;
42
- image: string;
43
- favicon: string;
44
- publishedDate?: undefined;
45
- score?: undefined;
46
- })[];
47
- costDollars: {
48
- total: number;
49
- search: {
50
- neural: number;
51
- };
52
- contents: {
53
- text: number;
54
- };
55
- };
56
- };
57
- export default _default;
58
- //# sourceMappingURL=exa-search-1748337344119.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337344119.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337344119.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBAgIE"}
@@ -1,3 +0,0 @@
1
- import type { SearchResponse } from 'exa-js';
2
- export declare const SEARCH_RESULTS: SearchResponse<any>[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAM7C,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC,EAAgC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAmB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,qBAAqB,GAAI,IAAI,QAAQ,WAA4B,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG;IAC/C,KAAK,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC;CA4BhE,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -1,103 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { computed, type ReadonlySignal } from '@preact/signals-core';
6
- import { Array, pipe } from 'effect';
7
-
8
- import { type Blueprint } from '@dxos/blueprints';
9
- import { Obj, type Type, type Ref, type Relation } from '@dxos/echo';
10
- import { type Queue } from '@dxos/echo-db';
11
- import { ComplexSet } from '@dxos/util';
12
-
13
- import { ContextBinding } from './binding';
14
-
15
- /**
16
- * Manages bindings of blueprints and objects to a conversation.
17
- */
18
- export class ContextBinder {
19
- constructor(private readonly _queue: Queue) {}
20
-
21
- /**
22
- * Reactive query of all bindings.
23
- */
24
- // TODO(burdon): Cache value?
25
- readonly bindings: ReadonlySignal<Bindings> = computed(() => this._reduce(this._queue.objects));
26
-
27
- // TODO(burdon): load refs?
28
- readonly blueprints: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]> = computed(() => [
29
- ...this.bindings.value.blueprints,
30
- ]);
31
- readonly objects: ReadonlySignal<Ref.Ref<Type.Expando>[]> = computed(() => [...this.bindings.value.objects]);
32
-
33
- /**
34
- * Asynchronous query of all bindings.
35
- */
36
- async query(): Promise<Bindings> {
37
- const queueItems = await this._queue.queryObjects();
38
- return this._reduce(queueItems);
39
- }
40
-
41
- // TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
42
- async bind(props: BindingProps): Promise<void> {
43
- if (!props.blueprints?.length && !props.objects?.length) {
44
- return;
45
- }
46
-
47
- await this._queue.append([
48
- Obj.make(ContextBinding, {
49
- blueprints: {
50
- added: props.blueprints ?? [],
51
- removed: [],
52
- },
53
- objects: {
54
- added: props.objects ?? [],
55
- removed: [],
56
- },
57
- }),
58
- ]);
59
- }
60
-
61
- async unbind(props: BindingProps): Promise<void> {
62
- if (!props.blueprints?.length && !props.objects?.length) {
63
- return;
64
- }
65
-
66
- await this._queue.append([
67
- Obj.make(ContextBinding, {
68
- blueprints: {
69
- added: [],
70
- removed: props.blueprints ?? [],
71
- },
72
- objects: {
73
- added: [],
74
- removed: props.objects ?? [],
75
- },
76
- }),
77
- ]);
78
- }
79
-
80
- private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
81
- return pipe(
82
- items,
83
- Array.filter(Obj.instanceOf(ContextBinding)),
84
- Array.reduce(new Bindings(), (context, item) => {
85
- item.blueprints.removed.forEach((item) => context.blueprints.delete(item));
86
- item.blueprints.added.forEach((item) => context.blueprints.add(item));
87
- item.objects.removed.forEach((item) => context.objects.delete(item));
88
- item.objects.added.forEach((item) => context.objects.add(item));
89
- return context;
90
- }),
91
- );
92
- }
93
- }
94
-
95
- export type BindingProps = Partial<{
96
- blueprints: Ref.Ref<Blueprint.Blueprint>[];
97
- objects: Ref.Ref<Type.Expando>[];
98
- }>;
99
-
100
- export class Bindings {
101
- blueprints = new ComplexSet<Ref.Ref<Blueprint.Blueprint>>((ref) => ref.dxn.toString());
102
- objects = new ComplexSet<Ref.Ref<Type.Expando>>((ref) => ref.dxn.toString());
103
- }
@@ -1,32 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { Blueprint } from '@dxos/blueprints';
8
- import { Type } from '@dxos/echo';
9
-
10
- /**
11
- * Thread message that binds or unbinds contextual objects to a conversation.
12
- */
13
- // TODO(burdon): Make ContentBlock.
14
- export const ContextBinding = Schema.Struct({
15
- blueprints: Schema.Struct({
16
- added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
17
- removed: Schema.Array(Type.Ref(Blueprint.Blueprint)),
18
- }),
19
-
20
- // TODO(burdon): Type.Expando => Type.Obj (or Obj.Any?)
21
- objects: Schema.Struct({
22
- added: Schema.Array(Type.Ref(Type.Expando)),
23
- removed: Schema.Array(Type.Ref(Type.Expando)),
24
- }),
25
- }).pipe(
26
- Type.Obj({
27
- typename: 'dxos.org/type/ContextBinding',
28
- version: '0.1.0',
29
- }),
30
- );
31
-
32
- export interface ContextBinding extends Schema.Schema.Type<typeof ContextBinding> {}
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './binder';
6
- export * from './binding';
@@ -1,97 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { AiTool, AiToolkit } from '@effect/ai';
6
- import { Effect, Schema } from 'effect';
7
- import Exa from 'exa-js';
8
-
9
- import { CredentialsService } from '@dxos/functions';
10
- import { log } from '@dxos/log';
11
-
12
- import { SEARCH_RESULTS } from '../testing';
13
-
14
- export class ExaToolkit extends AiToolkit.make(
15
- AiTool.make('exa_search', {
16
- description: 'Search the web for information',
17
- parameters: {
18
- query: Schema.String.annotations({ description: 'The query to search for' }),
19
- },
20
- success: Schema.Unknown,
21
- failure: Schema.Never,
22
- }).addRequirement<CredentialsService>(),
23
- ) {}
24
-
25
- export const LiveExaHandler = ExaToolkit.toLayer({
26
- exa_search: Effect.fn(function* ({ query }) {
27
- const credential = yield* CredentialsService.getCredential({ service: 'exa.ai' });
28
- const exa = new Exa(credential.apiKey);
29
-
30
- const context = yield* Effect.promise(async () =>
31
- exa.searchAndContents(query, {
32
- type: 'auto',
33
- text: {
34
- maxCharacters: 3_000,
35
- },
36
- livecrawl: 'always',
37
- }),
38
- );
39
-
40
- log.info('exa search', { query, costDollars: context.costDollars });
41
-
42
- return context;
43
- }),
44
- });
45
-
46
- export const MockExaHandler = ExaToolkit.toLayer({
47
- exa_search: Effect.fn(function* ({ query }) {
48
- // Find result with closest matching autoprompt using weighted Levenshtein distance
49
- const result = SEARCH_RESULTS.reduce(
50
- (closest, current) => {
51
- if (!current.autopromptString) {
52
- return closest;
53
- }
54
- if (!closest) {
55
- return current;
56
- }
57
-
58
- // Calculate Levenshtein distance
59
- const dist1 = levenshteinDistance(query, current.autopromptString);
60
- const dist2 = levenshteinDistance(query, closest.autopromptString || '');
61
-
62
- // Weight by length of the longer string to normalize
63
- const weight1 = dist1 / Math.max(query.length, current.autopromptString.length);
64
- const weight2 = dist2 / Math.max(query.length, closest.autopromptString?.length || 0);
65
-
66
- return weight1 < weight2 ? current : closest;
67
- },
68
- null as (typeof SEARCH_RESULTS)[0] | null,
69
- );
70
-
71
- return result;
72
- }),
73
- });
74
-
75
- const levenshteinDistance = (str1: string, str2: string): number => {
76
- const m = str1.length;
77
- const n = str2.length;
78
- const dp: number[][] = Array(m + 1)
79
- .fill(null)
80
- .map(() => Array(n + 1).fill(0));
81
-
82
- for (let i = 0; i <= m; i++) {
83
- dp[i][0] = i;
84
- }
85
- for (let j = 0; j <= n; j++) {
86
- dp[0][j] = j;
87
- }
88
-
89
- for (let i = 1; i <= m; i++) {
90
- for (let j = 1; j <= n; j++) {
91
- dp[i][j] =
92
- str1[i - 1] === str2[j - 1] ? dp[i - 1][j - 1] : Math.min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1;
93
- }
94
- }
95
-
96
- return dp[m][n];
97
- };
@@ -1,64 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { AnthropicClient } from '@effect/ai-anthropic';
6
- import { FetchHttpClient } from '@effect/platform';
7
- import { describe, it } from '@effect/vitest';
8
- import { Config, Effect, Layer, pipe } from 'effect';
9
-
10
- import { AiService, AiServiceRouter, ToolExecutionService, ToolResolverService } from '@dxos/ai';
11
- import { tapHttpErrors } from '@dxos/ai/testing';
12
- import { TestHelpers } from '@dxos/effect';
13
- import { DatabaseService } from '@dxos/functions';
14
- import { log } from '@dxos/log';
15
- import { DataType } from '@dxos/schema';
16
-
17
- import { makeGraphWriterHandler, makeGraphWriterToolkit } from './graph';
18
- import { AiSession } from '../session';
19
-
20
- // import { type EchoTestBuilder } from '@dxos/echo-db/testing';
21
-
22
- const TestLayer = pipe(
23
- AiService.model('@anthropic/claude-3-5-sonnet-20241022'),
24
- Layer.provideMerge(DatabaseService.notAvailable),
25
- Layer.provideMerge(ToolResolverService.layerEmpty),
26
- Layer.provideMerge(ToolExecutionService.layerEmpty),
27
- Layer.provide(AiServiceRouter.AiServiceRouter),
28
- Layer.provide(
29
- AnthropicClient.layerConfig({
30
- apiKey: Config.redacted('ANTHROPIC_API_KEY'),
31
- transformClient: tapHttpErrors,
32
- }),
33
- ),
34
- Layer.provide(FetchHttpClient.layer),
35
- );
36
-
37
- describe('graph', () => {
38
- // let builder: EchoTestBuilder;
39
- // test('findRelatedSchema', async () => {
40
- // const db = await createEchoDatabase();
41
- // const relatedSchemas = await findRelatedSchema(db, Schema.Struct({}));
42
- // });
43
-
44
- it.effect.skip(
45
- 'calculator',
46
- Effect.fn(
47
- function* ({ expect }) {
48
- const graphWriteToolkit = makeGraphWriterToolkit({ schema: [DataType.Project] });
49
-
50
- const session = new AiSession();
51
- const response = yield* session
52
- .run({
53
- prompt: 'What is 10 + 20?',
54
- history: [],
55
- toolkit: graphWriteToolkit,
56
- })
57
- .pipe(Effect.provide(makeGraphWriterHandler(graphWriteToolkit)));
58
- log.info('response', { response });
59
- },
60
- Effect.provide(TestLayer),
61
- TestHelpers.runIf(process.env.ANTHROPIC_API_KEY),
62
- ),
63
- );
64
- });