@dxos/assistant 0.8.2-main.12df754 → 0.8.2-main.2f9c567
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-DEIGOD4U.mjs → chunk-OLO6SVOL.mjs} +21 -21
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +272 -152
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +82 -86
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-7VH7NMIM.cjs → chunk-CI5Q7FBG.cjs} +6 -6
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +300 -183
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +72 -77
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-7JI4MDGL.mjs → chunk-Y3SYOFFJ.mjs} +21 -21
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +272 -152
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +82 -86
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/types.d.ts +133 -133
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +9 -9
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/cypher/echo-data-source.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/session.d.ts +32 -7
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +17 -0
- package/dist/types/src/session/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/version-pin.test.d.ts +2 -0
- package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
- package/dist/types/src/testing/query-promts.d.ts +3 -3
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +4 -4
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +25 -23
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/ai-service/client.test.ts +5 -5
- package/src/ai-service/ollama-client.ts +7 -7
- package/src/ai-service/types.ts +14 -14
- package/src/bin/chat.ts +2 -2
- package/src/conversation/conversation.test.ts +3 -3
- package/src/conversation/types.ts +10 -10
- package/src/cypher/combinators.test.ts +4 -4
- package/src/cypher/echo-data-source.ts +7 -5
- package/src/cypher/execution-plan.test.ts +1 -1
- package/src/cypher/query-executor.test.ts +1 -1
- package/src/cypher/schema.test.ts +3 -3
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +24 -17
- package/src/session/session.ts +285 -149
- package/src/session/version-pin.test.ts +26 -0
- package/src/session/version-pin.ts +43 -0
- package/src/testing/artifacts.test.ts +22 -22
- package/src/testing/query-promts.ts +5 -5
- package/src/testing/query.test.ts +3 -3
- package/src/testing/test-data.ts +62 -55
- package/src/testing/test-schema.ts +28 -29
- package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +0 -7
- package/dist/lib/node/chunk-7VH7NMIM.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-7JI4MDGL.mjs.map +0 -7
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { Schema
|
|
2
|
-
|
|
3
|
-
export declare const Contact:
|
|
4
|
-
id:
|
|
5
|
-
name:
|
|
6
|
-
email:
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
/** @deprecated */
|
|
3
|
+
export declare const Contact: Schema.mutable<Schema.Struct<{
|
|
4
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
5
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
6
|
+
email: Schema.optional<typeof Schema.String>;
|
|
7
7
|
}>>;
|
|
8
|
-
export interface Contact extends
|
|
8
|
+
export interface Contact extends Schema.Schema.Type<typeof Contact> {
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
export declare const Project: Schema.mutable<Schema.Struct<{
|
|
12
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
13
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
14
|
+
description: Schema.optional<typeof Schema.String>;
|
|
14
15
|
}>>;
|
|
15
|
-
export interface Project extends
|
|
16
|
+
export interface Project extends Schema.Schema.Type<typeof Project> {
|
|
16
17
|
}
|
|
17
|
-
export declare const Task:
|
|
18
|
-
id:
|
|
19
|
-
name:
|
|
20
|
-
description:
|
|
18
|
+
export declare const Task: Schema.mutable<Schema.Struct<{
|
|
19
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
20
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
21
|
+
description: Schema.optional<typeof Schema.String>;
|
|
21
22
|
project: import("@dxos/echo-schema").Ref$<{
|
|
22
23
|
name: string;
|
|
23
24
|
description?: string | undefined;
|
|
@@ -29,22 +30,23 @@ export declare const Task: S.mutable<S.Struct<{
|
|
|
29
30
|
email?: string | undefined;
|
|
30
31
|
}>;
|
|
31
32
|
}>>;
|
|
32
|
-
export interface Task extends
|
|
33
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/** @deprecated */
|
|
36
|
+
export declare const Organization: Schema.mutable<Schema.Struct<{
|
|
37
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
38
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
39
|
+
projects: Schema.Array$<import("@dxos/echo-schema").Ref$<{
|
|
38
40
|
name: string;
|
|
39
41
|
description?: string | undefined;
|
|
40
42
|
id: string;
|
|
41
43
|
}>>;
|
|
42
|
-
employees:
|
|
44
|
+
employees: Schema.Array$<import("@dxos/echo-schema").Ref$<{
|
|
43
45
|
name: string;
|
|
44
46
|
id: string;
|
|
45
47
|
email?: string | undefined;
|
|
46
48
|
}>>;
|
|
47
49
|
}>>;
|
|
48
|
-
export interface
|
|
50
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {
|
|
49
51
|
}
|
|
50
52
|
//# sourceMappingURL=test-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-schema.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"test-schema.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,kBAAkB;AAClB,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEtE,kBAAkB;AAClB,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEtE,eAAO,MAAM,IAAI;;;;;;;;;;;;;;GAeb,CAAC;AACL,MAAM,WAAW,IAAK,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC;CAAG;AAEhE,kBAAkB;AAClB,eAAO,MAAM,YAAY;;;;;;;;;;;;;GAcrB,CAAC;AACL,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.2f9c567",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -40,22 +40,23 @@
|
|
|
40
40
|
"parjs": "^1.3.9",
|
|
41
41
|
"parsimmon": "^1.18.1",
|
|
42
42
|
"ulidx": "^2.3.0",
|
|
43
|
-
"@dxos/artifact": "0.8.2-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/echo
|
|
48
|
-
"@dxos/echo-
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/log": "0.8.2-main.
|
|
53
|
-
"@dxos/node-std": "0.8.2-main.
|
|
54
|
-
"@dxos/
|
|
43
|
+
"@dxos/artifact": "0.8.2-main.2f9c567",
|
|
44
|
+
"@dxos/context": "0.8.2-main.2f9c567",
|
|
45
|
+
"@dxos/async": "0.8.2-main.2f9c567",
|
|
46
|
+
"@dxos/debug": "0.8.2-main.2f9c567",
|
|
47
|
+
"@dxos/echo": "0.8.2-main.2f9c567",
|
|
48
|
+
"@dxos/echo-db": "0.8.2-main.2f9c567",
|
|
49
|
+
"@dxos/echo-schema": "0.8.2-main.2f9c567",
|
|
50
|
+
"@dxos/invariant": "0.8.2-main.2f9c567",
|
|
51
|
+
"@dxos/keys": "0.8.2-main.2f9c567",
|
|
52
|
+
"@dxos/log": "0.8.2-main.2f9c567",
|
|
53
|
+
"@dxos/node-std": "0.8.2-main.2f9c567",
|
|
54
|
+
"@dxos/live-object": "0.8.2-main.2f9c567",
|
|
55
|
+
"@dxos/util": "0.8.2-main.2f9c567"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@types/parsimmon": "^1.10.9",
|
|
58
|
-
"effect": "3.
|
|
59
|
+
"effect": "3.14.21",
|
|
59
60
|
"inquirer": "^12.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { test, describe } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { defineTool, Message, ToolResult, type Tool } from '@dxos/artifact';
|
|
@@ -58,8 +58,8 @@ describe.skip('AI Service Client', () => {
|
|
|
58
58
|
name: 'custodian',
|
|
59
59
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
60
60
|
parameters: toJsonSchema(
|
|
61
|
-
|
|
62
|
-
magicWord:
|
|
61
|
+
Schema.Struct({
|
|
62
|
+
magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
63
63
|
}),
|
|
64
64
|
),
|
|
65
65
|
};
|
|
@@ -194,8 +194,8 @@ describe.skip('Ollama Client', () => {
|
|
|
194
194
|
defineTool('test', {
|
|
195
195
|
name: 'encrypt',
|
|
196
196
|
description: 'Encrypt a message',
|
|
197
|
-
schema:
|
|
198
|
-
message:
|
|
197
|
+
schema: Schema.Struct({
|
|
198
|
+
message: Schema.String.annotations({ description: 'The message to encrypt' }),
|
|
199
199
|
}),
|
|
200
200
|
execute: async ({ message }) => ToolResult.Success(message.split('').reverse().join('')),
|
|
201
201
|
}),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { type MessageContentBlock, defineTool, type Tool, ToolResult } from '@dxos/artifact';
|
|
8
8
|
import { ObjectId } from '@dxos/echo-schema';
|
|
@@ -388,8 +388,8 @@ const WELL_KNOWN_TOOLS: Record<string, Tool> = {
|
|
|
388
388
|
[ToolTypes.TextToImage]: defineTool('system', {
|
|
389
389
|
name: 'text-to-image',
|
|
390
390
|
description: 'Generate an image from a text prompt',
|
|
391
|
-
schema:
|
|
392
|
-
prompt:
|
|
391
|
+
schema: Schema.Struct({
|
|
392
|
+
prompt: Schema.String.annotations({ description: 'The text prompt describing the image to generate' }),
|
|
393
393
|
}),
|
|
394
394
|
execute: async ({ prompt }) => {
|
|
395
395
|
const image = await fetch(SAMPLE_IMAGE_URL).then(async (res) => Buffer.from(await res.arrayBuffer()));
|
|
@@ -467,15 +467,15 @@ class OllamaDecoderStream extends TransformStream<string, OllamaResponseData> {
|
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
class ModelDoesNotSupportToolsError extends
|
|
470
|
+
class ModelDoesNotSupportToolsError extends Schema.TaggedError<ModelDoesNotSupportToolsError>()(
|
|
471
471
|
'ModelDoesNotSupportToolsError',
|
|
472
472
|
{
|
|
473
|
-
model:
|
|
473
|
+
model: Schema.String,
|
|
474
474
|
},
|
|
475
475
|
) {}
|
|
476
476
|
|
|
477
|
-
class ModelNotFoundError extends
|
|
478
|
-
model:
|
|
477
|
+
class ModelNotFoundError extends Schema.TaggedError<ModelNotFoundError>()('ModelNotFoundError', {
|
|
478
|
+
model: Schema.String,
|
|
479
479
|
}) {}
|
|
480
480
|
|
|
481
481
|
const parseOllamaError = (error: string): Error => {
|
package/src/ai-service/types.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { Tool, Message, type MessageContentBlock } from '@dxos/artifact';
|
|
8
8
|
import { type ObjectId } from '@dxos/echo-schema';
|
|
@@ -11,9 +11,9 @@ import { DEFAULT_EDGE_MODELS, DEFAULT_OLLAMA_MODELS } from './defs';
|
|
|
11
11
|
|
|
12
12
|
export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
|
|
13
13
|
|
|
14
|
-
export const LLMModel =
|
|
14
|
+
export const LLMModel = Schema.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
|
|
15
15
|
|
|
16
|
-
export type LLMModel =
|
|
16
|
+
export type LLMModel = Schema.Schema.Type<typeof LLMModel>;
|
|
17
17
|
|
|
18
18
|
export const ToolTypes = Object.freeze({
|
|
19
19
|
// TODO(dmaretskyi): Not implemented yet.
|
|
@@ -24,47 +24,47 @@ export const ToolTypes = Object.freeze({
|
|
|
24
24
|
/**
|
|
25
25
|
* Client GPT request.
|
|
26
26
|
*/
|
|
27
|
-
export const GenerateRequest =
|
|
27
|
+
export const GenerateRequest = Schema.Struct({
|
|
28
28
|
/**
|
|
29
29
|
* Preferred model or system default.
|
|
30
30
|
*/
|
|
31
|
-
model:
|
|
31
|
+
model: Schema.optional(LLMModel),
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Tools available for the LLM.
|
|
35
35
|
*/
|
|
36
|
-
tools:
|
|
36
|
+
tools: Schema.optional(Schema.Array(Tool).pipe(Schema.mutable)),
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* System instructions to the LLM.
|
|
40
40
|
*/
|
|
41
|
-
systemPrompt:
|
|
41
|
+
systemPrompt: Schema.optional(Schema.String),
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* History of messages to include in the context window.
|
|
45
45
|
*/
|
|
46
46
|
// TODO(burdon): Rename messages.
|
|
47
|
-
history:
|
|
47
|
+
history: Schema.optional(Schema.Array(Message)),
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Current request.
|
|
51
51
|
*/
|
|
52
|
-
prompt:
|
|
52
|
+
prompt: Schema.optional(Message),
|
|
53
53
|
});
|
|
54
|
-
export type GenerateRequest =
|
|
54
|
+
export type GenerateRequest = Schema.Schema.Type<typeof GenerateRequest>;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Non-streaming response.
|
|
58
58
|
*/
|
|
59
|
-
export const GenerateResponse =
|
|
60
|
-
messages:
|
|
59
|
+
export const GenerateResponse = Schema.Struct({
|
|
60
|
+
messages: Schema.Array(Message),
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Number of tokens used in the response.
|
|
64
64
|
*/
|
|
65
|
-
tokenCount:
|
|
65
|
+
tokenCount: Schema.optional(Schema.Number),
|
|
66
66
|
});
|
|
67
|
-
export type GenerateResponse =
|
|
67
|
+
export type GenerateResponse = Schema.Schema.Type<typeof GenerateResponse>;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Server-Sent Events (SSE) stream from the AI service.
|
package/src/bin/chat.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
createSystemPrompt,
|
|
20
20
|
createTestData,
|
|
21
21
|
Contact,
|
|
22
|
-
|
|
22
|
+
Organization,
|
|
23
23
|
Project,
|
|
24
24
|
Task,
|
|
25
25
|
} from '../testing';
|
|
@@ -33,7 +33,7 @@ const dataSource = createTestData();
|
|
|
33
33
|
|
|
34
34
|
const cypherTool = createCypherTool(dataSource);
|
|
35
35
|
|
|
36
|
-
const schemaTypes = [
|
|
36
|
+
const schemaTypes = [Organization, Project, Task, Contact];
|
|
37
37
|
|
|
38
38
|
const spaceId = SpaceId.random();
|
|
39
39
|
const threadId = ObjectId.random();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { createUserMessage, defineTool, ToolResult } from '@dxos/artifact';
|
|
@@ -40,8 +40,8 @@ describe.skip('Conversation tests', () => {
|
|
|
40
40
|
const custodian = defineTool('testing', {
|
|
41
41
|
name: 'custodian',
|
|
42
42
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
43
|
-
schema:
|
|
44
|
-
magicWord:
|
|
43
|
+
schema: Schema.Struct({
|
|
44
|
+
magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
45
45
|
}),
|
|
46
46
|
execute: async ({ magicWord }) => {
|
|
47
47
|
if (magicWord === 'pretty please') {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { type Message, type MessageContentBlock } from '@dxos/artifact';
|
|
8
8
|
import { toJsonSchema, JsonSchemaType, ObjectId } from '@dxos/echo-schema';
|
|
@@ -17,11 +17,11 @@ export const createUserMessage = (text: string): Message => ({
|
|
|
17
17
|
/**
|
|
18
18
|
* @deprecated Use {@link LLMTool} instead.
|
|
19
19
|
*/
|
|
20
|
-
export const ToolDefinition =
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
20
|
+
export const ToolDefinition = Schema.Struct({
|
|
21
|
+
name: Schema.String,
|
|
22
|
+
description: Schema.String,
|
|
23
23
|
parameters: JsonSchemaType,
|
|
24
|
-
execute:
|
|
24
|
+
execute: Schema.Any,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -83,14 +83,14 @@ export const ToolResult = Object.freeze({
|
|
|
83
83
|
Break: (result: unknown): ToolResult => ({ kind: 'break', result }),
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
export type DefineToolParams<Params extends
|
|
86
|
+
export type DefineToolParams<Params extends Schema.Schema.AnyNoContext> = {
|
|
87
87
|
name: string;
|
|
88
88
|
description: string;
|
|
89
89
|
schema: Params;
|
|
90
|
-
execute: (params:
|
|
90
|
+
execute: (params: Schema.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export const defineTool = <Params extends
|
|
93
|
+
export const defineTool = <Params extends Schema.Schema.AnyNoContext>({
|
|
94
94
|
name,
|
|
95
95
|
description,
|
|
96
96
|
schema,
|
|
@@ -101,7 +101,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
|
|
|
101
101
|
description,
|
|
102
102
|
parameters: toFunctionParameterSchema(schema),
|
|
103
103
|
execute: (params, context) => {
|
|
104
|
-
const sanitized =
|
|
104
|
+
const sanitized = Schema.decodeSync(schema)(params);
|
|
105
105
|
return execute(sanitized, context);
|
|
106
106
|
},
|
|
107
107
|
};
|
|
@@ -110,7 +110,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
|
|
|
110
110
|
/**
|
|
111
111
|
* Adapts schems to be able to pass to AI providers.
|
|
112
112
|
*/
|
|
113
|
-
const toFunctionParameterSchema = (schema:
|
|
113
|
+
const toFunctionParameterSchema = (schema: Schema.Schema.All) => {
|
|
114
114
|
const jsonSchema = toJsonSchema(schema);
|
|
115
115
|
log('tool schema', { jsonSchema });
|
|
116
116
|
delete jsonSchema.anyOf;
|
|
@@ -77,7 +77,7 @@ describe('Cypher Combinators', () => {
|
|
|
77
77
|
test('match clause', ({ expect }) => {
|
|
78
78
|
testParser(matchClause, 'MATCH (n:Person)');
|
|
79
79
|
testParser(matchClause, 'MATCH (n:Person)-[r:KNOWS]->(m:Person)');
|
|
80
|
-
testParser(matchClause, 'MATCH (o:
|
|
80
|
+
testParser(matchClause, 'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)');
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
test('where clause', ({ expect }) => {
|
|
@@ -116,15 +116,15 @@ describe('Cypher Combinators', () => {
|
|
|
116
116
|
);
|
|
117
117
|
testParser(
|
|
118
118
|
cypherQuery,
|
|
119
|
-
'MATCH (o:
|
|
119
|
+
'MATCH (o:Organization)-[:HAS_EMPLOYEE]->(e:Employee)-[:WORKS_ON]->(p:Project) WHERE o.name = "DXOS" AND p.name = "Composer" RETURN e.name, e.id, p.name, p.id',
|
|
120
120
|
);
|
|
121
121
|
testParser(
|
|
122
122
|
cypherQuery,
|
|
123
|
-
'MATCH (n:
|
|
123
|
+
'MATCH (n:Organization {name: "DXOS"})-[:HAS_EMPLOYEE]->(m:Employee)<-[:WORKS_ON]-(p:Project {name: "Composer"}) RETURN m.name AS employee',
|
|
124
124
|
);
|
|
125
125
|
testParser(
|
|
126
126
|
cypherQuery,
|
|
127
|
-
"MATCH (org:
|
|
127
|
+
"MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
|
|
128
128
|
);
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
5
7
|
import { raise } from '@dxos/debug';
|
|
6
|
-
import { type EchoDatabase, Filter, type
|
|
7
|
-
import { getSchema, getSchemaTypename,
|
|
8
|
+
import { type EchoDatabase, Filter, type AnyLiveObject } from '@dxos/echo-db';
|
|
9
|
+
import { getSchema, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
|
|
8
10
|
import { log } from '@dxos/log';
|
|
9
11
|
|
|
10
12
|
import type { DataSource, Node, Relationship } from './query-executor';
|
|
@@ -62,7 +64,7 @@ export class EchoDataSource implements DataSource {
|
|
|
62
64
|
).flat();
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
private async _getAllSchema(): Promise<
|
|
67
|
+
private async _getAllSchema(): Promise<Schema.Schema.AnyNoContext[]> {
|
|
66
68
|
return [
|
|
67
69
|
...(await this._db.schemaRegistry.query().run()),
|
|
68
70
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
@@ -70,7 +72,7 @@ export class EchoDataSource implements DataSource {
|
|
|
70
72
|
].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
private _objectToNode(object:
|
|
75
|
+
private _objectToNode(object: AnyLiveObject<any>): Node {
|
|
74
76
|
const { id, ...properties } = object;
|
|
75
77
|
return {
|
|
76
78
|
id,
|
|
@@ -80,7 +82,7 @@ export class EchoDataSource implements DataSource {
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
private async _projectRefRelationship(object:
|
|
85
|
+
private async _projectRefRelationship(object: AnyLiveObject<any>, prop: string): Promise<Relationship[]> {
|
|
84
86
|
if (!object[prop]) {
|
|
85
87
|
return [];
|
|
86
88
|
}
|
|
@@ -21,7 +21,7 @@ describe('Execution Plan', () => {
|
|
|
21
21
|
test('complex query', ({ expect }) => {
|
|
22
22
|
const plan = createExecutionPlan(
|
|
23
23
|
parseCypherQuery(
|
|
24
|
-
"MATCH (org:
|
|
24
|
+
"MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'}) RETURN c.name",
|
|
25
25
|
),
|
|
26
26
|
);
|
|
27
27
|
log('', { plan });
|
|
@@ -25,7 +25,7 @@ test.skip('run', async ({ expect }) => {
|
|
|
25
25
|
const result = await executeQuery(
|
|
26
26
|
dataSource,
|
|
27
27
|
`
|
|
28
|
-
MATCH (org:
|
|
28
|
+
MATCH (org:Organization {name: 'DXOS'})-[:ORG_EMPLOYEES]->(c:Contact)<-[:TASK_ASSIGNEE]-(t:Task)-[:TASK_PROJECT]->(p:Project {name: 'Composer'})
|
|
29
29
|
RETURN c.name, t.name
|
|
30
30
|
`,
|
|
31
31
|
);
|
|
@@ -7,10 +7,10 @@ import { test } from 'vitest';
|
|
|
7
7
|
import { toJsonSchema } from '@dxos/echo-schema';
|
|
8
8
|
|
|
9
9
|
import { formatJsonSchemaForLLM } from './schema';
|
|
10
|
-
import { Contact,
|
|
10
|
+
import { Contact, Organization, Project, Task } from '../testing';
|
|
11
11
|
|
|
12
|
-
test('
|
|
13
|
-
const jsonSchema = [
|
|
12
|
+
test('Organization-Project-Task-Contact schema', async ({ expect }) => {
|
|
13
|
+
const jsonSchema = [Organization, Project, Task, Contact].map((schema) => toJsonSchema(schema));
|
|
14
14
|
const result = formatJsonSchemaForLLM(jsonSchema);
|
|
15
15
|
// log('result', { result });
|
|
16
16
|
expect(result).toHaveLength(8);
|
package/src/session/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { inspect } from 'node:util';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
type MessageContentBlock,
|
|
16
16
|
} from '@dxos/artifact';
|
|
17
17
|
import { AIServiceEdgeClient } from '@dxos/assistant';
|
|
18
|
-
import {
|
|
18
|
+
import { Type } from '@dxos/echo';
|
|
19
|
+
import { create, ObjectId } from '@dxos/echo-schema';
|
|
19
20
|
import { DXN } from '@dxos/keys';
|
|
20
21
|
import { log } from '@dxos/log';
|
|
21
22
|
|
|
@@ -23,14 +24,19 @@ import { AISession } from './session';
|
|
|
23
24
|
import { AI_SERVICE_ENDPOINT } from '../testing';
|
|
24
25
|
|
|
25
26
|
// Define a calendar event artifact schema.
|
|
26
|
-
const CalendarEventSchema =
|
|
27
|
-
title:
|
|
28
|
-
startTime:
|
|
29
|
-
endTime:
|
|
30
|
-
description:
|
|
31
|
-
}).pipe(
|
|
27
|
+
const CalendarEventSchema = Schema.Struct({
|
|
28
|
+
title: Schema.String,
|
|
29
|
+
startTime: Schema.String,
|
|
30
|
+
endTime: Schema.String,
|
|
31
|
+
description: Schema.String,
|
|
32
|
+
}).pipe(
|
|
33
|
+
Type.def({
|
|
34
|
+
typename: 'example.com/type/CalendarEvent',
|
|
35
|
+
version: '0.1.0',
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
32
38
|
|
|
33
|
-
type CalendarEvent =
|
|
39
|
+
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
34
40
|
|
|
35
41
|
// TODO(burdon): Flaky.
|
|
36
42
|
describe.skip('AISession with Ollama', () => {
|
|
@@ -39,7 +45,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
39
45
|
// const aiClient = new OllamaClient({
|
|
40
46
|
// overrides: { model: 'llama3.1:8b' },
|
|
41
47
|
// });
|
|
42
|
-
const session = new AISession({ operationModel: '
|
|
48
|
+
const session = new AISession({ operationModel: 'configured' });
|
|
43
49
|
|
|
44
50
|
const objects = new Set<string>();
|
|
45
51
|
|
|
@@ -53,7 +59,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
53
59
|
defineTool('calendar', {
|
|
54
60
|
name: 'query',
|
|
55
61
|
description: 'Query the calendar for events',
|
|
56
|
-
schema:
|
|
62
|
+
schema: Schema.Struct({}),
|
|
57
63
|
execute: async () => {
|
|
58
64
|
return ToolResult.Success(CALENDAR_EVENTS);
|
|
59
65
|
},
|
|
@@ -65,13 +71,13 @@ describe.skip('AISession with Ollama', () => {
|
|
|
65
71
|
id: 'artifact:dxos.org/plugin/table',
|
|
66
72
|
name: 'Table',
|
|
67
73
|
instructions: 'Use this to create and manage tables. Each table has a unique id.',
|
|
68
|
-
schema:
|
|
74
|
+
schema: Schema.Struct({}),
|
|
69
75
|
tools: [
|
|
70
76
|
defineTool('table', {
|
|
71
77
|
name: 'create',
|
|
72
78
|
description: 'Create a table',
|
|
73
|
-
schema:
|
|
74
|
-
data:
|
|
79
|
+
schema: Schema.Struct({
|
|
80
|
+
data: Schema.Array(Schema.Any).annotations({ description: 'Array of data payloads to add as rows' }),
|
|
75
81
|
}),
|
|
76
82
|
execute: async ({ data }) => {
|
|
77
83
|
log('create table', { data });
|
|
@@ -89,12 +95,12 @@ describe.skip('AISession with Ollama', () => {
|
|
|
89
95
|
name: 'Map',
|
|
90
96
|
instructions:
|
|
91
97
|
'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
|
|
92
|
-
schema:
|
|
98
|
+
schema: Schema.Struct({}),
|
|
93
99
|
tools: [
|
|
94
100
|
defineTool('map', {
|
|
95
101
|
name: 'create',
|
|
96
102
|
description: 'Create a map',
|
|
97
|
-
schema:
|
|
103
|
+
schema: Schema.Struct({
|
|
98
104
|
source: ArtifactId.annotations({
|
|
99
105
|
description: 'The table that will be used as the source of the map',
|
|
100
106
|
}),
|
|
@@ -119,7 +125,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
119
125
|
id: 'artifact:dxos.org/plugin/script',
|
|
120
126
|
name: 'Script',
|
|
121
127
|
instructions: 'Use this to create and manage scripts',
|
|
122
|
-
schema:
|
|
128
|
+
schema: Schema.Struct({}),
|
|
123
129
|
tools: [],
|
|
124
130
|
});
|
|
125
131
|
|
|
@@ -140,6 +146,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
140
146
|
client: aiClient,
|
|
141
147
|
tools: [],
|
|
142
148
|
artifacts: [calendarArtifact, tableArtifact, mapArtifact, scriptArtifact],
|
|
149
|
+
requiredArtifactIds: [calendarArtifact.id, tableArtifact.id, mapArtifact.id, scriptArtifact.id],
|
|
143
150
|
history: [],
|
|
144
151
|
generationOptions: {
|
|
145
152
|
model: '@anthropic/claude-3-5-haiku-20241022',
|