@dxos/assistant 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/extraction/index.mjs +118 -161
- package/dist/lib/browser/extraction/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +977 -156
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/extraction/index.mjs +118 -161
- package/dist/lib/node-esm/extraction/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +977 -156
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/conversation/context.d.ts +14 -7
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +11 -12
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +14 -18
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +85 -0
- package/dist/types/src/execution-graph.d.ts.map +1 -0
- package/dist/types/src/execution-graph.test.d.ts +2 -0
- package/dist/types/src/execution-graph.test.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +60 -52
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +24 -13
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +1 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +18 -5
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/GenericToolkit.d.ts +84 -0
- package/dist/types/src/session/GenericToolkit.d.ts.map +1 -0
- package/dist/types/src/session/artifact-diff.d.ts +2 -2
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/error-handling.d.ts +2 -2
- package/dist/types/src/session/error-handling.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +4 -174
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +3 -3
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +15 -11
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +7 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -3
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/types/artifact.d.ts +20 -0
- package/dist/types/src/types/artifact.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -31
- package/src/conversation/context.ts +49 -17
- package/src/conversation/conversation.ts +28 -23
- package/src/diff.test.ts +3 -3
- package/src/diff.ts +5 -0
- package/src/execution-graph.test.ts +740 -0
- package/src/execution-graph.ts +509 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +46 -54
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +10 -9
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +38 -44
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
- package/src/extraction/extraction.ts +7 -6
- package/src/extraction/quotes.ts +2 -2
- package/src/functions/services.ts +93 -50
- package/src/index.ts +2 -1
- package/src/session/GenericToolkit.ts +130 -0
- package/src/session/artifact-diff.ts +2 -2
- package/src/session/error-handling.ts +6 -4
- package/src/session/format.test.ts +5 -4
- package/src/session/format.ts +17 -12
- package/src/session/index.ts +2 -0
- package/src/session/observer.ts +4 -3
- package/src/session/session.conversations.json +1 -0
- package/src/session/session.test.ts +51 -210
- package/src/session/session.ts +40 -28
- package/src/session/toolkit.ts +19 -13
- package/src/session/version-pin.ts +4 -5
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -0
- package/src/templates/{system.tpl → instructions/system.tpl} +10 -12
- package/src/templates/system.ts +2 -2
- package/src/{types.ts → types/artifact.ts} +22 -3
- package/src/types/index.ts +5 -0
- package/dist/lib/browser/chunk-3K5SRE5A.mjs +0 -404
- package/dist/lib/browser/chunk-3K5SRE5A.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W7AIB6DP.mjs +0 -406
- package/dist/lib/node-esm/chunk-W7AIB6DP.mjs.map +0 -7
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/types/src/session/version-pin.test.d.ts +0 -2
- package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -16
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/session/__snapshots__/session.test.ts.snap +0 -32
- package/src/session/version-pin.test.ts +0 -7
- package/src/summarization/summarization.test.ts +0 -197
- /package/dist/lib/browser/{named-entity-recognition-QPYHML66.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/node-esm/{named-entity-recognition-2HDF46YX.mjs.map → chunk-HSLMI22Q.mjs.map} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.e8ec1fe",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -38,41 +38,38 @@
|
|
|
38
38
|
"src"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@automerge/automerge": "3.1.
|
|
42
|
-
"@effect/ai": "0.
|
|
43
|
-
"@effect/
|
|
44
|
-
"@effect/platform": "^0.
|
|
45
|
-
"@
|
|
46
|
-
"@preact/signals-core": "^1.9.0",
|
|
41
|
+
"@automerge/automerge": "3.1.2",
|
|
42
|
+
"@effect/ai": "0.29.1",
|
|
43
|
+
"@effect/experimental": "0.56.0",
|
|
44
|
+
"@effect/platform": "^0.92.1",
|
|
45
|
+
"@preact/signals-core": "^1.12.1",
|
|
47
46
|
"@xenova/transformers": "^2.17.2",
|
|
48
|
-
"chalk": "^4.1.0",
|
|
49
|
-
"handlebars": "4.7.8",
|
|
50
47
|
"lodash.defaultsdeep": "^4.6.1",
|
|
51
|
-
"@dxos/ai": "0.8.4-main.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/echo": "0.8.4-main.
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/log": "0.8.4-main.
|
|
67
|
-
"@dxos/node-std": "0.8.4-main.
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
48
|
+
"@dxos/ai": "0.8.4-main.e8ec1fe",
|
|
49
|
+
"@dxos/async": "0.8.4-main.e8ec1fe",
|
|
50
|
+
"@dxos/context": "0.8.4-main.e8ec1fe",
|
|
51
|
+
"@dxos/debug": "0.8.4-main.e8ec1fe",
|
|
52
|
+
"@dxos/echo": "0.8.4-main.e8ec1fe",
|
|
53
|
+
"@dxos/echo-db": "0.8.4-main.e8ec1fe",
|
|
54
|
+
"@dxos/blueprints": "0.8.4-main.e8ec1fe",
|
|
55
|
+
"@dxos/effect": "0.8.4-main.e8ec1fe",
|
|
56
|
+
"@dxos/errors": "0.8.4-main.e8ec1fe",
|
|
57
|
+
"@dxos/echo-protocol": "0.8.4-main.e8ec1fe",
|
|
58
|
+
"@dxos/functions-runtime": "0.8.4-main.e8ec1fe",
|
|
59
|
+
"@dxos/graph": "0.8.4-main.e8ec1fe",
|
|
60
|
+
"@dxos/invariant": "0.8.4-main.e8ec1fe",
|
|
61
|
+
"@dxos/keys": "0.8.4-main.e8ec1fe",
|
|
62
|
+
"@dxos/live-object": "0.8.4-main.e8ec1fe",
|
|
63
|
+
"@dxos/log": "0.8.4-main.e8ec1fe",
|
|
64
|
+
"@dxos/node-std": "0.8.4-main.e8ec1fe",
|
|
65
|
+
"@dxos/functions": "0.8.4-main.e8ec1fe",
|
|
66
|
+
"@dxos/types": "0.8.4-main.e8ec1fe",
|
|
67
|
+
"@dxos/schema": "0.8.4-main.e8ec1fe",
|
|
68
|
+
"@dxos/util": "0.8.4-main.e8ec1fe"
|
|
71
69
|
},
|
|
72
70
|
"devDependencies": {
|
|
73
71
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
74
|
-
"effect": "3.
|
|
75
|
-
"inquirer": "^12.0.0"
|
|
72
|
+
"effect": "3.18.3"
|
|
76
73
|
},
|
|
77
74
|
"peerDependencies": {
|
|
78
75
|
"effect": "^3.13.3"
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type ReadonlySignal, computed } from '@preact/signals-core';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import * as Array from 'effect/Array';
|
|
7
|
+
import * as Context from 'effect/Context';
|
|
8
|
+
import * as Function from 'effect/Function';
|
|
9
|
+
import * as Schema from 'effect/Schema';
|
|
8
10
|
|
|
9
11
|
import { Blueprint } from '@dxos/blueprints';
|
|
10
|
-
import {
|
|
12
|
+
import { Resource } from '@dxos/context';
|
|
13
|
+
import { DXN, Filter, Obj, Query, type Ref, type Relation, Type } from '@dxos/echo';
|
|
11
14
|
import { type Queue } from '@dxos/echo-db';
|
|
15
|
+
import { invariant } from '@dxos/invariant';
|
|
12
16
|
import { ComplexSet } from '@dxos/util';
|
|
13
17
|
|
|
14
18
|
/**
|
|
@@ -57,41 +61,69 @@ export class Bindings {
|
|
|
57
61
|
* Manages bindings of blueprints and objects to a conversation.
|
|
58
62
|
*/
|
|
59
63
|
// TODO(burdon): Context should manage ephemeral state of bindings until prompt is issued?
|
|
60
|
-
export class AiContextBinder {
|
|
64
|
+
export class AiContextBinder extends Resource {
|
|
61
65
|
/**
|
|
62
66
|
* Reactive query of all bindings.
|
|
63
67
|
*/
|
|
64
68
|
// TODO(burdon): Cache value?
|
|
65
|
-
|
|
69
|
+
private _bindings?: ReadonlySignal<Bindings>;
|
|
70
|
+
private _blueprints?: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]>;
|
|
71
|
+
private _objects?: ReadonlySignal<Ref.Ref<Type.Expando>[]>;
|
|
66
72
|
|
|
67
|
-
readonly
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
constructor(private readonly _queue: Queue) {
|
|
74
|
+
super();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get bindings() {
|
|
78
|
+
invariant(this._bindings, 'AiContextBinder not open');
|
|
79
|
+
return this._bindings;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get blueprints() {
|
|
83
|
+
invariant(this._blueprints, 'AiContextBinder not open');
|
|
84
|
+
return this._blueprints;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get objects() {
|
|
88
|
+
invariant(this._objects, 'AiContextBinder not open');
|
|
89
|
+
return this._objects;
|
|
90
|
+
}
|
|
70
91
|
|
|
71
|
-
|
|
92
|
+
// TODO(wittjosiah): Use parent context?
|
|
93
|
+
protected override async _open(): Promise<void> {
|
|
94
|
+
const query = this._queue.query(Query.select(Filter.everything()));
|
|
95
|
+
this._ctx.onDispose(query.subscribe(() => {}));
|
|
96
|
+
this._bindings = computed(() => this._reduce(query.objects));
|
|
97
|
+
this._blueprints = computed(() => [...this.bindings.value.blueprints]);
|
|
98
|
+
this._objects = computed(() => [...this.bindings.value.objects]);
|
|
99
|
+
}
|
|
72
100
|
|
|
73
|
-
|
|
101
|
+
protected override async _close(): Promise<void> {
|
|
102
|
+
this._bindings = undefined;
|
|
103
|
+
this._blueprints = undefined;
|
|
104
|
+
this._objects = undefined;
|
|
105
|
+
}
|
|
74
106
|
|
|
75
107
|
/**
|
|
76
108
|
* Asynchronous query of all bindings.
|
|
77
109
|
*/
|
|
78
110
|
async query(): Promise<Bindings> {
|
|
79
|
-
const
|
|
80
|
-
return this._reduce(
|
|
111
|
+
const { objects } = await this._queue.query(Query.select(Filter.everything())).run();
|
|
112
|
+
return this._reduce(objects);
|
|
81
113
|
}
|
|
82
114
|
|
|
83
115
|
// TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
|
|
84
116
|
async bind(props: BindingProps): Promise<void> {
|
|
85
|
-
if (!props.blueprints?.length && !props.objects?.length) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
117
|
const blueprints =
|
|
90
118
|
props.blueprints?.filter((ref) => !this.blueprints.peek().find((b) => b.dxn.toString() === ref.dxn.toString())) ??
|
|
91
119
|
[];
|
|
92
120
|
const objects =
|
|
93
121
|
props.objects?.filter((ref) => !this.objects.peek().find((o) => o.dxn.toString() === ref.dxn.toString())) ?? [];
|
|
94
122
|
|
|
123
|
+
if (!blueprints.length && !objects.length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
95
127
|
await this._queue.append([
|
|
96
128
|
Obj.make(ContextBinding, {
|
|
97
129
|
blueprints: {
|
|
@@ -126,7 +158,7 @@ export class AiContextBinder {
|
|
|
126
158
|
}
|
|
127
159
|
|
|
128
160
|
private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
|
|
129
|
-
return pipe(
|
|
161
|
+
return Function.pipe(
|
|
130
162
|
items,
|
|
131
163
|
Array.filter(Obj.instanceOf(ContextBinding)),
|
|
132
164
|
Array.reduce(new Bindings(), (context, item) => {
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import type * as Toolkit from '@effect/ai/Toolkit';
|
|
6
|
+
import * as Array from 'effect/Array';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Option from 'effect/Option';
|
|
7
9
|
|
|
10
|
+
import { Resource } from '@dxos/context';
|
|
8
11
|
import { Obj } from '@dxos/echo';
|
|
9
12
|
import { type Queue } from '@dxos/echo-db';
|
|
10
|
-
import { DatabaseService } from '@dxos/
|
|
13
|
+
import { DatabaseService } from '@dxos/echo-db';
|
|
11
14
|
import { log } from '@dxos/log';
|
|
12
|
-
import {
|
|
15
|
+
import { Message } from '@dxos/types';
|
|
13
16
|
|
|
14
17
|
import {
|
|
15
18
|
AiSession,
|
|
@@ -21,29 +24,21 @@ import {
|
|
|
21
24
|
|
|
22
25
|
import { AiContextBinder, AiContextService, type ContextBinding } from './context';
|
|
23
26
|
|
|
24
|
-
export type AiConversationRunRequirements<Tools extends AiTool.Any> =
|
|
25
|
-
| AiSessionRunRequirements
|
|
26
|
-
| AiTool.ToHandler<Tools>;
|
|
27
|
-
|
|
28
27
|
export interface AiConversationRunParams {
|
|
29
28
|
prompt: string;
|
|
30
29
|
system?: string;
|
|
31
30
|
observer?: GenerationObserver;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
export type AiConversationOptions = {
|
|
35
|
-
queue: Queue<DataType.Message | ContextBinding>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
33
|
/**
|
|
39
34
|
* Durable conversation state (initiated by users and agents) backed by a Queue.
|
|
40
35
|
* Executes tools based on AI responses and supports cancellation of in-progress requests.
|
|
41
36
|
*/
|
|
42
|
-
export class AiConversation {
|
|
37
|
+
export class AiConversation extends Resource {
|
|
43
38
|
/**
|
|
44
39
|
* Message and binding queue.
|
|
45
40
|
*/
|
|
46
|
-
private readonly _queue: Queue<
|
|
41
|
+
private readonly _queue: Queue<Message.Message | ContextBinding>;
|
|
47
42
|
|
|
48
43
|
/**
|
|
49
44
|
* Blueprints bound to the conversation.
|
|
@@ -53,13 +48,23 @@ export class AiConversation {
|
|
|
53
48
|
/**
|
|
54
49
|
* Toolkit from the current session request.
|
|
55
50
|
*/
|
|
56
|
-
private _toolkit:
|
|
51
|
+
private _toolkit: Toolkit.WithHandler<any> | undefined;
|
|
57
52
|
|
|
58
|
-
public constructor(
|
|
59
|
-
|
|
53
|
+
public constructor(queue: Queue<Message.Message | ContextBinding>) {
|
|
54
|
+
super();
|
|
55
|
+
this._queue = queue;
|
|
60
56
|
this._context = new AiContextBinder(this._queue);
|
|
61
57
|
}
|
|
62
58
|
|
|
59
|
+
protected override async _open(): Promise<void> {
|
|
60
|
+
// TODO(wittjosiah): Pass in parent context?
|
|
61
|
+
await this._context.open();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected override async _close(): Promise<void> {
|
|
65
|
+
await this._context.close();
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
public get context() {
|
|
64
69
|
return this._context;
|
|
65
70
|
}
|
|
@@ -68,17 +73,17 @@ export class AiConversation {
|
|
|
68
73
|
return this._toolkit;
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
public async getHistory(): Promise<
|
|
76
|
+
public async getHistory(): Promise<Message.Message[]> {
|
|
72
77
|
const queueItems = await this._queue.queryObjects();
|
|
73
|
-
return queueItems.filter(Obj.instanceOf(
|
|
78
|
+
return queueItems.filter(Obj.instanceOf(Message.Message));
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
/**
|
|
77
82
|
* Creates a new cancelable request effect.
|
|
78
83
|
*/
|
|
79
|
-
createRequest
|
|
84
|
+
createRequest(
|
|
80
85
|
params: AiConversationRunParams,
|
|
81
|
-
): Effect.Effect<
|
|
86
|
+
): Effect.Effect<Message.Message[], AiSessionRunError, AiSessionRunRequirements> {
|
|
82
87
|
return Effect.gen(this, function* () {
|
|
83
88
|
const session = new AiSession();
|
|
84
89
|
const history = yield* Effect.promise(() => this.getHistory());
|
|
@@ -95,7 +100,7 @@ export class AiConversation {
|
|
|
95
100
|
);
|
|
96
101
|
|
|
97
102
|
// Create toolkit.
|
|
98
|
-
const toolkit = yield* createToolkit
|
|
103
|
+
const toolkit = yield* createToolkit({ blueprints });
|
|
99
104
|
this._toolkit = toolkit;
|
|
100
105
|
|
|
101
106
|
const start = Date.now();
|
|
@@ -107,7 +112,7 @@ export class AiConversation {
|
|
|
107
112
|
});
|
|
108
113
|
|
|
109
114
|
// Process request.
|
|
110
|
-
const messages = yield* session.run
|
|
115
|
+
const messages = yield* session.run({ history, blueprints, objects, toolkit, ...params }).pipe(
|
|
111
116
|
Effect.provideService(AiContextService, {
|
|
112
117
|
binder: this.context,
|
|
113
118
|
}),
|
package/src/diff.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { createDocAccessor } from '@dxos/echo-db';
|
|
8
8
|
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
9
|
-
import {
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
10
10
|
import { trim } from '@dxos/util';
|
|
11
11
|
|
|
12
12
|
import { applyDiffs } from './diff';
|
|
@@ -15,7 +15,7 @@ describe('diff', () => {
|
|
|
15
15
|
it('should apply diffs', async () => {
|
|
16
16
|
const builder = new EchoTestBuilder();
|
|
17
17
|
const { db, graph } = await builder.createDatabase();
|
|
18
|
-
graph.schemaRegistry.addSchema([
|
|
18
|
+
graph.schemaRegistry.addSchema([Text.Text]);
|
|
19
19
|
|
|
20
20
|
const document = trim`
|
|
21
21
|
# Hello World
|
|
@@ -24,7 +24,7 @@ describe('diff', () => {
|
|
|
24
24
|
But not this one.
|
|
25
25
|
`;
|
|
26
26
|
|
|
27
|
-
const text = db.add(
|
|
27
|
+
const text = db.add(Text.make(document));
|
|
28
28
|
const accessor = createDocAccessor(text, ['content']);
|
|
29
29
|
const result = applyDiffs(accessor, [
|
|
30
30
|
`- There'z a typo in this sentence.`,
|
package/src/diff.ts
CHANGED
|
@@ -11,6 +11,11 @@ import { isNonNullable } from '@dxos/util';
|
|
|
11
11
|
// Relevant info:
|
|
12
12
|
// https://github.com/Minahil-official/GPT-4.1-Promting-Guide?tab=readme-ov-file#-apply-patch-tool-format-v4a-diff
|
|
13
13
|
|
|
14
|
+
// TODO(burdon): Anthropic only.
|
|
15
|
+
// https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool#example-str-replace-command
|
|
16
|
+
// AI_TOOL_NOT_FOUND: str_replace_based_edit_tool
|
|
17
|
+
// 'str_replace_based_edit_tool',
|
|
18
|
+
|
|
14
19
|
// TOOD(burdon): Support append to end (no "-").
|
|
15
20
|
|
|
16
21
|
export type Diff = {
|