@dxos/assistant 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea
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-ILL2CN3G.mjs → chunk-4VIJTKPM.mjs} +128 -148
- package/dist/lib/browser/chunk-4VIJTKPM.mjs.map +7 -0
- package/dist/lib/browser/extraction/index.mjs +7 -7
- package/dist/lib/browser/extraction/index.mjs.map +2 -2
- package/dist/lib/browser/index.mjs +157 -118
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/{chunk-GVKA7VL3.mjs → chunk-AUUC7II4.mjs} +128 -148
- package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +7 -0
- package/dist/lib/node-esm/extraction/index.mjs +7 -7
- package/dist/lib/node-esm/extraction/index.mjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +157 -118
- 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 +7 -7
- 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/extraction/extraction-ner-function/extraction-ner-function.d.ts +13 -9
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +14 -8
- 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 +3 -2
- package/dist/types/src/functions/services.d.ts.map +1 -1
- 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 +7 -5
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +1 -1
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +6 -2
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +3 -2
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +2 -2
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/{types.d.ts → types/artifact.d.ts} +3 -3
- 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 +21 -27
- package/src/conversation/context.ts +49 -17
- package/src/conversation/conversation.ts +18 -9
- package/src/diff.ts +5 -0
- package/src/execution-graph.test.ts +1 -1
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +1 -1
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +1 -1
- package/src/extraction/extraction.ts +2 -2
- package/src/extraction/quotes.ts +2 -2
- package/src/functions/services.ts +9 -4
- package/src/session/artifact-diff.ts +2 -2
- package/src/session/error-handling.ts +4 -3
- package/src/session/format.test.ts +1 -1
- package/src/session/format.ts +8 -5
- package/src/session/observer.ts +2 -1
- package/src/session/session.test.ts +7 -4
- package/src/session/session.ts +9 -2
- package/src/session/toolkit.ts +4 -2
- package/src/session/version-pin.ts +2 -2
- package/src/summarization/summarization.test.ts +4 -3
- package/src/{types.ts → types/artifact.ts} +2 -2
- package/src/types/index.ts +5 -0
- package/dist/lib/browser/chunk-ILL2CN3G.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GVKA7VL3.mjs.map +0 -7
- package/dist/types/src/types.d.ts.map +0 -1
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.ae835ea",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -40,40 +40,34 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@automerge/automerge": "3.1.2",
|
|
42
42
|
"@effect/ai": "0.29.1",
|
|
43
|
-
"@effect/ai-anthropic": "^0.19.2",
|
|
44
43
|
"@effect/experimental": "0.56.0",
|
|
45
44
|
"@effect/platform": "^0.92.1",
|
|
46
|
-
"@effect/platform-node": "^0.98.3",
|
|
47
45
|
"@preact/signals-core": "^1.12.1",
|
|
48
46
|
"@xenova/transformers": "^2.17.2",
|
|
49
|
-
"chalk": "^4.1.0",
|
|
50
|
-
"handlebars": "4.7.8",
|
|
51
47
|
"lodash.defaultsdeep": "^4.6.1",
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/debug": "0.8.4-main.
|
|
57
|
-
"@dxos/echo": "0.8.4-main.
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/util": "0.8.4-main.a4bbb77"
|
|
48
|
+
"@dxos/async": "0.8.4-main.ae835ea",
|
|
49
|
+
"@dxos/blueprints": "0.8.4-main.ae835ea",
|
|
50
|
+
"@dxos/context": "0.8.4-main.ae835ea",
|
|
51
|
+
"@dxos/echo": "0.8.4-main.ae835ea",
|
|
52
|
+
"@dxos/debug": "0.8.4-main.ae835ea",
|
|
53
|
+
"@dxos/echo-db": "0.8.4-main.ae835ea",
|
|
54
|
+
"@dxos/ai": "0.8.4-main.ae835ea",
|
|
55
|
+
"@dxos/errors": "0.8.4-main.ae835ea",
|
|
56
|
+
"@dxos/effect": "0.8.4-main.ae835ea",
|
|
57
|
+
"@dxos/functions": "0.8.4-main.ae835ea",
|
|
58
|
+
"@dxos/graph": "0.8.4-main.ae835ea",
|
|
59
|
+
"@dxos/invariant": "0.8.4-main.ae835ea",
|
|
60
|
+
"@dxos/live-object": "0.8.4-main.ae835ea",
|
|
61
|
+
"@dxos/keys": "0.8.4-main.ae835ea",
|
|
62
|
+
"@dxos/node-std": "0.8.4-main.ae835ea",
|
|
63
|
+
"@dxos/log": "0.8.4-main.ae835ea",
|
|
64
|
+
"@dxos/schema": "0.8.4-main.ae835ea",
|
|
65
|
+
"@dxos/echo-protocol": "0.8.4-main.ae835ea",
|
|
66
|
+
"@dxos/util": "0.8.4-main.ae835ea"
|
|
72
67
|
},
|
|
73
68
|
"devDependencies": {
|
|
74
69
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
75
|
-
"effect": "3.18.3"
|
|
76
|
-
"inquirer": "^12.0.0"
|
|
70
|
+
"effect": "3.18.3"
|
|
77
71
|
},
|
|
78
72
|
"peerDependencies": {
|
|
79
73
|
"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,9 +2,12 @@
|
|
|
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
13
|
import { DatabaseService } from '@dxos/functions';
|
|
@@ -27,15 +30,11 @@ export interface AiConversationRunParams {
|
|
|
27
30
|
observer?: GenerationObserver;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
export type AiConversationOptions = {
|
|
31
|
-
queue: Queue<DataType.Message | ContextBinding>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
33
|
/**
|
|
35
34
|
* Durable conversation state (initiated by users and agents) backed by a Queue.
|
|
36
35
|
* Executes tools based on AI responses and supports cancellation of in-progress requests.
|
|
37
36
|
*/
|
|
38
|
-
export class AiConversation {
|
|
37
|
+
export class AiConversation extends Resource {
|
|
39
38
|
/**
|
|
40
39
|
* Message and binding queue.
|
|
41
40
|
*/
|
|
@@ -51,11 +50,21 @@ export class AiConversation {
|
|
|
51
50
|
*/
|
|
52
51
|
private _toolkit: Toolkit.WithHandler<any> | undefined;
|
|
53
52
|
|
|
54
|
-
public constructor(
|
|
55
|
-
|
|
53
|
+
public constructor(queue: Queue<DataType.Message | ContextBinding>) {
|
|
54
|
+
super();
|
|
55
|
+
this._queue = queue;
|
|
56
56
|
this._context = new AiContextBinder(this._queue);
|
|
57
57
|
}
|
|
58
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
|
+
|
|
59
68
|
public get context() {
|
|
60
69
|
return this._context;
|
|
61
70
|
}
|
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 = {
|
|
@@ -6,7 +6,7 @@ import { describe, expect, it } from '@effect/vitest';
|
|
|
6
6
|
|
|
7
7
|
import { AgentStatus } from '@dxos/ai';
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { ObjectId } from '@dxos/echo
|
|
9
|
+
import { ObjectId } from '@dxos/echo/internal';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { DataType } from '@dxos/schema';
|
|
12
12
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { AiService } from '@dxos/ai';
|
|
9
9
|
import { Obj } from '@dxos/echo';
|
|
10
|
-
import { create } from '@dxos/echo
|
|
10
|
+
import { create } from '@dxos/echo/internal';
|
|
11
11
|
import { type FunctionDefinition, defineFunction } from '@dxos/functions';
|
|
12
12
|
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
13
13
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// @ts-nocheck
|
|
7
7
|
|
|
8
8
|
import { asyncTimeout } from '@dxos/async';
|
|
9
|
-
import { create } from '@dxos/echo
|
|
9
|
+
import { create } from '@dxos/echo/internal';
|
|
10
10
|
import { DatabaseService, defineFunction } from '@dxos/functions';
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout } from '@dxos/async';
|
|
8
|
-
import { Expando } from '@dxos/echo
|
|
8
|
+
import { Expando } from '@dxos/echo/internal';
|
|
9
9
|
import { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { DataType } from '@dxos/schema';
|
package/src/extraction/quotes.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { Filter, Query } from '@dxos/echo';
|
|
8
|
+
import { ObjectId } from '@dxos/echo/internal';
|
|
8
9
|
import { type EchoDatabase } from '@dxos/echo-db';
|
|
9
|
-
import { ObjectId } from '@dxos/echo-schema';
|
|
10
10
|
import { DXN } from '@dxos/keys';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
|
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Tool from '@effect/ai/Tool';
|
|
6
|
+
import type * as Toolkit from '@effect/ai/Toolkit';
|
|
7
|
+
import * as Context from 'effect/Context';
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as Record from 'effect/Record';
|
|
11
|
+
import * as Schema from 'effect/Schema';
|
|
7
12
|
|
|
8
13
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
9
14
|
import { todo } from '@dxos/debug';
|
|
10
15
|
import { Query } from '@dxos/echo';
|
|
11
|
-
import { DatabaseService, FunctionDefinition, FunctionInvocationService
|
|
16
|
+
import { DatabaseService, Function, FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
12
17
|
import { invariant } from '@dxos/invariant';
|
|
13
18
|
|
|
14
19
|
/**
|
|
@@ -40,7 +45,7 @@ export const makeToolResolverFromFunctions = (
|
|
|
40
45
|
|
|
41
46
|
const {
|
|
42
47
|
objects: [dbFunction],
|
|
43
|
-
} = yield* DatabaseService.runQuery(Query.type(
|
|
48
|
+
} = yield* DatabaseService.runQuery(Query.type(Function.Function, { key: id }));
|
|
44
49
|
|
|
45
50
|
const functionDef = dbFunction
|
|
46
51
|
? FunctionDefinition.deserialize(dbFunction)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
6
|
|
|
7
|
+
import { type ObjectId } from '@dxos/echo/internal';
|
|
7
8
|
import { type ObjectVersion } from '@dxos/echo-db';
|
|
8
|
-
import { type ObjectId } from '@dxos/echo-schema';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolves artifact ids to their versions.
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import * as AiError from '@effect/ai/AiError';
|
|
6
|
+
import * as HttpClientError from '@effect/platform/HttpClientError';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
8
9
|
|
|
9
10
|
import { AiModelError } from '../errors';
|
|
10
11
|
|
package/src/session/format.ts
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Function from 'effect/Function';
|
|
8
|
+
import * as Option from 'effect/Option';
|
|
6
9
|
|
|
7
10
|
import { Template } from '@dxos/blueprints';
|
|
8
11
|
import { Obj } from '@dxos/echo';
|
|
12
|
+
import { type ObjectId } from '@dxos/echo/internal';
|
|
9
13
|
import { ObjectVersion } from '@dxos/echo-db';
|
|
10
|
-
import { type ObjectId } from '@dxos/echo-schema';
|
|
11
14
|
import { DatabaseService } from '@dxos/functions';
|
|
12
15
|
import { log } from '@dxos/log';
|
|
13
16
|
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
@@ -28,7 +31,7 @@ export const formatSystemPrompt = ({
|
|
|
28
31
|
objects = [],
|
|
29
32
|
}: Pick<AiSessionRunParams<any>, 'system' | 'blueprints' | 'objects'>) =>
|
|
30
33
|
Effect.gen(function* () {
|
|
31
|
-
const blueprintDefs = yield* pipe(
|
|
34
|
+
const blueprintDefs = yield* Function.pipe(
|
|
32
35
|
blueprints,
|
|
33
36
|
Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),
|
|
34
37
|
Effect.flatMap(Effect.forEach((template) => DatabaseService.loadOption(template.source))),
|
|
@@ -47,7 +50,7 @@ export const formatSystemPrompt = ({
|
|
|
47
50
|
),
|
|
48
51
|
);
|
|
49
52
|
|
|
50
|
-
const objectDefs = yield* pipe(
|
|
53
|
+
const objectDefs = yield* Function.pipe(
|
|
51
54
|
objects,
|
|
52
55
|
Effect.forEach((object) =>
|
|
53
56
|
Effect.succeed(trim`
|
|
@@ -60,7 +63,7 @@ export const formatSystemPrompt = ({
|
|
|
60
63
|
Effect.map((objects) => (objects.length > 0 ? ['## Context Objects', ...objects].join('\n\n') : undefined)),
|
|
61
64
|
);
|
|
62
65
|
|
|
63
|
-
return yield* pipe(
|
|
66
|
+
return yield* Function.pipe(
|
|
64
67
|
Effect.succeed([system, blueprintDefs, objectDefs].filter((def): def is string => def !== undefined)),
|
|
65
68
|
Effect.map((parts) => parts.join('\n\n')),
|
|
66
69
|
);
|
package/src/session/observer.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
6
7
|
|
|
7
8
|
import { type AiParser, type ConsolePrinter } from '@dxos/ai';
|
|
8
9
|
import { type DataType } from '@dxos/schema';
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Tool from '@effect/ai/Tool';
|
|
6
|
+
import * as Toolkit from '@effect/ai/Toolkit';
|
|
6
7
|
import { describe, it } from '@effect/vitest';
|
|
7
|
-
import
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as Schema from 'effect/Schema';
|
|
8
11
|
|
|
9
12
|
import { AiService, MemoizedAiService, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
10
13
|
import { AiServiceTestingPreset } from '@dxos/ai/testing';
|
|
@@ -30,7 +33,7 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
30
33
|
|
|
31
34
|
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
const TestToolkit = Toolkit.make(
|
|
34
37
|
Tool.make('Calculator', {
|
|
35
38
|
description: 'Basic calculator tool',
|
|
36
39
|
parameters: {
|
|
@@ -43,7 +46,7 @@ class TestToolkit extends Toolkit.make(
|
|
|
43
46
|
}),
|
|
44
47
|
failure: Schema.Never,
|
|
45
48
|
}),
|
|
46
|
-
)
|
|
49
|
+
);
|
|
47
50
|
|
|
48
51
|
// Tool handlers.
|
|
49
52
|
const toolkitLayer = TestToolkit.toLayer({
|
package/src/session/session.ts
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import type * as AiError from '@effect/ai/AiError';
|
|
6
|
+
import * as LanguageModel from '@effect/ai/LanguageModel';
|
|
7
|
+
import type * as Tool from '@effect/ai/Tool';
|
|
8
|
+
import type * as Toolkit from '@effect/ai/Toolkit';
|
|
9
|
+
import * as Chunk from 'effect/Chunk';
|
|
10
|
+
import * as Effect from 'effect/Effect';
|
|
11
|
+
import type * as Schema from 'effect/Schema';
|
|
12
|
+
import * as Stream from 'effect/Stream';
|
|
7
13
|
|
|
8
14
|
import {
|
|
9
15
|
AiParser,
|
|
@@ -37,6 +43,7 @@ export type AiSessionRunRequirements =
|
|
|
37
43
|
|
|
38
44
|
export type AiSessionRunParams<Tools extends Record<string, Tool.Any>> = {
|
|
39
45
|
prompt: string;
|
|
46
|
+
// TODO(wittjosiah): Rename to systemPrompt.
|
|
40
47
|
system?: string;
|
|
41
48
|
history?: DataType.Message[];
|
|
42
49
|
objects?: Obj.Any[];
|
package/src/session/toolkit.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import type * as Tool from '@effect/ai/Tool';
|
|
6
|
+
import * as Toolkit from '@effect/ai/Toolkit';
|
|
7
|
+
import type * as Context from 'effect/Context';
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
7
9
|
|
|
8
10
|
import { type AiToolNotFoundError, ToolExecutionService, type ToolId, ToolResolverService } from '@dxos/ai';
|
|
9
11
|
import { type Blueprint } from '@dxos/blueprints';
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
+
import { type AnyEchoObject, ObjectId } from '@dxos/echo/internal';
|
|
7
8
|
import { type ObjectVersion } from '@dxos/echo-db';
|
|
8
9
|
import { getVersion } from '@dxos/echo-db';
|
|
9
|
-
import { type AnyEchoObject, ObjectId } from '@dxos/echo-schema';
|
|
10
10
|
import { type ContentBlock } from '@dxos/schema';
|
|
11
11
|
|
|
12
12
|
// TODO(dmaretskyi): Extract.
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// ISSUE(burdon): defineFunction
|
|
6
6
|
// @ts-nocheck
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import * as Function from 'effect/Function';
|
|
9
|
+
import * as Schema from 'effect/Schema';
|
|
9
10
|
import { beforeAll, describe, test } from 'vitest';
|
|
10
11
|
|
|
11
12
|
import { AiService, MixedStreamParser } from '@dxos/ai';
|
|
@@ -79,7 +80,7 @@ const summarizationFn = defineFunction({
|
|
|
79
80
|
}),
|
|
80
81
|
);
|
|
81
82
|
|
|
82
|
-
return DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')));
|
|
83
|
+
return DataType.makeText(Function.pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')));
|
|
83
84
|
},
|
|
84
85
|
});
|
|
85
86
|
|
|
@@ -136,7 +137,7 @@ const refinementFn = defineFunction({
|
|
|
136
137
|
}),
|
|
137
138
|
);
|
|
138
139
|
return {
|
|
139
|
-
summary: DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : ''))),
|
|
140
|
+
summary: DataType.makeText(Function.pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : ''))),
|
|
140
141
|
};
|
|
141
142
|
},
|
|
142
143
|
});
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { type ObjectId } from '@dxos/echo
|
|
7
|
+
import { type ObjectId } from '@dxos/echo/internal';
|
|
8
8
|
import { DXN, LOCAL_SPACE_TAG, type SpaceId } from '@dxos/keys';
|
|
9
9
|
import { trim } from '@dxos/util';
|
|
10
10
|
|